Comments (5)
More options were added in this PR
from hello_imgui.
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.
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.
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.
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)
- Custom patched ImGui version HOT 3
- Google Closure compiler support is almost perfect except for this one line. HOT 22
- Offline usage: avoid re-downloading glfw and freetype HOT 2
- Custom drawing behind GUI not possible due to Impl_Frame_3D_ClearColor() HOT 2
- macOS bundle support HOT 2
- Can I change a borderless window size? HOT 3
- Metal backend + emscripten favicon and shell template HOT 22
- Ability to put user menu items between the App Menu and the View Menu HOT 1
- Sdl Dpi awareness on Windows / multiple monitors HOT 1
- New back-end default HOT 3
- adding generated files to assets directory? HOT 8
- freetype dependency in Windows HOT 4
- how to add a toolbar (or other fixed windows) that limits the available main docking space? HOT 9
- Is there a way to make input_text to show only the last part of the text while deactivated HOT 2
- offline build HOT 13
- FontAwesome solid vs. regular HOT 4
- Problems with implot from vcpkg HOT 1
- RunnerParams backendType compatibility is broken HOT 1
- text blurry when connected to a non-retina external monitor HOT 4
- Improve HELLOIMGUI_WIN32_NO_CONSOLE implementation HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from hello_imgui.