()
| 398 | func (di *DurationInput) WidgetValue() any { return &di.Duration } |
| 399 | |
| 400 | func (di *DurationInput) Init() { |
| 401 | di.Frame.Init() |
| 402 | tree.AddChild(di, func(w *Spinner) { |
| 403 | w.SetStep(1).SetPageStep(10) |
| 404 | w.SetTooltip("The value of time") |
| 405 | w.Updater(func() { |
| 406 | if di.Unit == "" { |
| 407 | di.setAutoUnit() |
| 408 | } |
| 409 | w.SetValue(float32(di.Duration) / float32(durationUnitsMap[di.Unit])) |
| 410 | }) |
| 411 | w.OnChange(func(e events.Event) { |
| 412 | di.Duration = time.Duration(w.Value * float32(durationUnitsMap[di.Unit])) |
| 413 | di.SendChange() |
| 414 | }) |
| 415 | }) |
| 416 | tree.AddChild(di, func(w *Chooser) { |
| 417 | Bind(&di.Unit, w) |
| 418 | |
| 419 | units := make([]ChooserItem, len(durationUnits)) |
| 420 | for i, u := range durationUnits { |
| 421 | units[i] = ChooserItem{Value: u} |
| 422 | } |
| 423 | |
| 424 | w.SetItems(units...) |
| 425 | w.SetTooltip("The unit of time") |
| 426 | w.OnChange(func(e events.Event) { |
| 427 | di.Update() |
| 428 | }) |
| 429 | }) |
| 430 | } |
| 431 | |
| 432 | // setAutoUnit sets the [DurationInput.Unit] automatically based on the current duration. |
| 433 | func (di *DurationInput) setAutoUnit() { |
nothing calls this directly
no test coverage detected