From 866356dc3f4b9745ac7a8681a5e74c511712e221 Mon Sep 17 00:00:00 2001 From: Derek Reid Date: Wed, 1 Jun 2022 09:29:11 +0100 Subject: [PATCH 1/9] merge from main Manually merged --- calendarLayout.go | 100 ++++++++++++++++++++++++++++++++ home.go | 4 +- location.go | 141 ++++++++++++++++++++++++++++++++++++++++++---- 3 files changed, 231 insertions(+), 14 deletions(-) create mode 100644 calendarLayout.go diff --git a/calendarLayout.go b/calendarLayout.go new file mode 100644 index 0000000..9a09157 --- /dev/null +++ b/calendarLayout.go @@ -0,0 +1,100 @@ +package main + +import ( + "math" + + "fyne.io/fyne/v2" +) + +// Declare conformity with Layout interface +var ( + _ fyne.Layout = (*calendarLayout)(nil) + padding float32 = 0 + cellSize float64 = 32 +) + +type calendarLayout struct { + Cols int + vertical, adapt bool +} + +func NewCalendarLayout(s float64) fyne.Layout { + cellSize = s + return &calendarLayout{Cols: 7} +} + +func (g *calendarLayout) horizontal() bool { + if g.adapt { + return fyne.IsHorizontal(fyne.CurrentDevice().Orientation()) + } + + return !g.vertical +} + +func (g *calendarLayout) countRows(objects []fyne.CanvasObject) int { + count := 0 + for _, child := range objects { + if child.Visible() { + count++ + } + } + + return int(math.Ceil(float64(count) / float64(g.Cols))) +} + +// Get the leading (top or left) edge of a grid cell. +// size is the ideal cell size and the offset is which col or row its on. +func getLeading(size float64, offset int) float32 { + ret := (size + float64(padding)) * float64(offset) + + return float32(math.Round(ret)) +} + +// Get the trailing (bottom or right) edge of a grid cell. +// size is the ideal cell size and the offset is which col or row its on. +func getTrailing(size float64, offset int) float32 { + return getLeading(size, offset+1) - padding +} + +// Layout is called to pack all child objects into a specified size. +// For a GridLayout this will pack objects into a table format with the number +// of columns specified in our constructor. +func (g *calendarLayout) Layout(objects []fyne.CanvasObject, size fyne.Size) { + row, col := 0, 0 + i := 0 + for _, child := range objects { + if !child.Visible() { + continue + } + + x1 := getLeading(cellSize, col) + y1 := getLeading(cellSize, row) + x2 := getTrailing(cellSize, col) + y2 := getTrailing(cellSize, row) + + child.Move(fyne.NewPos(x1, y1)) + child.Resize(fyne.NewSize(x2-x1, y2-y1)) + + if g.horizontal() { + if (i+1)%g.Cols == 0 { + row++ + col = 0 + } else { + col++ + } + } else { + if (i+1)%g.Cols == 0 { + col++ + row = 0 + } else { + row++ + } + } + i++ + } +} + +func (g *calendarLayout) MinSize(objects []fyne.CanvasObject) fyne.Size { + rows := g.countRows(objects) + return fyne.NewSize(float32(cellSize+float64(padding))*7, float32(cellSize+float64(padding))*float32(rows)) +} diff --git a/home.go b/home.go index 083ea96..d98aabe 100644 --- a/home.go +++ b/home.go @@ -83,7 +83,7 @@ func (n *nomad) autoCompleteEntry(homeContainer *fyne.Container) *CompletionEntr n.store.list = append(n.store.list, c) n.store.save() - l := newLocation(c, n.session) + l := newLocation(c, n.session, n) homeContainer.Objects = append(homeContainer.Objects[:len(homeContainer.Objects)-1], l, homeContainer.Objects[len(homeContainer.Objects)-1]) } } @@ -106,7 +106,7 @@ func (n *nomad) makeHome() fyne.CanvasObject { cells := []fyne.CanvasObject{} for _, c := range n.store.cities() { - cells = append(cells, newLocation(c, n.session)) + cells = append(cells, newLocation(c, n.session, n)) } layout := &nomadLayout{} diff --git a/location.go b/location.go index db938e0..c9a50ef 100644 --- a/location.go +++ b/location.go @@ -3,7 +3,9 @@ package main import ( "fmt" "image/color" + "strconv" "strings" + "time" "fyne.io/fyne/v2" "fyne.io/fyne/v2/canvas" @@ -22,18 +24,126 @@ type location struct { location *city session *unsplashSession - date *widget.Select time *widget.SelectEntry button *widget.Button dots *fyne.Container + + selectedDay int + selectedMonth int + selectedYear int + + dateButton *widget.Button + monthLabel *widget.RichText + monthPrevious *widget.Button + monthNext *widget.Button + + dateContainer *fyne.Container + calendar *fyne.Container +} + +func daysOfMonth(l *location) []fyne.CanvasObject { + start, _ := time.Parse("2006-1-2", strconv.Itoa(l.selectedYear)+"-"+strconv.Itoa(l.selectedMonth)+"-"+strconv.Itoa(1)) + + buttons := []fyne.CanvasObject{} + + //account for Go time pkg starting on sunday at index 0 + dayIndex := int(start.Weekday()) + if dayIndex == 0 { + dayIndex += 7 + } + + //add spacers if week doesn't start on Monday + for i := 0; i < dayIndex-1; i++ { + buttons = append(buttons, layout.NewSpacer()) + } + + for d := start; d.Month() == start.Month(); d = d.AddDate(0, 0, 1) { + + s := fmt.Sprint(d.Day()) + var b fyne.CanvasObject = widget.NewButton(s, func() { + //functionality for task #12 "Change time using calendar and time picker affecting all city" + //to go here + fmt.Println("Date selected = "+s, d.Month(), d.Year()) + }) + + buttons = append(buttons, b) + } + + return buttons +} + +func monthYear(l *location) string { + return time.Month(l.selectedMonth).String() + " " + strconv.Itoa(l.selectedYear) +} + +func dayMonthYear(l *location) string { + d, _ := time.Parse("2006-1-2", strconv.Itoa(l.selectedYear)+"-"+strconv.Itoa(l.selectedMonth)+"-"+strconv.Itoa(l.selectedDay)) + return d.Weekday().String()[:3] + " " + d.Month().String() + " " + strconv.Itoa(d.Year()) +} + +func columnHeadings(textSize float32) []fyne.CanvasObject { + l := []fyne.CanvasObject{} + for i := 0; i < 7; i++ { + j := i + 1 + if j == 7 { + j = 0 + } + + var canvasObject fyne.CanvasObject = canvas.NewText(strings.ToUpper(time.Weekday(j).String()[:3]), color.NRGBA{0xFF, 0xFF, 0xFF, 0xBF}) + canvasObject.(*canvas.Text).TextSize = textSize + canvasObject.(*canvas.Text).Alignment = fyne.TextAlignCenter + l = append(l, canvasObject) + } + + return l +} + +func calendarObjects(l *location) []fyne.CanvasObject { + c := columnHeadings(8) + c = append(c, daysOfMonth(l)...) + + return c +} + +func navigation(l *location) { + + l.monthPrevious = widget.NewButtonWithIcon("", theme.NavigateBackIcon(), func() { + l.selectedMonth-- + if l.selectedMonth < 1 { + l.selectedMonth = 12 + l.selectedYear-- + } + l.monthLabel.ParseMarkdown(monthYear(l)) + + l.calendar.Objects = calendarObjects(l) + }) + l.monthNext = widget.NewButtonWithIcon("", theme.NavigateNextIcon(), func() { + l.selectedMonth++ + if l.selectedMonth > 12 { + l.selectedMonth = 1 + l.selectedYear++ + } + l.monthLabel.ParseMarkdown(monthYear(l)) + + l.calendar.Objects = calendarObjects(l) + }) + + l.monthLabel = widget.NewRichTextFromMarkdown(monthYear(l)) +} + +func calendar(l *location) { + l.calendar = container.New(NewCalendarLayout(32), calendarObjects(l)...) + + b := container.New(layout.NewBorderLayout(nil, nil, l.monthPrevious, l.monthNext), + l.monthPrevious, l.monthNext, container.NewCenter(l.monthLabel)) + + l.dateContainer = container.NewVBox(b, l.calendar) } -func newLocation(loc *city, session *unsplashSession) *location { +func newLocation(loc *city, session *unsplashSession, n *nomad) *location { l := &location{location: loc, session: session} l.ExtendBaseWidget(l) - l.date = widget.NewSelect([]string{}, func(string) {}) - l.date.PlaceHolder = loc.localTime.Format("Mon 02 Jan") l.time = widget.NewSelectEntry(listTimes()) l.time.PlaceHolder = "22:00" // longest l.time.Wrapping = fyne.TextWrapOff @@ -53,23 +163,30 @@ func newLocation(loc *city, session *unsplashSession) *location { l.dots = container.NewVBox(layout.NewSpacer(), l.button) + l.selectedDay = time.Now().Day() + l.selectedMonth = int(time.Now().Month()) + l.selectedYear = time.Now().Year() + + navigation(l) + calendar(l) + + l.dateButton = widget.NewButton(dayMonthYear(l), func() { + widget.ShowPopUpAtPosition(l.dateContainer, n.main.Canvas(), fyne.NewPos(0, l.Size().Height)) //wait for merge to use "homeContainer" for second object position + }) + return l } func (l *location) CreateRenderer() fyne.WidgetRenderer { bg := canvas.NewImageFromResource(theme.FileImageIcon()) bg.Translucency = 0.5 - city := widget.NewRichTextFromMarkdown("# " + strings.ToUpper(l.location.name)) - - location := canvas.NewText(" "+strings.ToUpper(l.location.country)+" · "+l.location.localTime.Format("MST"), locationTextColor) - location.TextStyle.Monospace = true - location.TextSize = 10 - location.Move(fyne.NewPos(theme.Padding(), city.MinSize().Height-location.TextSize*.5)) - input := container.NewBorder(nil, nil, l.date, l.time) + city := widget.NewRichTextFromMarkdown("# " + l.location.name) + location := widget.NewRichTextFromMarkdown("## " + l.location.country + " · " + l.location.localTime.Format("MST")) + input := container.NewBorder(nil, nil, l.dateButton, l.time) c := container.NewMax(bg, container.NewBorder(nil, - container.NewVBox(container.NewHBox(container.NewWithoutLayout(city, location), layout.NewSpacer(), l.dots), input), nil, nil)) + container.NewVBox(city, location, input), nil, nil)) go func() { if l.session == nil { From c9ad0a44cdf676e3797ea041b41f1e67e39b2bc9 Mon Sep 17 00:00:00 2001 From: Derek Reid Date: Wed, 1 Jun 2022 09:57:13 +0100 Subject: [PATCH 2/9] Menu dots --- location.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/location.go b/location.go index c9a50ef..b7af88d 100644 --- a/location.go +++ b/location.go @@ -184,9 +184,10 @@ func (l *location) CreateRenderer() fyne.WidgetRenderer { location := widget.NewRichTextFromMarkdown("## " + l.location.country + " · " + l.location.localTime.Format("MST")) input := container.NewBorder(nil, nil, l.dateButton, l.time) + locationAndDots := container.NewBorder(nil, nil, location, l.dots) c := container.NewMax(bg, container.NewBorder(nil, - container.NewVBox(city, location, input), nil, nil)) + container.NewVBox(city, locationAndDots, input), nil, nil)) go func() { if l.session == nil { From 65aff203f4b864af40b568788f146aa2ae2174e1 Mon Sep 17 00:00:00 2001 From: Derek Reid Date: Wed, 1 Jun 2022 10:06:36 +0100 Subject: [PATCH 3/9] removed comment --- location.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/location.go b/location.go index b7af88d..79ba9d6 100644 --- a/location.go +++ b/location.go @@ -171,7 +171,7 @@ func newLocation(loc *city, session *unsplashSession, n *nomad) *location { calendar(l) l.dateButton = widget.NewButton(dayMonthYear(l), func() { - widget.ShowPopUpAtPosition(l.dateContainer, n.main.Canvas(), fyne.NewPos(0, l.Size().Height)) //wait for merge to use "homeContainer" for second object position + widget.ShowPopUpAtPosition(l.dateContainer, n.main.Canvas(), fyne.NewPos(0, l.Size().Height)) }) return l From c3c1fd4975816a729e2a85c31db8c2b1a5f3334c Mon Sep 17 00:00:00 2001 From: Derek Reid Date: Wed, 1 Jun 2022 10:23:44 +0100 Subject: [PATCH 4/9] Text alignment --- location.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/location.go b/location.go index 79ba9d6..6c6821c 100644 --- a/location.go +++ b/location.go @@ -181,13 +181,15 @@ func (l *location) CreateRenderer() fyne.WidgetRenderer { bg := canvas.NewImageFromResource(theme.FileImageIcon()) bg.Translucency = 0.5 city := widget.NewRichTextFromMarkdown("# " + l.location.name) - location := widget.NewRichTextFromMarkdown("## " + l.location.country + " · " + l.location.localTime.Format("MST")) - + location := canvas.NewText(" "+strings.ToUpper(l.location.country)+" · "+l.location.localTime.Format("MST"), locationTextColor) + location.TextStyle.Monospace = true + location.TextSize = 10 + location.Move(fyne.NewPos(theme.Padding(), city.MinSize().Height-location.TextSize*.5)) input := container.NewBorder(nil, nil, l.dateButton, l.time) - locationAndDots := container.NewBorder(nil, nil, location, l.dots) + c := container.NewMax(bg, container.NewBorder(nil, - container.NewVBox(city, locationAndDots, input), nil, nil)) + container.NewVBox(container.NewHBox(container.NewWithoutLayout(city, location), layout.NewSpacer(), l.dots), input), nil, nil)) go func() { if l.session == nil { From 95989bce4f69c8e7d3012601c71c63bded9e9c48 Mon Sep 17 00:00:00 2001 From: Derek Reid Date: Thu, 2 Jun 2022 14:20:25 +0100 Subject: [PATCH 5/9] calendar widget --- calendar.go | 139 ++++++++++++++++++++++++++++++++++++++++++++++++++++ location.go | 125 +++------------------------------------------- 2 files changed, 145 insertions(+), 119 deletions(-) create mode 100644 calendar.go diff --git a/calendar.go b/calendar.go new file mode 100644 index 0000000..6d121d6 --- /dev/null +++ b/calendar.go @@ -0,0 +1,139 @@ +package main + +import ( + "fmt" + "image/color" + "strconv" + "strings" + "time" + + "fyne.io/fyne/v2" + "fyne.io/fyne/v2/canvas" + "fyne.io/fyne/v2/container" + "fyne.io/fyne/v2/layout" + "fyne.io/fyne/v2/theme" + "fyne.io/fyne/v2/widget" +) + +type calendar struct { + widget.BaseWidget + + monthPrevious *widget.Button + monthNext *widget.Button + monthLabel *widget.RichText + + day int + month int + year int + + dates *fyne.Container +} + +func daysOfMonth(c *calendar) []fyne.CanvasObject { + start, _ := time.Parse("2006-1-2", strconv.Itoa(c.year)+"-"+strconv.Itoa(c.month)+"-"+strconv.Itoa(1)) + + buttons := []fyne.CanvasObject{} + + //account for Go time pkg starting on sunday at index 0 + dayIndex := int(start.Weekday()) + if dayIndex == 0 { + dayIndex += 7 + } + + //add spacers if week doesn't start on Monday + for i := 0; i < dayIndex-1; i++ { + buttons = append(buttons, layout.NewSpacer()) + } + + for d := start; d.Month() == start.Month(); d = d.AddDate(0, 0, 1) { + + s := fmt.Sprint(d.Day()) + var b fyne.CanvasObject = widget.NewButton(s, func() { + //functionality for task #12 "Change time using calendar and time picker affecting all city" + //to go here + fmt.Println("Date selected = "+s, c.month, c.year) + }) + + buttons = append(buttons, b) + } + + return buttons +} + +func monthYear(c *calendar) string { + return time.Month(c.month).String() + " " + strconv.Itoa(c.year) +} + +func dayMonthYear(c *calendar) string { + d, _ := time.Parse("2006-1-2", strconv.Itoa(c.year)+"-"+strconv.Itoa(c.month)+"-"+strconv.Itoa(c.day)) + return d.Weekday().String()[:3] + " " + d.Month().String() + " " + strconv.Itoa(d.Year()) +} + +func columnHeadings(textSize float32) []fyne.CanvasObject { + l := []fyne.CanvasObject{} + for i := 0; i < 7; i++ { + j := i + 1 + if j == 7 { + j = 0 + } + + var canvasObject fyne.CanvasObject = canvas.NewText(strings.ToUpper(time.Weekday(j).String()[:3]), color.NRGBA{0xFF, 0xFF, 0xFF, 0xBF}) + canvasObject.(*canvas.Text).TextSize = textSize + canvasObject.(*canvas.Text).Alignment = fyne.TextAlignCenter + l = append(l, canvasObject) + } + + return l +} + +func calendarObjects(c *calendar) []fyne.CanvasObject { + cH := columnHeadings(8) + cH = append(cH, daysOfMonth(c)...) + + return cH +} + +func (c *calendar) CreateRenderer() fyne.WidgetRenderer { + + c.monthPrevious = widget.NewButtonWithIcon("", theme.NavigateBackIcon(), func() { + c.month-- + if c.month < 1 { + c.month = 12 + c.year-- + } + c.monthLabel.ParseMarkdown(monthYear(c)) + + c.dates.Objects = calendarObjects(c) + }) + c.monthNext = widget.NewButtonWithIcon("", theme.NavigateNextIcon(), func() { + c.month++ + if c.month > 12 { + c.month = 1 + c.year++ + } + c.monthLabel.ParseMarkdown(monthYear(c)) + + c.dates.Objects = calendarObjects(c) + }) + + c.monthLabel = widget.NewRichTextFromMarkdown(monthYear(c)) + + cH := columnHeadings(8) + cH = append(cH, daysOfMonth(c)...) + + nav := container.New(layout.NewBorderLayout(nil, nil, c.monthPrevious, c.monthNext), + c.monthPrevious, c.monthNext, container.NewCenter(c.monthLabel)) + + c.dates = container.New(NewCalendarLayout(32), cH...) + + dateContainer := container.NewVBox(nav, c.dates) + return widget.NewSimpleRenderer(dateContainer) +} + +func newCalendar() *calendar { + + c := &calendar{day: time.Now().Day(), month: int(time.Now().Month()), year: time.Now().Year()} + c.ExtendBaseWidget(c) + + return c +} diff --git a/location.go b/location.go index 6c6821c..91a2bf5 100644 --- a/location.go +++ b/location.go @@ -3,9 +3,7 @@ package main import ( "fmt" "image/color" - "strconv" "strings" - "time" "fyne.io/fyne/v2" "fyne.io/fyne/v2/canvas" @@ -28,116 +26,9 @@ type location struct { button *widget.Button dots *fyne.Container - selectedDay int - selectedMonth int - selectedYear int + dateButton *widget.Button - dateButton *widget.Button - monthLabel *widget.RichText - monthPrevious *widget.Button - monthNext *widget.Button - - dateContainer *fyne.Container - calendar *fyne.Container -} - -func daysOfMonth(l *location) []fyne.CanvasObject { - start, _ := time.Parse("2006-1-2", strconv.Itoa(l.selectedYear)+"-"+strconv.Itoa(l.selectedMonth)+"-"+strconv.Itoa(1)) - - buttons := []fyne.CanvasObject{} - - //account for Go time pkg starting on sunday at index 0 - dayIndex := int(start.Weekday()) - if dayIndex == 0 { - dayIndex += 7 - } - - //add spacers if week doesn't start on Monday - for i := 0; i < dayIndex-1; i++ { - buttons = append(buttons, layout.NewSpacer()) - } - - for d := start; d.Month() == start.Month(); d = d.AddDate(0, 0, 1) { - - s := fmt.Sprint(d.Day()) - var b fyne.CanvasObject = widget.NewButton(s, func() { - //functionality for task #12 "Change time using calendar and time picker affecting all city" - //to go here - fmt.Println("Date selected = "+s, d.Month(), d.Year()) - }) - - buttons = append(buttons, b) - } - - return buttons -} - -func monthYear(l *location) string { - return time.Month(l.selectedMonth).String() + " " + strconv.Itoa(l.selectedYear) -} - -func dayMonthYear(l *location) string { - d, _ := time.Parse("2006-1-2", strconv.Itoa(l.selectedYear)+"-"+strconv.Itoa(l.selectedMonth)+"-"+strconv.Itoa(l.selectedDay)) - return d.Weekday().String()[:3] + " " + d.Month().String() + " " + strconv.Itoa(d.Year()) -} - -func columnHeadings(textSize float32) []fyne.CanvasObject { - l := []fyne.CanvasObject{} - for i := 0; i < 7; i++ { - j := i + 1 - if j == 7 { - j = 0 - } - - var canvasObject fyne.CanvasObject = canvas.NewText(strings.ToUpper(time.Weekday(j).String()[:3]), color.NRGBA{0xFF, 0xFF, 0xFF, 0xBF}) - canvasObject.(*canvas.Text).TextSize = textSize - canvasObject.(*canvas.Text).Alignment = fyne.TextAlignCenter - l = append(l, canvasObject) - } - - return l -} - -func calendarObjects(l *location) []fyne.CanvasObject { - c := columnHeadings(8) - c = append(c, daysOfMonth(l)...) - - return c -} - -func navigation(l *location) { - - l.monthPrevious = widget.NewButtonWithIcon("", theme.NavigateBackIcon(), func() { - l.selectedMonth-- - if l.selectedMonth < 1 { - l.selectedMonth = 12 - l.selectedYear-- - } - l.monthLabel.ParseMarkdown(monthYear(l)) - - l.calendar.Objects = calendarObjects(l) - }) - l.monthNext = widget.NewButtonWithIcon("", theme.NavigateNextIcon(), func() { - l.selectedMonth++ - if l.selectedMonth > 12 { - l.selectedMonth = 1 - l.selectedYear++ - } - l.monthLabel.ParseMarkdown(monthYear(l)) - - l.calendar.Objects = calendarObjects(l) - }) - - l.monthLabel = widget.NewRichTextFromMarkdown(monthYear(l)) -} - -func calendar(l *location) { - l.calendar = container.New(NewCalendarLayout(32), calendarObjects(l)...) - - b := container.New(layout.NewBorderLayout(nil, nil, l.monthPrevious, l.monthNext), - l.monthPrevious, l.monthNext, container.NewCenter(l.monthLabel)) - - l.dateContainer = container.NewVBox(b, l.calendar) + calendar *calendar } func newLocation(loc *city, session *unsplashSession, n *nomad) *location { @@ -163,15 +54,11 @@ func newLocation(loc *city, session *unsplashSession, n *nomad) *location { l.dots = container.NewVBox(layout.NewSpacer(), l.button) - l.selectedDay = time.Now().Day() - l.selectedMonth = int(time.Now().Month()) - l.selectedYear = time.Now().Year() - - navigation(l) - calendar(l) + l.calendar = newCalendar() - l.dateButton = widget.NewButton(dayMonthYear(l), func() { - widget.ShowPopUpAtPosition(l.dateContainer, n.main.Canvas(), fyne.NewPos(0, l.Size().Height)) + l.dateButton = widget.NewButton(dayMonthYear(l.calendar), func() { + //widget.ShowPopUpAtPosition(l.dateContainer, n.main.Canvas(), fyne.NewPos(0, l.Size().Height)) + widget.ShowPopUpAtPosition(l.calendar, n.main.Canvas(), fyne.NewPos(0, l.Size().Height)) //newCalendarPopAtPos }) return l From c060c2463bf1ff46e8224863c8c6d2fa9db17ec7 Mon Sep 17 00:00:00 2001 From: Derek Reid Date: Thu, 2 Jun 2022 14:42:30 +0100 Subject: [PATCH 6/9] newCalendarPopUpAtPos added --- calendar.go | 11 +++++++---- location.go | 3 +-- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/calendar.go b/calendar.go index 6d121d6..760e2b3 100644 --- a/calendar.go +++ b/calendar.go @@ -21,6 +21,7 @@ type calendar struct { monthPrevious *widget.Button monthNext *widget.Button monthLabel *widget.RichText + canvas fyne.Canvas day int month int @@ -93,6 +94,11 @@ func calendarObjects(c *calendar) []fyne.CanvasObject { return cH } +func newCalendarPopUpAtPos(c *calendar, canvas fyne.Canvas, pos fyne.Position) { + c.canvas = canvas + widget.ShowPopUpAtPosition(c, canvas, pos) +} + func (c *calendar) CreateRenderer() fyne.WidgetRenderer { c.monthPrevious = widget.NewButtonWithIcon("", theme.NavigateBackIcon(), func() { @@ -118,13 +124,10 @@ func (c *calendar) CreateRenderer() fyne.WidgetRenderer { c.monthLabel = widget.NewRichTextFromMarkdown(monthYear(c)) - cH := columnHeadings(8) - cH = append(cH, daysOfMonth(c)...) - nav := container.New(layout.NewBorderLayout(nil, nil, c.monthPrevious, c.monthNext), c.monthPrevious, c.monthNext, container.NewCenter(c.monthLabel)) - c.dates = container.New(NewCalendarLayout(32), cH...) + c.dates = container.New(NewCalendarLayout(32), calendarObjects(c)...) dateContainer := container.NewVBox(nav, c.dates) return widget.NewSimpleRenderer(dateContainer) diff --git a/location.go b/location.go index 91a2bf5..ce5320d 100644 --- a/location.go +++ b/location.go @@ -57,8 +57,7 @@ func newLocation(loc *city, session *unsplashSession, n *nomad) *location { l.calendar = newCalendar() l.dateButton = widget.NewButton(dayMonthYear(l.calendar), func() { - //widget.ShowPopUpAtPosition(l.dateContainer, n.main.Canvas(), fyne.NewPos(0, l.Size().Height)) - widget.ShowPopUpAtPosition(l.calendar, n.main.Canvas(), fyne.NewPos(0, l.Size().Height)) //newCalendarPopAtPos + newCalendarPopUpAtPos(l.calendar, n.main.Canvas(), fyne.NewPos(0, l.Size().Height)) }) return l From 29d3251d23d3c2e3be199e807f32bd3d3f2b35d4 Mon Sep 17 00:00:00 2001 From: Derek Reid Date: Thu, 2 Jun 2022 14:44:08 +0100 Subject: [PATCH 7/9] Hide overlay on selection --- calendar.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/calendar.go b/calendar.go index 760e2b3..6f3aea3 100644 --- a/calendar.go +++ b/calendar.go @@ -50,6 +50,10 @@ func daysOfMonth(c *calendar) []fyne.CanvasObject { s := fmt.Sprint(d.Day()) var b fyne.CanvasObject = widget.NewButton(s, func() { + + overlayList := c.canvas.Overlays().List() + overlayList[0].Hide() + //functionality for task #12 "Change time using calendar and time picker affecting all city" //to go here fmt.Println("Date selected = "+s, c.month, c.year) From f281b2c90c6758a0096517f6639a31a359b3713f Mon Sep 17 00:00:00 2001 From: Derek Reid Date: Thu, 2 Jun 2022 15:21:38 +0100 Subject: [PATCH 8/9] Align date button This will matter when the text changes --- location.go | 1 + 1 file changed, 1 insertion(+) diff --git a/location.go b/location.go index ce5320d..5c54a9d 100644 --- a/location.go +++ b/location.go @@ -59,6 +59,7 @@ func newLocation(loc *city, session *unsplashSession, n *nomad) *location { l.dateButton = widget.NewButton(dayMonthYear(l.calendar), func() { newCalendarPopUpAtPos(l.calendar, n.main.Canvas(), fyne.NewPos(0, l.Size().Height)) }) + l.dateButton.Alignment = widget.ButtonAlignLeading return l } From a6aa124271c8d7fe3c145d47d04c0f4638a26e43 Mon Sep 17 00:00:00 2001 From: Derek Reid Date: Thu, 2 Jun 2022 18:35:51 +0100 Subject: [PATCH 9/9] Narrowed parameter scope --- home.go | 4 ++-- location.go | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/home.go b/home.go index d98aabe..07f3280 100644 --- a/home.go +++ b/home.go @@ -83,7 +83,7 @@ func (n *nomad) autoCompleteEntry(homeContainer *fyne.Container) *CompletionEntr n.store.list = append(n.store.list, c) n.store.save() - l := newLocation(c, n.session, n) + l := newLocation(c, n.session, n.main.Canvas()) homeContainer.Objects = append(homeContainer.Objects[:len(homeContainer.Objects)-1], l, homeContainer.Objects[len(homeContainer.Objects)-1]) } } @@ -106,7 +106,7 @@ func (n *nomad) makeHome() fyne.CanvasObject { cells := []fyne.CanvasObject{} for _, c := range n.store.cities() { - cells = append(cells, newLocation(c, n.session, n)) + cells = append(cells, newLocation(c, n.session, n.main.Canvas())) } layout := &nomadLayout{} diff --git a/location.go b/location.go index 5c54a9d..48fc118 100644 --- a/location.go +++ b/location.go @@ -31,7 +31,7 @@ type location struct { calendar *calendar } -func newLocation(loc *city, session *unsplashSession, n *nomad) *location { +func newLocation(loc *city, session *unsplashSession, canvas fyne.Canvas) *location { l := &location{location: loc, session: session} l.ExtendBaseWidget(l) @@ -57,7 +57,7 @@ func newLocation(loc *city, session *unsplashSession, n *nomad) *location { l.calendar = newCalendar() l.dateButton = widget.NewButton(dayMonthYear(l.calendar), func() { - newCalendarPopUpAtPos(l.calendar, n.main.Canvas(), fyne.NewPos(0, l.Size().Height)) + newCalendarPopUpAtPos(l.calendar, canvas, fyne.NewPos(0, l.Size().Height)) }) l.dateButton.Alignment = widget.ButtonAlignLeading