Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[bug] AddFont not working depending on scale factor on windows #759

Open
0xkalle opened this issue Feb 9, 2024 · 10 comments
Open

[bug] AddFont not working depending on scale factor on windows #759

0xkalle opened this issue Feb 9, 2024 · 10 comments
Labels
bug Something isn't working

Comments

@0xkalle
Copy link

0xkalle commented Feb 9, 2024

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

  1. Set Scale in windows to 100 / 125 / 150 %
  2. Run my demo
  3. see the fonts in window.

Results are:
100%
100

125%
125

150%
150

Version

(latest)

OS

windows 10

@wxblue
Copy link

wxblue commented Feb 21, 2024

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
	}

@0xkalle
Copy link
Author

0xkalle commented Feb 27, 2024

I'll try that later today. Thanks. :)

@0xkalle
Copy link
Author

0xkalle commented Feb 27, 2024

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?

@gucio321
Copy link
Collaborator

idk, could you check if this issue still exists on master?

@0xkalle
Copy link
Author

0xkalle commented Feb 27, 2024

I'll check. Last time I couldn't get it to run with master. I'll try again and report back. :)

@0xkalle
Copy link
Author

0xkalle commented Mar 7, 2024

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:

2024-03-07.08-17-50.mp4

@gucio321
Copy link
Collaborator

gucio321 commented Jul 7, 2024

@0xkalle May I ask you to try again with v0.8.1?
The issue from your previous post was fixed in #810

@gucio321 gucio321 added the Before cimgui-go migration This issue was related to imgui-go and we need to confirm it still applies cimgui-go label Jul 7, 2024
@0xkalle
Copy link
Author

0xkalle commented Jul 8, 2024

@0xkalle May I ask you to try again with v0.8.1? The issue from your previous post was fixed in #810

"Grow to death" is gone. 👍

Font sizes are not working like described in the initial post of the thread #759 (comment)

@gucio321 gucio321 removed the Before cimgui-go migration This issue was related to imgui-go and we need to confirm it still applies cimgui-go label Jul 10, 2024
@0xkalle
Copy link
Author

0xkalle commented Oct 11, 2024

@gucio321 does it make sence to test with 0.9.X again? :)

@gucio321
Copy link
Collaborator

Meh, not really. I think it's still a bug in giu unfortunately

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants