Cleanup: use _NUM suffix for space/region type ranges

- Replace SPACE_TYPE_LAST with SPACE_TYPE_NUM (adding 1).
- Rename RGN_TYPE_LEN to RGN_TYPE_NUM

This makes it possible to tag space-type/region-type combinations
with `bool tag[SPACE_TYPE_NUM][RGN_TYPE_NUM]` which reads more clearly
than `bool tag[SPACE_TYPE_LAST + 1][RGN_TYPE_LEN]`.
This commit is contained in:
Campbell Barton 2022-04-12 11:59:25 +10:00
parent 6f1ad5f5e7
commit 2451d7d57e
4 changed files with 11 additions and 11 deletions

View File

@ -2176,12 +2176,12 @@ struct RegionTypeAlignInfo {
* Needed for detecting which header displays the space-type switcher.
*/
bool hidden;
} by_type[RGN_TYPE_LEN];
} by_type[RGN_TYPE_NUM];
};
static void region_align_info_from_area(ScrArea *area, struct RegionTypeAlignInfo *r_align_info)
{
for (int index = 0; index < RGN_TYPE_LEN; index++) {
for (int index = 0; index < RGN_TYPE_NUM; index++) {
r_align_info->by_type[index].alignment = -1;
/* Default to true, when it doesn't exist - it's effectively hidden. */
r_align_info->by_type[index].hidden = true;
@ -2189,7 +2189,7 @@ static void region_align_info_from_area(ScrArea *area, struct RegionTypeAlignInf
LISTBASE_FOREACH (ARegion *, region, &area->regionbase) {
const int index = region->regiontype;
if ((uint)index < RGN_TYPE_LEN) {
if ((uint)index < RGN_TYPE_NUM) {
r_align_info->by_type[index].alignment = RGN_ALIGN_ENUM_FROM_MASK(region->alignment);
r_align_info->by_type[index].hidden = (region->flag & RGN_FLAG_HIDDEN) != 0;
}
@ -2252,7 +2252,7 @@ static short region_alignment_from_header_and_tool_header_state(
static void region_align_info_to_area_for_headers(
const struct RegionTypeAlignInfo *region_align_info_src,
const struct RegionTypeAlignInfo *region_align_info_dst,
ARegion *region_by_type[RGN_TYPE_LEN])
ARegion *region_by_type[RGN_TYPE_NUM])
{
/* Abbreviate access. */
const short header_alignment_src = region_align_info_src->by_type[RGN_TYPE_HEADER].alignment;
@ -2365,12 +2365,12 @@ static void region_align_info_to_area_for_headers(
}
static void region_align_info_to_area(
ScrArea *area, const struct RegionTypeAlignInfo region_align_info_src[RGN_TYPE_LEN])
ScrArea *area, const struct RegionTypeAlignInfo region_align_info_src[RGN_TYPE_NUM])
{
ARegion *region_by_type[RGN_TYPE_LEN] = {NULL};
ARegion *region_by_type[RGN_TYPE_NUM] = {NULL};
LISTBASE_FOREACH (ARegion *, region, &area->regionbase) {
const int index = region->regiontype;
if ((uint)index < RGN_TYPE_LEN) {
if ((uint)index < RGN_TYPE_NUM) {
region_by_type[index] = region;
}
}
@ -2437,7 +2437,7 @@ void ED_area_newspace(bContext *C, ScrArea *area, int type, const bool skip_regi
*/
bool sync_header_alignment = false;
struct RegionTypeAlignInfo region_align_info[RGN_TYPE_LEN];
struct RegionTypeAlignInfo region_align_info[RGN_TYPE_NUM];
if ((slold != NULL) && (slold->link_flag & SPACE_FLAG_TYPE_TEMPORARY) == 0) {
region_align_info_from_area(area, region_align_info);
sync_header_alignment = true;

View File

@ -664,7 +664,7 @@ typedef enum eRegion_Type {
* context (surface, mirror view). Does not represent any real region. */
RGN_TYPE_XR = 13,
#define RGN_TYPE_LEN (RGN_TYPE_XR + 1)
#define RGN_TYPE_NUM (RGN_TYPE_XR + 1)
} eRegion_Type;
/* use for function args */

View File

@ -2057,7 +2057,7 @@ typedef enum eSpace_Type {
SPACE_STATUSBAR = 22,
SPACE_SPREADSHEET = 23
#define SPACE_TYPE_LAST SPACE_SPREADSHEET
#define SPACE_TYPE_NUM (SPACE_SPREADSHEET + 1)
} eSpace_Type;
/* use for function args */

View File

@ -551,7 +551,7 @@ void WM_toolsystem_refresh_screen_area(WorkSpace *workspace, ViewLayer *view_lay
void WM_toolsystem_refresh_screen_window(wmWindow *win)
{
WorkSpace *workspace = WM_window_get_active_workspace(win);
bool space_type_has_tools[SPACE_TYPE_LAST + 1] = {0};
bool space_type_has_tools[SPACE_TYPE_NUM] = {0};
LISTBASE_FOREACH (bToolRef *, tref, &workspace->tools) {
space_type_has_tools[tref->space_type] = true;
}