Compare commits
No commits in common. "df2e8f1b07f0e34c423385bc8fd9fc25f39d823c" and "4e8823ef9f681d395891546e1689d06e761ed995" have entirely different histories.
df2e8f1b07
...
4e8823ef9f
42
checkbox.go
42
checkbox.go
@ -4,11 +4,9 @@ import "git.tebibyte.media/tomo/tomo"
|
|||||||
import "git.tebibyte.media/tomo/tomo/input"
|
import "git.tebibyte.media/tomo/tomo/input"
|
||||||
import "git.tebibyte.media/tomo/tomo/event"
|
import "git.tebibyte.media/tomo/tomo/event"
|
||||||
|
|
||||||
var _ tomo.Object = new(Checkbox)
|
|
||||||
|
|
||||||
// Checkbox is a control that can be toggled.
|
// Checkbox is a control that can be toggled.
|
||||||
type Checkbox struct {
|
type Checkbox struct {
|
||||||
box tomo.Box
|
tomo.Box
|
||||||
value bool
|
value bool
|
||||||
on struct {
|
on struct {
|
||||||
valueChange event.FuncBroadcaster
|
valueChange event.FuncBroadcaster
|
||||||
@ -17,30 +15,18 @@ type Checkbox struct {
|
|||||||
|
|
||||||
// NewCheckbox creates a new checkbox with the specified value.
|
// NewCheckbox creates a new checkbox with the specified value.
|
||||||
func NewCheckbox (value bool) *Checkbox {
|
func NewCheckbox (value bool) *Checkbox {
|
||||||
checkbox := &Checkbox {
|
box := &Checkbox {
|
||||||
box: tomo.NewBox(),
|
Box: tomo.NewBox(),
|
||||||
}
|
}
|
||||||
checkbox.box.SetRole(tomo.R("objects", "Checkbox"))
|
box.SetRole(tomo.R("objects", "Checkbox"))
|
||||||
checkbox.SetValue(value)
|
box.SetValue(value)
|
||||||
|
|
||||||
checkbox.box.OnButtonDown(checkbox.handleButtonDown)
|
box.OnButtonDown(box.handleButtonDown)
|
||||||
checkbox.box.OnButtonUp(checkbox.handleButtonUp)
|
box.OnButtonUp(box.handleButtonUp)
|
||||||
checkbox.box.OnKeyDown(checkbox.handleKeyDown)
|
box.OnKeyDown(box.handleKeyDown)
|
||||||
checkbox.box.OnKeyUp(checkbox.handleKeyUp)
|
box.OnKeyUp(box.handleKeyUp)
|
||||||
checkbox.box.SetFocusable(true)
|
box.SetFocusable(true)
|
||||||
return checkbox
|
return box
|
||||||
}
|
|
||||||
|
|
||||||
// GetBox returns the underlying box.
|
|
||||||
func (this *Checkbox) GetBox () tomo.Box {
|
|
||||||
return this.box
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetFocused sets whether or not this checkbox has keyboard focus. If set to
|
|
||||||
// true, this method will steal focus away from whichever object currently has
|
|
||||||
// focus.
|
|
||||||
func (this *Checkbox) SetFocused (focused bool) {
|
|
||||||
this.box.SetFocused(focused)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Value returns the value of the checkbox.
|
// Value returns the value of the checkbox.
|
||||||
@ -52,8 +38,8 @@ func (this *Checkbox) Value () bool {
|
|||||||
func (this *Checkbox) SetValue (value bool) {
|
func (this *Checkbox) SetValue (value bool) {
|
||||||
this.value = value
|
this.value = value
|
||||||
// the theme shall decide what checked and unchecked states look like
|
// the theme shall decide what checked and unchecked states look like
|
||||||
this.box.SetTag("checked", value)
|
this.SetTag("checked", value)
|
||||||
this.box.SetTag("unchecked", !value)
|
this.SetTag("unchecked", !value)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Toggle toggles the value of the checkbox between true and false.
|
// Toggle toggles the value of the checkbox between true and false.
|
||||||
@ -85,7 +71,7 @@ func (this *Checkbox) handleButtonDown (button input.Button) bool {
|
|||||||
|
|
||||||
func (this *Checkbox) handleButtonUp (button input.Button) bool {
|
func (this *Checkbox) handleButtonUp (button input.Button) bool {
|
||||||
if !isClickingButton(button) { return false }
|
if !isClickingButton(button) { return false }
|
||||||
if this.box.Window().MousePosition().In(this.box.Bounds()) {
|
if this.Window().MousePosition().In(this.Bounds()) {
|
||||||
this.Toggle()
|
this.Toggle()
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
|
@ -8,12 +8,10 @@ import "git.tebibyte.media/tomo/tomo/canvas"
|
|||||||
import "git.tebibyte.media/tomo/objects/layouts"
|
import "git.tebibyte.media/tomo/objects/layouts"
|
||||||
import "git.tebibyte.media/tomo/objects/internal"
|
import "git.tebibyte.media/tomo/objects/internal"
|
||||||
|
|
||||||
var _ tomo.Object = new(HSVAColorPicker)
|
|
||||||
|
|
||||||
// HSVAColorPicker allows the user to pick a color by controlling its HSVA
|
// HSVAColorPicker allows the user to pick a color by controlling its HSVA
|
||||||
// parameters.
|
// parameters.
|
||||||
type HSVAColorPicker struct {
|
type HSVAColorPicker struct {
|
||||||
box tomo.ContainerBox
|
tomo.ContainerBox
|
||||||
value internal.HSVA
|
value internal.HSVA
|
||||||
|
|
||||||
pickerMap *hsvaColorPickerMap
|
pickerMap *hsvaColorPickerMap
|
||||||
@ -28,15 +26,15 @@ type HSVAColorPicker struct {
|
|||||||
// NewHSVAColorPicker creates a new color picker with the specified color.
|
// NewHSVAColorPicker creates a new color picker with the specified color.
|
||||||
func NewHSVAColorPicker (value color.Color) *HSVAColorPicker {
|
func NewHSVAColorPicker (value color.Color) *HSVAColorPicker {
|
||||||
picker := &HSVAColorPicker {
|
picker := &HSVAColorPicker {
|
||||||
box: tomo.NewContainerBox(),
|
ContainerBox: tomo.NewContainerBox(),
|
||||||
}
|
}
|
||||||
picker.box.SetRole(tomo.R("objects", "ColorPicker"))
|
picker.SetRole(tomo.R("objects", "ColorPicker"))
|
||||||
picker.box.SetAttr(tomo.ALayout(layouts.Row { true, false, false }))
|
picker.SetAttr(tomo.ALayout(layouts.Row { true, false, false }))
|
||||||
picker.pickerMap = newHsvaColorPickerMap(picker)
|
picker.pickerMap = newHsvaColorPickerMap(picker)
|
||||||
picker.box.Add(picker.pickerMap)
|
picker.Add(picker.pickerMap)
|
||||||
|
|
||||||
picker.hueSlider = NewVerticalSlider(0.0)
|
picker.hueSlider = NewVerticalSlider(0.0)
|
||||||
picker.box.Add(picker.hueSlider)
|
picker.Add(picker.hueSlider)
|
||||||
picker.hueSlider.OnValueChange(func () {
|
picker.hueSlider.OnValueChange(func () {
|
||||||
picker.value.H = picker.hueSlider.Value()
|
picker.value.H = picker.hueSlider.Value()
|
||||||
picker.on.valueChange.Broadcast()
|
picker.on.valueChange.Broadcast()
|
||||||
@ -44,7 +42,7 @@ func NewHSVAColorPicker (value color.Color) *HSVAColorPicker {
|
|||||||
})
|
})
|
||||||
|
|
||||||
picker.alphaSlider = NewVerticalSlider(0.0)
|
picker.alphaSlider = NewVerticalSlider(0.0)
|
||||||
picker.box.Add(picker.alphaSlider)
|
picker.Add(picker.alphaSlider)
|
||||||
picker.alphaSlider.OnValueChange(func () {
|
picker.alphaSlider.OnValueChange(func () {
|
||||||
picker.value.A = uint16(picker.alphaSlider.Value() * 0xFFFF)
|
picker.value.A = uint16(picker.alphaSlider.Value() * 0xFFFF)
|
||||||
picker.on.valueChange.Broadcast()
|
picker.on.valueChange.Broadcast()
|
||||||
@ -56,18 +54,6 @@ func NewHSVAColorPicker (value color.Color) *HSVAColorPicker {
|
|||||||
return picker
|
return picker
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetBox returns the underlying box.
|
|
||||||
func (this *HSVAColorPicker) GetBox () tomo.Box {
|
|
||||||
return this.box
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetFocused sets whether or not this color picker has keyboard focus. If set
|
|
||||||
// to true, this method will steal focus away from whichever object currently
|
|
||||||
// has focus.
|
|
||||||
func (this *HSVAColorPicker) SetFocused (focused bool) {
|
|
||||||
this.box.SetFocused(focused)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Value returns the color of the picker.
|
// Value returns the color of the picker.
|
||||||
func (this *HSVAColorPicker) Value () color.Color {
|
func (this *HSVAColorPicker) Value () color.Color {
|
||||||
return this.value
|
return this.value
|
||||||
|
40
dropdown.go
40
dropdown.go
@ -6,12 +6,10 @@ import "git.tebibyte.media/tomo/tomo/input"
|
|||||||
import "git.tebibyte.media/tomo/tomo/event"
|
import "git.tebibyte.media/tomo/tomo/event"
|
||||||
import "git.tebibyte.media/tomo/objects/layouts"
|
import "git.tebibyte.media/tomo/objects/layouts"
|
||||||
|
|
||||||
var _ tomo.Object = new(Dropdown)
|
|
||||||
|
|
||||||
// Dropdown is a non-editable text input that allows the user to pick a value
|
// Dropdown is a non-editable text input that allows the user to pick a value
|
||||||
// from a list.
|
// from a list.
|
||||||
type Dropdown struct {
|
type Dropdown struct {
|
||||||
box tomo.ContainerBox
|
tomo.ContainerBox
|
||||||
label *Label
|
label *Label
|
||||||
|
|
||||||
value string
|
value string
|
||||||
@ -26,40 +24,28 @@ type Dropdown struct {
|
|||||||
// NewDropdown creates a new dropdown input with the specified items
|
// NewDropdown creates a new dropdown input with the specified items
|
||||||
func NewDropdown (items ...string) *Dropdown {
|
func NewDropdown (items ...string) *Dropdown {
|
||||||
dropdown := &Dropdown {
|
dropdown := &Dropdown {
|
||||||
box: tomo.NewContainerBox(),
|
ContainerBox: tomo.NewContainerBox(),
|
||||||
label: NewLabel(""),
|
label: NewLabel(""),
|
||||||
}
|
}
|
||||||
dropdown.box.SetRole(tomo.R("objects", "Dropdown"))
|
dropdown.SetRole(tomo.R("objects", "Dropdown"))
|
||||||
dropdown.box.SetAttr(tomo.ALayout(layouts.Row { true, false }))
|
dropdown.SetAttr(tomo.ALayout(layouts.Row { true, false }))
|
||||||
dropdown.box.Add(dropdown.label)
|
dropdown.Add(dropdown.label)
|
||||||
dropdown.box.Add(NewIcon(tomo.IconListChoose, tomo.IconSizeSmall))
|
dropdown.Add(NewIcon(tomo.IconListChoose, tomo.IconSizeSmall))
|
||||||
|
|
||||||
dropdown.SetItems(items...)
|
dropdown.SetItems(items...)
|
||||||
if len(items) > 0 {
|
if len(items) > 0 {
|
||||||
dropdown.SetValue(items[0])
|
dropdown.SetValue(items[0])
|
||||||
}
|
}
|
||||||
|
|
||||||
dropdown.box.SetInputMask(true)
|
dropdown.SetInputMask(true)
|
||||||
dropdown.box.OnButtonDown(dropdown.handleButtonDown)
|
dropdown.OnButtonDown(dropdown.handleButtonDown)
|
||||||
dropdown.box.OnButtonUp(dropdown.handleButtonUp)
|
dropdown.OnButtonUp(dropdown.handleButtonUp)
|
||||||
dropdown.box.OnKeyDown(dropdown.handleKeyDown)
|
dropdown.OnKeyDown(dropdown.handleKeyDown)
|
||||||
dropdown.box.OnKeyUp(dropdown.handleKeyUp)
|
dropdown.OnKeyUp(dropdown.handleKeyUp)
|
||||||
dropdown.box.SetFocusable(true)
|
dropdown.SetFocusable(true)
|
||||||
return dropdown
|
return dropdown
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetBox returns the underlying box.
|
|
||||||
func (this *Dropdown) GetBox () tomo.Box {
|
|
||||||
return this.box
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetFocused sets whether or not this dropdown has keyboard focus. If set to
|
|
||||||
// true, this method will steal focus away from whichever object currently has
|
|
||||||
// focus.
|
|
||||||
func (this *Dropdown) SetFocused (focused bool) {
|
|
||||||
this.box.SetFocused(focused)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Value returns the value of the dropdown. This does not necissarily have to be
|
// Value returns the value of the dropdown. This does not necissarily have to be
|
||||||
// in the list of items.
|
// in the list of items.
|
||||||
func (this *Dropdown) Value () string {
|
func (this *Dropdown) Value () string {
|
||||||
@ -121,7 +107,7 @@ func (this *Dropdown) handleButtonDown (button input.Button) bool {
|
|||||||
|
|
||||||
func (this *Dropdown) handleButtonUp (button input.Button) bool {
|
func (this *Dropdown) handleButtonUp (button input.Button) bool {
|
||||||
if !isClickingButton(button) { return false }
|
if !isClickingButton(button) { return false }
|
||||||
if this.box.Window().MousePosition().In(this.box.Bounds()) {
|
if this.Window().MousePosition().In(this.Bounds()) {
|
||||||
this.Choose()
|
this.Choose()
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
|
Loading…
Reference in New Issue
Block a user