mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-07 10:25:37 +00:00
widget: document update and paint methods on textView
This commit updates the textView to better describe the expectations and behaviors of the Update and Paint* methods. Signed-off-by: Chris Waldon <christopher.waldon.dev@gmail.com>
This commit is contained in:
+11
-3
@@ -186,8 +186,8 @@ func (e *textView) calculateViewSize(gtx layout.Context) image.Point {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Update the text, reshaping it as necessary. If not nil, eventHandling will be invoked after reshaping the text to
|
// Update the text, reshaping it as necessary. If not nil, eventHandling will be invoked after reshaping the text to
|
||||||
// allow parent widgets to adapt to any changes in text content or positioning. If eventHandling invalidates the
|
// allow parent widgets to adapt to any changes in text content or positioning. If eventHandling modifies the contents
|
||||||
// Text, Update will ensure that it is valid again before returning.
|
// of the textView, it is guaranteed to be reshaped (and ready for painting) before Update returns.
|
||||||
func (e *textView) Update(gtx layout.Context, lt *text.Shaper, font text.Font, size unit.Sp, eventHandling func(gtx layout.Context)) {
|
func (e *textView) Update(gtx layout.Context, lt *text.Shaper, font text.Font, size unit.Sp, eventHandling func(gtx layout.Context)) {
|
||||||
if e.locale != gtx.Locale {
|
if e.locale != gtx.Locale {
|
||||||
e.locale = gtx.Locale
|
e.locale = gtx.Locale
|
||||||
@@ -234,7 +234,9 @@ func (e *textView) Update(gtx layout.Context, lt *text.Shaper, font text.Font, s
|
|||||||
e.makeValid()
|
e.makeValid()
|
||||||
}
|
}
|
||||||
|
|
||||||
// PaintSelection paints the contrasting background for selected text.
|
// PaintSelection clips and paints the visible text selection rectangles. Callers
|
||||||
|
// are expected to apply an appropriate paint material with a paint.ColorOp or
|
||||||
|
// similar prior to calling PaintSelection.
|
||||||
func (e *textView) PaintSelection(gtx layout.Context) {
|
func (e *textView) PaintSelection(gtx layout.Context) {
|
||||||
localViewport := image.Rectangle{Max: e.viewSize}
|
localViewport := image.Rectangle{Max: e.viewSize}
|
||||||
docViewport := image.Rectangle{Max: e.viewSize}.Add(e.scrollOff)
|
docViewport := image.Rectangle{Max: e.viewSize}.Add(e.scrollOff)
|
||||||
@@ -247,6 +249,9 @@ func (e *textView) PaintSelection(gtx layout.Context) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// PaintText clips and paints the visible text glyph outlines. Callers
|
||||||
|
// are expected to apply an appropriate paint material with a paint.ColorOp or
|
||||||
|
// similar prior to calling PaintSelection.
|
||||||
func (e *textView) PaintText(gtx layout.Context) {
|
func (e *textView) PaintText(gtx layout.Context) {
|
||||||
m := op.Record(gtx.Ops)
|
m := op.Record(gtx.Ops)
|
||||||
viewport := image.Rectangle{
|
viewport := image.Rectangle{
|
||||||
@@ -288,6 +293,9 @@ func (e *textView) caretWidth(gtx layout.Context) int {
|
|||||||
return carWidth2
|
return carWidth2
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// PaintCaret clips and paints the caret rectangle. Callers
|
||||||
|
// are expected to apply an appropriate paint material with a paint.ColorOp or
|
||||||
|
// similar prior to calling PaintSelection.
|
||||||
func (e *textView) PaintCaret(gtx layout.Context) {
|
func (e *textView) PaintCaret(gtx layout.Context) {
|
||||||
carWidth2 := e.caretWidth(gtx)
|
carWidth2 := e.caretWidth(gtx)
|
||||||
caretPos, carAsc, carDesc := e.CaretInfo()
|
caretPos, carAsc, carDesc := e.CaretInfo()
|
||||||
|
|||||||
Reference in New Issue
Block a user