apps/gophers: clean up font family code

Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
Elias Naur
2019-10-05 23:12:20 +02:00
parent 1b44594411
commit bb796ddf37
+19 -29
View File
@@ -42,8 +42,6 @@ import (
) )
type UI struct { type UI struct {
family *shape.Family
mono *shape.Family
fab *ActionButton fab *ActionButton
usersList *layout.List usersList *layout.List
users []*user users []*user
@@ -59,7 +57,6 @@ type UI struct {
} }
type userPage struct { type userPage struct {
family *shape.Family
user *user user *user
commitsList *layout.List commitsList *layout.List
commits []*github.Commit commits []*github.Commit
@@ -87,11 +84,9 @@ type ActionButton struct {
sendIco *icon sendIco *icon
} }
var fonts struct { var families struct {
regular *sfnt.Font primary *shape.Family
bold *sfnt.Font mono *shape.Family
italic *sfnt.Font
mono *sfnt.Font
} }
var theme struct { var theme struct {
@@ -110,10 +105,14 @@ func colorMaterial(ops *op.Ops, color color.RGBA) op.MacroOp {
} }
func init() { func init() {
fonts.regular = mustLoadFont(goregular.TTF) families.primary = &shape.Family{
fonts.bold = mustLoadFont(gobold.TTF) Regular: mustLoadFont(goregular.TTF),
fonts.italic = mustLoadFont(goitalic.TTF) Bold: mustLoadFont(gobold.TTF),
fonts.mono = mustLoadFont(gomono.TTF) Italic: mustLoadFont(goitalic.TTF),
}
families.mono = &shape.Family{
Regular: mustLoadFont(gomono.TTF),
}
var ops op.Ops var ops op.Ops
theme.text = colorMaterial(&ops, rgb(0x333333)) theme.text = colorMaterial(&ops, rgb(0x333333))
theme.tertText = colorMaterial(&ops, rgb(0xbbbbbb)) theme.tertText = colorMaterial(&ops, rgb(0xbbbbbb))
@@ -124,14 +123,6 @@ func init() {
func newUI(fetchCommits func(string)) *UI { func newUI(fetchCommits func(string)) *UI {
u := &UI{ u := &UI{
fetchCommits: fetchCommits, fetchCommits: fetchCommits,
family: &shape.Family{
Regular: fonts.regular,
Italic: fonts.italic,
Bold: fonts.bold,
},
mono: &shape.Family{
Regular: fonts.mono,
},
} }
u.usersList = &layout.List{ u.usersList = &layout.List{
Axis: layout.Vertical, Axis: layout.Vertical,
@@ -141,7 +132,7 @@ func newUI(fetchCommits func(string)) *UI {
icons: []*icon{}, icons: []*icon{},
} }
u.edit2 = &text.Editor{ u.edit2 = &text.Editor{
Family: u.family, Family: families.primary,
Face: text.Face{ Face: text.Face{
Style: text.Italic, Style: text.Italic,
}, },
@@ -154,7 +145,7 @@ func newUI(fetchCommits func(string)) *UI {
} }
u.edit2.SetText("Single line editor. Edit me!") u.edit2.SetText("Single line editor. Edit me!")
u.edit = &text.Editor{ u.edit = &text.Editor{
Family: u.family, Family: families.primary,
Size: unit.Sp(16), Size: unit.Sp(16),
Material: theme.text, Material: theme.text,
//Alignment: text.End, //Alignment: text.End,
@@ -197,7 +188,7 @@ func (u *UI) layoutTimings(gtx *layout.Context) {
layout.Align(layout.NE).Layout(gtx, func() { layout.Align(layout.NE).Layout(gtx, func() {
layout.Inset{Top: unit.Dp(16)}.Layout(gtx, func() { layout.Inset{Top: unit.Dp(16)}.Layout(gtx, func() {
txt := fmt.Sprintf("m: %d %s", mallocs, u.profile.Timings) txt := fmt.Sprintf("m: %d %s", mallocs, u.profile.Timings)
text.Label{Material: theme.text, Size: unit.Sp(10), Text: txt}.Layout(gtx, u.mono) text.Label{Material: theme.text, Size: unit.Sp(10), Text: txt}.Layout(gtx, families.mono)
}) })
}) })
} }
@@ -221,7 +212,6 @@ func (u *UI) Layout(gtx *layout.Context) {
func (u *UI) newUserPage(user *user) *userPage { func (u *UI) newUserPage(user *user) *userPage {
up := &userPage{ up := &userPage{
family: u.family,
user: user, user: user,
commitsList: &layout.List{Axis: layout.Vertical}, commitsList: &layout.List{Axis: layout.Vertical},
} }
@@ -257,7 +247,7 @@ func (up *userPage) commit(gtx *layout.Context, index int) {
c2 := f.Flexible(1, func() { c2 := f.Flexible(1, func() {
gtx.Constraints.Width.Min = gtx.Constraints.Width.Max gtx.Constraints.Width.Min = gtx.Constraints.Width.Max
layout.Inset{Left: unit.Dp(8)}.Layout(gtx, func() { layout.Inset{Left: unit.Dp(8)}.Layout(gtx, func() {
label.Layout(gtx, up.family) label.Layout(gtx, families.primary)
}) })
}) })
f.Layout(c1, c2) f.Layout(c1, c2)
@@ -305,7 +295,7 @@ func (u *UI) layoutUsers(gtx *layout.Context) {
in := layout.Inset{Top: unit.Dp(16), Right: unit.Dp(8), Bottom: unit.Dp(8), Left: unit.Dp(8)} in := layout.Inset{Top: unit.Dp(16), Right: unit.Dp(8), Bottom: unit.Dp(8), Left: unit.Dp(8)}
in.Layout(gtx, func() { in.Layout(gtx, func() {
lbl := text.Label{Material: grey, Size: unit.Sp(11), Text: "GOPHERS"} lbl := text.Label{Material: grey, Size: unit.Sp(11), Text: "GOPHERS"}
lbl.Layout(gtx, u.family) lbl.Layout(gtx, families.primary)
}) })
}) })
c1 := s.Expand(func() { c1 := s.Expand(func() {
@@ -371,14 +361,14 @@ func (u *UI) user(gtx *layout.Context, index int) {
f := baseline() f := baseline()
f.Init(gtx) f.Init(gtx)
c1 := f.Rigid(func() { c1 := f.Rigid(func() {
text.Label{Material: theme.text, Size: unit.Sp(13), Text: user.name}.Layout(gtx, u.family) text.Label{Material: theme.text, Size: unit.Sp(13), Text: user.name}.Layout(gtx, families.primary)
}) })
c2 := f.Flexible(1, func() { c2 := f.Flexible(1, func() {
gtx.Constraints.Width.Min = gtx.Constraints.Width.Max gtx.Constraints.Width.Min = gtx.Constraints.Width.Max
layout.Align(layout.E).Layout(gtx, func() { layout.Align(layout.E).Layout(gtx, func() {
layout.Inset{Left: unit.Dp(2)}.Layout(gtx, func() { layout.Inset{Left: unit.Dp(2)}.Layout(gtx, func() {
lbl := text.Label{Material: theme.text, Size: unit.Sp(10), Text: "3 hours ago"} lbl := text.Label{Material: theme.text, Size: unit.Sp(10), Text: "3 hours ago"}
lbl.Layout(gtx, u.family) lbl.Layout(gtx, families.primary)
}) })
}) })
}) })
@@ -387,7 +377,7 @@ func (u *UI) user(gtx *layout.Context, index int) {
c2 := f.Rigid(func() { c2 := f.Rigid(func() {
in := layout.Inset{Top: unit.Dp(4)} in := layout.Inset{Top: unit.Dp(4)}
in.Layout(gtx, func() { in.Layout(gtx, func() {
text.Label{Material: theme.tertText, Size: unit.Sp(12), Text: user.company}.Layout(gtx, u.family) text.Label{Material: theme.tertText, Size: unit.Sp(12), Text: user.company}.Layout(gtx, families.primary)
}) })
}) })
f.Layout(c1, c2) f.Layout(c1, c2)