MCPcopy Create free account
hub / github.com/efogdev/mpris-timer / NewSidebar

Function NewSidebar

internal/ui/ui.go:155–265  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

153}
154
155func NewSidebar() *adw.NavigationPage {
156 sidebar := adw.NewNavigationPage(gtk.NewBox(gtk.OrientationVertical, 0), "Presets")
157 sidebar.SetOverflow(gtk.OverflowHidden)
158
159 flowBox = gtk.NewFlowBox()
160 flowBox.SetHomogeneous(true)
161 flowBox.SetMinChildrenPerLine(1)
162 flowBox.SetMaxChildrenPerLine(3)
163 flowBox.SetSelectionMode(gtk.SelectionBrowse)
164 flowBox.SetVAlign(gtk.AlignCenter)
165 flowBox.SetColumnSpacing(16)
166 flowBox.SetRowSpacing(16)
167 flowBox.AddCSSClass("flow-box")
168
169 for idx, preset := range core.UserPrefs.Presets {
170 label := gtk.NewLabel(preset)
171 label.SetCursorFromName("pointer")
172 label.AddCSSClass("preset-lbl")
173 label.SetHAlign(gtk.AlignCenter)
174 label.SetVAlign(gtk.AlignCenter)
175 flowBox.Append(label)
176
177 onActivate := func() {
178 time := core.TimeFromPreset(preset)
179
180 if hrsLabel == nil || minLabel == nil || secLabel == nil {
181 return
182 }
183
184 hrsLabel.SetText(core.NumToLabelText(time.Hour()))
185 minLabel.SetText(core.NumToLabelText(time.Minute()))
186 secLabel.SetText(core.NumToLabelText(time.Second()))
187
188 if core.UserPrefs.StartPresetOnClick && initComplete {
189 core.Overrides.Duration = time.Hour()*60*60 + time.Minute()*60 + time.Second()
190 saveSize()
191 win.Close()
192 return
193 } else {
194 startBtn.SetCanFocus(true)
195 startBtn.GrabFocus()
196 }
197 }
198
199 mouseCtrl := gtk.NewGestureClick()
200 mouseCtrl.ConnectReleased(func(nPress int, x, y float64) {
201 onActivate()
202 })
203
204 child := flowBox.ChildAtIndex(idx)
205 child.ConnectActivate(onActivate)
206 child.AddController(mouseCtrl)
207
208 if preset == core.UserPrefs.DefaultPreset {
209 flowBox.SelectChild(child)
210 initialPreset = child
211 }
212

Callers 1

NewTimePickerFunction · 0.85

Calls 7

TimeFromPresetFunction · 0.92
NumToLabelTextFunction · 0.92
IsGdkKeyvalNumberFunction · 0.92
ParseKeyvalFunction · 0.92
saveSizeFunction · 0.85
getMinHeightFunction · 0.85
GdkKeyvalsMethod · 0.80

Tested by

no test coverage detected