From 5e6e1217dab6107f9bd8af77cd5da8bb933ca69c Mon Sep 17 00:00:00 2001 From: Chris Waldon Date: Thu, 23 Mar 2023 11:02:51 -0400 Subject: [PATCH] widget: expose truncation status of Selectable This commit adds an exported method to enable widgets to detect when the text displayed by a Selectable has been truncated. This can be used to implement proper show-full-text-in-an-overlay behavior in a parent widget. I haven't attempted to implement that in core yet, as it is a complex feature involving animation and pointer interaction. Signed-off-by: Chris Waldon --- widget/selectable.go | 6 ++++++ widget/text.go | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/widget/selectable.go b/widget/selectable.go index 83b2a2ad..ff4da67d 100644 --- a/widget/selectable.go +++ b/widget/selectable.go @@ -160,6 +160,12 @@ func (l *Selectable) SetText(s string) { } } +// Truncated returns whether the text has been truncated by the text shaper to +// fit within available constraints. +func (l *Selectable) Truncated() bool { + return l.text.Truncated() +} + // Layout clips to the dimensions of the selectable, updates the shaped text, configures input handling, and paints // the text and selection rectangles. The provided textMaterial and selectionMaterial ops are used to set the // paint material for the text and selection rectangles, respectively. diff --git a/widget/text.go b/widget/text.go index ebc784d1..2b4d33a2 100644 --- a/widget/text.go +++ b/widget/text.go @@ -447,6 +447,12 @@ func (e *textView) MoveCoord(pos image.Point) { e.caret.xoff = 0 } +// Truncated returns whether the text in the textView is currently +// truncated due to a restriction on the number of lines. +func (e *textView) Truncated() bool { + return e.index.truncated +} + func (e *textView) layoutText(lt *text.Shaper) { e.Seek(0, io.SeekStart) var r io.Reader = e -- 2.45.2