WIP components (as built)
This commit is contained in:
98 files changed
+2746
-1204
No files matched your search
+32
-19
@@ -9,14 +9,14 @@ import (
|
||||
"mujicaui/theme"
|
||||
)
|
||||
|
||||
// ChartTooltipLine is one row of a tooltip; a zero Color shows no marker.
|
||||
// ChartTooltipLine pairs readout text with an optional marker.
|
||||
type ChartTooltipLine struct {
|
||||
Text string
|
||||
Color ui.Color
|
||||
Shape int
|
||||
}
|
||||
|
||||
// ChartTooltip floats painted lines beside window point (x, y), avoiding edges.
|
||||
// ChartTooltip shows readouts beside a window point, avoiding edges.
|
||||
func ChartTooltip(c *ui.Context, x, y float32, lines []ChartTooltipLine) *ui.Element {
|
||||
if len(lines) == 0 {
|
||||
panic("mujica: ChartTooltip needs a line")
|
||||
@@ -37,29 +37,42 @@ func ChartTooltip(c *ui.Context, x, y float32, lines []ChartTooltipLine) *ui.Ele
|
||||
}
|
||||
w += pad * 2
|
||||
ww, wh := c.Size()
|
||||
left, top := x+gap, y+gap
|
||||
if left+w > ww-4 {
|
||||
left = x - gap - w
|
||||
w, h = min(w, max(1, ww-8)), min(h, max(1, wh-8))
|
||||
left, top := overlayPlace(c, ui.Rect{X: x, Y: y}, w, h, gap)
|
||||
if x+gap+w <= ww-4 {
|
||||
left = max(4, x+gap)
|
||||
} else {
|
||||
left = max(4, min(x-gap-w, ww-4-w))
|
||||
}
|
||||
if top+h > wh-4 {
|
||||
top = y - gap - h
|
||||
}
|
||||
left, top = max(4, left), max(4, top)
|
||||
var tip *ui.Element
|
||||
ui.Overlay(c, func() {
|
||||
tip = ui.Box(c).Absolute().Left(left).Top(top).Size(w, h).PassThrough().Role(ui.RoleNone)
|
||||
overlayStyle(c, tip, 1)
|
||||
tip.Draw(func(p *ui.Painter, r ui.Rect) {
|
||||
at := r.Y + pad
|
||||
tip = ui.Column(c).Absolute().Left(left).Top(top).Size(w, h).Role(ui.RoleNone)
|
||||
overlayStyle(c, tip, overlayEnter(c, tip))
|
||||
tip.Children(func() {
|
||||
inner := max(1, w-2*pad)
|
||||
content := float32(0)
|
||||
for i, l := range lines {
|
||||
tx := r.X + pad
|
||||
width := inner
|
||||
if l.Color.A > 0 {
|
||||
internal.Marker(p, l.Shape, tx+5, at+lh[i]/2, 9, l.Color)
|
||||
tx += 14
|
||||
width = max(1, width-14)
|
||||
}
|
||||
p.RichText(tx, at, 0, ui.Span{Text: l.Text, Size: size, Weight: chartTipWeight(i), Color: k.Text})
|
||||
at += lh[i]
|
||||
_, lh[i] = c.MeasureText(width, ui.Span{Text: l.Text, Size: size, Weight: chartTipWeight(i)})
|
||||
content += lh[i]
|
||||
}
|
||||
ui.Scroll(c).Fill().Padding(pad).Children(func() {
|
||||
ui.Box(c).Width(inner).Height(content).Shrink(0).Draw(func(p *ui.Painter, r ui.Rect) {
|
||||
at := r.Y
|
||||
for i, l := range lines {
|
||||
tx, width := r.X, inner
|
||||
if l.Color.A > 0 {
|
||||
internal.Marker(p, l.Shape, tx+5, at+lh[i]/2, 9, l.Color)
|
||||
tx, width = tx+14, max(1, width-14)
|
||||
}
|
||||
p.RichText(tx, at, width, ui.Span{Text: l.Text, Size: size, Weight: chartTipWeight(i), Color: k.Text})
|
||||
at += lh[i]
|
||||
}
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
return tip
|
||||
@@ -73,7 +86,7 @@ func chartTipWeight(i int) int {
|
||||
return 400
|
||||
}
|
||||
|
||||
// chartTipLines splits a readout at " · " into a heading and rows.
|
||||
// chartTipLines splits a readout into tooltip lines.
|
||||
func chartTipLines(readout string) []ChartTooltipLine {
|
||||
var out []ChartTooltipLine
|
||||
for _, s := range strings.Split(readout, " · ") {
|
||||
|
||||
Reference in new issue
Block a user