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 Dec 14, 2023
1 parent 82ec7ad commit 01a67ed
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 @@ -432,10 +432,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 @@ -14,7 +14,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 @@ -25,7 +25,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 @@ -39,7 +39,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 @@ -51,7 +51,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 Down Expand Up @@ -86,7 +86,7 @@ func TestNewCalendar_Resize(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 @@ -108,7 +108,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 @@ -150,7 +151,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 01a67ed

Please sign in to comment.