mirror of
https://github.com/vsariola/sointu.git
synced 2025-06-04 01:28:45 -04:00
refactor(tracker): make NumericUpDown use widgetForIcon instead loading icons by itself
This commit is contained in:
parent
24ebc99b92
commit
394e2834e9
@ -4,7 +4,6 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"image"
|
"image"
|
||||||
"image/color"
|
"image/color"
|
||||||
"log"
|
|
||||||
|
|
||||||
"golang.org/x/exp/shiny/materialdesign/icons"
|
"golang.org/x/exp/shiny/materialdesign/icons"
|
||||||
|
|
||||||
@ -22,11 +21,6 @@ import (
|
|||||||
"gioui.org/widget/material"
|
"gioui.org/widget/material"
|
||||||
)
|
)
|
||||||
|
|
||||||
var defaultNumericLeftIcon *widget.Icon
|
|
||||||
var defaultNumericRightIcon *widget.Icon
|
|
||||||
var defaultNumericUpIcon *widget.Icon
|
|
||||||
var defaultNumericDownIcon *widget.Icon
|
|
||||||
|
|
||||||
type NumberInput struct {
|
type NumberInput struct {
|
||||||
Value int
|
Value int
|
||||||
dragStartValue int
|
dragStartValue int
|
||||||
@ -93,9 +87,9 @@ func (s NumericUpDownStyle) Layout(gtx C) D {
|
|||||||
gtx.Constraints.Min.Y -= int(border * 2)
|
gtx.Constraints.Min.Y -= int(border * 2)
|
||||||
gtx.Constraints.Max = gtx.Constraints.Min
|
gtx.Constraints.Max = gtx.Constraints.Min
|
||||||
layout.Flex{Axis: layout.Horizontal, Alignment: layout.Middle}.Layout(gtx,
|
layout.Flex{Axis: layout.Horizontal, Alignment: layout.Middle}.Layout(gtx,
|
||||||
layout.Rigid(s.button(gtx.Constraints.Max.Y, defaultNumericLeftIcon, -1, &s.NumberInput.clickDecrease)),
|
layout.Rigid(s.button(gtx.Constraints.Max.Y, widgetForIcon(icons.NavigationArrowBack), -1, &s.NumberInput.clickDecrease)),
|
||||||
layout.Flexed(1, s.layoutText),
|
layout.Flexed(1, s.layoutText),
|
||||||
layout.Rigid(s.button(gtx.Constraints.Max.Y, defaultNumericRightIcon, 1, &s.NumberInput.clickIncrease)),
|
layout.Rigid(s.button(gtx.Constraints.Max.Y, widgetForIcon(icons.NavigationArrowForward), 1, &s.NumberInput.clickIncrease)),
|
||||||
)
|
)
|
||||||
if s.NumberInput.Value < s.Min {
|
if s.NumberInput.Value < s.Min {
|
||||||
s.NumberInput.Value = s.Min
|
s.NumberInput.Value = s.Min
|
||||||
@ -198,23 +192,3 @@ func (s NumericUpDownStyle) layoutClick(gtx layout.Context, delta int, click *ge
|
|||||||
stack.Load()
|
stack.Load()
|
||||||
return layout.Dimensions{Size: gtx.Constraints.Min}
|
return layout.Dimensions{Size: gtx.Constraints.Min}
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
|
||||||
var err error
|
|
||||||
defaultNumericLeftIcon, err = widget.NewIcon(icons.NavigationArrowBack)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
defaultNumericRightIcon, err = widget.NewIcon(icons.NavigationArrowForward)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
defaultNumericUpIcon, err = widget.NewIcon(icons.NavigationArrowDropUp)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
defaultNumericDownIcon, err = widget.NewIcon(icons.NavigationArrowDropDown)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user