Skip to content

Commit facb45f

Browse files
committed
gh-87: support sub styles (per element customization)
1 parent 0b74f02 commit facb45f

20 files changed

+647
-243
lines changed

deps/imgui/imgui.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3579,6 +3579,9 @@ const char* ImGui::GetStyleColorName(ImGuiCol idx)
35793579
case ImGuiCol_Header: return "Header";
35803580
case ImGuiCol_HeaderHovered: return "HeaderHovered";
35813581
case ImGuiCol_HeaderActive: return "HeaderActive";
3582+
case ImGuiCol_CollapsingHeader: return "CollapsingHeader";
3583+
case ImGuiCol_CollapsingHeaderHovered: return "CollapsingHeaderHovered";
3584+
case ImGuiCol_CollapsingHeaderActive: return "CollapsingHeaderActive";
35823585
case ImGuiCol_Separator: return "Separator";
35833586
case ImGuiCol_SeparatorHovered: return "SeparatorHovered";
35843587
case ImGuiCol_SeparatorActive: return "SeparatorActive";

deps/imgui/imgui.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1711,9 +1711,12 @@ enum ImGuiCol_
17111711
ImGuiCol_Button,
17121712
ImGuiCol_ButtonHovered,
17131713
ImGuiCol_ButtonActive,
1714-
ImGuiCol_Header, // Header* colors are used for CollapsingHeader, TreeNode, Selectable, MenuItem
1714+
ImGuiCol_Header, // Header* colors are used for TreeNode, Selectable, MenuItem
17151715
ImGuiCol_HeaderHovered,
17161716
ImGuiCol_HeaderActive,
1717+
ImGuiCol_CollapsingHeader, // Collapsing header colors
1718+
ImGuiCol_CollapsingHeaderHovered,
1719+
ImGuiCol_CollapsingHeaderActive,
17171720
ImGuiCol_Separator,
17181721
ImGuiCol_SeparatorHovered,
17191722
ImGuiCol_SeparatorActive,

editor/styles/dark.yml

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ m_desc:
5050
hover_stationary_delay: 0.15
5151
hover_delay_short: 0.15
5252
hover_delay_normal: 0.4
53+
font_scale: 1
5354
palette:
5455
colors:
5556
- key: color_1
@@ -87,7 +88,7 @@ m_desc:
8788
- key: color_15
8889
value: 0.0588235 0.470588 0.929412 1
8990
- key: color_17
90-
value: 0.0823529 0.0823529 0.0823529 1
91+
value: 0.0823529 0.0823529 0.0823529 0.647059
9192
- key: color_18
9293
value: 0.529412 0.729412 0.988235 1
9394
- key: color_19
@@ -96,8 +97,6 @@ m_desc:
9697
value: 0.992157 0.94902 0.258824 1
9798
- key: color_21
9899
value: 0.0823529 0.0823529 0.0823529 0.647856
99-
- key: color_22
100-
value: 0.0823529 0.0823529 0.0823529 0.647059
101100
colors:
102101
- type: Text
103102
value: color_0
@@ -153,6 +152,12 @@ m_desc:
153152
value: color_13
154153
- type: HeaderActive
155154
value: color_15
155+
- type: CollapsingHeader
156+
value: color_5
157+
- type: CollapsingHeaderHovered
158+
value: color_14
159+
- type: CollapsingHeaderActive
160+
value: color_14
156161
- type: Separator
157162
value: color_10
158163
- type: SeparatorHovered
@@ -164,7 +169,7 @@ m_desc:
164169
- type: ResizeGripHovered
165170
value: color_14
166171
- type: ResizeGripActive
167-
value: color_13
172+
value: color_20
168173
- type: TabHovered
169174
value: color_3
170175
- type: Tab
@@ -178,7 +183,7 @@ m_desc:
178183
- type: TabDimmedSelected
179184
value: color_3
180185
- type: TabDimmedSelectedOverline
181-
value: color_17
186+
value: color_3
182187
- type: DockingPreview
183188
value: color_14
184189
- type: DockingEmptyBg
@@ -214,19 +219,28 @@ m_desc:
214219
- type: NavWindowingDimBg
215220
value: color_21
216221
- type: ModalWindowDimBg
217-
value: color_22
222+
value: color_17
218223
fonts:
219-
- tag: "medium"
224+
- tag: medium
220225
file: "editor/fonts/inter/inter_28pt_medium"
221-
- tag: "bold"
226+
- tag: bold
222227
file: "editor/fonts/inter/inter_28pt_bold"
223-
- tag: "black"
228+
- tag: black
224229
file: "editor/fonts/inter/inter_28pt_black"
225-
- tag: "italic"
230+
- tag: italic
226231
file: "editor/fonts/inter/inter_28pt_italic"
227-
- tag: "light"
232+
- tag: light
228233
file: "editor/fonts/inter/inter_28pt_light"
229-
- tag: "medium_light"
234+
- tag: medium_light
230235
file: "editor/fonts/inter/inter_28pt_medium_italic"
231-
- tag: "regular"
232-
file: "editor/fonts/inter/inter_28pt_regular"
236+
- tag: regular
237+
file: "editor/fonts/inter/inter_28pt_regular"
238+
sub_styles:
239+
- key: panel
240+
value:
241+
colors:
242+
- type: WindowBg
243+
value: color_3
244+
- key: header
245+
value:
246+
font: bold

