Files
gio/widget/material/radiobutton.go
T
Elias Naur 3e0b72304a all: replace deprecated pointer.Rect with clip.Rect
Converted with

gofmt -w -r 'pointer.Rect(r) -> clip.Rect(r)' .
gofmt -w -r 'pointer.Ellipse(r) -> clip.Ellipse(layout.FRect(r))' .

combined with 'goimports -w .' to clean up imports.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-11-03 14:12:31 +01:00

49 lines
1.2 KiB
Go

// SPDX-License-Identifier: Unlicense OR MIT
package material
import (
"image"
"gioui.org/layout"
"gioui.org/op/clip"
"gioui.org/unit"
"gioui.org/widget"
)
type RadioButtonStyle struct {
checkable
Key string
Group *widget.Enum
}
// RadioButton returns a RadioButton with a label. The key specifies
// the value for the Enum.
func RadioButton(th *Theme, group *widget.Enum, key, label string) RadioButtonStyle {
return RadioButtonStyle{
Group: group,
checkable: checkable{
Label: label,
Color: th.Palette.Fg,
IconColor: th.Palette.ContrastBg,
TextSize: th.TextSize.Scale(14.0 / 16.0),
Size: unit.Dp(26),
shaper: th.Shaper,
checkedStateIcon: th.Icon.RadioChecked,
uncheckedStateIcon: th.Icon.RadioUnchecked,
},
Key: key,
}
}
// Layout updates enum and displays the radio button.
func (r RadioButtonStyle) Layout(gtx layout.Context) layout.Dimensions {
hovered, hovering := r.Group.Hovered()
dims := r.layout(gtx, r.Group.Value == r.Key, hovering && hovered == r.Key)
defer clip.Rect(image.Rectangle{Max: dims.Size}).Push(gtx.Ops).Pop()
gtx.Constraints.Min = dims.Size
r.Group.Layout(gtx, r.Key)
return dims
}