UI: Add uiItemL_ex with extra highlight and redalert arguments.
Will be used for dialog boxes:
Differential D6934
UI: Allow to draw uiItemL in white (as selected) Authored by Yevgeny Makarov (jenkm) on Feb 25 2020, 8:06 PM.
Details UI: Add uiItemL_ex with extra highlight and redalert arguments. Will be used for dialog boxes:
Diff Detail
Event TimelineComment Actions This looks better and allows better separation between header and text paragraph. But I'm not sure if we consider this somewhat abuse of the selected state - seems a bit like a hack? I'll let @Brecht Van Lommel (brecht) be the judge. Comment Actions I guess the UI_SELECT_DRAW flag is just for these purposes. UI_SELECT = (1 << 0), /* use when the button is pressed */ UI_SELECT_DRAW = (1 << 5), /* Display selected, doesn't impact interaction. */ We also already use this "hack" for Splash Screen to draw version number. Comment Actions Interesting. Although could we get the same result by adding a new uiBut.flag instead? As in follow the pattern of UI_BUT_REDALERT (UI_interface.h) as there is also a similar UI_BUT_INACTIVE too. LIke "UI_BUT_TEXTHI" or similar. then check for that in interface_widgets.c widget_state() and set the text color to use TH_TEXT_HI. It looks like you'd also want to alter uiItemL so that it returns a pointer to the uiBut it creates, like the others. Then you could do something like: uiBut *title = uiItemL(layout, title, ICON_ERROR); UI_but_flag_enable(title, UI_BUT_TEXTHI); Comment Actions This is overkill IMHO. If I can't change that white color, that's not good. Comment Actions
Why not test the patch and find out for yourself? But yes, he should not have said "white" but instead mentioned that it used Menu Back "selected" color rather than the usual "text" color. Comment Actions You can add an uiItemL_ex function with an extra const bool highlight argument. This can then be extended as needed. uiItem functions do not return uiBut* pointers, they're meant to abstract away individual buttons. This is just drawing a label with the Text Highlight color from the theme, which is perfectly fine. What's poor here is the name UI_SELECT_DRAW, it could be renamed to UI_TEXT_HIGHLIGHT to make more clear what it does. Comment Actions I would if I knew how.
Alright, thanks for the explanation. I was worried a bit. lol Comment Actions
The current uses of UI_SELECT_DRAW make a bit more sense as it is altering press-able buttons. Would be nice to keep this behavior separate so we could later make other (possible) changes to those types of buttons, like outline color, etc. Is it a thought to go with your uiItemL_ex() idea but use a new uiBut flag like UI_TEXT_HIGHLIGHT? That way it would be a bit more targeted. And we could even use it for non-label things if we really wanted to. Comment Actions
The uiItemL_ returns a pointer. The current code: static uiBut *uiItemL_(uiLayout *layout, const char *name, int icon) { ... } void uiItemL(uiLayout *layout, const char *name, int icon) { uiItemL_(layout, name, icon); } I just added: void uiItemL_select(uiLayout *layout, const char *name, int icon) { uiBut *but = uiItemL_(layout, name, icon); UI_but_flag_enable(but, UI_SELECT_DRAW); } It's a minimalistic code, and it's easy to use. uiItemL_select(layout, title, ICON_NONE);
The UI_SELECT_DRAW already exists, it's not my idea. I'm not sure it will be used much so I don't see the need to do anything complicated for now. In the theme editor, this (color used) is called "Selected", so there is a reason to call it "Selected" instead of "Highlighted". Comment Actions In any case, regardless of how it will be implemented internally, it is convenient to have a uiItemL_select() wrapper to make it easy to use. That's exactly what's done in this patch. Comment Actions Yes, I'm talking about the public API, not static functions.
Yes, but when making changes like these it's good to check if the naming makes sense and refactor as needed, to ensure we are not propagating bad code further.
That may be true for popups, but uiItemL is used outside of those too. I believe it's using the text highlight color in most places. The fact that it's using the selected color for popups is more of a hack, since it clearly has nothing to do with selection. Regardless, please use uiItemL_ex. We have that convention for adding functions with more arguments, so that it's easily extensible when more arguments are needed rather than adding a function for every variation. Comment Actions Hey, if you are going to go through the trouble of adding a uiItemL_ex() in that way (called after uiItemL_) then it might be nice to support an "alignment" argument. As in you could center text in a block if you wanted to, by just removing UI_BUT_TEXT_LEFT and UI_BUT_TEXT_RIGHT. Unfortunately we don't have a UI_BUT_TEXT_CENTER defined as that is just the default. But a new enum could be defined for passing to it. Could come in handy for titling sometimes (like on a popover) if a horizontal rule was added afterward. Just a thought anyway. But probably off-topic. |