giu: [bug] AddFont not working depending on scale factor on windows
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
main.go
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)
}
To Reproduce
- Set Scale in windows to 100 / 125 / 150 %
- Run my demo
- see the fonts in window.
Results are:
100%
125%
150%
Version
(latest)
OS
windows 10
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 20
OMG I got it! This is all because of we do the following:
so, at the moment, when user requests font with font info A, it actually doesn’t exist, because the only loaded font info is B (which is B := A.size = scale*A.size)
fix comming soon.
I for now just use a local giu version and exclude the lines mentioned above. Yes, the font sizes do not adjust automatically, but in my usecase that is not important, because font sizes are adjusted by window size anyways.
okey, I can reproduce on linux (when I remove GOOS part). For some reason, if I modify the fontInfo.size anyhow, it doesn’t actually change the size.
We need to test with cpp stuff as technically this should work… Let me check that out later
@gucio321 More than happy to help debuging it. 😃 I am just not into imgui enough to understand everything (maybe yet 😉 ).
I’ll check what you mentioned as soon as I have time and let you know what happens.
@0xkalle thank you for testing. Unfortunately I can’t say anything about windows as I’m working on linux all the time and my windows is not dev-friendly atm…
If you’d like to debug this I’d really appreciate.
FIrst of all I’d check what this scale even is and whether without these lines it works better or something:
(This is FontAtlasProcessor.go:314 on master). You can use
go mod vendorin your test repo (should work with cimgui-go now)“Grow to death” is gone. 👍
Font sizes are not working like described in the initial post of the thread https://github.com/AllenDang/giu/issues/759#issue-2126893620
Use original key for extraFontMap in FontAtlasProsessor.go