Topic: Styling and richtext.lua
tothxa![]() Topic Opener |
Posted at: 2023-01-08, 01:28
Working on #5717 I came to realise that keyboard shortcut help would be much better autogenerated. This led me to examine how formatting works, and I was surprised that:
I gather making all UI styleable is one of our important development goals, so I wonder how these problems should be solved.
Then what should be the name of the style that is now implemented in ![]() ![]() |
Nordfriese![]() |
Posted at: 2023-01-08, 10:38
I'm not sure what you mean exactly. Both richtext.lua and text_layout.* simply provide wrappers around richtext tags. For maximum control, you can write text with tags directly, like
Or you can use the convenience functions, like
The Lua wrappers have the problem that colours and fontsizes are hardcoded, but this will eventually be fixed in the wrapper, to fix all use cases at once. This is also why you shouldn't use direct styling for anything that a theme should be able to modify – the C++ way uses theme-specific colours and font sizes, with direct styling that responsibility falls to you. Except for simple, non-theme-specific tags like ![]() ![]() |
tothxa![]() Topic Opener |
Posted at: 2023-01-08, 13:12
I mean functions in
So I'd like to correct these things, and my questions are about what the right approach would be. ![]() ![]() |
Nordfriese![]() |
Posted at: 2023-01-08, 13:36
This is all part of the bigger task of placing all UI elements under the theme's control. Lua code should not hardcode any font size or colour attributes; instead those should be fetched from C++ which looks them up in the current theme's definition. So the proper way would be to add a function to the Lua interface In C++ then simply use
You shouldn't need to, especially after https://github.com/widelands/widelands/pull/5734 ![]() ![]() |
tothxa![]() Topic Opener |
Posted at: 2023-01-08, 14:31
OK, I think I can do this for everything that currently has hardcoded style in Now to the last part of the original post: What common prefix should I use for the font and paragraph styles extracted from ![]() ![]() |
Nordfriese![]() |
Posted at: 2023-01-08, 15:00
+1
Most other functions in text_layout are called ![]() ![]() |
tothxa![]() Topic Opener |
Posted at: 2023-01-08, 15:18
Sorry, I meant font and paragraph styles in ![]() ![]() |