mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-06 09:55:40 +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:
@@ -10,11 +10,13 @@ import (
|
||||
|
||||
type CheckBoxStyle struct {
|
||||
checkable
|
||||
CheckBox *widget.Bool
|
||||
}
|
||||
|
||||
func CheckBox(th *Theme, label string) CheckBoxStyle {
|
||||
func CheckBox(th *Theme, checkBox *widget.Bool, label string) CheckBoxStyle {
|
||||
return CheckBoxStyle{
|
||||
checkable{
|
||||
CheckBox: checkBox,
|
||||
checkable: checkable{
|
||||
Label: label,
|
||||
Color: th.Color.Text,
|
||||
IconColor: th.Color.Primary,
|
||||
@@ -28,9 +30,9 @@ func CheckBox(th *Theme, label string) CheckBoxStyle {
|
||||
}
|
||||
|
||||
// Layout updates the checkBox and displays it.
|
||||
func (c CheckBoxStyle) Layout(gtx layout.Context, checkBox *widget.Bool) layout.Dimensions {
|
||||
checkBox.Update(gtx)
|
||||
dims := c.layout(gtx, checkBox.Value)
|
||||
checkBox.Layout(gtx)
|
||||
func (c CheckBoxStyle) Layout(gtx layout.Context) layout.Dimensions {
|
||||
c.CheckBox.Update(gtx)
|
||||
dims := c.layout(gtx, c.CheckBox.Value)
|
||||
c.CheckBox.Layout(gtx)
|
||||
return dims
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user