mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-04 00:45:35 +00:00
text,widget{,/material}: [API] move all shaping parameters into text.Parameters
This commit moves the min/max width of shaped text and the text's Locale into
text.Parameters. They were previously passed as separate function parameters to
the shaper, but this made little sense and added visual noise. This is a breaking
change, but only if you previously invoked the shaping API directly.
Callers of text.(*Shaper).LayoutString should change:
shaper.LayoutString(params, minWidth, maxWidth, locale, "string")
to
params.MinWidth=minWidth
params.MaxWidth=maxWidth
params.Locale=locale
shaper.LayoutString(params, "string")
Callers of text.(*Shaper).Layout should do likewise.
Signed-off-by: Chris Waldon <christopher.waldon.dev@gmail.com>
This commit is contained in:
+11
-1
@@ -48,8 +48,15 @@ func (s stringSource) ReadAt(b []byte, offset int64) (int, error) {
|
||||
func (s stringSource) ReplaceRunes(byteOffset, runeCount int64, str string) {
|
||||
}
|
||||
|
||||
// Selectable holds text selection state.
|
||||
// Selectable displays selectable text.
|
||||
type Selectable struct {
|
||||
// Alignment controls the alignment of the text.
|
||||
Alignment text.Alignment
|
||||
// MaxLines is the maximum number of lines of text to be displayed.
|
||||
MaxLines int
|
||||
// Truncator is the symbol to use at the end of the final line of text
|
||||
// if text was cut off. Defaults to "…" if left empty.
|
||||
Truncator string
|
||||
initialized bool
|
||||
source stringSource
|
||||
// scratch is a buffer reused to efficiently read text out of the
|
||||
@@ -171,6 +178,9 @@ func (l *Selectable) Truncated() bool {
|
||||
// paint material for the text and selection rectangles, respectively.
|
||||
func (l *Selectable) Layout(gtx layout.Context, lt *text.Shaper, font text.Font, size unit.Sp, textMaterial, selectionMaterial op.CallOp) layout.Dimensions {
|
||||
l.initialize()
|
||||
l.text.Alignment = l.Alignment
|
||||
l.text.MaxLines = l.MaxLines
|
||||
l.text.Truncator = l.Truncator
|
||||
l.text.Update(gtx, lt, font, size, l.handleEvents)
|
||||
dims := l.text.Dimensions()
|
||||
defer clip.Rect(image.Rectangle{Max: dims.Size}).Push(gtx.Ops).Pop()
|
||||
|
||||
Reference in New Issue
Block a user