Overview
Ember's preferences system provides persistent storage for application settings, user preferences, and workspace state. The system is built around the AppPreferences and AppPreferencesManager classes.
AppPreferencesManager
The central singleton for accessing and managing preferences.
Basic Usage
bool darkMode = prefs.GetThemeMode() == ThemeMode::Dark;
int fontSize = prefs.GetFontSize();
prefs.SetThemeMode(ThemeMode::Dark);
prefs.SetFontSize(12);
prefs.SavePreferences();
static AppPreferencesManager & GetInstance()
Initialization
auto& prefs = AppPreferencesManager::GetInstance();
prefs.LoadPreferences();
Preference Categories
Theme Settings
| Setting | Type | Description |
| ThemeMode | Enum | Light, Dark, or System |
| AccentColor | wxColour | UI accent color |
| FontSize | int | Base font size |
| FontFamily | string | Font family name |
prefs.SetThemeMode(ThemeMode::Dark);
ThemeMode mode = prefs.GetThemeMode();
prefs.SetAccentColor(wxColour(0, 120, 215));
wxColour accent = prefs.GetAccentColor();
Window Settings
| Setting | Type | Description |
| WindowPosition | Point | Main window position |
| WindowSize | Size | Main window size |
| WindowMaximized | bool | Maximized state |
| AuiPerspective | string | Panel layout |
prefs.SetWindowSettings(WindowSettings{
.position = {100, 100},
.size = {1280, 720},
.maximized = false
});
auto settings = prefs.GetWindowSettings();
Main Panel Settings
| Setting | Type | Description |
| ShowGrid | bool | Show background grid |
| GridSize | int | Grid cell size |
| SnapToGrid | bool | Enable grid snapping |
| CanvasColor | Color | Background color |
MainPanelSettings panel;
panel.show_grid = true;
panel.grid_size = 20;
panel.snap_to_grid = true;
prefs.SetMainPanelSettings(panel);
Behavior Tree View Settings
| Setting | Type | Description |
| DefaultZoom | float | Initial zoom level |
| AutoFitOnLoad | bool | Fit tree to view on load |
| AnimateTransitions | bool | Animate view changes |
| NodeSpacing | int | Space between nodes |
| LevelSpacing | int | Space between tree levels |
BehaviorTreeViewSettings btView;
btView.default_zoom = 1.0f;
btView.auto_fit_on_load = true;
btView.node_spacing = 50;
btView.level_spacing = 80;
prefs.SetBehaviorTreeViewSettings(btView);
File Explorer Settings
| Setting | Type | Description |
| ViewMode | Enum | Tree, Grid, or Split |
| SortBy | Enum | Name, Date, Size, Type |
| SortAscending | bool | Sort direction |
| ShowHiddenFiles | bool | Show hidden files |
| IconSize | Enum | Small, Medium, Large |
FileExplorerSettings explorer;
explorer.view_mode = FileExplorerViewMode::Split;
explorer.sort_by = SortBy::Name;
explorer.icon_size = IconSize::Medium;
prefs.SetFileExplorerSettings(explorer);
Parser Settings
| Setting | Type | Description |
| DefaultProfile | string | Default parser profile |
| ValidateOnLoad | bool | Validate trees on load |
| PreserveComments | bool | Preserve XML comments |
ParserPreferences parser;
parser.default_profile = "BehaviorTree.CPP v4";
parser.validate_on_load = true;
prefs.SetParserPreferences(parser);
Keyboard Shortcuts
| Setting | Type | Description |
| Shortcuts | map | Action → Key mapping |
wxString shortcut = prefs.GetShortcut("file.open");
prefs.SetShortcut("file.open", "Ctrl+Shift+O");
Recent Files
prefs.AddRecentFile("/path/to/file.xml");
auto recentFiles = prefs.GetRecentFiles();
prefs.ClearRecentFiles();
Preference Enums
ThemeMode
enum class ThemeMode {
Light,
Dark,
System
};
StartupMode
enum class StartupMode {
Empty,
LastProject,
Welcome
};
FileExplorerViewMode
enum class FileExplorerViewMode {
Tree,
Grid,
Split
};
SortBy
enum class SortBy {
Name,
DateModified,
Size,
Type
};
IconSize
enum class IconSize {
Small,
Medium,
Large
};
Storage Location
Preferences are stored in JSON format:
| Platform | Location |
| Linux | ~/.config/ember/preferences.json |
| Windows | APPDATA%\Ember\preferences.json |
| macOS | ~/Library/Application Support/Ember/preferences.json |
JSON Structure
{
"version": 1,
"theme": {
"mode": "dark",
"accent_color": "#0078D7",
"font_size": 12
},
"window": {
"x": 100,
"y": 100,
"width": 1280,
"height": 720,
"maximized": false,
"perspective": "..."
},
"behavior_tree_view": {
"default_zoom": 1.0,
"auto_fit_on_load": true,
"node_spacing": 50
},
"recent_files": [
"/path/to/recent1.xml",
"/path/to/recent2.xml"
]
}
Change Notifications
Register callbacks to be notified of preference changes:
int callbackId = prefs.RegisterChangeCallback([](const std::string& key) {
if (key == "theme.mode") {
ApplyTheme();
}
});
prefs.UnregisterChangeCallback(callbackId);
The UI for editing preferences:
if (dlg.ShowModal() == wxID_OK) {
}
Preferences dialog for configuring EmberForge application settings.
Dialog Sections
| Section | Settings |
| General | Startup, language, updates |
| Appearance | Theme, colors, fonts |
| Editor | Grid, snapping, zoom |
| Parser | Profiles, validation |
| Keyboard | Shortcut customization |
Best Practices
Reading Preferences
class MyPanel {
void OnPreferencesChanged(const std::string& key) {
if (key.starts_with("theme.")) {
m_cachedTheme = prefs.GetThemeMode();
ApplyTheme();
}
}
ThemeMode m_cachedTheme;
};
Providing Defaults
int zoom = prefs.GetInt("view.zoom", 100);
bool grid = prefs.GetBool("view.show_grid", true);
Saving State
void MainFrame::OnClose(wxCloseEvent& event) {
auto& prefs = AppPreferencesManager::GetInstance();
prefs.SetWindowSettings(GetWindowSettings());
prefs.SetString("window.perspective",
prefs.SavePreferences();
event.Skip();
}
wxAuiManager * m_auiManager
See Also