Refactor: internal.RuleDiamond and internal.Frame ornaments

RuleDiamond draws the rule-diamond-rule of Heading, Dialog, Result, Card
titles and the ornament Divider; Frame draws the inset line with corner
diamonds of Card and decorated Dialog. Both snap the diamonds, and the
rule's diamond sits on the pixel-aligned line.

Snapshots: card (all densities, light and dark) moves the title rule's
diamond onto the rule's pixel row, an 8x8 region. Decorated dialog
(both densities, light and dark) loses the surface-colored halo under
each corner diamond, so the frame line now runs into the diamond as on
Card and the panel border is no longer notched at the corners.
Heading, Divider and Result render unchanged.
This commit is contained in:
ZacharyZhang-NY committed 2026-10-05 13:44:59 -04:00
1 parent c22a09d327
commit 0651debf9d
16 files changed
+36 -48

No files matched your search

+24 -2
View File
@@ -17,11 +17,33 @@ func Fade(e *ui.Element, d time.Duration) *ui.Element {
// Rule draws a pixel-aligned 1 DIP horizontal line at y.
func Rule(p *ui.Painter, x0, x1, y float32, c ui.Color) {
yy := ruleY(p, y)
p.Line(x0, yy, x1, yy, 1, c)
}
// ruleY moves y to where a 1 DIP line fills whole device pixels.
func ruleY(p *ui.Painter, y float32) float32 {
s := float64(p.Scale())
px := math.Floor(float64(y) * s)
if int(math.Round(s))%2 == 1 {
px += 0.5
}
yy := float32(px / s)
p.Line(x0, yy, x1, yy, 1, c)
return float32(px / s)
}
// RuleDiamond draws a rule across the middle of r, broken by gap on each side of a size diamond.
func RuleDiamond(p *ui.Painter, r ui.Rect, gap, size float32, col ui.Color) {
cx, cy := r.X+r.W/2, ruleY(p, r.Y+r.H/2)
p.Line(r.X, cy, cx-gap, cy, 1, col)
p.Line(cx+gap, cy, r.X+r.W, cy, 1, col)
p.FillPath(Diamond(Snap(p, cx), Snap(p, cy), size), col)
}
// Frame strokes a 1 DIP line inset inside r with a size diamond on each corner.
func Frame(p *ui.Painter, r ui.Rect, inset, size float32, col ui.Color) {
f := ui.Rect{X: r.X + inset, Y: r.Y + inset, W: r.W - 2*inset, H: r.H - 2*inset}
p.Stroke(f, col, 1, 1)
for _, pt := range [4][2]float32{{f.X, f.Y}, {f.X + f.W, f.Y}, {f.X, f.Y + f.H}, {f.X + f.W, f.Y + f.H}} {
p.FillPath(Diamond(Snap(p, pt[0]), Snap(p, pt[1]), size), col)
}
}