Skip to content

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

@Geo5

Description

@Geo5

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions