Skip to content

Commit

Permalink
demo docking: add setup_my_theme
Browse files Browse the repository at this point in the history
  • Loading branch information
pthom committed Oct 1, 2024
1 parent 457fd07 commit aa8f75b
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 23 deletions.
35 changes: 24 additions & 11 deletions bindings/imgui_bundle/demos_cpp/demos_immapp/demo_docking.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -788,6 +788,29 @@ std::vector<HelloImGui::DockingParams> CreateAlternativeLayouts(AppState& appSta
}


//////////////////////////////////////////////////////////////////////////
// Define the app initial theme
//////////////////////////////////////////////////////////////////////////
void SetupMyTheme()
{
// Example of theme customization at App startup
// This function is called in the callback `SetupImGuiStyle` in order to apply a custom theme:
// runnerParams.callbacks.SetupImGuiStyle = SetupMyTheme;

// Apply default style
HelloImGui::ImGuiDefaultSettings::SetupDefaultImGuiStyle();
// Create a tweaked theme
ImGuiTheme::ImGuiTweakedTheme tweakedTheme;
tweakedTheme.Theme = ImGuiTheme::ImGuiTheme_MaterialFlat;
tweakedTheme.Tweaks.Rounding = 10.0f;
// Apply the tweaked theme
ImGuiTheme::ApplyTweakedTheme(tweakedTheme); // Note: you can also push/pop the theme in order to apply it only to a specific part of the Gui: ImGuiTheme::PushTweakedTheme(tweakedTheme) / ImGuiTheme::PopTweakedTheme()
// Then apply further modifications to ImGui style
ImGui::GetStyle().ItemSpacing = ImVec2(6, 4); // Reduce spacing between items ((8, 4) by default)
ImGui::GetStyle().Colors[ImGuiCol_Text] = ImVec4(0.8, 0.8, 0.85, 1.0); // Change text color
}


//////////////////////////////////////////////////////////////////////////
// main(): here, we simply fill RunnerParams, then run the application
//////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -868,18 +891,8 @@ int main(int, char**)
runnerParams.callbacks.PostInit = [&appState] { LoadMyAppSettings(appState);};
runnerParams.callbacks.BeforeExit = [&appState] { SaveMyAppSettings(appState);};

//
// Change style
//
// 1. Change theme
auto& tweakedTheme = runnerParams.imGuiWindowParams.tweakedTheme;
tweakedTheme.Theme = ImGuiTheme::ImGuiTheme_MaterialFlat;
tweakedTheme.Tweaks.Rounding = 10.f;
// 2. Customize ImGui style at startup
runnerParams.callbacks.SetupImGuiStyle = []() {
// Reduce spacing between items ((8, 4) by default)
ImGui::GetStyle().ItemSpacing = ImVec2(6.f, 4.f);
};
runnerParams.callbacks.SetupImGuiStyle = SetupMyTheme;

//#############################################################################################
// Part 2: Define the application layout and windows
Expand Down
33 changes: 22 additions & 11 deletions bindings/imgui_bundle/demos_python/demos_immapp/demo_docking.py
Original file line number Diff line number Diff line change
Expand Up @@ -779,6 +779,27 @@ def create_alternative_layouts(app_state: AppState) -> List[hello_imgui.DockingP
return [alternative_layout, tabs_layout]


##########################################################################
# Define the app initial theme
##########################################################################
def setup_my_theme():
"""Example of theme customization at App startup
This function is called in the callback `setup_imgui_style` in order to apply a custom theme:
runner_params.callbacks.setup_imgui_style = setup_my_theme()
"""
# Apply default style
hello_imgui.imgui_default_settings.setup_default_imgui_style()
# Create a tweaked theme
tweaked_theme = hello_imgui.ImGuiTweakedTheme()
tweaked_theme.theme = hello_imgui.ImGuiTheme_.material_flat
tweaked_theme.tweaks.rounding = 10.0
# Apply the tweaked theme
hello_imgui.apply_tweaked_theme(tweaked_theme) # Note: you can also push/pop the theme in order to apply it only to a specific part of the Gui: hello_imgui.push_tweaked_theme(tweaked_theme) / hello_imgui.pop_tweaked_theme()
# Then apply further modifications to ImGui style
imgui.get_style().item_spacing = (6, 4) # Reduce spacing between items ((8, 4) by default)
imgui.get_style().set_color_(imgui.Col_.text, ImVec4(0.8, 0.8, 0.85, 1.0)) # Change text color


##########################################################################
# main(): here, we simply fill RunnerParams, then run the application
##########################################################################
Expand Down Expand Up @@ -861,18 +882,8 @@ def main():
runner_params.callbacks.post_init = lambda: load_my_app_settings(app_state)
runner_params.callbacks.before_exit = lambda: save_my_app_settings(app_state)

#
# Change style
#
# 1. Change theme
tweaked_theme = runner_params.imgui_window_params.tweaked_theme
tweaked_theme.theme = hello_imgui.ImGuiTheme_.material_flat
tweaked_theme.tweaks.rounding = 10.0
# 2. Customize ImGui style at startup
def setup_imgui_style():
# Reduce spacing between items ((8, 4) by default)
imgui.get_style().item_spacing = (6, 4)
runner_params.callbacks.setup_imgui_style = setup_imgui_style
runner_params.callbacks.setup_imgui_style = setup_my_theme

#
# Part 2: Define the application layout and windows
Expand Down

0 comments on commit aa8f75b

Please sign in to comment.