• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

fyne-io / fyne / 27502714592

14 Jun 2026 07:16AM UTC coverage: 60.153% (-0.03%) from 60.178%
27502714592

Pull #6361

github

toaster
[.github/workflows] remove linters which are already part of golangci-lint
Pull Request #6361: use golangci-lint to run multiple linters

84 of 143 new or added lines in 38 files covered. (58.74%)

3 existing lines in 2 files now uncovered.

26803 of 44558 relevant lines covered (60.15%)

674.84 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/widget/date_entry.go
1
package widget
2

3
import (
4
        "time"
5

6
        "fyne.io/fyne/v2"
7
        "fyne.io/fyne/v2/theme"
8
)
9

10
var (
11
        _ fyne.Widget      = (*DateEntry)(nil)
12
        _ fyne.Tappable    = (*DateEntry)(nil)
13
        _ fyne.Disableable = (*DateEntry)(nil)
14
)
15

16
// DateEntry is an input field which supports selecting from a fixed set of options.
17
//
18
// Since: 2.6
19
type DateEntry struct {
20
        Entry
21
        Date      *time.Time
22
        OnChanged func(*time.Time) `json:"-"`
23

24
        dropDown *Calendar
25
        popUp    *PopUp
26
}
27

28
// NewDateEntry creates a date input where the date can be selected or typed.
29
//
30
// Since: 2.6
31
func NewDateEntry() *DateEntry {
×
32
        e := &DateEntry{}
×
33
        e.ExtendBaseWidget(e)
×
34
        e.Wrapping = fyne.TextWrap(fyne.TextTruncateClip)
×
35
        return e
×
36
}
×
37

38
// CreateRenderer returns a new renderer for this select entry.
39
func (e *DateEntry) CreateRenderer() fyne.WidgetRenderer {
×
40
        e.ExtendBaseWidget(e)
×
41

×
42
        dateFormat := getLocaleDateFormat()
×
43
        e.Validator = func(in string) error {
×
44
                _, err := time.Parse(dateFormat, in)
×
45
                return err
×
46
        }
×
47
        e.Entry.OnChanged = func(in string) {
×
48
                if in == "" {
×
49
                        e.Date = nil
×
50

×
51
                        if f := e.OnChanged; f != nil {
×
52
                                f(nil)
×
53
                        }
×
54
                }
55
                t, err := time.Parse(dateFormat, in)
×
56
                if err != nil {
×
57
                        return
×
58
                }
×
59

60
                e.Date = &t
×
61

×
62
                if f := e.OnChanged; f != nil {
×
63
                        f(&t)
×
64
                }
×
65
        }
66

67
        if e.ActionItem == nil {
×
68
                e.ActionItem = e.setupDropDown()
×
69
                if e.Disabled() {
×
70
                        e.ActionItem.(fyne.Disableable).Disable()
×
71
                }
×
72
        }
73

74
        return e.Entry.CreateRenderer()
×
75
}
76

77
// Enable this widget, updating any style or features appropriately.
78
func (e *DateEntry) Enable() {
×
79
        if e.ActionItem != nil {
×
80
                if d, ok := e.ActionItem.(fyne.Disableable); ok {
×
81
                        d.Enable()
×
82
                }
×
83
        }
84
        e.Entry.Enable()
×
85
}
86

87
// Disable this widget so that it cannot be interacted with, updating any style appropriately.
88
func (e *DateEntry) Disable() {
×
89
        if e.ActionItem != nil {
×
90
                if d, ok := e.ActionItem.(fyne.Disableable); ok {
×
91
                        d.Disable()
×
92
                }
×
93
        }
94
        e.Entry.Disable()
×
95
}
96

97
// MinSize returns the minimal size of the select entry.
98
func (e *DateEntry) MinSize() fyne.Size {
×
99
        e.ExtendBaseWidget(e)
×
100
        return e.Entry.MinSize()
×
101
}
×
102

103
// Move changes the relative position of the date entry.
104
func (e *DateEntry) Move(pos fyne.Position) {
×
105
        e.Entry.Move(pos)
×
106
        if e.popUp != nil {
×
107
                e.popUp.Move(e.popUpPos())
×
108
        }
×
109
}
110

111
// Resize changes the size of the date entry.
112
func (e *DateEntry) Resize(size fyne.Size) {
×
113
        e.Entry.Resize(size)
×
114
        if e.popUp != nil {
×
115
                e.popUp.Resize(fyne.NewSize(size.Width, e.popUp.Size().Height))
×
116
        }
×
117
}
118

119
// SetDate will update the widget to a specific date.
120
// You can pass nil to unselect a date.
121
func (e *DateEntry) SetDate(d *time.Time) {
×
122
        if d == nil {
×
123
                e.Date = nil
×
NEW
124
                e.SetText("")
×
125

×
126
                return
×
127
        }
×
128

129
        e.setDate(*d)
×
130
}
131

132
func (e *DateEntry) popUpPos() fyne.Position {
×
133
        entryPos := fyne.CurrentApp().Driver().AbsolutePositionForObject(e.super())
×
134
        return entryPos.Add(fyne.NewPos(0, e.Size().Height-e.Theme().Size(theme.SizeNameInputBorder)))
×
135
}
×
136

137
func (e *DateEntry) setDate(d time.Time) {
×
138
        e.Date = &d
×
139
        if e.popUp != nil {
×
140
                e.popUp.Hide()
×
141
        }
×
142

NEW
143
        e.SetText(d.Format(getLocaleDateFormat()))
×
144
}
145

146
func (e *DateEntry) setupDropDown() *Button {
×
147
        if e.dropDown == nil {
×
148
                e.dropDown = NewCalendar(time.Now(), e.setDate)
×
149
        }
×
150
        dropDownButton := NewButton("", func() {
×
151
                c := fyne.CurrentApp().Driver().CanvasForObject(e.super())
×
152
                if c == nil {
×
153
                        // DateEntry detached from its canvas; cannot host calendar
×
154
                        // dropdown (see fyne-io/fyne#5965).
×
155
                        return
×
156
                }
×
157

158
                e.popUp = NewPopUp(e.dropDown, c)
×
159
                e.popUp.ShowAtPosition(e.popUpPos())
×
160
                e.popUp.Resize(fyne.NewSize(e.Size().Width, e.popUp.MinSize().Height))
×
161
        })
162
        dropDownButton.Importance = LowImportance
×
163
        dropDownButton.SetIcon(e.Theme().Icon(theme.IconNameCalendar))
×
164
        return dropDownButton
×
165
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc