()
| 312 | func (ti *TimeInput) WidgetValue() any { return &ti.Time } |
| 313 | |
| 314 | func (ti *TimeInput) Init() { |
| 315 | ti.Frame.Init() |
| 316 | |
| 317 | style := func(s *styles.Style) { |
| 318 | s.Min.X.Em(8) |
| 319 | s.Max.X.Em(10) |
| 320 | if ti.IsReadOnly() { // must inherit abilities when read only for table |
| 321 | s.Abilities = ti.Styles.Abilities |
| 322 | } |
| 323 | } |
| 324 | |
| 325 | tree.AddChild(ti, func(w *TextField) { |
| 326 | w.SetTooltip("The date") |
| 327 | w.SetLeadingIcon(icons.CalendarToday, func(e events.Event) { |
| 328 | d := NewBody().AddTitle("Select date") |
| 329 | dp := NewDatePicker(d).SetTime(ti.Time) |
| 330 | d.AddBottomBar(func(parent Widget) { |
| 331 | d.AddCancel(parent) |
| 332 | d.AddOK(parent).OnClick(func(e events.Event) { |
| 333 | ti.Time = dp.Time |
| 334 | ti.UpdateChange() |
| 335 | }) |
| 336 | }) |
| 337 | d.RunDialog(w) |
| 338 | }) |
| 339 | w.Styler(style) |
| 340 | w.Updater(func() { |
| 341 | w.SetReadOnly(ti.IsReadOnly()) |
| 342 | w.SetText(ti.Time.Format("1/2/2006")) |
| 343 | }) |
| 344 | w.SetValidator(func() error { |
| 345 | d, err := time.Parse("1/2/2006", w.Text()) |
| 346 | if err != nil { |
| 347 | return err |
| 348 | } |
| 349 | // new date and old time |
| 350 | ti.Time = time.Date(d.Year(), d.Month(), d.Day(), ti.Time.Hour(), ti.Time.Minute(), ti.Time.Second(), ti.Time.Nanosecond(), ti.Time.Location()) |
| 351 | ti.SendChange() |
| 352 | return nil |
| 353 | }) |
| 354 | }) |
| 355 | |
| 356 | tree.AddChild(ti, func(w *TextField) { |
| 357 | w.SetTooltip("The time") |
| 358 | w.SetLeadingIcon(icons.Schedule, func(e events.Event) { |
| 359 | d := NewBody().AddTitle("Edit time") |
| 360 | tp := NewTimePicker(d).SetTime(ti.Time) |
| 361 | d.AddBottomBar(func(parent Widget) { |
| 362 | d.AddCancel(parent) |
| 363 | d.AddOK(parent).OnClick(func(e events.Event) { |
| 364 | ti.Time = tp.Time |
| 365 | ti.UpdateChange() |
| 366 | }) |
| 367 | }) |
| 368 | d.RunDialog(w) |
| 369 | }) |
| 370 | w.Styler(style) |
| 371 | w.Updater(func() { |
nothing calls this directly
no test coverage detected