mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-04 17:05:38 +00:00
widget/material: rename material.go to theme.go
Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
@@ -0,0 +1,75 @@
|
||||
// SPDX-License-Identifier: Unlicense OR MIT
|
||||
|
||||
package material
|
||||
|
||||
import (
|
||||
"image"
|
||||
"image/color"
|
||||
|
||||
"gioui.org/f32"
|
||||
"gioui.org/font"
|
||||
"gioui.org/layout"
|
||||
"gioui.org/op/paint"
|
||||
"gioui.org/text"
|
||||
"gioui.org/unit"
|
||||
"golang.org/x/exp/shiny/materialdesign/icons"
|
||||
)
|
||||
|
||||
type Theme struct {
|
||||
Shaper *text.Shaper
|
||||
Color struct {
|
||||
Primary color.RGBA
|
||||
Text color.RGBA
|
||||
Hint color.RGBA
|
||||
InvText color.RGBA
|
||||
}
|
||||
TextSize unit.Value
|
||||
checkBoxCheckedIcon *Icon
|
||||
checkBoxUncheckedIcon *Icon
|
||||
radioCheckedIcon *Icon
|
||||
radioUncheckedIcon *Icon
|
||||
}
|
||||
|
||||
func NewTheme() *Theme {
|
||||
t := &Theme{
|
||||
Shaper: font.Default(),
|
||||
}
|
||||
t.Color.Primary = rgb(0x3f51b5)
|
||||
t.Color.Text = rgb(0x000000)
|
||||
t.Color.Hint = rgb(0xbbbbbb)
|
||||
t.Color.InvText = rgb(0xffffff)
|
||||
t.TextSize = unit.Sp(16)
|
||||
|
||||
t.checkBoxCheckedIcon = mustIcon(NewIcon(icons.ToggleCheckBox))
|
||||
t.checkBoxUncheckedIcon = mustIcon(NewIcon(icons.ToggleCheckBoxOutlineBlank))
|
||||
t.radioCheckedIcon = mustIcon(NewIcon(icons.ToggleRadioButtonChecked))
|
||||
t.radioUncheckedIcon = mustIcon(NewIcon(icons.ToggleRadioButtonUnchecked))
|
||||
|
||||
return t
|
||||
}
|
||||
|
||||
func mustIcon(ic *Icon, err error) *Icon {
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return ic
|
||||
}
|
||||
|
||||
func rgb(c uint32) color.RGBA {
|
||||
return argb(0xff000000 | c)
|
||||
}
|
||||
|
||||
func argb(c uint32) color.RGBA {
|
||||
return color.RGBA{A: uint8(c >> 24), R: uint8(c >> 16), G: uint8(c >> 8), B: uint8(c)}
|
||||
}
|
||||
|
||||
func fill(gtx *layout.Context, col color.RGBA) {
|
||||
cs := gtx.Constraints
|
||||
d := image.Point{X: cs.Width.Min, Y: cs.Height.Min}
|
||||
dr := f32.Rectangle{
|
||||
Max: f32.Point{X: float32(d.X), Y: float32(d.Y)},
|
||||
}
|
||||
paint.ColorOp{Color: col}.Add(gtx.Ops)
|
||||
paint.PaintOp{Rect: dr}.Add(gtx.Ops)
|
||||
gtx.Dimensions = layout.Dimensions{Size: d}
|
||||
}
|
||||
Reference in New Issue
Block a user