GithubHelp home page GithubHelp logo

More FontAwesome options about hello_imgui HOT 5 CLOSED

pthom avatar pthom commented on May 21, 2024
More FontAwesome options

from hello_imgui.

Comments (5)

pthom avatar pthom commented on May 21, 2024 1

More options were added in this PR

from hello_imgui.

pthom avatar pthom commented on May 21, 2024

Hello,

There are lots of possible customizations that users might desire when it comes to fonts (glyph range, glyph layout options, additional icon fonts other than font awesome, etc).

Thus, at the moment, the user is given the possibility to completely override the font loading function (simply by setting runnerParams.callbacks.LoadAdditionalFonts. I suspect you know this already)). This gives the maximum level of customization, and keeps the API simple.

For example, in src/hello_imgui_demos/hello_imgui_demodocking/hello_imgui_demodocking.main.cpp, we have this:

void MyLoadFonts()
{
    // First, we load the default fonts (the font that was loaded first is the default font)
    HelloImGui::ImGuiDefaultSettings::LoadDefaultFont_WithFontAwesomeIcons();

    // Then we load a second font from
    // Since this font is in a local assets/ folder, it was embedded automatically
    std::string fontFilename = "fonts/Akronim-Regular.ttf";
    gAkronimFont = HelloImGui::LoadFontTTF_WithFontAwesomeIcons(fontFilename, 40.f);
}

...

    // Custom load fonts
    runnerParams.callbacks.LoadAdditionalFonts = MyLoadFonts;

I think it could be possible to update the available functions inside src/hello_imgui/imgui_default_settings.h (these functions enable users to build their own font loading function). You seem to know more than me about font configurations. Would you like to work on a PR related to this?

from hello_imgui.

codecat avatar codecat commented on May 21, 2024

Sure! After taking a quick look, it seems there might already have been an attempt at adding customization to font configurations in HelloImGui::LoadFontTTF? There's a makeFontConfig lambda which I don't think has to be a lambda right now, so I suspect it was going to be some kind of default for a parameter.

Do you think lambda's for font configurations is a good idea? Perhaps something like this could work:

LoadFontTTF("fonts/DroidSans.ttf", 12.0f, [](ImFontConfig& config) {
  // modify the config here
  config.GlyphMinAdvanceX = 18;
  config.GlyphMaxAdvanceX = 18;
});

And then probably exposing MergeFontAwesomeToLastFont with the same kind of lambda function.

from hello_imgui.

pthom avatar pthom commented on May 21, 2024

I don't know if a lambda is the most appropriate. The important thing to know is that the ImFontConfig instance has to live during the whole application lifecycle (imgui only takes a pointer to it, which should not be dangling).

This is why I added this static container:

 static std::map<std::string, ImFontConfig> allFontConfigs;
    allFontConfigs[fontFilename] = makeFontConfig();
    auto& fontConfig = allFontConfigs.at(fontFilename);

from hello_imgui.

codecat avatar codecat commented on May 21, 2024

If you look at the code of AddFontFromMemoryTTF, it doesn't actually keep the pointer around at all:

https://github.com/ocornut/imgui/blob/5f45047fb67c2147c6a1b1798b98d401e7998b51/imgui_draw.cpp#L2133

So it's safe to just keep it on the stack, which will simplify a lot of this code.

I'll do a pull request shortly!

from hello_imgui.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.