[Bf-blender-cvs] [3ab935c8a97] blender-projects-basics: Project Settings: Add sections support and display some text for testing

Julian Eisel noreply at git.blender.org
Tue Oct 4 02:16:41 CEST 2022


Commit: 3ab935c8a97a727962f723fee4ba7891c5c0b825
Author: Julian Eisel
Date:   Tue Oct 4 02:15:04 2022 +0200
Branches: blender-projects-basics
https://developer.blender.org/rB3ab935c8a97a727962f723fee4ba7891c5c0b825

Project Settings: Add sections support and display some text for testing

===================================================================

M	release/scripts/startup/bl_ui/space_project_settings.py
M	release/scripts/startup/bl_ui/space_userpref.py
M	release/scripts/startup/bl_ui/utils.py
M	source/blender/editors/space_project_settings/space_project_settings.cc
M	source/blender/makesdna/DNA_space_types.h
M	source/blender/makesrna/RNA_enum_items.h
M	source/blender/makesrna/intern/rna_space.c

===================================================================

diff --git a/release/scripts/startup/bl_ui/space_project_settings.py b/release/scripts/startup/bl_ui/space_project_settings.py
index cd30d5bbe26..9fa42334e87 100644
--- a/release/scripts/startup/bl_ui/space_project_settings.py
+++ b/release/scripts/startup/bl_ui/space_project_settings.py
@@ -2,6 +2,7 @@
 import bpy
 from bpy.types import Header, Menu, Panel
 from bpy.app.translations import pgettext_iface as iface_
+from bl_ui.utils import CenterAlignMixIn
 
 
 # -----------------------------------------------------------------------------
@@ -19,7 +20,7 @@ class PROJECTSETTINGS_HT_header(Header):
         # TODO, wrong operator
         layout.operator(
             "wm.save_userpref",
-            text=iface_("Save Project") + (" *" if is_dirty else ""),
+            text=iface_("Save Project Settings") + (" *" if is_dirty else ""),
             translate=False,
         )
 
@@ -48,14 +49,13 @@ class PROJECTSETTINGS_PT_navigation_bar(Panel):
     def draw(self, context):
         layout = self.layout
 
-        # prefs = context.preferences
+        space_data = context.space_data
 
         col = layout.column()
 
         col.scale_x = 1.3
         col.scale_y = 1.3
-        col.label(text="Test")
-        # col.prop(prefs, "active_section", expand=True)
+        col.prop(space_data, "active_section", expand=True)
 
 
 class PROJECTSETTINGS_MT_editor_menus(Menu):
@@ -97,6 +97,16 @@ class PROJECTSETTINGS_PT_save_project_settings(Panel):
 
         PROJECTSETTINGS_HT_header.draw_buttons(layout, context)
 
