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:
Chris Waldon
2023-06-22 15:06:22 -04:00
committed by Elias Naur
parent 6384ab6087
commit acab582487
6 changed files with 19 additions and 5 deletions
+3 -1
View File
@@ -51,7 +51,7 @@ type IconButtonStyle struct {
}
func Button(th *Theme, button *widget.Clickable, txt string) ButtonStyle {
return ButtonStyle{
b := ButtonStyle{
Text: txt,
Color: th.Palette.ContrastFg,
CornerRadius: 4,
@@ -64,6 +64,8 @@ func Button(th *Theme, button *widget.Clickable, txt string) ButtonStyle {
Button: button,
shaper: th.Shaper,
}
b.Font.Typeface = th.Face
return b
}
func ButtonLayout(th *Theme, button *widget.Clickable) ButtonLayoutStyle {
+3 -1
View File
@@ -14,7 +14,7 @@ type CheckBoxStyle struct {
}
func CheckBox(th *Theme, checkBox *widget.Bool, label string) CheckBoxStyle {
return CheckBoxStyle{
c := CheckBoxStyle{
CheckBox: checkBox,
checkable: checkable{
Label: label,
@@ -27,6 +27,8 @@ func CheckBox(th *Theme, checkBox *widget.Bool, label string) CheckBoxStyle {
uncheckedStateIcon: th.Icon.CheckBoxUnchecked,
},
}
c.checkable.Font.Typeface = th.Face
return c
}
// Layout updates the checkBox and displays it.
+4 -1
View File
@@ -33,7 +33,10 @@ type EditorStyle struct {
func Editor(th *Theme, editor *widget.Editor, hint string) EditorStyle {
return EditorStyle{
Editor: editor,
Editor: editor,
Font: font.Font{
Typeface: th.Face,
},
TextSize: th.TextSize,
Color: th.Palette.Fg,
shaper: th.Shaper,
+3 -1
View File
@@ -105,13 +105,15 @@ func Overline(th *Theme, txt string) LabelStyle {
}
func Label(th *Theme, size unit.Sp, txt string) LabelStyle {
return LabelStyle{
l := LabelStyle{
Text: txt,
Color: th.Palette.Fg,
SelectionColor: f32color.MulAlpha(th.Palette.ContrastBg, 0x60),
TextSize: size,
Shaper: th.Shaper,
}
l.Font.Typeface = th.Face
return l
}
func (l LabelStyle) Layout(gtx layout.Context) layout.Dimensions {
+3 -1
View File
@@ -17,7 +17,7 @@ type RadioButtonStyle struct {
// 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{
r := RadioButtonStyle{
Group: group,
checkable: checkable{
Label: label,
@@ -32,6 +32,8 @@ func RadioButton(th *Theme, group *widget.Enum, key, label string) RadioButtonSt
},
Key: key,
}
r.checkable.Font.Typeface = th.Face
return r
}
// Layout updates enum and displays the radio button.
+3
View File
@@ -7,6 +7,7 @@ import (
"golang.org/x/exp/shiny/materialdesign/icons"
"gioui.org/font"
"gioui.org/text"
"gioui.org/unit"
"gioui.org/widget"
@@ -41,6 +42,8 @@ type Theme struct {
RadioChecked *widget.Icon
RadioUnchecked *widget.Icon
}
// Face selects the default typeface for text.
Face font.Typeface
// FingerSize is the minimum touch target size.
FingerSize unit.Dp