-
I'm still a bit mystified as to how exactly a custom default font can be set when creating a cogentcore application. Suppose that I have the .ttf of the font, or whatever file defines the font. Probably I should embed it, right? Then, how can i make the cogentcore application actually use that as the default font? The documentation on this is a bit lacking. This is a great font, by the way - one i hope to use with a cogentcore application: |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
Yes, the documentation is certainly incomplete in this area right now, but we will definitely improve it going forward. It is possible to do this now, although the API for this may change after issues like #568, which we are planning to work on in the next few weeks. Regardless, here is the code I got working for this now (to make all widgets in the app use the embedded font by default): package main
import (
"embed"
"cogentcore.org/core/base/mergefs"
"cogentcore.org/core/core"
"cogentcore.org/core/paint"
"cogentcore.org/core/styles"
)
//go:embed myFonts/*.ttf
var myFonts embed.FS
func main() {
core.TheApp.SetSceneInit(func(sc *core.Scene) {
sc.SetWidgetInit(func(w core.Widget) {
w.AsWidget().Styler(func(s *styles.Style) {
s.Font.Family = "My Font"
})
})
})
b := core.NewBody()
paint.FontLibrary.FontsFS = mergefs.Merge(paint.FontLibrary.FontsFS, myFonts)
paint.FontLibrary.UpdateFontsAvail()
core.NewText(b).SetText("Hello, world!")
b.RunMainWindow()
} Please let me know if that works for you and if you have any questions. We will probably make that API easier in the future. |
Beta Was this translation helpful? Give feedback.
-
Thanks very much ; Here is the test I've made of this I downloaded the font from here https://github.com/madmalik/mononoki/releases/download/1.6/mononoki.zip and extracted it
Here I've made a test file to render:
It wasn't immediately apparent that the app is rendering the text as html. One odd thing, there seems to be an extra space after after replacing the Now, if I might be so bold as to ask how to eliminate the margin between the lines so that the box drawing characters appear connected, so it looks like this: |
Beta Was this translation helpful? Give feedback.
Yes, the documentation is certainly incomplete in this area right now, but we will definitely improve it going forward. It is possible to do this now, although the API for this may change after issues like #568, which we are planning to work on in the next few weeks. Regardless, here is the code I got working for this now (to make all widgets in the app use the embedded font by default):