From 36671ba7d31c2287748e22966a92c5e94ff850cc Mon Sep 17 00:00:00 2001 From: Trevor Slocum Date: Mon, 26 Oct 2020 10:41:47 -0700 Subject: [PATCH] Rename SetBorderPadding and GetBorderPadding as SetPadding and GetPadding --- CHANGELOG | 1 + box.go | 24 +++++++++++++++++++----- contextmenu.go | 2 +- demos/presentation/code.go | 2 +- demos/presentation/table.go | 4 ++-- demos/presentation/treeview.go | 2 +- form.go | 2 +- modal.go | 4 ++-- 8 files changed, 28 insertions(+), 13 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 9b0a210..af51a8c 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -19,6 +19,7 @@ v1.5.1 (WIP) - Optimize TextView (writing is 90% faster, drawing is 50% faster) - Remove return values from methods which return their primitive (breaks chaining) - Remove Application.ForceDraw (Application.Draw may be called anywhere) +- Rename SetBorderPadding and GetBorderPadding as SetPadding and GetPadding - Rename Pages as Panels - Support bracketed paste mode via tcell diff --git a/box.go b/box.go index 3d04042..b5c1c99 100644 --- a/box.go +++ b/box.go @@ -19,7 +19,7 @@ type Box struct { // Whether or not the box is visible. visible bool - // Border padding. + // Padding. paddingTop, paddingBottom, paddingLeft, paddingRight int // The border color when the box has focus. @@ -94,15 +94,15 @@ func NewBox() *Box { return b } -// GetBorderPadding returns the size of the borders around the box content. -func (b *Box) GetBorderPadding() (top, bottom, left, right int) { +// GetPadding returns the size of the padding around the box content. +func (b *Box) GetPadding() (top, bottom, left, right int) { b.l.RLock() defer b.l.RUnlock() return b.paddingTop, b.paddingBottom, b.paddingLeft, b.paddingRight } -// SetBorderPadding sets the size of the borders around the box content. -func (b *Box) SetBorderPadding(top, bottom, left, right int) { +// SetPadding sets the size of the padding around the box content. +func (b *Box) SetPadding(top, bottom, left, right int) { b.l.Lock() defer b.l.Unlock() @@ -578,3 +578,17 @@ func (b *Box) GetFocusable() Focusable { return b.focus } + +// GetBorderPadding returns the size of the padding around the box content. It +// is provided for backwards compatibility. Application developers should use +// GetPadding instead. +func (b *Box) GetBorderPadding() (top, bottom, left, right int) { + return b.GetPadding() +} + +// SetBorderPadding sets the size of the padding around the box content. It +// is provided for backwards compatibility. Application developers should use +// SetPadding instead. +func (b *Box) SetBorderPadding(top, bottom, left, right int) { + b.SetPadding(top, bottom, left, right) +} diff --git a/contextmenu.go b/contextmenu.go index f767f69..c4ad7e7 100644 --- a/contextmenu.go +++ b/contextmenu.go @@ -34,7 +34,7 @@ func (c *ContextMenu) initializeList() { c.list.SetWrapAround(true) c.list.ShowFocus(false) c.list.SetBorder(true) - c.list.SetBorderPadding( + c.list.SetPadding( Styles.ContextMenuPaddingTop, Styles.ContextMenuPaddingBottom, Styles.ContextMenuPaddingLeft, diff --git a/demos/presentation/code.go b/demos/presentation/code.go index 3736b74..e9d4ea4 100644 --- a/demos/presentation/code.go +++ b/demos/presentation/code.go @@ -16,7 +16,7 @@ func Code(p cview.Primitive, width, height int, code string) cview.Primitive { codeView := cview.NewTextView() codeView.SetWrap(false) codeView.SetDynamicColors(true) - codeView.SetBorderPadding(1, 1, 2, 0) + codeView.SetPadding(1, 1, 2, 0) fmt.Fprint(codeView, code) f := cview.NewFlex() diff --git a/demos/presentation/table.go b/demos/presentation/table.go index 4f48bb6..0a84721 100644 --- a/demos/presentation/table.go +++ b/demos/presentation/table.go @@ -281,7 +281,7 @@ func Table(nextSlide func()) (title string, content cview.Primitive) { code := cview.NewTextView() code.SetWrap(false) code.SetDynamicColors(true) - code.SetBorderPadding(1, 1, 2, 0) + code.SetPadding(1, 1, 2, 0) list := cview.NewList() @@ -343,7 +343,7 @@ func Table(nextSlide func()) (title string, content cview.Primitive) { } list.ShowSecondaryText(false) - list.SetBorderPadding(1, 1, 2, 2) + list.SetPadding(1, 1, 2, 2) var demoTableText = []struct { text string diff --git a/demos/presentation/treeview.go b/demos/presentation/treeview.go index 0f71572..b98e200 100644 --- a/demos/presentation/treeview.go +++ b/demos/presentation/treeview.go @@ -155,7 +155,7 @@ func TreeView(nextSlide func()) (title string, content cview.Primitive) { treeCode.SetWrap(false) treeCode.SetDynamicColors(true) treeCode.SetText(strings.Replace(treeAllCode, "$$$", treeBasicCode, -1)) - treeCode.SetBorderPadding(1, 1, 2, 0) + treeCode.SetPadding(1, 1, 2, 0) flex := cview.NewFlex() flex.AddItem(tree, 0, 1, true) diff --git a/form.go b/form.go index d844175..96bc73a 100644 --- a/form.go +++ b/form.go @@ -145,7 +145,7 @@ type Form struct { // NewForm returns a new form. func NewForm() *Form { box := NewBox() - box.SetBorderPadding(1, 1, 1, 1) + box.SetPadding(1, 1, 1, 1) f := &Form{ Box: box, diff --git a/modal.go b/modal.go index 12ad872..de284af 100644 --- a/modal.go +++ b/modal.go @@ -46,7 +46,7 @@ func NewModal() *Modal { m.form.SetButtonBackgroundColor(Styles.PrimitiveBackgroundColor) m.form.SetButtonTextColor(Styles.PrimaryTextColor) m.form.SetBackgroundColor(Styles.ContrastBackgroundColor) - m.form.SetBorderPadding(0, 0, 0, 0) + m.form.SetPadding(0, 0, 0, 0) m.form.SetCancelFunc(func() { if m.done != nil { m.done(-1, "") @@ -57,7 +57,7 @@ func NewModal() *Modal { m.frame.SetBorder(true) m.frame.SetBorders(0, 0, 1, 0, 0, 0) m.frame.SetBackgroundColor(Styles.ContrastBackgroundColor) - m.frame.SetBorderPadding(1, 1, 1, 1) + m.frame.SetPadding(1, 1, 1, 1) m.focus = m return m