UI: Support layout based region resizing that still allows user resizing
No user visible changes expected. This is needed for the asset shelf (#104831), so that the user can resize the asset shelf region, but it's ensured to always be snapped to a multiple of the row height (which can change over redraws). Before this, `RGN_FLAG_DYNAMIC_SIZE` would have to be set so that regions can control their own size in the `ARegionType::layout()` callback. But this would also disable resizing the region by the user. Tagging regions as being dynamically sized and disabling user resizing are now two separate options/flags. Included changes: - Rename `RGN_FLAG_PREFSIZE_OR_HIDDEN` to `RGN_FLAG_NO_USER_RESIZE` and make that generally disable user resizing like `RGN_FLAG_DYNAMIC_SIZE` used to, so that it can be used for more than just the properties editor tabs region. - Ensure regions that relied on the previous `RGN_FLAG_DYNAMIC_SIZE` behavior that disallowed user resizing have the `RGN_FLAG_NO_USER_RESIZE` flag set too now. - Versioning to ensure the previous point for old files. - Update comments.
This commit is contained in:
@@ -29,7 +29,7 @@ extern "C" {
|
||||
|
||||
/* Blender file format version. */
|
||||
#define BLENDER_FILE_VERSION BLENDER_VERSION
|
||||
#define BLENDER_FILE_SUBVERSION 11
|
||||
#define BLENDER_FILE_SUBVERSION 12
|
||||
|
||||
/* Minimum Blender version that supports reading file written with the current
|
||||
* version. Older Blender versions will test this and cancel loading the file, showing a warning to
|
||||
|
||||
@@ -436,19 +436,7 @@ void blo_do_versions_400(FileData *fd, Library * /*lib*/, Main *bmain)
|
||||
version_vertex_weight_edit_preserve_threshold_exclusivity(bmain);
|
||||
}
|
||||
|
||||
/**
|
||||
* Versioning code until next subversion bump goes here.
|
||||
*
|
||||
* \note Be sure to check when bumping the version:
|
||||
* - #do_versions_after_linking_400 in this file.
|
||||
* - "versioning_userdef.c", #blo_do_versions_userdef
|
||||
* - "versioning_userdef.c", #do_versions_theme
|
||||
*
|
||||
* \note Keep this message at the bottom of the function.
|
||||
*/
|
||||
{
|
||||
/* Keep this block, even when empty. */
|
||||
|
||||
if (!MAIN_VERSION_FILE_ATLEAST(bmain, 400, 12)) {
|
||||
if (!DNA_struct_elem_find(fd->filesdna, "LightProbe", "int", "grid_bake_samples")) {
|
||||
LISTBASE_FOREACH (LightProbe *, lightprobe, &bmain->lightprobes) {
|
||||
lightprobe->grid_bake_samples = 2048;
|
||||
@@ -498,5 +486,36 @@ void blo_do_versions_400(FileData *fd, Library * /*lib*/, Main *bmain)
|
||||
}
|
||||
}
|
||||
FOREACH_NODETREE_END;
|
||||
|
||||
LISTBASE_FOREACH (bScreen *, screen, &bmain->screens) {
|
||||
LISTBASE_FOREACH (ScrArea *, area, &screen->areabase) {
|
||||
LISTBASE_FOREACH (SpaceLink *, sl, &area->spacedata) {
|
||||
ListBase *regionbase = (sl == area->spacedata.first) ? &area->regionbase :
|
||||
&sl->regionbase;
|
||||
|
||||
/* Layout based regions used to also disallow resizing, now these are separate flags.
|
||||
* Make sure they are set together for old regions. */
|
||||
LISTBASE_FOREACH (ARegion *, region, regionbase) {
|
||||
if (region->flag & RGN_FLAG_DYNAMIC_SIZE) {
|
||||
region->flag |= RGN_FLAG_NO_USER_RESIZE;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Versioning code until next subversion bump goes here.
|
||||
*
|
||||
* \note Be sure to check when bumping the version:
|
||||
* - #do_versions_after_linking_400 in this file.
|
||||
* - "versioning_userdef.c", #blo_do_versions_userdef
|
||||
* - "versioning_userdef.c", #do_versions_theme
|
||||
*
|
||||
* \note Keep this message at the bottom of the function.
|
||||
*/
|
||||
{
|
||||
/* Keep this block, even when empty. */
|
||||
}
|
||||
}
|
||||
|
||||
@@ -105,6 +105,11 @@ static void do_versions_theme(const UserDef *userdef, bTheme *btheme)
|
||||
FROM_DEFAULT_V4_UCHAR(space_node.node_zone_simulation);
|
||||
FROM_DEFAULT_V4_UCHAR(space_action.simulated_frames);
|
||||
}
|
||||
|
||||
if (!USER_VERSION_ATLEAST(400, 12)) {
|
||||
FROM_DEFAULT_V4_UCHAR(space_node.node_zone_repeat);
|
||||
}
|
||||
|
||||
/**
|
||||
* Versioning code until next subversion bump goes here.
|
||||
*
|
||||
@@ -116,7 +121,6 @@ static void do_versions_theme(const UserDef *userdef, bTheme *btheme)
|
||||
*/
|
||||
{
|
||||
/* Keep this block, even when empty. */
|
||||
FROM_DEFAULT_V4_UCHAR(space_node.node_zone_repeat);
|
||||
}
|
||||
|
||||
#undef FROM_DEFAULT_V4_UCHAR
|
||||
@@ -830,6 +834,15 @@ void blo_do_versions_userdef(UserDef *userdef)
|
||||
BKE_addon_remove_safe(&userdef->addons, "io_scene_obj");
|
||||
}
|
||||
|
||||
if (!USER_VERSION_ATLEAST(400, 12)) {
|
||||
#ifdef __APPLE__
|
||||
/* Drop OpenGL support on MAC devices as they don't support OpenGL 4.3. */
|
||||
if (userdef->gpu_backend == GPU_BACKEND_OPENGL) {
|
||||
userdef->gpu_backend = GPU_BACKEND_METAL;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* Versioning code until next subversion bump goes here.
|
||||
*
|
||||
@@ -841,13 +854,6 @@ void blo_do_versions_userdef(UserDef *userdef)
|
||||
*/
|
||||
{
|
||||
/* Keep this block, even when empty. */
|
||||
|
||||
#ifdef __APPLE__
|
||||
/* Drop OpenGL support on MAC devices as they don't support OpenGL 4.3. */
|
||||
if (userdef->gpu_backend == GPU_BACKEND_OPENGL) {
|
||||
userdef->gpu_backend = GPU_BACKEND_METAL;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
LISTBASE_FOREACH (bTheme *, btheme, &userdef->themes) {
|
||||
|
||||
@@ -1345,8 +1345,8 @@ static void region_rect_recursive(
|
||||
alignment = RGN_ALIGN_NONE;
|
||||
}
|
||||
|
||||
/* If both the #ARegion.sizex/y and the #ARegionType.prefsizex/y are 0,
|
||||
* the region is tagged as too small, even before the layout for dynamic regions is created.
|
||||
/* If both the #ARegion.sizex/y and the #ARegionType.prefsizex/y are 0, the region is tagged as
|
||||
* too small, even before the layout for dynamically sized regions is created.
|
||||
* #wm_draw_window_offscreen() allows the layout to be created despite the #RGN_FLAG_TOO_SMALL
|
||||
* flag being set. But there may still be regions that don't have a separate #ARegionType.layout
|
||||
* callback. For those, set a default #ARegionType.prefsizex/y so they can become visible. */
|
||||
@@ -1364,11 +1364,7 @@ static void region_rect_recursive(
|
||||
((region->sizex > 1) ? region->sizex + 0.5f : region->type->prefsizex);
|
||||
int prefsizey;
|
||||
|
||||
if (region->flag & RGN_FLAG_PREFSIZE_OR_HIDDEN) {
|
||||
prefsizex = UI_SCALE_FAC * region->type->prefsizex;
|
||||
prefsizey = UI_SCALE_FAC * region->type->prefsizey;
|
||||
}
|
||||
else if (region->regiontype == RGN_TYPE_HEADER) {
|
||||
if (region->regiontype == RGN_TYPE_HEADER) {
|
||||
prefsizey = ED_area_headersize();
|
||||
}
|
||||
else if (region->regiontype == RGN_TYPE_TOOL_HEADER) {
|
||||
|
||||
@@ -2871,7 +2871,7 @@ static int region_scale_modal(bContext *C, wmOperator *op, const wmEvent *event)
|
||||
else if (rmd->region->flag & RGN_FLAG_HIDDEN) {
|
||||
region_scale_toggle_hidden(C, rmd);
|
||||
}
|
||||
else if (rmd->region->flag & RGN_FLAG_DYNAMIC_SIZE) {
|
||||
else if (rmd->region->flag & RGN_FLAG_NO_USER_RESIZE) {
|
||||
rmd->region->sizex = rmd->origval;
|
||||
}
|
||||
}
|
||||
@@ -2913,7 +2913,7 @@ static int region_scale_modal(bContext *C, wmOperator *op, const wmEvent *event)
|
||||
else if (rmd->region->flag & RGN_FLAG_HIDDEN) {
|
||||
region_scale_toggle_hidden(C, rmd);
|
||||
}
|
||||
else if (rmd->region->flag & RGN_FLAG_DYNAMIC_SIZE) {
|
||||
else if (rmd->region->flag & RGN_FLAG_NO_USER_RESIZE) {
|
||||
rmd->region->sizey = rmd->origval;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -593,7 +593,7 @@ static void buttons_header_region_message_subscribe(const wmRegionMessageSubscri
|
||||
|
||||
static void buttons_navigation_bar_region_init(wmWindowManager *wm, ARegion *region)
|
||||
{
|
||||
region->flag |= RGN_FLAG_PREFSIZE_OR_HIDDEN;
|
||||
region->flag |= RGN_FLAG_NO_USER_RESIZE;
|
||||
|
||||
ED_region_panels_init(wm, region);
|
||||
region->v2d.keepzoom |= V2D_LOCKZOOM_X | V2D_LOCKZOOM_Y;
|
||||
|
||||
@@ -79,14 +79,14 @@ static SpaceLink *file_create(const ScrArea * /*area*/, const Scene * /*scene*/)
|
||||
BLI_addtail(&sfile->regionbase, region);
|
||||
region->regiontype = RGN_TYPE_UI;
|
||||
region->alignment = RGN_ALIGN_TOP;
|
||||
region->flag = RGN_FLAG_DYNAMIC_SIZE;
|
||||
region->flag = RGN_FLAG_DYNAMIC_SIZE | RGN_FLAG_NO_USER_RESIZE;
|
||||
|
||||
/* execute region */
|
||||
region = static_cast<ARegion *>(MEM_callocN(sizeof(ARegion), "execute region for file"));
|
||||
BLI_addtail(&sfile->regionbase, region);
|
||||
region->regiontype = RGN_TYPE_EXECUTE;
|
||||
region->alignment = RGN_ALIGN_BOTTOM;
|
||||
region->flag = RGN_FLAG_DYNAMIC_SIZE;
|
||||
region->flag = RGN_FLAG_DYNAMIC_SIZE | RGN_FLAG_NO_USER_RESIZE;
|
||||
|
||||
/* tools props region */
|
||||
region = static_cast<ARegion *>(MEM_callocN(sizeof(ARegion), "tool props for file"));
|
||||
|
||||
@@ -66,7 +66,7 @@ static SpaceLink *userpref_create(const ScrArea *area, const Scene * /*scene*/)
|
||||
BLI_addtail(&spref->regionbase, region);
|
||||
region->regiontype = RGN_TYPE_EXECUTE;
|
||||
region->alignment = RGN_ALIGN_BOTTOM | RGN_SPLIT_PREV;
|
||||
region->flag |= RGN_FLAG_DYNAMIC_SIZE;
|
||||
region->flag |= RGN_FLAG_DYNAMIC_SIZE | RGN_FLAG_NO_USER_RESIZE;
|
||||
|
||||
/* main region */
|
||||
region = static_cast<ARegion *>(MEM_callocN(sizeof(ARegion), "main region for userpref"));
|
||||
|
||||
@@ -713,16 +713,13 @@ enum {
|
||||
enum {
|
||||
RGN_FLAG_HIDDEN = (1 << 0),
|
||||
RGN_FLAG_TOO_SMALL = (1 << 1),
|
||||
/**
|
||||
* Force delayed re-initialization of region size data, so that region size is calculated
|
||||
* just big enough to show all its content (if enough space is available).
|
||||
* Note that only ED_region_header supports this right now.
|
||||
*/
|
||||
/** Enable dynamically changing the region size in the #ARegionType::layout() callback. */
|
||||
RGN_FLAG_DYNAMIC_SIZE = (1 << 2),
|
||||
/** Region data is NULL'd on read, never written. */
|
||||
RGN_FLAG_TEMP_REGIONDATA = (1 << 3),
|
||||
/** The region must either use its prefsizex/y or be hidden. */
|
||||
RGN_FLAG_PREFSIZE_OR_HIDDEN = (1 << 4),
|
||||
/** Region resizing by the user is disabled, but the region edge can still be dragged to
|
||||
* hide/unhide the region. */
|
||||
RGN_FLAG_NO_USER_RESIZE = (1 << 4),
|
||||
/** Size has been clamped (floating regions only). */
|
||||
RGN_FLAG_SIZE_CLAMP_X = (1 << 5),
|
||||
RGN_FLAG_SIZE_CLAMP_Y = (1 << 6),
|
||||
|
||||
Reference in New Issue
Block a user