feat: UI work to facilitate future improvements in midi-into-track-input

This commit is contained in:
qm210
2024-11-22 13:48:25 +01:00
parent 4169356845
commit ad690c7697
12 changed files with 191 additions and 40 deletions

View File

@ -48,7 +48,9 @@ type NumericUpDownStyle struct {
Tooltip component.Tooltip
Width unit.Dp
Height unit.Dp
Padding unit.Dp
shaper text.Shaper
Hidden bool
}
func NewNumberInput(v tracker.Int) *NumberInput {
@ -56,6 +58,10 @@ func NewNumberInput(v tracker.Int) *NumberInput {
}
func NumericUpDown(th *material.Theme, number *NumberInput, tooltip string) NumericUpDownStyle {
return NumericUpDownPadded(th, number, tooltip, 0)
}
func NumericUpDownPadded(th *material.Theme, number *NumberInput, tooltip string, padding int) NumericUpDownStyle {
bgColor := th.Palette.Fg
bgColor.R /= 4
bgColor.G /= 4
@ -74,11 +80,22 @@ func NumericUpDown(th *material.Theme, number *NumberInput, tooltip string) Nume
Tooltip: Tooltip(th, tooltip),
Width: unit.Dp(70),
Height: unit.Dp(20),
Padding: unit.Dp(padding),
shaper: *th.Shaper,
}
}
func (s *NumericUpDownStyle) Layout(gtx C) D {
if s.Hidden {
return D{}
}
if s.Padding <= 0 {
return s.layoutWithTooltip(gtx)
}
return layout.UniformInset(s.Padding).Layout(gtx, s.layoutWithTooltip)
}
func (s *NumericUpDownStyle) layoutWithTooltip(gtx C) D {
if s.Tooltip.Text.Text != "" {
return s.NumberInput.tipArea.Layout(gtx, s.Tooltip, s.actualLayout)
}