diff options
| author | Charlie Root <root@dangofactory.local> | 2026-10-05 23:58:26 +0900 |
|---|---|---|
| committer | Charlie Root <root@dangofactory.local> | 2026-10-05 23:58:26 +0900 |
| commit | e0465ad93dd2d2123a7cd6eb1bf497d0a6b47535 (patch) | |
| tree | e32c70445ff409cf6cc7b8a8d4c263c95f3a9cc9 | |
| parent | d4c6c11df0cf60dd956fe0d84f2edc97ffc8381d (diff) | |
| download | kukuri-main.tar.gz kukuri-main.tar.bz2 kukuri-main.zip | |
Three attempts at this and the cause was never the offset arithmetic. Measured
on build 86, the label mean angles were 45.9 / 130.3 / 209.1 / 319.9 degrees while
the wedge centres are 0 / 90 / 180 / 270. A constant ~45 degree error in all four
quadrants is not a magnitude problem, it is an origin problem.
The wedges are drawn at angles[i], which distributeAngles() fills starting from 0
and stepping clockwise, so item 0 sits at drawAngle 0 -- to the RIGHT, because
canvas angles run from 3 o'clock. The label loop was computing
`i * (360.0/n) - 90.0`, which assumes the first wedge is at the top. So the labels
were anchored a quarter turn away from the wedges, which is exactly one
separator, and no value of the constant would have fixed it.
The labels now take the wedge angles as a parameter and use angles[i] directly,
so a label and its wedge cannot disagree again -- including for a menu whose item
count is not 4 or which pins an item with an explicit `angle`.
Also worth recording: the two earlier attempts were tuning a constant while the
constant itself was wrong, and the measurements (19 px in the top quadrant, then
"all four on the boundaries") were consistent with an origin bug the whole time.
| -rw-r--r-- | modules/orgflow-ui/src/commonMain/kotlin/jp/orgflow/web/PieMenu.kt | 21 |
1 files changed, 17 insertions, 4 deletions
diff --git a/modules/orgflow-ui/src/commonMain/kotlin/jp/orgflow/web/PieMenu.kt b/modules/orgflow-ui/src/commonMain/kotlin/jp/orgflow/web/PieMenu.kt index 5bca08c..e7be9af 100644 --- a/modules/orgflow-ui/src/commonMain/kotlin/jp/orgflow/web/PieMenu.kt +++ b/modules/orgflow-ui/src/commonMain/kotlin/jp/orgflow/web/PieMenu.kt @@ -277,7 +277,7 @@ fun PieMenu( // ここで切り替えること。ハブを5つ目の扇のように塗らない事。 Text("W", color = cal.pieInk, fontWeight = FontWeight.Bold) // 項目名を円の中に置く。外側に置くとどの扇の名前か分からない。 - PieInDiscLabels(items, touched, cal.pieInk) + PieInDiscLabels(items, angles, touched, cal.pieInk) } } @@ -307,7 +307,12 @@ fun PieMenu( * 並び順に応じて 45 度ずらす**項目数を検査する。 */ @Composable -private fun PieInDiscLabels(items: List<PieItem>, touched: Int, ink: Color) { +private fun PieInDiscLabels( + items: List<PieItem>, + angles: List<Float>, + touched: Int, + ink: Color, +) { val n = items.size if (n == 0) return @@ -336,9 +341,17 @@ private fun PieInDiscLabels(items: List<PieItem>, touched: Int, ink: Color) { val cx0 = maxWidth.value / 2.0 val cy0 = maxHeight.value / 2.0 val half = boxW.value / 2.0 - val stepDeg = 360.0 / n for (i in items.indices) { - val ang = (i * stepDeg - 90.0) * PI / 180.0 + // The wedge for item i is drawn at angles[i] (see distributeAngles, + // which starts at 0 and steps clockwise). The label must use the SAME + // angle, not one derived from the index. + // + // 2026-10-05: this line was `i * (360.0/n) - 90.0`, which produced a + // constant quarter-turn offset -- measured label means were + // 45.9 / 130.3 / 209.1 / 319.9 degrees against wedge centres of + // 0 / 90 / 180 / 270, so every label landed one quadrant away, on a + // separator, no matter how the offset was tuned. + val ang = (angles.getOrNull(i) ?: (i * 360f / n)) * PI.toFloat() / 180f val it = items[i] Box( Modifier.offset( |
