SpaiR / imgui-java

JNI based binding for Dear ImGui
MIT License
587 stars 90 forks source link

Bug: Problem with adding a font #144

Closed ToshaEssential closed 1 year ago

ToshaEssential commented 1 year ago

Version

1.86.4

What happened?

I wanted to add a new standard font to the app. When adding ImFont and .build this problem occurs. Just black forms, instead of the interface.

Reproduction

Here's the code and the result, which I couldn't get rid of and somehow solve.

image.png

Source Code:

public class App extends Application {
    private static ImFont fontDefault;

    public static void main(String[] args) {
        launch(new App());
    }

    @Override
    protected void preRun() {
        ImGuiIO io = getIO();
        fontDefault = io.getFonts().addFontFromFileTTF("src/resources/fonts/Patsy_Sans.otf", 18f, io.getFonts().getGlyphRangesCyrillic());
        io.getFonts().build();
    }

    @Override
    protected void configure(Configuration config) {
        config.setTitle("TimeTracker");
        config.setFullScreen(true);
    }

    @Override
    public void process() {
        setNextWindowPos(0, 0);
        showStyleEditor(getStyle());
        begin("Time Panel", ImGuiWindowFlags.AlwaysAutoResize);
        for (int j = 0; j < 12; j++) {
            for (int i = 1; i <= 31; i++) {
                colorButton("Button:" + i + " " + j, new float[]{new Random().nextFloat(), new Random().nextFloat(),
                        new Random().nextFloat(), 1}, ImGuiColorEditFlags.NoTooltip);
                if (isItemHovered()) {
                    beginTooltip();
                    textColored(0, 1, 0.2f, 1, "March 21");
                    endTooltip();
                }
                sameLine(0, 1);
                if (i % 7 == 0) newLine();
            }
            newLine();
            newLine();
        }
        end();
    }
}

Relevant log output

The logs are all clear.
ToshaEssential commented 1 year ago

I used preRun() method to configure fonts. And after looking at the source examples in the repository I found that they use initImGui() method for configuration. After that, everything immediately worked as it should and the font appeared.