diff --git a/CHANGELOG b/CHANGELOG index d35534a..8fa1894 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -5,7 +5,7 @@ v1.5.1 (WIP) - Add Application.Init - Add Application.GetScreen and Application.GetScreenSize - Add SetVisible and GetVisible to all widgets -- Add TextView.SetBytes and TextView.GetBytes +- Add TextView.SetBytes, TextView.GetBytes and TextView.SetWrapWidth - Add TableCell.SetBytes, TableCell.GetBytes and TableCell.GetText - Fix List.Transform not calling handler set via SetChangedFunc - Fix WordWrap bounds out of range diff --git a/textview.go b/textview.go index d14d732..c723563 100644 --- a/textview.go +++ b/textview.go @@ -169,6 +169,9 @@ type TextView struct { // width are discarded. wrap bool + // The maximum line width when wrapping (0 = use TextView width). + wrapWidth int + // If set to true and if wrap is also true, lines are split at spaces or // after punctuation characters. wordWrap bool @@ -765,6 +768,15 @@ func (t *TextView) write(p []byte) (n int, err error) { return len(p), nil } +// SetWrapWidth set the maximum width of lines when wrapping is enabled. +// When set to 0 the width of the TextView is used. +func (t *TextView) SetWrapWidth(width int) { + t.Lock() + defer t.Unlock() + + t.wrapWidth = width +} + // SetReindexBuffer set a flag controlling whether the buffer is reindexed when // it is modified. This improves the performance of TextViews whose contents // always have line-breaks in the same location. This must be called after the @@ -797,6 +809,10 @@ func (t *TextView) reindexBuffer(width int) { return } + if t.wrapWidth > 0 && t.wrapWidth < width { + width = t.wrapWidth + } + // Initial states. var regionID []byte var (