Make value getters/setters more consistent

See #6
This commit is contained in:
2024-06-27 14:01:14 -04:00
parent d0ee6c432c
commit 638fc61d83
11 changed files with 128 additions and 105 deletions

View File

@@ -16,7 +16,7 @@ type Calendar struct {
monthLabel *Label
on struct {
edit event.FuncBroadcaster
valueChange event.FuncBroadcaster
}
}
@@ -33,13 +33,13 @@ func NewCalendar (tm time.Time) *Calendar {
prevButton.SetIcon(tomo.IconGoPrevious)
prevButton.OnClick(func () {
calendar.prevMonth()
calendar.on.edit.Broadcast()
calendar.on.valueChange.Broadcast()
})
nextButton := NewButton("")
nextButton.SetIcon(tomo.IconGoNext)
nextButton.OnClick(func () {
calendar.nextMonth()
calendar.on.edit.Broadcast()
calendar.on.valueChange.Broadcast()
})
calendar.monthLabel = NewLabel("")
calendar.monthLabel.SetAlign(tomo.AlignMiddle, tomo.AlignMiddle)
@@ -60,17 +60,22 @@ func NewCalendar (tm time.Time) *Calendar {
return calendar
}
// SetTime sets the date the calendar will display.
func (this *Calendar) SetTime (tm time.Time) {
// Value returns the time this calendar is displaying.
func (this *Calendar) Value () time.Time {
return this.time
}
// SetValue sets the date the calendar will display.
func (this *Calendar) SetValue (tm time.Time) {
if this.time == tm { return }
this.time = tm
this.refresh()
}
// OnEdit sets a function to be called when the user changes the date on the
// calendar.
func (this *Calendar) OnEdit (callback func ()) {
this.on.edit.Connect(callback)
// OnValueChange sets a function to be called when the user changes the date on
// the calendar.
func (this *Calendar) OnValueChange (callback func ()) {
this.on.valueChange.Connect(callback)
}
func (this *Calendar) prevMonth () {