mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-06 01:45:36 +00:00
widget/material: allow configuring default typeface on theme
This commit introduces the material.Theme.Face field, which will automatically populate the Font.Typeface in every text widget created using a constructor function in package material. Signed-off-by: Chris Waldon <christopher.waldon.dev@gmail.com>
This commit is contained in:
@@ -51,7 +51,7 @@ type IconButtonStyle struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func Button(th *Theme, button *widget.Clickable, txt string) ButtonStyle {
|
func Button(th *Theme, button *widget.Clickable, txt string) ButtonStyle {
|
||||||
return ButtonStyle{
|
b := ButtonStyle{
|
||||||
Text: txt,
|
Text: txt,
|
||||||
Color: th.Palette.ContrastFg,
|
Color: th.Palette.ContrastFg,
|
||||||
CornerRadius: 4,
|
CornerRadius: 4,
|
||||||
@@ -64,6 +64,8 @@ func Button(th *Theme, button *widget.Clickable, txt string) ButtonStyle {
|
|||||||
Button: button,
|
Button: button,
|
||||||
shaper: th.Shaper,
|
shaper: th.Shaper,
|
||||||
}
|
}
|
||||||
|
b.Font.Typeface = th.Face
|
||||||
|
return b
|
||||||
}
|
}
|
||||||
|
|
||||||
func ButtonLayout(th *Theme, button *widget.Clickable) ButtonLayoutStyle {
|
func ButtonLayout(th *Theme, button *widget.Clickable) ButtonLayoutStyle {
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ type CheckBoxStyle struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func CheckBox(th *Theme, checkBox *widget.Bool, label string) CheckBoxStyle {
|
func CheckBox(th *Theme, checkBox *widget.Bool, label string) CheckBoxStyle {
|
||||||
return CheckBoxStyle{
|
c := CheckBoxStyle{
|
||||||
CheckBox: checkBox,
|
CheckBox: checkBox,
|
||||||
checkable: checkable{
|
checkable: checkable{
|
||||||
Label: label,
|
Label: label,
|
||||||
@@ -27,6 +27,8 @@ func CheckBox(th *Theme, checkBox *widget.Bool, label string) CheckBoxStyle {
|
|||||||
uncheckedStateIcon: th.Icon.CheckBoxUnchecked,
|
uncheckedStateIcon: th.Icon.CheckBoxUnchecked,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
c.checkable.Font.Typeface = th.Face
|
||||||
|
return c
|
||||||
}
|
}
|
||||||
|
|
||||||
// Layout updates the checkBox and displays it.
|
// Layout updates the checkBox and displays it.
|
||||||
|
|||||||
@@ -33,7 +33,10 @@ type EditorStyle struct {
|
|||||||
|
|
||||||
func Editor(th *Theme, editor *widget.Editor, hint string) EditorStyle {
|
func Editor(th *Theme, editor *widget.Editor, hint string) EditorStyle {
|
||||||
return EditorStyle{
|
return EditorStyle{
|
||||||
Editor: editor,
|
Editor: editor,
|
||||||
|
Font: font.Font{
|
||||||
|
Typeface: th.Face,
|
||||||
|
},
|
||||||
TextSize: th.TextSize,
|
TextSize: th.TextSize,
|
||||||
Color: th.Palette.Fg,
|
Color: th.Palette.Fg,
|
||||||
shaper: th.Shaper,
|
shaper: th.Shaper,
|
||||||
|
|||||||
@@ -105,13 +105,15 @@ func Overline(th *Theme, txt string) LabelStyle {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func Label(th *Theme, size unit.Sp, txt string) LabelStyle {
|
func Label(th *Theme, size unit.Sp, txt string) LabelStyle {
|
||||||
return LabelStyle{
|
l := LabelStyle{
|
||||||
Text: txt,
|
Text: txt,
|
||||||
Color: th.Palette.Fg,
|
Color: th.Palette.Fg,
|
||||||
SelectionColor: f32color.MulAlpha(th.Palette.ContrastBg, 0x60),
|
SelectionColor: f32color.MulAlpha(th.Palette.ContrastBg, 0x60),
|
||||||
TextSize: size,
|
TextSize: size,
|
||||||
Shaper: th.Shaper,
|
Shaper: th.Shaper,
|
||||||
}
|
}
|
||||||
|
l.Font.Typeface = th.Face
|
||||||
|
return l
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l LabelStyle) Layout(gtx layout.Context) layout.Dimensions {
|
func (l LabelStyle) Layout(gtx layout.Context) layout.Dimensions {
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ type RadioButtonStyle struct {
|
|||||||
// RadioButton returns a RadioButton with a label. The key specifies
|
// RadioButton returns a RadioButton with a label. The key specifies
|
||||||
// the value for the Enum.
|
// the value for the Enum.
|
||||||
func RadioButton(th *Theme, group *widget.Enum, key, label string) RadioButtonStyle {
|
func RadioButton(th *Theme, group *widget.Enum, key, label string) RadioButtonStyle {
|
||||||
return RadioButtonStyle{
|
r := RadioButtonStyle{
|
||||||
Group: group,
|
Group: group,
|
||||||
checkable: checkable{
|
checkable: checkable{
|
||||||
Label: label,
|
Label: label,
|
||||||
@@ -32,6 +32,8 @@ func RadioButton(th *Theme, group *widget.Enum, key, label string) RadioButtonSt
|
|||||||
},
|
},
|
||||||
Key: key,
|
Key: key,
|
||||||
}
|
}
|
||||||
|
r.checkable.Font.Typeface = th.Face
|
||||||
|
return r
|
||||||
}
|
}
|
||||||
|
|
||||||
// Layout updates enum and displays the radio button.
|
// Layout updates enum and displays the radio button.
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import (
|
|||||||
|
|
||||||
"golang.org/x/exp/shiny/materialdesign/icons"
|
"golang.org/x/exp/shiny/materialdesign/icons"
|
||||||
|
|
||||||
|
"gioui.org/font"
|
||||||
"gioui.org/text"
|
"gioui.org/text"
|
||||||
"gioui.org/unit"
|
"gioui.org/unit"
|
||||||
"gioui.org/widget"
|
"gioui.org/widget"
|
||||||
@@ -41,6 +42,8 @@ type Theme struct {
|
|||||||
RadioChecked *widget.Icon
|
RadioChecked *widget.Icon
|
||||||
RadioUnchecked *widget.Icon
|
RadioUnchecked *widget.Icon
|
||||||
}
|
}
|
||||||
|
// Face selects the default typeface for text.
|
||||||
|
Face font.Typeface
|
||||||
|
|
||||||
// FingerSize is the minimum touch target size.
|
// FingerSize is the minimum touch target size.
|
||||||
FingerSize unit.Dp
|
FingerSize unit.Dp
|
||||||
|
|||||||
Reference in New Issue
Block a user