Open 0xkalle opened 4 months ago
Use original key for extraFontMap in FontAtlasProsessor.go
// Add extra fonts
for _, fontInfo := range a.extraFonts {
// Scale font size with DPI scale factor
key := fontInfo.String()
if runtime.GOOS == windows {
fontInfo.size *= Context.GetPlatform().GetContentScale()
}
// Store imgui.Font for PushFont
var f imgui.Font
if len(fontInfo.fontByte) == 0 {
f = fonts.AddFontFromFileTTFV(fontInfo.fontPath, fontInfo.size, imgui.DefaultFontConfig, ranges.Data())
} else {
f = fonts.AddFontFromMemoryTTFV(fontInfo.fontByte, fontInfo.size, imgui.DefaultFontConfig, ranges.Data())
}
a.extraFontMap[key] = &f
}
I'll try that later today. Thanks. :)
Works. :) Is it worth it to make a PR for this or should it be fixed in the upcoming c-imgui version if still needed?
idk, could you check if this issue still exists on master?
I'll check. Last time I couldn't get it to run with master. I'll try again and report back. :)
Still persists on master as well.
It also leads to this odd window that keeps getting bigger like mentioned in #155 . But I can see the fonts in the beginning and on 125% scaling they are not the fonts they should be and not in the right size.
Here is a screen recording:
https://github.com/AllenDang/giu/assets/31923808/a76bb72c-dddf-4c90-864d-4134d23c2ee3
What happend?
When adding font in different sizes with
AddFont
to the FontAtlas, it is working fine on 100% Scale. On other Scales it is not working or partly working. e.g. on 125% no custom fonts work while on 150% some work.Beside the example below I also made as simple as possible example repo: https://github.com/0xkalle/giu-font-test
I also tried to run with master. But it is crashing (even the hello world example crashes)
Code example
```golang package main import ( g "github.com/AllenDang/giu" ) var ( datafont_16 *g.FontInfo datafont_24 *g.FontInfo datafont_32 *g.FontInfo datafont_48 *g.FontInfo datafont_64 *g.FontInfo datafont_72 *g.FontInfo datafont_96 *g.FontInfo ) func loop() { g.SingleWindow().Layout( g.Label("0verlay Text 96").Font(datafont_96), g.Label("0verlay Text 72").Font(datafont_72), g.Label("0verlay Text 64").Font(datafont_64), g.Label("0verlay Text 48").Font(datafont_48), g.Label("0verlay Text 32").Font(datafont_32), g.Label("0verlay Text 24").Font(datafont_24), g.Label("0verlay Text 16").Font(datafont_16), ) } func main() { wnd := g.NewMasterWindow("Font test", 600, 400, 0) datafont_16 = g.Context.FontAtlas.AddFont("robotomono-m.ttf", 16) datafont_24 = g.Context.FontAtlas.AddFont("robotomono-m.ttf", 24) datafont_32 = g.Context.FontAtlas.AddFont("robotomono-m.ttf", 32) datafont_48 = g.Context.FontAtlas.AddFont("robotomono-m.ttf", 48) datafont_64 = g.Context.FontAtlas.AddFont("robotomono-m.ttf", 64) datafont_72 = g.Context.FontAtlas.AddFont("robotomono-m.ttf", 72) datafont_96 = g.Context.FontAtlas.AddFont("robotomono-m.ttf", 96) wnd.Run(loop) } ```main.go
To Reproduce
Results are: 100%![100](https://github.com/AllenDang/giu/assets/31923808/38415cea-311c-4c6f-9ba8-c4333190546d)
125%![125](https://github.com/AllenDang/giu/assets/31923808/df81c778-58e4-4f58-8a76-b500c0b837f9)
150%
Version
(latest)
OS
windows 10