Skip to content

Commit

Permalink
Merge pull request #4128 from andydotxyz/feature/textwraptruncate
Browse files Browse the repository at this point in the history
Move to a truncate mode separate to wrapping
  • Loading branch information
andydotxyz authored Aug 11, 2023
2 parents f8d94be + e6056c1 commit 310723c
Show file tree
Hide file tree
Showing 5 changed files with 421 additions and 87 deletions.
26 changes: 21 additions & 5 deletions text.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,25 @@ const (
TextAlignTrailing
)

// TextTruncation controls how a `Label` or `Entry` will truncate its text.
// The default value is `TextTruncateOff` which will not truncate.
//
// Since: 2.4
type TextTruncation int

const (
// TextTruncateOff means no truncation will be applied, it is the default.
// This means that the minimum size of a text block will be the space required to display it fully.
TextTruncateOff TextTruncation = iota
// TextTruncateClip will truncate text when it reaches the end of the available space.
TextTruncateClip
// TextTruncateEllipsis is like regular truncation except that an ellipses (…) will be inserted
// wherever text has been shortened to fit.
//
// Since: 2.4
TextTruncateEllipsis
)

// TextWrap represents how text longer than the widget's width will be wrapped.
type TextWrap int

Expand All @@ -21,12 +40,9 @@ const (
TextWrapOff TextWrap = iota
// TextTruncate trims the text to the widget's width, no wrapping is applied.
// If an entry is asked to truncate it will provide scrolling capabilities.
TextTruncate
// TextTruncateEllipsis is like regular truncation except that an ellipses (…) will be inserted
// wherever text has been shortened to fit.
//
// Since: 2.4
TextTruncateEllipsis
// Deprecated: Use `TextTruncateClip` value of the widget `Truncation` field instead
TextTruncate
// TextWrapBreak trims the line of characters to the widget's width adding the excess as new line.
// An Entry with text wrapping will scroll vertically if there is not enough space for all the text.
TextWrapBreak
Expand Down
8 changes: 5 additions & 3 deletions widget/label.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ import (
type Label struct {
BaseWidget
Text string
Alignment fyne.TextAlign // The alignment of the Text
Wrapping fyne.TextWrap // The wrapping of the Text
TextStyle fyne.TextStyle // The style of the label text
Alignment fyne.TextAlign // The alignment of the text
Wrapping fyne.TextWrap // The wrapping of the text
TextStyle fyne.TextStyle // The style of the label text
Truncation fyne.TextTruncation // The truncation mode of the text
provider *RichText
Importance Importance

Expand Down Expand Up @@ -145,6 +146,7 @@ func (l *Label) syncSegments() {
}

l.provider.Wrapping = l.Wrapping
l.provider.Truncation = l.Truncation
l.provider.Segments[0].(*TextSegment).Style = RichTextStyle{
Alignment: l.Alignment,
ColorName: color,
Expand Down
Loading

0 comments on commit 310723c

Please sign in to comment.