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

StyleSetter: apply SetFontSize for all default fonts (not only first one) #712

Open
Geo5 opened this issue Oct 8, 2023 · 12 comments
Open
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@Geo5
Copy link
Contributor

Geo5 commented Oct 8, 2023

What happend?

If one is adding fonts containing e.g. icons or other special charactes with FontAtlas.SetDefaultFont(...) and uses StyleSetter.SetFontSize(...).To(...) afterwards, only text/characters/glyphs contained in the last added default font are shown.

This seems to be, because new default fonts are prepended to the list of default fonts here in SetDefaultFont(...) and the StyleSetter.SetFontSize(...) uses index 0 of the default fonts.

The minimal example does currently not show any icon at all, because of #711 but looks as follows on v0.7.0:

Fonts_v0 7 0_1

I don't have any idea, how this could be fixed, because as far as i understand the magic happens by merging the default fonts in rebuildFontAtlas, which is not done for the extra fonts (which StyleSetter uses to do the styling)

Code example

main.go
package main

import (
	iconFonts "github.com/juliettef/IconFontCppHeaders"

	g "github.com/AllenDang/giu"
)

var IconFont = iconFonts.IconsForkAwesome

func Icon(name string) string {
	ret, ok := IconFont.Icons[name]
	if !ok {
		panic(name + " icon not found")
	}

	return ret
}

func loop() {
	g.SingleWindow().Layout(
		g.Style().SetFontSize(30).To(
			g.Label("Content line"),
			g.Label("Content line "+Icon("Check")),
		),

		g.Button("Normal button"),
		g.Button("Normal button"+Icon("Check")),
	)
}

func main() {
	wnd := g.NewMasterWindow("Multiple fonts and icons", 600, 400, g.MasterWindowFlagsNotResizable)

	// Change the default font to include icons
	g.Context.FontAtlas.SetDefaultFont("forkawesome-webfont.ttf", 20)

	wnd.Run(loop)
}

To Reproduce

  1. Run my demo

Version

master

OS

Linux

@Geo5 Geo5 added the bug Something isn't working label Oct 8, 2023
@gucio321
Copy link
Collaborator

so, if index 0 is the only case, fix here should be easy to do. It just needs some extra stuff in style setter to extend fonts field to a slice of fonts and push them all instead of only one font.
If I remember correctly I put index 0 there because I was too lazy to apply something more complex 😄.

@gucio321 gucio321 added enhancement New feature or request good first issue Good for newcomers and removed bug Something isn't working labels Feb 17, 2024
@gucio321 gucio321 changed the title [bug] StyleSetter.SetFontSize does not work as expected with icon fonts StyleSetter: apply SetFontSize for all default fonts (not only first one) Feb 17, 2024
@Geo5
Copy link
Contributor Author

Geo5 commented Feb 20, 2024

So you suggest making this

font *FontInfo

a slice of fonts and maybe adding a new function like this

giu/Style.go

Line 43 in 304f0b9

func PushFont(font *FontInfo) bool {

which takes a slice of fonts and just calls PushFont for all of them?

@gucio321
Copy link
Collaborator

Yeah and This

func (ss *StyleSetter) SetFontSize(size float32) *StyleSetter {
should apply to all default fonts

Also there is no need to add me method - setfont can be modified SetFont(fonrs .. FontInfo)

@MisustinIvan
Copy link
Contributor

I can get to work on this

@MisustinIvan
Copy link
Contributor

if I push multiple fonts, doesn't it just use the font on top of the stack? How does it then render the button with the icon?

@gucio321
Copy link
Collaborator

I suppose that when you push multiple fonts it tries to use this on top of the stack, then it tries the next and so on...

iirc there was something like MergeMode (?)
Maybe this is important?

@MisustinIvan
Copy link
Contributor

Is there by chance any way to view the current fonts on the stack?

@gucio321
Copy link
Collaborator

no idea... You can search in cimgui_funcs.go in cimgui-go repo but I'm affraid that no...

@MisustinIvan
Copy link
Contributor

Well i wrote something, but it doesn't work. If you want to take a look, its here.

@MisustinIvan
Copy link
Contributor

Bruh I read the read the source code all the way to dear imgui source and have no idea

@MisustinIvan
Copy link
Contributor

Still have to figure out why does it work withou setting the font size... I will think about it.

@MisustinIvan
Copy link
Contributor

Bruh I dont think there is a way to acomplish this without a major rewrite of a lot of things, which would in turn break a ton of other stuff. If you want icons in your font, just use a nerd font. They have all the icons from awesome and a lot more.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

3 participants