Skip to content

Commit ebb1574

Browse files
committed
Default "cinder" styling.
1 parent 15bf017 commit ebb1574

File tree

2 files changed

+103
-4
lines changed

2 files changed

+103
-4
lines changed

include/cinder/CinderImGui.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,20 @@ namespace ImGui {
7171
//! Returns whether the gamepad input is enabled
7272
bool isGamepadEnabled() const { return mGamepadEnabled; }
7373

74+
//! Sets the signal priority that will be use to connect the signals and render ImGui
7475
Options& signalPriority( int signalPriority );
7576
//! Returns the signal priority that will be use to connect the signals and render ImGui
7677
int getSignalPriority() const { return mSignalPriority; }
78+
79+
//! Sets the ImGuiStyle used during initialization.
80+
Options& style( const ImGuiStyle& style );
81+
//! Returns the ImGuiStyle used during initialization.
82+
const ImGuiStyle& getStyle() const { return mStyle; }
7783
protected:
7884
bool mAutoRender;
7985
bool mKeyboardEnabled;
8086
bool mGamepadEnabled;
87+
ImGuiStyle mStyle;
8188
ci::app::WindowRef mWindow;
8289
ci::fs::path mIniPath;
8390
int mSignalPriority;

src/cinder/CinderImGui.cpp

Lines changed: 96 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,89 @@ namespace ImGui {
2222
Options::Options()
2323
: mWindow( ci::app::getWindow() ), mAutoRender( true ), mIniPath(), mSignalPriority( 1 ), mKeyboardEnabled( true ), mGamepadEnabled( true )
2424
{
25+
//! Default Cinder styling
26+
mStyle.Alpha = 1.0f; // Global alpha applies to everything in ImGui
27+
mStyle.WindowPadding = ImVec2( 8, 8 ); // Padding within a window
28+
mStyle.WindowRounding = 7.0f; // Radius of window corners rounding. Set to 0.0f to have rectangular windows
29+
mStyle.WindowBorderSize = 1.0f; // Thickness of border around windows. Generally set to 0.0f or 1.0f. Other values not well tested.
30+
mStyle.WindowMinSize = ImVec2( 32, 32 ); // Minimum window size
31+
mStyle.WindowTitleAlign = ImVec2( 0.0f, 0.5f ); // Alignment for title bar text
32+
mStyle.ChildRounding = 0.0f; // Radius of child window corners rounding. Set to 0.0f to have rectangular child windows
33+
mStyle.ChildBorderSize = 1.0f; // Thickness of border around child windows. Generally set to 0.0f or 1.0f. Other values not well tested.
34+
mStyle.PopupRounding = 0.0f; // Radius of popup window corners rounding. Set to 0.0f to have rectangular child windows
35+
mStyle.PopupBorderSize = 1.0f; // Thickness of border around popup or tooltip windows. Generally set to 0.0f or 1.0f. Other values not well tested.
36+
mStyle.FramePadding = ImVec2( 4, 3 ); // Padding within a framed rectangle (used by most widgets)
37+
mStyle.FrameRounding = 0.0f; // Radius of frame corners rounding. Set to 0.0f to have rectangular frames (used by most widgets).
38+
mStyle.FrameBorderSize = 0.0f; // Thickness of border around frames. Generally set to 0.0f or 1.0f. Other values not well tested.
39+
mStyle.ItemSpacing = ImVec2( 8, 4 ); // Horizontal and vertical spacing between widgets/lines
40+
mStyle.ItemInnerSpacing = ImVec2( 4, 4 ); // Horizontal and vertical spacing between within elements of a composed widget (e.g. a slider and its label)
41+
mStyle.TouchExtraPadding = ImVec2( 0, 0 ); // Expand reactive bounding box for touch-based system where touch position is not accurate enough. Unfortunately we don't sort widgets so priority on overlap will always be given to the first widget. So don't grow this too much!
42+
mStyle.IndentSpacing = 21.0f; // Horizontal spacing when e.g. entering a tree node. Generally == (FontSize + FramePadding.x*2).
43+
mStyle.ColumnsMinSpacing = 6.0f; // Minimum horizontal spacing between two columns
44+
mStyle.ScrollbarSize = 16.0f; // Width of the vertical scrollbar, Height of the horizontal scrollbar
45+
mStyle.ScrollbarRounding = 9.0f; // Radius of grab corners rounding for scrollbar
46+
mStyle.GrabMinSize = 10.0f; // Minimum width/height of a grab box for slider/scrollbar
47+
mStyle.GrabRounding = 0.0f; // Radius of grabs corners rounding. Set to 0.0f to have rectangular slider grabs.
48+
mStyle.TabRounding = 4.0f; // Radius of upper corners of a tab. Set to 0.0f to have rectangular tabs.
49+
mStyle.TabBorderSize = 0.0f; // Thickness of border around tabs.
50+
mStyle.ButtonTextAlign = ImVec2( 0.5f, 0.5f ); // Alignment of button text when button is larger than text.
51+
mStyle.DisplayWindowPadding = ImVec2( 20, 20 ); // Window position are clamped to be visible within the display area or monitors by at least this amount. Only applies to regular windows.
52+
mStyle.DisplaySafeAreaPadding = ImVec2( 3, 3 ); // If you cannot see the edge of your screen (e.g. on a TV) increase the safe area padding. Covers popups/tooltips as well regular windows.
53+
mStyle.MouseCursorScale = 1.0f; // Scale software rendered mouse cursor (when io.MouseDrawCursor is enabled). May be removed later.
54+
mStyle.AntiAliasedLines = true; // Enable anti-aliasing on lines/borders. Disable if you are really short on CPU/GPU.
55+
mStyle.AntiAliasedFill = true; // Enable anti-aliasing on filled shapes (rounded rectangles, circles, etc.)
56+
mStyle.CurveTessellationTol = 1.25f; // Tessellation tolerance when using PathBezierCurveTo() without a specific number of segments. Decrease for highly tessellated curves (higher quality, more polygons), increase to reduce quality.
57+
58+
mStyle.Colors[ImGuiCol_Text] = ImVec4( 0.86f, 0.93f, 0.89f, 0.78f );
59+
mStyle.Colors[ImGuiCol_TextDisabled] = ImVec4( 0.86f, 0.93f, 0.89f, 0.28f );
60+
mStyle.Colors[ImGuiCol_WindowBg] = ImVec4( 0.14f, 0.15f, 0.15f, 0.96f );
61+
mStyle.Colors[ImGuiCol_ChildBg] = ImVec4( 0.14f, 0.15f, 0.15f, 1.00f );
62+
mStyle.Colors[ImGuiCol_PopupBg] = ImVec4( 0.16f, 0.18f, 0.17f, 0.96f );
63+
mStyle.Colors[ImGuiCol_Border] = ImVec4( 0.16f, 0.18f, 0.17f, 1.00f );
64+
mStyle.Colors[ImGuiCol_BorderShadow] = ImVec4( 0.00f, 0.00f, 0.00f, 0.00f );
65+
mStyle.Colors[ImGuiCol_FrameBg] = ImVec4( 0.16f, 0.18f, 0.17f, 1.00f );
66+
mStyle.Colors[ImGuiCol_FrameBgHovered] = ImVec4( 0.75f, 0.24f, 0.18f, 1.00f );
67+
mStyle.Colors[ImGuiCol_FrameBgActive] = ImVec4( 0.84f, 0.10f, 0.14f, 1.00f );
68+
mStyle.Colors[ImGuiCol_TitleBg] = ImVec4( 0.75f, 0.24f, 0.18f, 1.00f );
69+
mStyle.Colors[ImGuiCol_TitleBgActive] = ImVec4( 0.84f, 0.10f, 0.14f, 1.00f );
70+
mStyle.Colors[ImGuiCol_TitleBgCollapsed] = ImVec4( 0.84f, 0.10f, 0.14f, 1.00f );
71+
mStyle.Colors[ImGuiCol_MenuBarBg] = ImVec4( 0.14f, 0.15f, 0.15f, 1.00f );
72+
mStyle.Colors[ImGuiCol_ScrollbarBg] = ImVec4( 0.16f, 0.18f, 0.17f, 1.00f );
73+
mStyle.Colors[ImGuiCol_ScrollbarGrab] = ImVec4( 0.14f, 0.15f, 0.15f, 1.00f );
74+
mStyle.Colors[ImGuiCol_ScrollbarGrabHovered] = ImVec4( 0.75f, 0.24f, 0.18f, 1.00f );
75+
mStyle.Colors[ImGuiCol_ScrollbarGrabActive] = ImVec4( 0.84f, 0.10f, 0.14f, 1.00f );
76+
mStyle.Colors[ImGuiCol_CheckMark] = ImVec4( 0.75f, 0.24f, 0.18f, 1.00f );
77+
mStyle.Colors[ImGuiCol_SliderGrab] = ImVec4( 0.14f, 0.15f, 0.15f, 1.00f );
78+
mStyle.Colors[ImGuiCol_SliderGrabActive] = ImVec4( 0.16f, 0.18f, 0.17f, 1.00f );
79+
mStyle.Colors[ImGuiCol_Button] = ImVec4( 0.16f, 0.18f, 0.17f, 1.00f );
80+
mStyle.Colors[ImGuiCol_ButtonHovered] = ImVec4( 0.75f, 0.24f, 0.18f, 1.00f );
81+
mStyle.Colors[ImGuiCol_ButtonActive] = ImVec4( 0.84f, 0.10f, 0.14f, 1.00f );
82+
mStyle.Colors[ImGuiCol_Header] = ImVec4( 0.75f, 0.24f, 0.18f, 1.00f );
83+
mStyle.Colors[ImGuiCol_HeaderHovered] = ImVec4( 0.84f, 0.10f, 0.14f, 1.00f );
84+
mStyle.Colors[ImGuiCol_HeaderActive] = ImVec4( 0.88f, 0.17f, 0.21f, 1.00f );
85+
mStyle.Colors[ImGuiCol_Separator] = ImVec4( 0.14f, 0.16f, 0.19f, 1.00f );
86+
mStyle.Colors[ImGuiCol_SeparatorHovered] = ImVec4( 0.75f, 0.24f, 0.18f, 1.00f );
87+
mStyle.Colors[ImGuiCol_SeparatorActive] = ImVec4( 0.84f, 0.10f, 0.14f, 1.00f );
88+
mStyle.Colors[ImGuiCol_ResizeGrip] = ImVec4( 0.16f, 0.18f, 0.17f, 1.00f );
89+
mStyle.Colors[ImGuiCol_ResizeGripHovered] = ImVec4( 0.75f, 0.24f, 0.18f, 1.00f );
90+
mStyle.Colors[ImGuiCol_ResizeGripActive] = ImVec4( 0.84f, 0.10f, 0.14f, 1.00f );
91+
mStyle.Colors[ImGuiCol_Tab] = ImVec4( 0.75f, 0.24f, 0.18f, 1.00f );
92+
mStyle.Colors[ImGuiCol_TabHovered] = ImVec4( 0.84f, 0.10f, 0.14f, 1.00f );
93+
mStyle.Colors[ImGuiCol_TabActive] = ImVec4( 0.88f, 0.17f, 0.21f, 1.00f );
94+
mStyle.Colors[ImGuiCol_TabUnfocused] = ImVec4( 0.84f, 0.10f, 0.14f, 1.00f );
95+
mStyle.Colors[ImGuiCol_TabUnfocusedActive] = ImVec4( 0.84f, 0.10f, 0.14f, 1.00f );
96+
//mStyle.Colors[ImGuiCol_DockingPreview] = ImVec4( 0.75f, 0.24f, 0.18f, 1.00f );
97+
//mStyle.Colors[ImGuiCol_DockingEmptyBg] = ImVec4( 0.20f, 0.20f, 0.20f, 1.00f );
98+
mStyle.Colors[ImGuiCol_PlotLines] = ImVec4( 0.86f, 0.93f, 0.89f, 0.63f );
99+
mStyle.Colors[ImGuiCol_PlotLinesHovered] = ImVec4( 0.75f, 0.24f, 0.18f, 1.00f );
100+
mStyle.Colors[ImGuiCol_PlotHistogram] = ImVec4( 0.86f, 0.93f, 0.89f, 0.63f );
101+
mStyle.Colors[ImGuiCol_PlotHistogramHovered] = ImVec4( 0.75f, 0.24f, 0.18f, 1.00f );
102+
mStyle.Colors[ImGuiCol_TextSelectedBg] = ImVec4( 0.75f, 0.24f, 0.18f, 1.00f );
103+
mStyle.Colors[ImGuiCol_DragDropTarget] = ImVec4( 0.75f, 0.24f, 0.18f, 1.00f );
104+
mStyle.Colors[ImGuiCol_NavHighlight] = ImVec4( 0.75f, 0.24f, 0.18f, 1.00f );
105+
mStyle.Colors[ImGuiCol_NavWindowingHighlight] = ImVec4( 1.00f, 1.00f, 1.00f, 0.70f );
106+
mStyle.Colors[ImGuiCol_NavWindowingDimBg] = ImVec4( 0.80f, 0.80f, 0.80f, 0.20f );
107+
mStyle.Colors[ImGuiCol_ModalWindowDimBg] = ImVec4( 0.20f, 0.22f, 0.27f, 0.73f );
25108
}
26109

27110
Options& Options::window( const ci::app::WindowRef& window, int signalPriority )
@@ -61,6 +144,12 @@ namespace ImGui {
61144
return *this;
62145
}
63146

147+
Options& Options::style( const ImGuiStyle& style )
148+
{
149+
mStyle = style;
150+
return *this;
151+
}
152+
64153
ScopedId::ScopedId( int int_id )
65154
{
66155
ImGui::PushID( int_id );
@@ -371,7 +460,7 @@ static void ImGui_ImplCinder_PostDraw()
371460
sTriggerNewFrame = true;
372461
}
373462

374-
static bool ImGui_ImplCinder_Init( const ci::app::WindowRef& window, bool auto_render, int signalPriority )
463+
static bool ImGui_ImplCinder_Init( const ci::app::WindowRef& window, const ImGui::Options& options )
375464
{
376465
// Setup back-end capabilities flags
377466
ImGuiIO& io = ImGui::GetIO();
@@ -398,6 +487,9 @@ static bool ImGui_ImplCinder_Init( const ci::app::WindowRef& window, bool auto_r
398487
io.KeyMap[ImGuiKey_Insert] = ci::app::KeyEvent::KEY_INSERT;
399488
io.KeyMap[ImGuiKey_Space] = ci::app::KeyEvent::KEY_SPACE;
400489

490+
ImGuiStyle& imGuiStyle = ImGui::GetStyle();
491+
imGuiStyle = options.getStyle();
492+
401493
#ifndef CINDER_LINUX
402494
// clipboard callbacks
403495
io.SetClipboardTextFn = []( void* user_data, const char* text ) {
@@ -411,6 +503,7 @@ static bool ImGui_ImplCinder_Init( const ci::app::WindowRef& window, bool auto_r
411503
return (const char*)&strCopy[0];
412504
};
413505
#endif
506+
int signalPriority = options.getSignalPriority();
414507
sWindowConnections[window] += window->getSignalMouseDown().connect( signalPriority, ImGui_ImplCinder_MouseDown );
415508
sWindowConnections[window] += window->getSignalMouseUp().connect( signalPriority, ImGui_ImplCinder_MouseUp );
416509
sWindowConnections[window] += window->getSignalMouseMove().connect( signalPriority, ImGui_ImplCinder_MouseMove );
@@ -419,7 +512,7 @@ static bool ImGui_ImplCinder_Init( const ci::app::WindowRef& window, bool auto_r
419512
sWindowConnections[window] += window->getSignalKeyDown().connect( signalPriority, ImGui_ImplCinder_KeyDown );
420513
sWindowConnections[window] += window->getSignalKeyUp().connect( signalPriority, ImGui_ImplCinder_KeyUp );
421514
sWindowConnections[window] += window->getSignalResize().connect( signalPriority, ImGui_ImplCinder_Resize );
422-
if( auto_render ) {
515+
if( options.isAutoRenderEnabled() ) {
423516
sWindowConnections[window] += ci::app::App::get()->getSignalUpdate().connect( std::bind( ImGui_ImplCinder_NewFrameGuard, window ) );
424517
sWindowConnections[window] += window->getSignalPostDraw().connect( ImGui_ImplCinder_PostDraw );
425518
}
@@ -469,12 +562,11 @@ void ImGui::Initialize( const ImGui::Options& options )
469562
ImGui_ImplOpenGL3_Init();
470563
#endif
471564

565+
ImGui_ImplCinder_Init( window, options );
472566
if( options.isAutoRenderEnabled() ) {
473-
ImGui_ImplCinder_Init( window, true, options.getSignalPriority() );
474567
ImGui_ImplCinder_NewFrameGuard( window );
475568
}
476569
else {
477-
ImGui_ImplCinder_Init( window, false, options.getSignalPriority() );
478570
sTriggerNewFrame = false; //prevents resize() event from calling begin frame.
479571
}
480572

0 commit comments

Comments
 (0)