mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-03 00:16:15 +00:00
widget{,/material}: [API] split interactive and non-interactive text widgets
This commit separates the types for interactive and non-interactive text within package widget. widget.Selectable is used for all interactive text. widget.Label is used for all non-interactive text. There is no longer a field on widget.Label to provide it with a Selectable. If you want selectable text and are not relying upon the material pacakge API, you need to create widget.Selectables instead of widget.Labels. The material package's LabelStyle API is unchanged. Signed-off-by: Chris Waldon <christopher.waldon.dev@gmail.com>
This commit is contained in:
@@ -119,7 +119,7 @@ func (b ButtonStyle) Layout(gtx layout.Context) layout.Dimensions {
|
||||
return b.Inset.Layout(gtx, func(gtx layout.Context) layout.Dimensions {
|
||||
colMacro := op.Record(gtx.Ops)
|
||||
paint.ColorOp{Color: b.Color}.Add(gtx.Ops)
|
||||
return widget.Label{Alignment: text.Middle}.Layout(gtx, b.shaper, b.Font, b.TextSize, b.Text, colMacro.Stop(), op.CallOp{})
|
||||
return widget.Label{Alignment: text.Middle}.Layout(gtx, b.shaper, b.Font, b.TextSize, b.Text, colMacro.Stop())
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
@@ -76,7 +76,7 @@ func (c *checkable) layout(gtx layout.Context, checked, hovered bool) layout.Dim
|
||||
return layout.UniformInset(2).Layout(gtx, func(gtx layout.Context) layout.Dimensions {
|
||||
colMacro := op.Record(gtx.Ops)
|
||||
paint.ColorOp{Color: c.Color}.Add(gtx.Ops)
|
||||
return widget.Label{}.Layout(gtx, c.shaper, c.Font, c.TextSize, c.Label, colMacro.Stop(), op.CallOp{})
|
||||
return widget.Label{}.Layout(gtx, c.shaper, c.Font, c.TextSize, c.Label, colMacro.Stop())
|
||||
})
|
||||
}),
|
||||
)
|
||||
|
||||
@@ -61,7 +61,7 @@ func (e EditorStyle) Layout(gtx layout.Context) layout.Dimensions {
|
||||
|
||||
macro := op.Record(gtx.Ops)
|
||||
tl := widget.Label{Alignment: e.Editor.Alignment, MaxLines: maxlines}
|
||||
dims := tl.Layout(gtx, e.shaper, e.Font, e.TextSize, e.Hint, hintColor, selectionColor)
|
||||
dims := tl.Layout(gtx, e.shaper, e.Font, e.TextSize, e.Hint, hintColor)
|
||||
call := macro.Stop()
|
||||
|
||||
if w := dims.Size.X; gtx.Constraints.Min.X < w {
|
||||
|
||||
@@ -14,6 +14,9 @@ import (
|
||||
"gioui.org/widget"
|
||||
)
|
||||
|
||||
// LabelStyle configures the presentation of text. If the State field is set, the
|
||||
// label will be laid out as interactive (able to be selected and copied). Otherwise,
|
||||
// the label will be non-interactive.
|
||||
type LabelStyle struct {
|
||||
// Face defines the text style.
|
||||
Font text.Font
|
||||
@@ -109,6 +112,12 @@ func (l LabelStyle) Layout(gtx layout.Context) layout.Dimensions {
|
||||
paint.ColorOp{Color: l.SelectionColor}.Add(gtx.Ops)
|
||||
selectColor := selectColorMacro.Stop()
|
||||
|
||||
tl := widget.Label{Alignment: l.Alignment, MaxLines: l.MaxLines, Selectable: l.State}
|
||||
return tl.Layout(gtx, l.shaper, l.Font, l.TextSize, l.Text, textColor, selectColor)
|
||||
if l.State != nil {
|
||||
if l.State.Text() != l.Text {
|
||||
l.State.SetText(l.Text)
|
||||
}
|
||||
return l.State.Layout(gtx, l.shaper, l.Font, l.TextSize, textColor, selectColor)
|
||||
}
|
||||
tl := widget.Label{Alignment: l.Alignment, MaxLines: l.MaxLines}
|
||||
return tl.Layout(gtx, l.shaper, l.Font, l.TextSize, l.Text, textColor)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user