Project Settings: Add sections support and display some text for testing
This commit is contained in:
parent
420cc8a093
commit
3ab935c8a9
|
@ -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.
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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.
|
||||
|
||||
|
|
|
@ -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, ®ion->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, ®ion->type->paneltypes, contexts, NULL);
|
||||
}
|
||||
|
||||
static void project_settings_main_region_listener(const wmRegionListenerParams *UNUSED(params))
|
||||
|
|
|
@ -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;
|
||||
|
||||
/** \} */
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue