Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions base/box.go
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,7 @@ func (b Box) MonoFace(Face gfx.MonoFace) Box {

// Ellipsis keeps a Text to one line and ends it with an ellipsis when it does not
// fit the width it gets, instead of clipping it. It is Paragraph(value, 1).
// In a Page, hovering truncated text shows its complete value in a tooltip.
func (b Box) Ellipsis() Box {
n := b.N()
n.Flags |= flagWrap
Expand Down
5 changes: 3 additions & 2 deletions base/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,9 @@ const (
// face describes the text rather than the element, so they have a byte of their own
// (Node.TextDecor).
const (
textItalic uint8 = 1 << iota // Italic: the face gfx.StyledTextEngine shapes
textStrike // Strike: one line through the middle of each line
textItalic uint8 = 1 << iota // Italic: the face gfx.StyledTextEngine shapes
textStrike // Strike: one line through the middle of each line
textTruncated // layout omitted text at MaxLines; no new Node storage
)

// flagRequired marks a page Label that appends the field title's required
Expand Down
9 changes: 7 additions & 2 deletions base/frame.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ type Extra struct {
memo int32 // 1 + the index the element's cache has with whoever declared it (memoFn), or 0
Draws int32 // 1 + the index of the element's Draw and DrawOver callbacks in frame.draws, or 0 for none
tooltip string // what Tooltip says over the element; empty for none
overflowTip string // full text already shortened by the application
tooltipSide uint8 // 1 + the TooltipSide TooltipOn opens the element's tip on; 0 is below
addons int32 // 1 + the index of the field's icon and button in frame.addons, or 0
focusGroup FocusAxis // FocusGroup: the arrow keys that move the focus between the controls inside; zero is none
Expand Down Expand Up @@ -417,6 +418,10 @@ func (f *Frame) End() {
f.reportScrolls()
f.Scrolls.sweep()
f.reportSplitters()
if f.page != nil {
previous := f.Surface.SetHoverHintOwner(f.page.root)
defer f.Surface.SetHoverHintOwner(previous)
}
f.PaintChild(0)
f.raiseOverNativeViews()
if f.popupLayer != 0 {
Expand All @@ -428,8 +433,8 @@ func (f *Frame) End() {
if f.popupLayer != 0 {
f.Surface.PopLayer()
}
if f.tooltips {
f.paintTooltipFn(f)
if f.tooltips || f.page != nil {
f.paintTooltip()
} else if f.paintTooltipFn != nil {
f.tooltip = nil
}
Expand Down
1 change: 1 addition & 0 deletions base/layout.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ func (f *Frame) measure(axis int) {
f.measureLeaf(n)
}
if n.Kind == kindText && n.Flags&flagWrap != 0 && axis == AxisY {
n.TextDecor &^= textTruncated
first := int32(len(f.Lines))
// An empty text has no line at all, as WrapLines gives it none; anything
// else that fits is one line and needs no breaking.
Expand Down
19 changes: 16 additions & 3 deletions base/page.go
Original file line number Diff line number Diff line change
Expand Up @@ -302,8 +302,10 @@ type Page struct {
pointer gfx.Point // where the pointer was at the last pointer event
pointerIn bool // a pointer event put it there, and no exit has taken it away
hoverArea gfx.ID // the scroll area or self-scrolling table the pointer is on
selects []*SelectState // the Selects of the last paint, which Wheel scrolls
labels []string // scratch for Choice's labels
hoverText gfx.HoverHint // changes wake a page even when text has no pointer target
pointerDown bool
selects []*SelectState // the Selects of the last paint, which Wheel scrolls
labels []string // scratch for Choice's labels
memos map[gfx.ID]*memoEntry
memoBoxes []memoBox
memoChecks []memoCheckOf
Expand Down Expand Up @@ -570,6 +572,12 @@ func (p *Page) onKey(event gfx.KeyEvent) gfx.EventResult {
}

func (p *Page) onPointer(event gfx.PointerEvent) gfx.EventResult {
switch event.Kind {
case gfx.PointerDown:
p.pointerDown = true
case gfx.PointerUp, gfx.PointerExit:
p.pointerDown = false
}
switch event.Kind {
case gfx.PointerMove, gfx.PointerDown, gfx.PointerUp:
p.pointer, p.pointerIn = gfx.Point{X: event.X, Y: event.Y}, true
Expand All @@ -590,6 +598,9 @@ func (p *Page) onPointer(event gfx.PointerEvent) gfx.EventResult {
p.hoverArea = p.hoverPlaceAt(p.pointer.X, p.pointer.Y)
}
entered := wasArea != p.hoverArea
text := p.HoveredText()
textChanged := !text.SameText(p.hoverText)
p.hoverText = text
var result gfx.EventResult
if done, ok := p.dropPointer(event); ok {
result = done
Expand All @@ -602,7 +613,8 @@ func (p *Page) onPointer(event gfx.PointerEvent) gfx.EventResult {
} else if p.basePointer != nil {
result = p.basePointer(event)
}
result.Repaint = result.Repaint || entered
result.Repaint = result.Repaint || entered || textChanged ||
text.Text != "" && (event.Kind == gfx.PointerDown || event.Kind == gfx.PointerUp)
return result
}

Expand Down Expand Up @@ -847,6 +859,7 @@ func (p *Page) paintOnce(Surface *gfx.Canvas, bounds Rect, View func(C)) {
p.Nodes = append(p.Nodes[:0], protoNode{scope: p.root, named: true, parentNode: -1}) // node 0, the root column
View(&p.ctx)
f.End()
p.hoverText = p.HoveredText()
if p.settleContainers() {
p.retry = true
}
Expand Down
8 changes: 8 additions & 0 deletions base/paint.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,10 @@ func (f *Frame) PaintChild(i int32) {
}
}

if extra.overflowTip != "" && f.page != nil {
canvas.HoverHint(f.page.root, r, extra.overflowTip, n.ID)
}

// A Text and an Icon draw with their color, which is the one the looks give.
color := n.Color
n.Color = fade(style.Color, f.Opacity)
Expand Down Expand Up @@ -365,6 +369,10 @@ func (f *Frame) paintText(n *Node) {
f.paintStrike(line, bounds, style, alignment)
}
}
if n.TextDecor&textTruncated != 0 && f.page != nil && f.Exts[n.Ext].overflowTip == "" {
r.Height = min(r.Height, float32(n.LineCount)*lh)
f.Surface.HoverHint(f.page.root, r, n.Text)
}
return
}
height := max(n.Pref[AxisY]-top-bottom, 0)
Expand Down
28 changes: 18 additions & 10 deletions base/text_wrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,17 @@ import (
// that did not change can append the saved lines instead of measuring every
// prefix again.
type wrapCache struct {
Text string
Size float32
Weight float32
mono bool
italic bool
Face gfx.MonoFace
width float32
MaxLines int
Lines []string
filled bool
Text string
Size float32
Weight float32
mono bool
italic bool
Face gfx.MonoFace
width float32
MaxLines int
Lines []string
filled bool
truncated bool
}

// wrapText appends the lines of a wrapped Text, breaking them as gfx.Canvas.WrapLines
Expand Down Expand Up @@ -51,10 +52,17 @@ func (f *Frame) wrapText(dst []string, n *Node) []string {
if wrapped.filled && wrapped.Text == n.Text && wrapped.Size == n.FontSize && wrapped.Weight == n.Weight &&
wrapped.mono == mono && wrapped.italic == italic && wrapped.Face == face &&
wrapped.width == width && wrapped.MaxLines == maxLines {
if wrapped.truncated {
n.TextDecor |= textTruncated
}
return append(dst, wrapped.Lines...)
}
start := len(dst)
dst = f.Surface.WrapLinesStyle(dst, n.Text, n.textStyle(), width, maxLines, cache)
wrapped.truncated = cache.Truncated()
if wrapped.truncated {
n.TextDecor |= textTruncated
}
wrapped.Text, wrapped.Size, wrapped.Weight, wrapped.mono, wrapped.italic, wrapped.Face = n.Text, n.FontSize, n.Weight, mono, italic, face
wrapped.width, wrapped.MaxLines = width, maxLines
wrapped.Lines = append(wrapped.Lines[:0], dst[start:]...)
Expand Down
21 changes: 21 additions & 0 deletions base/tooltip.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,27 @@ import (
// popovers, menus and dialogs.
const TooltipLayer = 1000

// OverflowTooltip supplies the complete value when an application shortened
// the displayed text itself, possibly across several highlighted labels. Call
// it only when content was omitted. Unlike Tooltip it declares no control and
// leaves the enclosing row's pointer, focus and accessibility unchanged. Text
// truncated by Ellipsis or MaxLines supplies its complete value automatically.
func (b Box) OverflowTooltip(text string) Box {
b.f.Extra(b.i).overflowTip = text
return b
}

// HoveredText returns this page's visible truncation hint under the pointer.
func (p *Page) HoveredText() gfx.HoverHint {
if p == nil || !p.pointerIn || p.View.Frame == nil || p.View.Frame.Surface == nil {
return gfx.HoverHint{}
}
return p.View.Frame.Surface.HoverHintAt(p.root, p.pointer.X, p.pointer.Y)
}

// PointerDown reports a held pointer button, including a press on plain text.
func (p *Page) PointerDown() bool { return p != nil && p.pointerDown }

// Tooltip names what the element does in a tip that appears beside it while the
// pointer rests on it, and is its description for assistive technology: what an
// icon-only button needs. The tip hides on a press and stays hidden until the
Expand Down
14 changes: 7 additions & 7 deletions cmd/viva/components_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions cmd/viva/templates/chart_area.go.txt
Original file line number Diff line number Diff line change
Expand Up @@ -502,8 +502,7 @@ func chartBeginFrame(canvas *gfx.Canvas, theme gfx.Theme, bounds gfx.Rect, spec
// Edge ticks remain anchored to their data, but their labels must
// fit inside the chart container rather than spill into a neighbor.
x := min(max(plot.X+frac*plot.Width-width/2, area.X), area.X+area.Width-width)
text = canvas.FitLine(text, fontSize, gfx.WeightRegular, width)
canvas.Label(text, gfx.Rect{X: x, Y: plot.Y + plot.Height + chartAxisGap*scale, Width: width, Height: rowHeight}, labelStyle)
labelEllipsis(canvas, text, gfx.Rect{X: x, Y: plot.Y + plot.Height + chartAxisGap*scale, Width: width, Height: rowHeight}, labelStyle, gfx.ID{})
}
}
return chartFrame{layout: layout, plot: ChartPlot{ChartLayout: layout, Plot: plot, geo: geo}, scale: scale}
Expand Down
18 changes: 9 additions & 9 deletions cmd/viva/templates/combobox.go.txt
Original file line number Diff line number Diff line change
Expand Up @@ -218,9 +218,9 @@ func (combobox *Combobox) AddItem(item ComboboxItem) gfx.Rect {
labelWidth = maxLabelWidth
}

combobox.canvas.Label(combobox.canvas.FitLine(item.Label, sizeM, gfx.WeightRegular, labelWidth), gfx.Rect{X: bounds.X + 8, Y: bounds.Y, Width: labelWidth, Height: bounds.Height}, gfx.TextStyle{
labelEllipsis(combobox.canvas, item.Label, gfx.Rect{X: bounds.X + 8, Y: bounds.Y, Width: labelWidth, Height: bounds.Height}, gfx.TextStyle{
Size: sizeM, Weight: gfx.WeightRegular, Color: foreground,
})
}, item.ID)

detailX := bounds.X + 8 + labelWidth + 8
detailWidth := comboboxMax(0, bounds.X+8+contentWidth-detailX)
Expand All @@ -229,9 +229,9 @@ func (combobox *Combobox) AddItem(item ComboboxItem) gfx.Rect {
if item.Disabled {
detailColor.Alpha *= .5
}
combobox.canvas.Label(combobox.canvas.FitLine(item.Detail, sizeS, gfx.WeightRegular, detailWidth), gfx.Rect{X: detailX, Y: bounds.Y, Width: detailWidth, Height: bounds.Height}, gfx.TextStyle{
labelEllipsis(combobox.canvas, item.Detail, gfx.Rect{X: detailX, Y: bounds.Y, Width: detailWidth, Height: bounds.Height}, gfx.TextStyle{
Size: sizeS, Weight: gfx.WeightRegular, Color: detailColor,
})
}, item.ID)
}
}
if item.Selected {
Expand Down Expand Up @@ -454,22 +454,22 @@ func (combobox Combobox) paintInput() {
if labelWidth > maxLabelWidth {
labelWidth = maxLabelWidth
}
canvas.Label(canvas.FitLine(options.Value, sizeM, gfx.WeightRegular, labelWidth), gfx.Rect{X: bounds.X + inset, Y: bounds.Y, Width: labelWidth, Height: bounds.Height}, gfx.TextStyle{
labelEllipsis(canvas, options.Value, gfx.Rect{X: bounds.X + inset, Y: bounds.Y, Width: labelWidth, Height: bounds.Height}, gfx.TextStyle{
Size: sizeM, Weight: gfx.WeightRegular, Color: foreground,
})
}, options.InputID)
detailX := bounds.X + inset + labelWidth + 8
detailWidth := comboboxMax(0, bounds.X+inset+availableWidth-detailX)
if detailWidth > 0 {
detailColor := combobox.theme.MutedForeground
if options.Disabled {
detailColor.Alpha *= 0.50
}
canvas.Label(canvas.FitLine(options.Detail, sizeS, gfx.WeightRegular, detailWidth), gfx.Rect{X: detailX, Y: bounds.Y, Width: detailWidth, Height: bounds.Height}, gfx.TextStyle{
labelEllipsis(canvas, options.Detail, gfx.Rect{X: detailX, Y: bounds.Y, Width: detailWidth, Height: bounds.Height}, gfx.TextStyle{
Size: sizeS, Weight: gfx.WeightRegular, Color: detailColor,
})
}, options.InputID)
}
} else if options.Query == "" || options.InputID.IsZero() || canvas.Focused() != options.InputID || options.Disabled {
canvas.Label(canvas.FitLine(value, combobox.theme.Metrics.FontSizeM, gfx.WeightRegular, availableWidth), textRect, gfx.TextStyle{Size: combobox.theme.Metrics.FontSizeM, Weight: gfx.WeightRegular, Color: foreground})
labelEllipsis(canvas, value, textRect, gfx.TextStyle{Size: combobox.theme.Metrics.FontSizeM, Weight: gfx.WeightRegular, Color: foreground}, options.InputID)
}
if !options.InputID.IsZero() {
canvas.HitWithOptions(options.InputID, bounds, options.Label, gfx.HitOptions{
Expand Down
8 changes: 5 additions & 3 deletions cmd/viva/templates/dropdown_menu.go.txt
Original file line number Diff line number Diff line change
Expand Up @@ -907,17 +907,19 @@ func (menu *menuSurface) paintItem(bounds gfx.Rect, item menuItem) {
canvas.Label(label, gfx.Rect{X: bounds.X + left, Y: labelY, Width: labelWidth, Height: labelHeight}, gfx.TextStyle{
Size: theme.Metrics.FontSizeM, Weight: gfx.WeightRegular, Color: foreground,
})
if label != "" && label != item.Label {
canvas.HoverHint(0, gfx.Rect{X: bounds.X + left, Y: labelY, Width: labelWidth, Height: labelHeight}, item.Label, item.ID)
}
if item.Description != "" {
color := theme.MutedForeground
if active {
color = foreground
}
color = dropdownMenuOpacity(color, item.Disabled)
width := max(0, bounds.Width-left-right-menu.hitInset)
value := canvas.FitLine(item.Description, theme.Metrics.FontSizeS, gfx.WeightRegular, width)
canvas.Label(value, gfx.Rect{X: bounds.X + left, Y: descriptionY, Width: width, Height: descriptionHeight}, gfx.TextStyle{
labelEllipsis(canvas, item.Description, gfx.Rect{X: bounds.X + left, Y: descriptionY, Width: width, Height: descriptionHeight}, gfx.TextStyle{
Size: theme.Metrics.FontSizeS, Weight: gfx.WeightRegular, Color: color,
})
}, item.ID)
}
menu.declareItemHit(bounds, item)
}
Expand Down
6 changes: 3 additions & 3 deletions cmd/viva/templates/hierarchy_menu.go.txt
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ func PaintHierarchyMenu(canvas *gfx.Canvas, theme gfx.Theme, anchor gfx.Rect, m
}
paintChevron(canvas, &hierarchyLeftIcon, gfx.Rect{X: bounds.X + 8, Y: bounds.Y, Width: 16, Height: bounds.Height}, look.Foreground)
text := gfx.Rect{X: bounds.X + 32, Y: bounds.Y, Width: max(bounds.Width-40, 0), Height: bounds.Height}
canvas.Label(canvas.FitLine(label, theme.Metrics.FontSizeM, gfx.WeightRegular, text.Width), text, gfx.TextStyle{Size: theme.Metrics.FontSizeM, Color: look.Foreground})
labelEllipsis(canvas, label, text, gfx.TextStyle{Size: theme.Metrics.FontSizeM, Color: look.Foreground}, o.OptionIDs.At(hierarchyBackIndex))
canvas.HitWithOptions(o.OptionIDs.At(hierarchyBackIndex), bounds, label, gfx.HitOptions{Role: gfx.RoleButton, Description: m.Nodes[parent].Path, SkipFocus: true})
menu.top += bounds.Height
menu.viewHeight = max(menu.viewHeight-bounds.Height, 0)
Expand Down Expand Up @@ -261,7 +261,7 @@ func PaintHierarchyMenu(canvas *gfx.Canvas, theme gfx.Theme, anchor gfx.Rect, m
reserve += 16
}
labelWidth := max(rowBounds.Width-reserve, 0)
canvas.Label(canvas.FitLine(info.Name, theme.Metrics.FontSizeM, gfx.WeightRegular, labelWidth), gfx.Rect{X: rowBounds.X + 8, Y: rowBounds.Y, Width: labelWidth, Height: rowBounds.Height}, gfx.TextStyle{Size: theme.Metrics.FontSizeM, Color: color})
labelEllipsis(canvas, info.Name, gfx.Rect{X: rowBounds.X + 8, Y: rowBounds.Y, Width: labelWidth, Height: rowBounds.Height}, gfx.TextStyle{Size: theme.Metrics.FontSizeM, Color: color}, id)
switch {
case info.Count > 0 && rowBounds.Width >= reserve:
chevron := &chevronRightIcon
Expand Down Expand Up @@ -323,7 +323,7 @@ func paintAction(m *HierarchyMenuState, menu *menuSurface, action HierarchyMenuA
}
color := look.Foreground
label := gfx.Rect{X: row.X + 8, Y: row.Y, Width: max(row.Width-16, 0), Height: row.Height}
canvas.Label(canvas.FitLine(action.Label, theme.Metrics.FontSizeM, gfx.WeightRegular, label.Width), label, gfx.TextStyle{Size: theme.Metrics.FontSizeM, Color: color})
labelEllipsis(canvas, action.Label, label, gfx.TextStyle{Size: theme.Metrics.FontSizeM, Color: color}, action.ID)
row.Width = max(row.Width-menu.hitInset, 0)
canvas.HitWithOptions(action.ID, row, action.Label, gfx.HitOptions{Role: gfx.RoleMenuItem, Disabled: action.Disabled, SkipFocus: true})
})
Expand Down
10 changes: 10 additions & 0 deletions cmd/viva/templates/label.go.txt
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,13 @@ func (label LabelPainter) Paint(text string) {
})
}
}

// labelEllipsis keeps the complete value alongside the fitted label. Its
// control may declare its hit after painting; that hit still owns the pointer.
func labelEllipsis(canvas *gfx.Canvas, value string, bounds gfx.Rect, style gfx.TextStyle, target gfx.ID) {
shown := canvas.FitLine(value, style.Size, style.Weight, bounds.Width)
canvas.Label(shown, bounds, style)
if shown != "" && shown != value {
canvas.HoverHint(0, bounds, value, target)
}
}
Loading
Loading