Skip to content

Commit

Permalink
replace default gofont with source sans pro (decred#208)
Browse files Browse the repository at this point in the history
  • Loading branch information
oshorefueled authored Jul 24, 2020
1 parent e92fac4 commit ebd04a1
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
25 changes: 24 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ import (
"strings"
"sync"

"gioui.org/font/gofont"
"gioui.org/font/opentype"
"gioui.org/text"

_ "net/http/pprof"

"gioui.org/app"
Expand Down Expand Up @@ -79,7 +83,26 @@ func main() {
wg.Done()
}()

win, err := ui.CreateWindow(wal, decredIcons)
var collection []text.FontFace
source, err := pkger.Open("/ui/assets/fonts/source_sans_pro_regular.otf")
if err != nil {
fmt.Println("Failed to load font")
collection = gofont.Collection()
} else {
stat, err := source.Stat()
if err != nil {
fmt.Println(err)
}
bytes := make([]byte, stat.Size())
source.Read(bytes)
fnt, err := opentype.Parse(bytes)
if err != nil {
fmt.Println(err)
}
collection = append(collection, text.FontFace{Font: text.Font{}, Face: fnt})
}

win, err := ui.CreateWindow(wal, decredIcons, collection)
if err != nil {
fmt.Printf("Could not initialize window: %s\ns", err)
return
Expand Down
7 changes: 4 additions & 3 deletions ui/window.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ import (
"image"
"time"

"gioui.org/text"

"github.com/raedahgroup/godcr/ui/values"

"gioui.org/font/gofont"
"gioui.org/op"

"gioui.org/app"
Expand Down Expand Up @@ -56,10 +57,10 @@ type Window struct {
// Should never be called more than once as it calls
// app.NewWindow() which does not support being called more
// than once.
func CreateWindow(wal *wallet.Wallet, decredIcons map[string]image.Image) (*Window, error) {
func CreateWindow(wal *wallet.Wallet, decredIcons map[string]image.Image, collection []text.FontFace) (*Window, error) {
win := new(Window)
win.window = app.NewWindow(app.Title("godcr"))
theme := decredmaterial.NewTheme(gofont.Collection())
theme := decredmaterial.NewTheme(collection)
if theme == nil {
return nil, errors.New("Unexpected error while loading theme")
}
Expand Down

0 comments on commit ebd04a1

Please sign in to comment.