From c90e430fdfdad1d5584765f46d34d88044113785 Mon Sep 17 00:00:00 2001 From: Trevor Slocum Date: Sun, 5 Jan 2020 09:41:15 -0800 Subject: [PATCH] Add optional message displayed after Checkbox --- CHANGELOG | 4 +++- FORK.md | 1 + checkbox.go | 4 ++-- demos/form/main.go | 2 +- demos/presentation/form.go | 2 +- demos/unicode/main.go | 2 +- form.go | 9 +++++---- 7 files changed, 14 insertions(+), 10 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 1ffa4f2..f5cae68 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,5 +1,7 @@ v0.2.2 (WIP) -- Fix dropdown mouse capture behavior +- Add optional message displayed after Checkbox +- Fix Dropdown mouse capture behavior +- Fix TextView region highlighting on last line v0.2.1 (2020-01-01) - Add initial mouse support (some widgets are unsupported) diff --git a/FORK.md b/FORK.md index d5a7d23..5b5f80a 100644 --- a/FORK.md +++ b/FORK.md @@ -28,6 +28,7 @@ maintainers and allowing code changes which may be outside of tview's scope. The following tview pull requests have been merged into cview: - [#378 Throttle resize handling](https://github.com/rivo/tview/pull/378) +- [#368 Add support for displaying text next to a checkbox](https://github.com/rivo/tview/pull/368) - [#363 Mouse support](https://github.com/rivo/tview/pull/363) - [#353 Add window size change handler](https://github.com/rivo/tview/pull/353) - [#347 Handle ANSI code 39 and 49](https://github.com/rivo/tview/pull/347) diff --git a/checkbox.go b/checkbox.go index 15a9def..62ab9c3 100644 --- a/checkbox.go +++ b/checkbox.go @@ -14,10 +14,10 @@ type Checkbox struct { // Whether or not this box is checked. checked bool - // The text to be displayed before the input area. + // The text to be displayed before the checkbox. label string - // The text to be displayed after the checkbox + // The text to be displayed after the checkbox. message string // The screen width of the label area. A value of 0 means use the width of diff --git a/demos/form/main.go b/demos/form/main.go index 4129048..80d6df9 100644 --- a/demos/form/main.go +++ b/demos/form/main.go @@ -11,8 +11,8 @@ func main() { AddDropDown("Title", []string{"Mr.", "Ms.", "Mrs.", "Dr.", "Prof."}, 0, nil). AddInputField("First name", "", 20, nil, nil). AddInputField("Last name", "", 20, nil, nil). - AddCheckbox("Age 18+", false, nil). AddPasswordField("Password", "", 10, '*', nil). + AddCheckbox("", "Age 18+", false, nil). AddButton("Save", nil). AddButton("Quit", func() { app.Stop() diff --git a/demos/presentation/form.go b/demos/presentation/form.go index ab28b5f..74340e9 100644 --- a/demos/presentation/form.go +++ b/demos/presentation/form.go @@ -34,8 +34,8 @@ func Form(nextSlide func()) (title string, content cview.Primitive) { AddInputField("First name:", "", 20, nil, nil). AddInputField("Last name:", "", 20, nil, nil). AddDropDown("Role:", []string{"Engineer", "Manager", "Administration"}, 0, nil). - AddCheckbox("On vacation:", false, nil). AddPasswordField("Password:", "", 10, '*', nil). + AddCheckbox("", "On vacation", false, nil). AddButton("Save", nextSlide). AddButton("Cancel", nextSlide) f.SetBorder(true).SetTitle("Employee Information") diff --git a/demos/unicode/main.go b/demos/unicode/main.go index e2815b0..0db6637 100644 --- a/demos/unicode/main.go +++ b/demos/unicode/main.go @@ -14,8 +14,8 @@ func main() { form := cview.NewForm() form.AddDropDown("称谓", []string{"先生", "女士", "博士", "老师", "师傅"}, 0, nil). AddInputField("姓名", "", 20, nil, nil). - AddCheckbox("年龄 18+", false, nil). AddPasswordField("密码", "", 10, '*', nil). + AddCheckbox("", "年龄 18+", false, nil). AddButton("保存", func() { _, title := form.GetFormItem(0).(*cview.DropDown).GetCurrentOption() userName := form.GetFormItem(1).(*cview.InputField).GetText() diff --git a/form.go b/form.go index 492a2e1..0f09d95 100644 --- a/form.go +++ b/form.go @@ -215,12 +215,13 @@ func (f *Form) AddDropDown(label string, options []string, initialOption int, se return f } -// AddCheckbox adds a checkbox to the form. It has a label, an initial state, -// and an (optional) callback function which is invoked when the state of the -// checkbox was changed by the user. -func (f *Form) AddCheckbox(label string, checked bool, changed func(checked bool)) *Form { +// AddCheckbox adds a checkbox to the form. It has a label, a message, an +// initial state, and an (optional) callback function which is invoked when the +// state of the checkbox was changed by the user. +func (f *Form) AddCheckbox(label string, message string, checked bool, changed func(checked bool)) *Form { f.items = append(f.items, NewCheckbox(). SetLabel(label). + SetMessage(message). SetChecked(checked). SetChangedFunc(changed)) return f