RadialMenuMath

Core mathematical functions for RadialMenu positioning and selection.

These functions are public to allow developers building custom RadialMenu implementations to reuse the positioning algorithms.

The key algorithm is calculateCenterAngle which ensures menu items never appear off-screen regardless of where the user touches.

Since

1.0.0

Types

Link copied to clipboard

Zones describing where on the screen the touch occurred.

Functions

Link copied to clipboard
fun calculateCenterAngle(x: Float, y: Float, screenWidth: Float, screenHeight: Float, isRtl: Boolean = false): Float

Calculates the optimal center angle for the radial menu fan based on touch position, ensuring items always appear on-screen.

Link copied to clipboard
fun detectZone(x: Float, y: Float, screenWidth: Float, screenHeight: Float, edgeThreshPx: Float): RadialMenuMath.MenuZone

Detects which screen zone the touch point falls in.

Link copied to clipboard
fun edgeHugLayout(zone: RadialMenuMath.MenuZone, screenWidth: Float, screenHeight: Float, itemCount: Int, itemSizePx: Float, gapPx: Float, padPx: Float): List<Offset>

Computes item center positions for the edge-hug L-shaped layout.

Link copied to clipboard
fun getNearestItemSelection(pointerX: Float, pointerY: Float, itemPositions: List<Offset>, deadZonePx: Float = RadialMenuDefaults.DEAD_ZONE_PX): Int?

Selects the nearest item by Euclidean distance from the pointer.

Link copied to clipboard
fun getSelectionFromDrag(dragX: Float, dragY: Float, centerAngle: Float, itemCount: Int, spreadDegrees: Float = RadialMenuDefaults.ICON_SPREAD_DEGREES, deadZonePx: Float = RadialMenuDefaults.DEAD_ZONE_PX, selectionDeadZoneDeg: Float = RadialMenuDefaults.SELECTION_DEAD_ZONE_DEG): Int?

Determines which item index the user is dragging toward.

Link copied to clipboard

Normalizes any angle to the 0 to 360 degree range.