frang75 / nappgui_src

SDK for building cross-platform desktop apps in ANSI-C
https://www.nappgui.com
MIT License
506 stars 50 forks source link

Adjusting font for all controls on a form #51

Open MikeLorenz opened 1 year ago

MikeLorenz commented 1 year ago

The fonts on all the samples look very small to me & I would love to be able to adjust that. It would be interesting to take the GuiHello sample and add a slider to adjust the font size of all the controls in the window. Is that possible?

frang75 commented 1 year ago

Hi @MikeLorenz!

NAppGUI gets the standard font size from the Win32 global settings. Please check these steps:

1) Open regedit. This is a Win32 application. If the font size is different from GuiHello, then it is a bug in NAppGUI and I need to fix it.

2) If the size of both applications is the same, I have to include a new function in NAppGUI gui_global_font() so that all components use the same font.

Keep in touch!

font_size

MikeLorenz commented 1 year ago

On my system, the font looks exactly the same as regedit.

I apologize that I wasn't being clear in my question. For people with vision issues it would be nice to be able to adjust the font in the app: for the app developer to send a new font size to a panel, and have that send it to all its children. It would be up to the developer to decide how the user does it. It could be a slider, but also could be something like ctrl-mousewheel like many browsers do.

If your proposed gui_global_font() would do that, then great!

frang75 commented 1 year ago

Thanks for the clarification. In that case gui_global_font() would not work correctly. Although all controls use the system font by default, it is possible to change it in some of them with functions like label_font() or button_font(). In these cases, the proportion between fonts should be respected.

What we need is a function that allows us to change the scaling of all control fonts: gui_font_scale(const real32_t scale);

scale > 1 --> All fonts will grow proportionally. scale > 0 && < 1 --> All fonts will shrink proportionally. scale == 1 --> All fonts will return to their original size.

In addition, this function must recompute the window layout, so that the controls are resized correctly, respecting the spacing and composition of the window.