Browse Source

Separated form item "done" function from "finished" function. Resolves #39

merge-requests/1/merge
Oliver 5 years ago
parent
commit
f855bee020
  1. 12
      checkbox.go
  2. 12
      dropdown.go
  3. 9
      form.go
  4. 12
      inputfield.go

12
checkbox.go

@ -38,6 +38,10 @@ type Checkbox struct {
// are done entering text. The key which was pressed is provided (tab,
// shift-tab, or escape).
done func(tcell.Key)
// A callback function set by the Form class and called when the user leaves
// this form item.
finished func(tcell.Key)
}
// NewCheckbox returns a new input field.
@ -132,9 +136,10 @@ func (c *Checkbox) SetDoneFunc(handler func(key tcell.Key)) *Checkbox {
return c
}
// SetFinishedFunc calls SetDoneFunc().
// SetFinishedFunc sets a callback invoked when the user leaves this form item.
func (c *Checkbox) SetFinishedFunc(handler func(key tcell.Key)) FormItem {
return c.SetDoneFunc(handler)
c.finished = handler
return c
}
// Draw draws this primitive onto the screen.
@ -190,6 +195,9 @@ func (c *Checkbox) InputHandler() func(event *tcell.EventKey, setFocus func(p Pr
if c.done != nil {
c.done(key)
}
if c.finished != nil {
c.finished(key)
}
}
})
}

12
dropdown.go

@ -63,6 +63,10 @@ type DropDown struct {
// are done selecting options. The key which was pressed is provided (tab,
// shift-tab, or escape).
done func(tcell.Key)
// A callback function set by the Form class and called when the user leaves
// this form item.
finished func(tcell.Key)
}
// NewDropDown returns a new drop-down.
@ -221,9 +225,10 @@ func (d *DropDown) SetDoneFunc(handler func(key tcell.Key)) *DropDown {
return d
}
// SetFinishedFunc calls SetDoneFunc().
// SetFinishedFunc sets a callback invoked when the user leaves this form item.
func (d *DropDown) SetFinishedFunc(handler func(key tcell.Key)) FormItem {
return d.SetDoneFunc(handler)
d.finished = handler
return d
}
// Draw draws this primitive onto the screen.
@ -379,6 +384,9 @@ func (d *DropDown) InputHandler() func(event *tcell.EventKey, setFocus func(p Pr
if d.done != nil {
d.done(key)
}
if d.finished != nil {
d.finished(key)
}
}
})
}

9
form.go

@ -231,7 +231,14 @@ func (f *Form) Clear(includeButtons bool) *Form {
// AddFormItem adds a new item to the form. This can be used to add your own
// objects to the form. Note, however, that the Form class will override some
// of its attributes to make it work in the form context.
// of its attributes to make it work in the form context. Specifically, these
// are:
//
// - The label width
// - The label color
// - The background color
// - The field text color
// - The field background color
func (f *Form) AddFormItem(item FormItem) *Form {
f.items = append(f.items, item)
return f

12
inputfield.go

@ -63,6 +63,10 @@ type InputField struct {
// are done entering text. The key which was pressed is provided (tab,
// shift-tab, enter, or escape).
done func(tcell.Key)
// A callback function set by the Form class and called when the user leaves
// this form item.
finished func(tcell.Key)
}
// NewInputField returns a new input field.
@ -197,9 +201,10 @@ func (i *InputField) SetDoneFunc(handler func(key tcell.Key)) *InputField {
return i
}
// SetFinishedFunc calls SetDoneFunc().
// SetFinishedFunc sets a callback invoked when the user leaves this form item.
func (i *InputField) SetFinishedFunc(handler func(key tcell.Key)) FormItem {
return i.SetDoneFunc(handler)
i.finished = handler
return i
}
// Draw draws this primitive onto the screen.
@ -347,6 +352,9 @@ func (i *InputField) InputHandler() func(event *tcell.EventKey, setFocus func(p
if i.done != nil {
i.done(key)
}
if i.finished != nil {
i.finished(key)
}
}
})
}

Loading…
Cancel
Save