Page MenuHome

UI: Unify drawing style of UILists and Tree row buttons.
Needs ReviewPublic

Authored by Alessio Monti di Sopra (a.monti) on Jan 17 2022, 6:58 PM.

Details

Summary

This patch tries to harmonize the drawing of UILists and the new "Tree view" row buttons:

  • They now share their theme settings, under User interface -> List Item
  • UILists buttons are now drawn only when selected or on hover, as it's currently done for the "Tree View"

Also included in the patch is a way to highlight text in the selected tree row.

Diff Detail

Repository
rB Blender

Event Timeline

Alessio Monti di Sopra (a.monti) requested review of this revision.Jan 17 2022, 6:58 PM
Alessio Monti di Sopra (a.monti) created this revision.
Julian Eisel (Severin) requested changes to this revision.Jan 27 2022, 5:33 PM

It makes definitely sense to me to synchronize or share the colors here. The current blue color is way to extreme and attention grabbing. In fact I also worked on a patch already, but didn't finish it.
I'm also a fan of keeping highlights subtle, which this patch does, so another +1.


  • This needs versioning code so the highlight color works for preferences saved in earlier versions, see do_versions_theme().
  • Since this also adds highlighting to list-rows, it has the same issue as noted here https://developer.blender.org/D12549#363450. I can look into this, but it should be addressed before or when this lands.

@Pablo Vazquez (pablovazquez) do you think we should add own theme colors for tree-rows, or is it fine to share colors with list rows?

source/blender/editors/interface/interface_widgets.c
3701–3720

There's not really a point in keeping two functions here, widget_treerow() can just include what widget_treerow_exec() does.

4555

Would suggest removing that since it can be confusing (what's "later"?) and just notes an implementation detail that's not really relevant here.

source/blender/editors/interface/tree_view.cc
626

Can just check but->flag & UI_BUT_LIST_ITEM here, just like ui_layout_list_set_labels_active(). In fact, we could just call that function on the row layout (and of course rename it to ui_layout_list_or_tree_row_set_labels_active(). I prefer that over throwing this into the (already ugly) polish function.

643

If we're reusing this, we should rename the flag to UI_BLOCK_LIST_OR_TREE_ITEM

This revision now requires changes to proceed.Jan 27 2022, 5:33 PM
  • This needs versioning code so the highlight color works for preferences saved in earlier versions, see do_versions_theme().

Right, completely forgot about it, sorry.
I'll update the diff also including the various name changes.

Ah, I didn't know about that other patch.
For this overlap problem I tried to expand ui_handle_tree_hover() to also manage this case too, but as @Harley Acheson (harley) already found, it doesn't seem to work as expected..

Between the two I would always favor a patch that simplifies (yours) over one that continues with the current mess (mine).

@Alessio Monti di Sopra (a.monti) - For this overlap problem I tried to expand ui_handle_tree_hover() to also manage this case too, but as @Harley Acheson (harley) already found, it doesn't seem to work as expected..

For completeness I also applied this patch and then added my attempt at fixing that child-item issue with ui_region_handler and had no luck. That basically looks like this:

static int ui_region_handler(bContext *C, const wmEvent *event, void *UNUSED(userdata))
{
  ...
  if (retval == WM_UI_HANDLER_CONTINUE && listbox) {

    uiBut *hovered_row = ui_list_row_find_mouse_over(region, event->xy);
    if (hovered_row) {
      hovered_row->flag |= UI_ACTIVE;
    }

    retval = ui_handle_list_event(C, event, region, listbox);
  ...

The above (roughly) matches what is happening for ui_handle_tree_hover, but a bit simpler. But still didn't work. LOL.

The above (roughly) matches what is happening for ui_handle_tree_hover, but a bit simpler. But still didn't work. LOL.

No idea.. What I did instead is to expand that function to include both the list and tree cases while keeping the same logic and, it doesn't work.
The only thing I noticed in debug is that the function gets executed a lot of times in a row with different "events" and slightly different cursor positions. Not sure if that is expected, as I'm definitely not familiar with that.

One other thing: to expand ui_handle_tree_hover()I wanted to change the first check to use UI_BLOCK_LIST_OR_TREE_ITEM, that's not possible though, as the flag gets disabled to avoid tagging for theme unwanted labels.

@Julian Eisel (Severin) @Harley Acheson (harley) The more I look at this system the more I hate it to be honest, I'm wondering if moving everything inside a single function (that manage both the theming flag and the set active part) would be better or not, something like this:

-void ui_layout_list_set_labels_active(uiLayout *layout)
+void ui_layout_list_or_tree_row_manage_labels(uiLayout *layout, bool active)
 {
   LISTBASE_FOREACH (uiButtonItem *, bitem, &layout->items) {
     if (bitem->item.type != ITEM_BUTTON) {
-      ui_layout_list_set_labels_active((uiLayout *)(&bitem->item));
+      ui_layout_list_or_tree_row_set_labels_active((uiLayout *)(&bitem->item), active);
     }
-    else if (bitem->but->flag & UI_BUT_LIST_ITEM) {
-      UI_but_flag_enable(bitem->but, UI_SELECT);
+    else if (ELEM(bitem->but->type, UI_BTYPE_LABEL, UI_BTYPE_TEXT)) {
+      UI_but_flag_enable(bitem->but, UI_BUT_LIST_OR_TREE_ITEM);
+      if (active) {
+        UI_but_flag_enable(bitem->but, UI_SELECT);
+      }
     }
   }
 }

and keep the block flag active for other checks.

Alessio Monti di Sopra (a.monti) edited the summary of this revision. (Show Details)

Actually, it's probably better to just update the patch with that mentioned change included, so that it's clearer what I mean.


  • added versioning code
  • moved theme flagging from the item functions (uiItemL() and uiItemFullR()) to ui_layout_list_or_tree_row_manage_labels(), where previously there was only the set active logic
  • expanded ui_handle_tree_hover() logic to manage uiLists as well [currently not working as intended]
  • renamed variables and functions to mention the "tree" part
  • added the missing bit to make the highlighting work when hovering overlapped buttons in uiLists

    @Julian Eisel (Severin) it was in ui_but_update_from_old_block(), in interface.c, everything seems to work correctly now but I'm not sure if that has other implications
  • better names and comments here and there

@Pablo Vazquez (pablovazquez) do you think we should add own theme colors for tree-rows, or is it fine to share colors with list rows?

I think it's okay to use list row colors since it serves a similar purpose, look-alike, and we already have way too many theme settings.