Fix T71810: Flipping Sidebar with tabs breaks alignment
Panel alignment was only updated when panel size changed. Now we can also recognize changes in the category tabs offset and tag panels for alignment updates.
This commit is contained in:
parent
267061e8f4
commit
5d69d2a863
Notes:
blender-bot
2023-02-14 10:11:49 +01:00
Referenced by issue #71810, UI: Flipping a Sidebar with more tabs isn't aligned correct
|
@ -1640,7 +1640,12 @@ struct Panel *UI_panel_begin(struct ScrArea *sa,
|
|||
struct PanelType *pt,
|
||||
struct Panel *pa,
|
||||
bool *r_open);
|
||||
void UI_panel_end(uiBlock *block, int width, int height, bool open);
|
||||
void UI_panel_end(const struct ScrArea *sa,
|
||||
const struct ARegion *ar,
|
||||
uiBlock *block,
|
||||
int width,
|
||||
int height,
|
||||
bool open);
|
||||
void UI_panels_scale(struct ARegion *ar, float new_width);
|
||||
void UI_panel_label_offset(struct uiBlock *block, int *r_x, int *r_y);
|
||||
int UI_panel_size_y(const struct Panel *pa);
|
||||
|
|
|
@ -131,7 +131,7 @@ typedef enum eSpaceButtons_Align {
|
|||
BUT_AUTO = 2,
|
||||
} eSpaceButtons_Align;
|
||||
|
||||
static int panel_aligned(ScrArea *sa, ARegion *ar)
|
||||
static int panel_aligned(const ScrArea *sa, const ARegion *ar)
|
||||
{
|
||||
if (sa->spacetype == SPACE_PROPERTIES && ar->regiontype == RGN_TYPE_WINDOW) {
|
||||
return BUT_VERTICAL;
|
||||
|
@ -367,7 +367,19 @@ Panel *UI_panel_begin(
|
|||
return pa;
|
||||
}
|
||||
|
||||
void UI_panel_end(uiBlock *block, int width, int height, bool open)
|
||||
static float panel_region_offset_x_get(const ARegion *ar, int align)
|
||||
{
|
||||
if (UI_panel_category_is_visible(ar)) {
|
||||
if (align == BUT_VERTICAL && (RGN_ALIGN_ENUM_FROM_MASK(ar->alignment) != RGN_ALIGN_RIGHT)) {
|
||||
return UI_PANEL_CATEGORY_MARGIN_WIDTH;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void UI_panel_end(
|
||||
const ScrArea *sa, const ARegion *ar, uiBlock *block, int width, int height, bool open)
|
||||
{
|
||||
Panel *pa = block->panel;
|
||||
|
||||
|
@ -391,6 +403,7 @@ void UI_panel_end(uiBlock *block, int width, int height, bool open)
|
|||
}
|
||||
else {
|
||||
int old_sizex = pa->sizex, old_sizey = pa->sizey;
|
||||
int old_region_ofsx = pa->runtime.region_ofsx;
|
||||
|
||||
/* update width/height if non-zero */
|
||||
if (width != 0) {
|
||||
|
@ -405,6 +418,11 @@ void UI_panel_end(uiBlock *block, int width, int height, bool open)
|
|||
pa->runtime_flag |= PNL_ANIM_ALIGN;
|
||||
pa->ofsy += old_sizey - pa->sizey;
|
||||
}
|
||||
|
||||
int align = panel_aligned(sa, ar);
|
||||
if (old_region_ofsx != panel_region_offset_x_get(ar, align)) {
|
||||
pa->runtime_flag |= PNL_ANIM_ALIGN;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1004,7 +1022,6 @@ static bool uiAlignPanelStep(ScrArea *sa, ARegion *ar, const float fac, const bo
|
|||
int a, tot = 0;
|
||||
bool done;
|
||||
int align = panel_aligned(sa, ar);
|
||||
bool has_category_tabs = UI_panel_category_is_visible(ar);
|
||||
|
||||
/* count active, not tabbed panels */
|
||||
for (pa = ar->panels.first; pa; pa = pa->next) {
|
||||
|
@ -1061,14 +1078,10 @@ static bool uiAlignPanelStep(ScrArea *sa, ARegion *ar, const float fac, const bo
|
|||
|
||||
/* no smart other default start loc! this keeps switching f5/f6/etc compatible */
|
||||
ps = panelsort;
|
||||
ps->pa->runtime.region_ofsx = panel_region_offset_x_get(ar, align);
|
||||
ps->pa->ofsx = 0;
|
||||
ps->pa->ofsy = -get_panel_size_y(ps->pa);
|
||||
|
||||
if (has_category_tabs) {
|
||||
if (align == BUT_VERTICAL && (RGN_ALIGN_ENUM_FROM_MASK(ar->alignment) != RGN_ALIGN_RIGHT)) {
|
||||
ps->pa->ofsx += UI_PANEL_CATEGORY_MARGIN_WIDTH;
|
||||
}
|
||||
}
|
||||
ps->pa->ofsx += ps->pa->runtime.region_ofsx;
|
||||
|
||||
for (a = 0; a < tot - 1; a++, ps++) {
|
||||
psnext = ps + 1;
|
||||
|
|
|
@ -2344,7 +2344,7 @@ static void ed_panel_draw(const bContext *C,
|
|||
}
|
||||
}
|
||||
|
||||
UI_panel_end(block, w, h, open);
|
||||
UI_panel_end(sa, ar, block, w, h, open);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -129,6 +129,12 @@ typedef struct ScrAreaMap {
|
|||
ListBase areabase;
|
||||
} ScrAreaMap;
|
||||
|
||||
typedef struct Panel_Runtime {
|
||||
/* Applied to Panel.ofsx, but saved separately so we can track changes between redraws. */
|
||||
int region_ofsx;
|
||||
char _pad[4];
|
||||
} Panel_Runtime;
|
||||
|
||||
/** The part from uiBlock that needs saved in file. */
|
||||
typedef struct Panel {
|
||||
struct Panel *next, *prev;
|
||||
|
@ -159,6 +165,8 @@ typedef struct Panel {
|
|||
void *activedata;
|
||||
/** Sub panels. */
|
||||
ListBase children;
|
||||
|
||||
Panel_Runtime runtime;
|
||||
} Panel;
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue