mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-05 09:25:38 +00:00
widgets, widgets/material: add RadioButton & Enum
Signed-off-by: Alexander Arin <fralx@yandex.ru>
This commit is contained in:
committed by
Elias Naur
parent
82e51019e1
commit
089ae31f0c
@@ -0,0 +1,42 @@
|
||||
// SPDX-License-Identifier: Unlicense OR MIT
|
||||
|
||||
// Package material implements the Material design.
|
||||
package material
|
||||
|
||||
import (
|
||||
"gioui.org/layout"
|
||||
"gioui.org/text"
|
||||
"gioui.org/unit"
|
||||
"gioui.org/widget"
|
||||
)
|
||||
|
||||
type RadioButton struct {
|
||||
checkable
|
||||
Key string
|
||||
}
|
||||
|
||||
// RadioButton returns a RadioButton with a label. The key specifies
|
||||
// the value for the Enum.
|
||||
func (t *Theme) RadioButton(key, label string) RadioButton {
|
||||
return RadioButton{
|
||||
checkable: checkable{
|
||||
Label: label,
|
||||
|
||||
Color: t.Color.Text,
|
||||
IconColor: t.Color.Primary,
|
||||
Font: text.Font{
|
||||
Size: t.TextSize.Scale(14.0 / 16.0),
|
||||
},
|
||||
Size: unit.Dp(26),
|
||||
shaper: t.Shaper,
|
||||
checkedStateIcon: t.radioCheckedIcon,
|
||||
uncheckedStateIcon: t.radioUncheckedIcon,
|
||||
},
|
||||
Key: key,
|
||||
}
|
||||
}
|
||||
|
||||
func (r RadioButton) Layout(gtx *layout.Context, enum *widget.Enum) {
|
||||
r.layout(gtx, enum.Value(gtx) == r.Key)
|
||||
enum.Layout(gtx, r.Key)
|
||||
}
|
||||
Reference in New Issue
Block a user