mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-01 15:45:38 +00:00
296303210f
Remove padding from the sides of the Slider to align them with
other components.
However, since sliders still need to be used with fingers try to
enforce a minimum finger height, if there is sufficient room.
The sides don't need similar treatment since after grabbing it's
possible to move the finger beyond the touch area, without losing
interaction.
To not enforce finger size, the theme can be adjusted:
theme.FingerSize = unit.Px(0)
Signed-off-by: Egon Elbre <egonelbre@gmail.com>
90 lines
2.0 KiB
Go
90 lines
2.0 KiB
Go
// SPDX-License-Identifier: Unlicense OR MIT
|
|
|
|
package material
|
|
|
|
import (
|
|
"image/color"
|
|
|
|
"gioui.org/text"
|
|
"gioui.org/unit"
|
|
"gioui.org/widget"
|
|
"golang.org/x/exp/shiny/materialdesign/icons"
|
|
)
|
|
|
|
// Palette contains the minimal set of colors that a widget may need to
|
|
// draw itself.
|
|
type Palette struct {
|
|
// Bg is the background color atop which content is currently being
|
|
// drawn.
|
|
Bg color.NRGBA
|
|
|
|
// Fg is a color suitable for drawing on top of Bg.
|
|
Fg color.NRGBA
|
|
|
|
// ContrastBg is a color used to draw attention to active,
|
|
// important, interactive widgets such as buttons.
|
|
ContrastBg color.NRGBA
|
|
|
|
// ContrastFg is a color suitable for content drawn on top of
|
|
// ContrastBg.
|
|
ContrastFg color.NRGBA
|
|
}
|
|
|
|
type Theme struct {
|
|
Shaper text.Shaper
|
|
Palette
|
|
TextSize unit.Value
|
|
Icon struct {
|
|
CheckBoxChecked *widget.Icon
|
|
CheckBoxUnchecked *widget.Icon
|
|
RadioChecked *widget.Icon
|
|
RadioUnchecked *widget.Icon
|
|
}
|
|
|
|
// FingerSize is the minimum touch target size.
|
|
FingerSize unit.Value
|
|
}
|
|
|
|
func NewTheme(fontCollection []text.FontFace) *Theme {
|
|
t := &Theme{
|
|
Shaper: text.NewCache(fontCollection),
|
|
}
|
|
t.Palette = Palette{
|
|
Fg: rgb(0x000000),
|
|
Bg: rgb(0xffffff),
|
|
ContrastBg: rgb(0x3f51b5),
|
|
ContrastFg: rgb(0xffffff),
|
|
}
|
|
t.TextSize = unit.Sp(16)
|
|
|
|
t.Icon.CheckBoxChecked = mustIcon(widget.NewIcon(icons.ToggleCheckBox))
|
|
t.Icon.CheckBoxUnchecked = mustIcon(widget.NewIcon(icons.ToggleCheckBoxOutlineBlank))
|
|
t.Icon.RadioChecked = mustIcon(widget.NewIcon(icons.ToggleRadioButtonChecked))
|
|
t.Icon.RadioUnchecked = mustIcon(widget.NewIcon(icons.ToggleRadioButtonUnchecked))
|
|
|
|
// 38dp is on the lower end of possible finger size.
|
|
t.FingerSize = unit.Dp(38)
|
|
|
|
return t
|
|
}
|
|
|
|
func (t Theme) WithPalette(p Palette) Theme {
|
|
t.Palette = p
|
|
return t
|
|
}
|
|
|
|
func mustIcon(ic *widget.Icon, err error) *widget.Icon {
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return ic
|
|
}
|
|
|
|
func rgb(c uint32) color.NRGBA {
|
|
return argb(0xff000000 | c)
|
|
}
|
|
|
|
func argb(c uint32) color.NRGBA {
|
|
return color.NRGBA{A: uint8(c >> 24), R: uint8(c >> 16), G: uint8(c >> 8), B: uint8(c)}
|
|
}
|