mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-05 09:25:38 +00:00
widget/material: allow changing height & radius of progressbar
Signed-off-by: sewn <sewn@disroot.org>
This commit is contained in:
@@ -15,6 +15,8 @@ import (
|
|||||||
|
|
||||||
type ProgressBarStyle struct {
|
type ProgressBarStyle struct {
|
||||||
Color color.NRGBA
|
Color color.NRGBA
|
||||||
|
Height unit.Dp
|
||||||
|
Radius unit.Dp
|
||||||
TrackColor color.NRGBA
|
TrackColor color.NRGBA
|
||||||
Progress float32
|
Progress float32
|
||||||
}
|
}
|
||||||
@@ -22,6 +24,8 @@ type ProgressBarStyle struct {
|
|||||||
func ProgressBar(th *Theme, progress float32) ProgressBarStyle {
|
func ProgressBar(th *Theme, progress float32) ProgressBarStyle {
|
||||||
return ProgressBarStyle{
|
return ProgressBarStyle{
|
||||||
Progress: progress,
|
Progress: progress,
|
||||||
|
Height: unit.Dp(4),
|
||||||
|
Radius: unit.Dp(2),
|
||||||
Color: th.Palette.ContrastBg,
|
Color: th.Palette.ContrastBg,
|
||||||
TrackColor: f32color.MulAlpha(th.Palette.Fg, 0x88),
|
TrackColor: f32color.MulAlpha(th.Palette.Fg, 0x88),
|
||||||
}
|
}
|
||||||
@@ -29,10 +33,8 @@ func ProgressBar(th *Theme, progress float32) ProgressBarStyle {
|
|||||||
|
|
||||||
func (p ProgressBarStyle) Layout(gtx layout.Context) layout.Dimensions {
|
func (p ProgressBarStyle) Layout(gtx layout.Context) layout.Dimensions {
|
||||||
shader := func(width int, color color.NRGBA) layout.Dimensions {
|
shader := func(width int, color color.NRGBA) layout.Dimensions {
|
||||||
const maxHeight = unit.Dp(4)
|
d := image.Point{X: width, Y: gtx.Dp(p.Height)}
|
||||||
rr := gtx.Dp(2)
|
rr := gtx.Dp(p.Radius)
|
||||||
|
|
||||||
d := image.Point{X: width, Y: gtx.Dp(maxHeight)}
|
|
||||||
|
|
||||||
defer clip.UniformRRect(image.Rectangle{Max: image.Pt(width, d.Y)}, rr).Push(gtx.Ops).Pop()
|
defer clip.UniformRRect(image.Rectangle{Max: image.Pt(width, d.Y)}, rr).Push(gtx.Ops).Pop()
|
||||||
paint.ColorOp{Color: color}.Add(gtx.Ops)
|
paint.ColorOp{Color: color}.Add(gtx.Ops)
|
||||||
|
|||||||
Reference in New Issue
Block a user