mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-05 09:25:38 +00:00
widget/material: move widget state object from Layout methods to constructors
Instead of, say,
var th *material.Theme
var btn *widget.Clickable
material.Button(th, "Click me").Layout(gtx, btn)
move the widget state objects to the constructor:
material.Button(th, btn, "Click me").Layout(gtx)
The advatage is that several widgets can now be used without
wrapping them in function literals. For example,
layout.Inset{}.Layout(gtx, func(gtx layout.Context) layout.Dimensions {
material.Button(th, "Click me").Layout(gtx, btn)
})
collapses to just
layout.Inset{}.Layout(gtx, material.Button(th, btn, "Click me").Layout)
Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
@@ -14,16 +14,18 @@ import (
|
||||
)
|
||||
|
||||
type ProgressBarStyle struct {
|
||||
Color color.RGBA
|
||||
Color color.RGBA
|
||||
Progress int
|
||||
}
|
||||
|
||||
func ProgressBar(th *Theme) ProgressBarStyle {
|
||||
func ProgressBar(th *Theme, progress int) ProgressBarStyle {
|
||||
return ProgressBarStyle{
|
||||
Color: th.Color.Primary,
|
||||
Progress: progress,
|
||||
Color: th.Color.Primary,
|
||||
}
|
||||
}
|
||||
|
||||
func (p ProgressBarStyle) Layout(gtx layout.Context, progress int) layout.Dimensions {
|
||||
func (p ProgressBarStyle) Layout(gtx layout.Context) layout.Dimensions {
|
||||
shader := func(width float32, color color.RGBA) layout.Dimensions {
|
||||
maxHeight := unit.Dp(4)
|
||||
rr := float32(gtx.Px(unit.Dp(2)))
|
||||
@@ -44,6 +46,7 @@ func (p ProgressBarStyle) Layout(gtx layout.Context, progress int) layout.Dimens
|
||||
return layout.Dimensions{Size: d}
|
||||
}
|
||||
|
||||
progress := p.Progress
|
||||
if progress > 100 {
|
||||
progress = 100
|
||||
} else if progress < 0 {
|
||||
|
||||
Reference in New Issue
Block a user