Files
gio/widget/material/radiobutton.go
T
Elias Naur f1e266a9e7 widget,widget/material: export Enum.Value
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>
2020-05-03 21:28:33 +02:00

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)
}