mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-01 15:45:38 +00:00
f1e266a9e7
The Value method both updated the enum value and returned it. In order to access the current value withoutm, expose the Value field of the enum and rename the method to Update. As a bonus we can get rid of the SetValue method as well. Updates gio#96 Signed-off-by: Elias Naur <mail@eliasnaur.com>
41 lines
948 B
Go
41 lines
948 B
Go
// SPDX-License-Identifier: Unlicense OR MIT
|
|
|
|
package material
|
|
|
|
import (
|
|
"gioui.org/layout"
|
|
"gioui.org/unit"
|
|
"gioui.org/widget"
|
|
)
|
|
|
|
type RadioButtonStyle struct {
|
|
checkable
|
|
Key string
|
|
}
|
|
|
|
// RadioButton returns a RadioButton with a label. The key specifies
|
|
// the value for the Enum.
|
|
func RadioButton(th *Theme, key, label string) RadioButtonStyle {
|
|
return RadioButtonStyle{
|
|
checkable: checkable{
|
|
Label: label,
|
|
|
|
Color: th.Color.Text,
|
|
IconColor: th.Color.Primary,
|
|
TextSize: th.TextSize.Scale(14.0 / 16.0),
|
|
Size: unit.Dp(26),
|
|
shaper: th.Shaper,
|
|
checkedStateIcon: th.radioCheckedIcon,
|
|
uncheckedStateIcon: th.radioUncheckedIcon,
|
|
},
|
|
Key: key,
|
|
}
|
|
}
|
|
|
|
// Layout updates enum and displays the radio button.
|
|
func (r RadioButtonStyle) Layout(gtx *layout.Context, enum *widget.Enum) {
|
|
enum.Update(gtx)
|
|
r.layout(gtx, enum.Value == r.Key)
|
|
enum.Layout(gtx, r.Key)
|
|
}
|