+class PROJECTSETTINGS_PT_setup(CenterAlignMixIn, Panel):
+    bl_space_type = 'PROJECT_SETTINGS'
+    bl_region_type = 'WINDOW'
+    bl_context = "general"
+    bl_label = "Setup"
+    bl_options = {'HIDE_HEADER'}
+
+    def draw_centered(self, context, layout):
+        layout.label(text="Testing")
+
 
 classes = (
     PROJECTSETTINGS_HT_header,
@@ -104,6 +114,7 @@ classes = (
     PROJECTSETTINGS_MT_view,
     PROJECTSETTINGS_PT_navigation_bar,
     PROJECTSETTINGS_PT_save_project_settings,
+    PROJECTSETTINGS_PT_setup,
 )
 
 if __name__ == "__main__":  # only for live edit.
diff --git a/release/scripts/startup/bl_ui/space_userpref.py b/release/scripts/startup/bl_ui/space_userpref.py
index 441babefd60..2b251776c9a 100644
--- a/release/scripts/startup/bl_ui/space_userpref.py
+++ b/release/scripts/startup/bl_ui/space_userpref.py
@@ -10,6 +10,7 @@ from bpy.app.translations import (
     pgettext_iface as iface_,
     pgettext_tip as tip_,
 )
+from bl_ui.utils import CenterAlignMixIn
 
 
 # -----------------------------------------------------------------------------
@@ -136,40 +137,6 @@ class USERPREF_PT_save_preferences(Panel):
         USERPREF_HT_header.draw_buttons(layout, context)
 
 
-# -----------------------------------------------------------------------------
-# Min-In Helpers
-
-# Panel mix-in.
-class CenterAlignMixIn:
-    """
-    Base class for panels to center align contents with some horizontal margin.
-    Deriving classes need to implement a ``draw_centered(context, layout)`` function.
-    """
-
-    def draw(self, context):
-        layout = self.layout
-        width = context.region.width
-        ui_scale = context.preferences.system.ui_scale
-        # No horizontal margin if region is rather small.
-        is_wide = width > (350 * ui_scale)
-
-        layout.use_property_split = True
-        layout.use_property_decorate = False  # No animation.
-
-        row = layout.row()
-        if is_wide:
-            row.label()  # Needed so col below is centered.
-
-        col = row.column()
-        col.ui_units_x = 50
-
-        # Implemented by sub-classes.
-        self.draw_centered(context, col)
-
-        if is_wide:
-            row.label()  # Needed so col above is centered.
-
-
 # -----------------------------------------------------------------------------
 # Interface Panels
 
diff --git a/release/scripts/startup/bl_ui/utils.py b/release/scripts/startup/bl_ui/utils.py
index 87f44601ff3..6c51de2395a 100644
--- a/release/scripts/startup/bl_ui/utils.py
+++ b/release/scripts/startup/bl_ui/utils.py
@@ -36,3 +36,41 @@ class PresetPanel:
         layout.operator_context = 'EXEC_DEFAULT'
 
         Menu.draw_preset(self, context)
+
+
+# -----------------------------------------------------------------------------
+# Mix-In Helpers
+
+# Panel mix-in.
+class CenterAlignMixIn:
+    """
+    Base class for panels to center align contents with some horizontal margin.
+    Deriving classes need to implement a ``draw_centered(context, layout)`` function.
+
+    Used by Preferences and Project Settings, and optimized for their display. May not work that
+    well in other cases.
+    """
+
+    def draw(self, context):
+        layout = self.layout
+        width = context.region.width
+        ui_scale = context.preferences.system.ui_scale
+        # No horizontal margin if region is rather small.
+        is_wide = width > (350 * ui_scale)
+
+        layout.use_property_split = True
+        layout.use_property_decorate = False  # No animation.
+
+        row = layout.row()
+        if is_wide:
+            row.label()  # Needed so col below is centered.
+
+        col = row.column()
+        col.ui_units_x = 50
+
+        # Implemented by sub-classes.
+        self.draw_centered(context, col)
+
+        if is_wide:
+            row.label()  # Needed so col above is centered.
+
diff --git a/source/blender/editors/space_project_settings/space_project_settings.cc b/source/blender/editors/space_project_settings/space_project_settings.cc
index 9c2d64d2204..f9fcceca074 100644
--- a/source/blender/editors/space_project_settings/space_project_settings.cc
+++ b/source/blender/editors/space_project_settings/space_project_settings.cc
@@ -3,6 +3,7 @@
 #include "BKE_screen.h"
 
 #include "BLI_string.h"
+#include "BLI_string_ref.hh"
 
 #include "BLO_read_write.h"
 
@@ -14,8 +15,13 @@
 
 #include "MEM_guardedalloc.h"
 
+#include "RNA_access.h"
+#include "RNA_enum_types.h"
+
 #include "UI_interface.h"
 
+using namespace blender;
+
 static SpaceLink *project_settings_create(const ScrArea *area, const Scene *UNUSED(scene))
 {
   SpaceProjectSettings *project_settings_space = MEM_cnew<SpaceProjectSettings>(
@@ -106,7 +112,26 @@ static void project_settings_main_region_init(wmWindowManager *wm, ARegion *regi
 
 static void project_settings_main_region_layout(const bContext *C, ARegion *region)
 {
-  ED_region_panels_layout_ex(C, region, &region->type->paneltypes, nullptr, nullptr);
+  SpaceProjectSettings *sproject_settings = CTX_wm_space_project_settings(C);
+
+  char id_lower[64];
+  const char *contexts[2] = {id_lower, NULL};
+
+  /* Avoid duplicating identifiers, use existing RNA enum. */
+  {
+    const EnumPropertyItem *items = rna_enum_project_settings_section_items;
+    int i = RNA_enum_from_value(items, sproject_settings->active_section);
+    /* Enum value not found: File is from the future. */
+    if (i == -1) {
+      i = 0;
+    }
+    StringRefNull id = items[i].identifier;
+    BLI_assert(id.size() < (int64_t)sizeof(id_lower));
+    STRNCPY(id_lower, id.c_str());
+    BLI_str_tolower_ascii(id_lower, strlen(id_lower));
+  }
+
+  ED_region_panels_layout_ex(C, region, &region->type->paneltypes, contexts, NULL);
 }
 
 static void project_settings_main_region_listener(const wmRegionListenerParams *UNUSED(params))
diff --git a/source/blender/makesdna/DNA_space_types.h b/source/blender/makesdna/DNA_space_types.h
index fba8b4715af..0413fe36ec0 100644
--- a/source/blender/makesdna/DNA_space_types.h
+++ b/source/blender/makesdna/DNA_space_types.h
@@ -1721,8 +1721,16 @@ typedef struct SpaceProjectSettings {
   char link_flag;
   char _pad0[6];
   /* End 'SpaceLink' header. */
+
+  char active_section; /* eSpaceProjectSettings_Section */
+  char _pad1[7];
 } SpaceProjectSettings;
 
+typedef enum eSpaceProjectSettings_Section {
+  PROJECT_SETTINGS_SECTION_GENERAL = 0,
+  PROJECT_SETTINGS_SECTION_ASSET_LIBRARIES = 1,
+} eSpaceProjectSettings_Section;
+
 /** \} */
 
 /* -------------------------------------------------------------------- */
diff --git a/source/blender/makesrna/RNA_enum_items.h b/source/blender/makesrna/RNA_enum_items.h
index 4bbf2caf7a8..a1426fa40b5 100644
--- a/source/blender/makesrna/RNA_enum_items.h
+++ b/source/blender/makesrna/RNA_enum_items.h
@@ -206,6 +206,8 @@ DEF_ENUM(rna_enum_context_mode_items)
 
 DEF_ENUM(rna_enum_preference_section_items)
 
+DEF_ENUM(rna_enum_project_settings_section_items)
+
 DEF_ENUM(rna_enum_attribute_type_items)
 DEF_ENUM(rna_enum_color_attribute_type_items)
 DEF_ENUM(rna_enum_attribute_type_with_auto_items)
diff --git a/source/blender/makesrna/intern/rna_space.c b/source/blender/makesrna/intern/rna_space.c
index 2dca05075f6..5bba9468b13 100644
--- a/source/blender/makesrna/intern/rna_space.c
+++ b/source/blender/makesrna/intern/rna_space.c
@@ -529,6 +529,12 @@ static const EnumPropertyItem rna_enum_curve_display_handle_items[] = {
     {0, NULL, 0, NULL, NULL},
 };
 
+const EnumPropertyItem rna_enum_project_settings_section_items[] = {
+    {PROJECT_SETTINGS_SECTION_GENERAL, "GENERAL", 0, "General", ""},
+    {PROJECT_SETTINGS_SECTION_ASSET_LIBRARIES, "ASSET_LIBRARIES", 0, "Asset Libraries", ""},
+    {0, NULL, 0, NULL, NULL},
+};
+
 #ifdef RNA_RUNTIME
 
 #  include "DNA_anim_types.h"
@@ -7151,6 +7157,12 @@ static void rna_def_space_project_settings(BlenderRNA *brna)
 
   srna = RNA_def_struct(brna, "SpaceProjectSettings", "Space");
   RNA_def_struct_ui_text(srna, "Space Project Settings", "Blender project space data");
+
+  PropertyRNA *prop;
+
+  prop = RNA_def_property(srna, "active_section", PROP_ENUM, PROP_NONE);
+  RNA_def_property_enum_items(prop, rna_enum_project_settings_section_items);
+  RNA_def_property_ui_text(prop, "Active Section", "Choose the category of options to display");
 }
 
 static void rna_def_node_tree_path(BlenderRNA *brna)



More information about the Bf-blender-cvs mailing list