Add optional message displayed after Checkbox
This commit is contained in:
parent
697baf37a8
commit
c90e430fdf
7 changed files with 14 additions and 10 deletions
|
@ -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)
|
||||
|
|
1
FORK.md
1
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)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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")
|
||||
|
|
|
@ -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()
|
||||
|
|
9
form.go
9
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
|
||||
|
|
Loading…
Reference in a new issue