mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-07 02:15:34 +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,13 +10,15 @@ import (
|
||||
|
||||
type RadioButtonStyle struct {
|
||||
checkable
|
||||
Key string
|
||||
Key string
|
||||
Group *widget.Enum
|
||||
}
|
||||
|
||||
// RadioButton returns a RadioButton with a label. The key specifies
|
||||
// the value for the Enum.
|
||||
func RadioButton(th *Theme, key, label string) RadioButtonStyle {
|
||||
func RadioButton(th *Theme, group *widget.Enum, key, label string) RadioButtonStyle {
|
||||
return RadioButtonStyle{
|
||||
Group: group,
|
||||
checkable: checkable{
|
||||
Label: label,
|
||||
|
||||
@@ -33,9 +35,9 @@ func RadioButton(th *Theme, key, label string) RadioButtonStyle {
|
||||
}
|
||||
|
||||
// Layout updates enum and displays the radio button.
|
||||
func (r RadioButtonStyle) Layout(gtx layout.Context, enum *widget.Enum) layout.Dimensions {
|
||||
enum.Update(gtx)
|
||||
dims := r.layout(gtx, enum.Value == r.Key)
|
||||
enum.Layout(gtx, r.Key)
|
||||
func (r RadioButtonStyle) Layout(gtx layout.Context) layout.Dimensions {
|
||||
r.Group.Update(gtx)
|
||||
dims := r.layout(gtx, r.Group.Value == r.Key)
|
||||
r.Group.Layout(gtx, r.Key)
|
||||
return dims
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user