forked from joejulian/gio
apps/gophers: clean up font family code
Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
+19
-29
@@ -42,8 +42,6 @@ import (
|
||||
)
|
||||
|
||||
type UI struct {
|
||||
family *shape.Family
|
||||
mono *shape.Family
|
||||
fab *ActionButton
|
||||
usersList *layout.List
|
||||
users []*user
|
||||
@@ -59,7 +57,6 @@ type UI struct {
|
||||
}
|
||||
|
||||
type userPage struct {
|
||||
family *shape.Family
|
||||
user *user
|
||||
commitsList *layout.List
|
||||
commits []*github.Commit
|
||||
@@ -87,11 +84,9 @@ type ActionButton struct {
|
||||
sendIco *icon
|
||||
}
|
||||
|
||||
var fonts struct {
|
||||
regular *sfnt.Font
|
||||
bold *sfnt.Font
|
||||
italic *sfnt.Font
|
||||
mono *sfnt.Font
|
||||
var families struct {
|
||||
primary *shape.Family
|
||||
mono *shape.Family
|
||||
}
|
||||
|
||||
var theme struct {
|
||||
@@ -110,10 +105,14 @@ func colorMaterial(ops *op.Ops, color color.RGBA) op.MacroOp {
|
||||
}
|
||||
|
||||
func init() {
|
||||
fonts.regular = mustLoadFont(goregular.TTF)
|
||||
fonts.bold = mustLoadFont(gobold.TTF)
|
||||
fonts.italic = mustLoadFont(goitalic.TTF)
|
||||
fonts.mono = mustLoadFont(gomono.TTF)
|
||||
families.primary = &shape.Family{
|
||||
Regular: mustLoadFont(goregular.TTF),
|
||||
Bold: mustLoadFont(gobold.TTF),
|
||||
Italic: mustLoadFont(goitalic.TTF),
|
||||
}
|
||||
families.mono = &shape.Family{
|
||||
Regular: mustLoadFont(gomono.TTF),
|
||||
}
|
||||
var ops op.Ops
|
||||
theme.text = colorMaterial(&ops, rgb(0x333333))
|
||||
theme.tertText = colorMaterial(&ops, rgb(0xbbbbbb))
|
||||
@@ -124,14 +123,6 @@ func init() {
|
||||
func newUI(fetchCommits func(string)) *UI {
|
||||
u := &UI{
|
||||
fetchCommits: fetchCommits,
|
||||
family: &shape.Family{
|
||||
Regular: fonts.regular,
|
||||
Italic: fonts.italic,
|
||||
Bold: fonts.bold,
|
||||
},
|
||||
mono: &shape.Family{
|
||||
Regular: fonts.mono,
|
||||
},
|
||||
}
|
||||
u.usersList = &layout.List{
|
||||
Axis: layout.Vertical,
|
||||
@@ -141,7 +132,7 @@ func newUI(fetchCommits func(string)) *UI {
|
||||
icons: []*icon{},
|
||||
}
|
||||
u.edit2 = &text.Editor{
|
||||
Family: u.family,
|
||||
Family: families.primary,
|
||||
Face: text.Face{
|
||||
Style: text.Italic,
|
||||
},
|
||||
@@ -154,7 +145,7 @@ func newUI(fetchCommits func(string)) *UI {
|
||||
}
|
||||
u.edit2.SetText("Single line editor. Edit me!")
|
||||
u.edit = &text.Editor{
|
||||
Family: u.family,
|
||||
Family: families.primary,
|
||||
Size: unit.Sp(16),
|
||||
Material: theme.text,
|
||||
//Alignment: text.End,
|
||||
@@ -197,7 +188,7 @@ func (u *UI) layoutTimings(gtx *layout.Context) {
|
||||
layout.Align(layout.NE).Layout(gtx, func() {
|
||||
layout.Inset{Top: unit.Dp(16)}.Layout(gtx, func() {
|
||||
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 {
|
||||
up := &userPage{
|
||||
family: u.family,
|
||||
user: user,
|
||||
commitsList: &layout.List{Axis: layout.Vertical},
|
||||
}
|
||||
@@ -257,7 +247,7 @@ func (up *userPage) commit(gtx *layout.Context, index int) {
|
||||
c2 := f.Flexible(1, func() {
|
||||
gtx.Constraints.Width.Min = gtx.Constraints.Width.Max
|
||||
layout.Inset{Left: unit.Dp(8)}.Layout(gtx, func() {
|
||||
label.Layout(gtx, up.family)
|
||||
label.Layout(gtx, families.primary)
|
||||
})
|
||||
})
|
||||
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(gtx, func() {
|
||||
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() {
|
||||
@@ -371,14 +361,14 @@ func (u *UI) user(gtx *layout.Context, index int) {
|
||||
f := baseline()
|
||||
f.Init(gtx)
|
||||
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() {
|
||||
gtx.Constraints.Width.Min = gtx.Constraints.Width.Max
|
||||
layout.Align(layout.E).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.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() {
|
||||
in := layout.Inset{Top: unit.Dp(4)}
|
||||
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)
|
||||
|
||||
Reference in New Issue
Block a user