forked from joejulian/gio
abb99eca5c
Signed-off-by: Elias Naur <mail@eliasnaur.com>
74 lines
1.9 KiB
Go
74 lines
1.9 KiB
Go
// SPDX-License-Identifier: Unlicense OR MIT
|
|
|
|
// Package material implements the Material design.
|
|
package material
|
|
|
|
import (
|
|
"image"
|
|
"image/color"
|
|
|
|
"gioui.org/f32"
|
|
"gioui.org/layout"
|
|
"gioui.org/op"
|
|
"gioui.org/op/paint"
|
|
"gioui.org/text"
|
|
"gioui.org/unit"
|
|
)
|
|
|
|
type Theme struct {
|
|
Shaper *text.Shaper
|
|
Color struct {
|
|
Primary color.RGBA
|
|
Text color.RGBA
|
|
Hint color.RGBA
|
|
}
|
|
TextSize unit.Value
|
|
}
|
|
|
|
func NewTheme(shaper *text.Shaper) *Theme {
|
|
t := &Theme{
|
|
Shaper: shaper,
|
|
}
|
|
t.Color.Primary = rgb(0x3f51b5)
|
|
t.Color.Text = rgb(0x000000)
|
|
t.Color.Hint = rgb(0xbbbbbb)
|
|
t.TextSize = unit.Sp(16)
|
|
return t
|
|
}
|
|
|
|
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.Max, Y: cs.Height.Max}
|
|
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, Baseline: d.Y}
|
|
}
|
|
|
|
// https://pomax.github.io/bezierinfo/#circles_cubic.
|
|
func rrect(ops *op.Ops, width, height, se, sw, nw, ne float32) {
|
|
w, h := float32(width), float32(height)
|
|
const c = 0.55228475 // 4*(sqrt(2)-1)/3
|
|
var b paint.Path
|
|
b.Begin(ops)
|
|
b.Move(f32.Point{X: w, Y: h - se})
|
|
b.Cube(f32.Point{X: 0, Y: se * c}, f32.Point{X: -se + se*c, Y: se}, f32.Point{X: -se, Y: se}) // SE
|
|
b.Line(f32.Point{X: sw - w + se, Y: 0})
|
|
b.Cube(f32.Point{X: -sw * c, Y: 0}, f32.Point{X: -sw, Y: -sw + sw*c}, f32.Point{X: -sw, Y: -sw}) // SW
|
|
b.Line(f32.Point{X: 0, Y: nw - h + sw})
|
|
b.Cube(f32.Point{X: 0, Y: -nw * c}, f32.Point{X: nw - nw*c, Y: -nw}, f32.Point{X: nw, Y: -nw}) // NW
|
|
b.Line(f32.Point{X: w - ne - nw, Y: 0})
|
|
b.Cube(f32.Point{X: ne * c, Y: 0}, f32.Point{X: ne, Y: ne - ne*c}, f32.Point{X: ne, Y: ne}) // NE
|
|
b.End().Add(ops)
|
|
}
|