Skip to content

Commit

Permalink
Default to single mode in calendar constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
PucklaJ committed Jul 17, 2023
1 parent 51508d7 commit 4ab0187
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
2 changes: 1 addition & 1 deletion cmd/calendar_demo/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func main() {

// Defines which date you would like the calendar to start
startingDate := time.Now()
calendar := xwidget.NewCalendar(startingDate, xwidget.CalendarSingle, d.onChanged)
calendar := xwidget.NewCalendar(startingDate, d.onChanged)

selection := widget.NewRadioGroup([]string{"Single", "Multi", "Range"}, func(s string) {
calendar.ClearSelection()
Expand Down
4 changes: 2 additions & 2 deletions widget/calendar.go
Original file line number Diff line number Diff line change
Expand Up @@ -416,10 +416,10 @@ func (c *Calendar) CreateRenderer() fyne.WidgetRenderer {
}

// NewCalendar creates a calendar instance
func NewCalendar(cT time.Time, selectionMode int, onChanged func([]time.Time)) *Calendar {
func NewCalendar(cT time.Time, onChanged func([]time.Time)) *Calendar {
c := &Calendar{
currentTime: cT,
SelectionMode: selectionMode,
SelectionMode: CalendarSingle,
OnChanged: onChanged,
}

Expand Down
16 changes: 9 additions & 7 deletions widget/calendar_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (

func TestNewCalendar(t *testing.T) {
now := time.Now()
c := NewCalendar(now, CalendarSingle, nil)
c := NewCalendar(now, nil)
assert.Equal(t, now.Day(), c.currentTime.Day())
assert.Equal(t, int(now.Month()), int(c.currentTime.Month()))
assert.Equal(t, now.Year(), c.currentTime.Year())
Expand All @@ -24,7 +24,7 @@ func TestNewCalendar(t *testing.T) {

func TestNewCalendar_ButtonDate(t *testing.T) {
date := time.Now()
c := NewCalendar(date, CalendarSingle, nil)
c := NewCalendar(date, nil)
_ = test.WidgetRenderer(c) // and render

endNextMonth := date.AddDate(0, 1, 0).AddDate(0, 0, -(date.Day() - 1))
Expand All @@ -38,7 +38,7 @@ func TestNewCalendar_ButtonDate(t *testing.T) {

func TestNewCalendar_Next(t *testing.T) {
date := time.Now()
c := NewCalendar(date, CalendarSingle, nil)
c := NewCalendar(date, nil)
_ = test.WidgetRenderer(c) // and render

assert.Equal(t, date.Format("January 2006"), c.monthLabel.Text)
Expand All @@ -50,7 +50,7 @@ func TestNewCalendar_Next(t *testing.T) {

func TestNewCalendar_Previous(t *testing.T) {
date := time.Now()
c := NewCalendar(date, CalendarSingle, nil)
c := NewCalendar(date, nil)
_ = test.WidgetRenderer(c) // and render

assert.Equal(t, date.Format("January 2006"), c.monthLabel.Text)
Expand All @@ -62,7 +62,7 @@ func TestNewCalendar_Previous(t *testing.T) {

func TestNewCalendar_Single(t *testing.T) {
date := time.Date(2023, time.June, 22, 13, 48, 45, 0, time.UTC)
c := NewCalendar(date, CalendarSingle, nil)
c := NewCalendar(date, nil)
_ = test.WidgetRenderer(c) // and render

btn := getDateButton(c.dates, 14)
Expand All @@ -84,7 +84,8 @@ func TestNewCalendar_Single(t *testing.T) {

func TestNewCalendar_Multi(t *testing.T) {
date := time.Date(2023, time.June, 22, 13, 48, 45, 0, time.UTC)
c := NewCalendar(date, CalendarMulti, nil)
c := NewCalendar(date, nil)
c.SelectionMode = CalendarMulti
_ = test.WidgetRenderer(c) // and render

test.Tap(getDateButton(c.dates, 4))
Expand Down Expand Up @@ -126,7 +127,8 @@ func TestNewCalendar_Multi(t *testing.T) {

func TestNewCalendar_Range(t *testing.T) {
date := time.Date(2023, time.June, 22, 13, 48, 45, 0, time.UTC)
c := NewCalendar(date, CalendarRange, nil)
c := NewCalendar(date, nil)
c.SelectionMode = CalendarRange
_ = test.WidgetRenderer(c) // and render

test.Tap(getDateButton(c.dates, 5))
Expand Down

0 comments on commit 4ab0187

Please sign in to comment.