Page MenuHome

UI: Active Default Buttons

Authored by Harley Acheson (harley) on Sat, Aug 24, 1:31 AM.



Buttons can have a flag set with UI_BUT_ACTIVE_DEFAULT to indicate they are the default button among a group. The button executed if just pressing "Enter". For example the "Save" button on the "Do want to save?" dialog.

Unfortunately the way that indication is currently drawn has a few problems.

  • The color is based on the "Inner Selected" of "Menu Item", which is not intuitive to find.
  • The color will usually look muddy since it is 50% mix of that color and the regular color.
  • The bend radius of the corners is hard-coded. So if you change the roundness of the buttons the corners will not match. For example you can see this if you make the buttons more or less rounded:

This patch fixes these problems and leaves the button looking nicer. The following shows current look on top, what below shows after the patch is applied. If you look closely at the top one you can actually see that the corner radius differs between the buttons and the corners of the Save button looks a bit grey since the blue isn't quite covering up the gray at the corners.

Diff Detail

rB Blender

Event Timeline

Harley Acheson (harley) edited the summary of this revision. (Show Details)

Missed that a function was no longer needed and could be removed.

This revision is now accepted and ready to land.Sat, Aug 24, 10:34 AM

This is much nicer that then current active button overlays.

Brecht Van Lommel (brecht) requested changes to this revision.Mon, Aug 26, 7:08 PM

Visually looks fine and it's always nice to simplify code.


The drawing code should not permantly modify any button flags. Maybe you can modify state, a little bit higher in this function?

diff --git a/source/blender/editors/interface/interface_widgets.c b/source/blender/editors/interface/interface_widgets.c
index 79212ee..594c425 100644
--- a/source/blender/editors/interface/interface_widgets.c
+++ b/source/blender/editors/interface/interface_widgets.c
@@ -4772,6 +4772,14 @@ void ui_draw_but(const bContext *C, ARegion *ar, uiStyle *style, uiBut *but, rct
+    if (but->block->flag & UI_BLOCK_POPOVER_ONCE) {
+      if ((state & UI_ACTIVE) && ui_but_is_popover_once_compat(but)) {
+        state |= UI_BUT_ACTIVE_DEFAULT;
+      }
+    }
     wt->state(wt, state, drawflag);
     if (wt->custom) {
       wt->custom(but, &wt->wcol, rect, state, roundboxalign);
This revision now requires changes to proceed.Mon, Aug 26, 7:08 PM

A change suggested by @Brecht Van Lommel (brecht)....

For setting default for active button on UI_BLOCK_POPOVER_ONCE we alter uiWidgetType.state instead of uiBut.flag

A down side to this patch is now there is no visible difference between a toggle property thats pressed, and a button that runs an operator.

Although in the context these are used - they're not displayed next to each other so there isn't so much room for confusion.

Code changes LGTM.

This revision was not accepted when it landed; it landed in state Needs Review.
This revision was automatically updated to reflect the committed changes.

@Harley Acheson (harley) recently the new file browser is making strange jokes to my mind, it exchanges it for a normal file browser, and no longer something that is part of blender, so now it comes naturally to me to use the arrows shortcuts for "tabbing" between the buttons, "save , don't save, cancel "
so I ask you ... it would be too expensive to add the tabbing on this section with the shortcut "tab" and with the arrows arrow shorcuts ??