engine/code/ui/ui_containers.hpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#pragma once
2929

3030
#include "ui/ui_attribute.hpp"
31+
#include "ui/ui_content.hpp"
3132
#include "ui/ui_element.hpp"
3233

3334
namespace wmoge {
@@ -147,4 +148,16 @@ namespace wmoge {
147148
UiAttribute<UiScroll> scroll_type{UiScroll::Vertical};
148149
};
149150

151+
/**
152+
* @class UiCollapsingPanel
153+
* @brief
154+
*/
155+
class UiCollapsingPanel : public UiPanel {
156+
public:
157+
UiCollapsingPanel() : UiPanel(UiElementType::CollapsingPanel) {}
158+
159+
UiSlot<UiText> header;
160+
UiAttribute<bool> default_open{true};
161+
};
162+
150163
}// namespace wmoge

engine/code/ui/ui_content.hpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ namespace wmoge {
6262
UiText() : UiSubElement(UiElementType::Text) {}
6363

6464
UiAttribute<std::string> text;
65-
UiAttributeOpt<Color4f> text_color;
6665
};
6766

6867
/**
@@ -74,7 +73,6 @@ namespace wmoge {
7473
UiTextWrapped() : UiSubElement(UiElementType::TextWrapped) {}
7574

7675
UiAttribute<std::string> text;
77-
UiAttributeOpt<Color4f> text_color;
7876
};
7977

8078
/**

engine/code/ui/ui_defs.hpp

Lines changed: 120 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434

3535
namespace wmoge {
3636

37+
/** @brief Cursor shown over ui element */
3738
enum class UiCursorType {
3839
Arrow = 0,
3940
TextInput,
@@ -46,6 +47,7 @@ namespace wmoge {
4647
NotAllowed
4748
};
4849

50+
/** @brief General ui direction value */
4951
enum class UiDir {
5052
None = 0,
5153
Left = 1,
@@ -54,17 +56,20 @@ namespace wmoge {
5456
Down = 4
5557
};
5658

59+
/** @brief Layout orientation */
5760
enum class UiOrientation {
5861
Horizontal,
5962
Vertical
6063
};
6164

65+
/** @brief Type of scroll areas */
6266
enum class UiScroll {
6367
Vertical,
6468
Horizontal,
6569
Mixed
6670
};
6771

72+
/** @brief Flag for window element */
6873
enum class UiWindowFlag {
6974
NoBringToFrontOnFocus,
7075
NoPadding,
@@ -74,16 +79,124 @@ namespace wmoge {
7479
NoScrollbar
7580
};
7681

82+
/** @brief Window element flags */
7783
using UiWindowFlags = Mask<UiWindowFlag>;
7884

79-
enum class UiTextInputFlag {
80-
CallbackAlways,
81-
EnterForSubmit,
82-
EscapeToClear,
83-
CompletionTab,
84-
HistoryScroll
85+
/** @brief Name of param in ui style */
86+
enum class UiParam {
87+
Alpha = 0,
88+
DisabledAlpha,
89+
WindowPaddingX,
90+
WindowPaddingY,
91+
WindowRounding,
92+
WindowBorderSize,
93+
WindowMinSizeX,
94+
WindowMinSizeY,
95+
WindowTitleAlignX,
96+
WindowTitleAlignY,
97+
ChildRounding,
98+
ChildBorderSize,
99+
PopupRounding,
100+
PopupBorderSize,
101+
FramePaddingX,
102+
FramePaddingY,
103+
FrameRounding,
104+
FrameBorderSize,
105+
ItemSpacingX,
106+
ItemSpacingY,
107+
ItemInnerSpacingX,
108+
ItemInnerSpacingY,
109+
IndentSpacing,
110+
CellPaddingX,
111+
CellPaddingY,
112+
ScrollbarSize,
113+
ScrollbarRounding,
114+
GrabMinSize,
115+
GrabRounding,
116+
TabRounding,
117+
TabBorderSize,
118+
TabBarBorderSize,
119+
TabBarOverlineSize,
120+
TableAngledHeadersAngle,
121+
TableAngledHeadersTextAlignX,
122+
TableAngledHeadersTextAlignY,
123+
ButtonTextAlignX,
124+
ButtonTextAlignY,
125+
SelectableTextAlignX,
126+
SelectableTextAlignY,
127+
SeparatorTextBorderSize,
128+
SeparatorTextAlignX,
129+
SeparatorTextAlignY,
130+
SeparatorTextPaddingX,
131+
SeparatorTextPaddingY,
132+
DockingSeparatorSize,
133+
Count
85134
};
86135

87-
using UiTextInputFlags = Mask<UiTextInputFlag>;
136+
/** @brief Name of color param in ui stype */
137+
enum class UiColor {
138+
Text = 0,
139+
TextDisabled,
140+
WindowBg,
141+
ChildBg,
142+
PopupBg,
143+
Border,
144+
BorderShadow,
145+
FrameBg,
146+
FrameBgHovered,
147+
FrameBgActive,
148+
TitleBg,
149+
TitleBgActive,
150+
TitleBgCollapsed,
151+
MenuBarBg,
152+
ScrollbarBg,
153+
ScrollbarGrab,
154+
ScrollbarGrabHovered,
155+
ScrollbarGrabActive,
156+
CheckMark,
157+
SliderGrab,
158+
SliderGrabActive,
159+
Button,
160+
ButtonHovered,
161+
ButtonActive,
162+
Header,
163+
HeaderHovered,
164+
HeaderActive,
165+
CollapsingHeader,
166+
CollapsingHeaderHovered,
167+
CollapsingHeaderActive,
168+
Separator,
169+
SeparatorHovered,
170+
SeparatorActive,
171+
ResizeGrip,
172+
ResizeGripHovered,
173+
ResizeGripActive,
174+
TabHovered,
175+
Tab,
176+
TabSelected,
177+
TabSelectedOverline,
178+
TabDimmed,
179+
TabDimmedSelected,
180+
TabDimmedSelectedOverline,
181+
DockingPreview,
182+
DockingEmptyBg,
183+
PlotLines,
184+
PlotLinesHovered,
185+
PlotHistogram,
186+
PlotHistogramHovered,
187+
TableHeaderBg,
188+
TableBorderStrong,
189+
TableBorderLight,
190+
TableRowBg,
191+
TableRowBgAlt,
192+
TextLink,
193+
TextSelectedBg,
194+
DragDropTarget,
195+
NavCursor,
196+
NavWindowingHighlight,
197+
NavWindowingDimBg,
198+
ModalWindowDimBg,
199+
Count
200+
};
88201

89202
}// namespace wmoge

engine/code/ui/ui_element.hpp

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ namespace wmoge {
5252
Modal,
5353
StackPanel,
5454
ScrollPanel,
55+
CollapsingPanel,
5556
MenuItem,
5657
Menu,
5758
MenuBar,
@@ -77,15 +78,8 @@ namespace wmoge {
7778
ComboBox,
7879
ListBox,
7980
ProgressBar
80-
8181
};
8282

83-
/**
84-
* @class UiUserData
85-
* @brief Base class for user data which can be attached to any ui element
86-
*/
87-
class UiUserData : public RefCnt {};
88-
8983
/**
9084
* @class UiElement
9185
* @brief Base class for all ui elements
@@ -96,7 +90,7 @@ namespace wmoge {
9690

9791
UiAttribute<Strid> tag;
9892
UiAttributeOpt<UiCursorType> cursor;
99-
UiAttribute<Ref<UiUserData>> user_data;
93+
UiAttribute<Strid> sub_style;
10094
const UiElementType type = UiElementType::Unknown;
10195
};
10296

engine/code/ui/ui_inputs.hpp

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -170,18 +170,17 @@ namespace wmoge {
170170
using OnHistory = std::function<void()>;
171171
using OnCompletion = std::function<void()>;
172172

173-
UiAttribute<UiTextInputFlags> flags;
174-
UiAttribute<std::string> text;
175-
UiAttributeOpt<std::string> hint;
176-
UiAttribute<bool> esc_to_clear{true};
177-
UiEvent<OnInput> on_input;
178-
UiEvent<OnEnter> on_enter;
179-
UiEvent<OnHistory> on_history_prev;
180-
UiEvent<OnHistory> on_history_next;
181-
UiEvent<OnCompletion> on_completion;
182-
UiSlot<UiCompletionPopup> completion_popup;
183-
UiAttribute<int> completion_popup_lines{10};
184-
UiAttribute<bool> completion_popup_bottom{false};
173+
UiAttribute<std::string> text;
174+
UiAttributeOpt<std::string> hint;
175+
UiAttribute<bool> esc_to_clear{true};
176+
UiEvent<OnInput> on_input;
177+
UiEvent<OnEnter> on_enter;
178+
UiEvent<OnHistory> on_history_prev;
179+
UiEvent<OnHistory> on_history_next;
180+
UiEvent<OnCompletion> on_completion;
181+
UiSlot<UiCompletionPopup> completion_popup;
182+
UiAttribute<int> completion_popup_lines{10};
183+
UiAttribute<bool> completion_popup_bottom{false};
185184
};
186185

187186
}// namespace wmoge

0 commit comments

Comments
 (0)