0.4.1
Loading...
Searching...
No Matches
NodeEditorStyleEditor.cpp
Go to the documentation of this file.
1// This file is part of INSTINCT, the INS Toolkit for Integrated
2// Navigation Concepts and Training by the Institute of Navigation of
3// the University of Stuttgart, Germany.
4//
5// This Source Code Form is subject to the terms of the Mozilla Public
6// License, v. 2.0. If a copy of the MPL was not distributed with this
7// file, You can obtain one at https://mozilla.org/MPL/2.0/.
8
10
11#include <imgui.h>
12#include <imgui_node_editor.h>
14
15namespace ed = ax::NodeEditor;
16
17namespace NAV::gui::windows
18{
19
21
22} // namespace NAV::gui::windows
23
24void NAV::gui::windows::ShowNodeEditorStyleEditor(bool* show, std::vector<ImVec4>& colors, const std::vector<const char*>& colorNames)
25{
26 if (!ImGui::Begin("Node Editor Style", show))
27 {
28 ImGui::End();
29 return;
30 }
31
32 auto paneWidth = ImGui::GetContentRegionAvail().x;
33
34 auto& editorStyle = ed::GetStyle();
35 ImGui::BeginHorizontal("Style buttons", ImVec2(paneWidth, 0), 1.0F);
36 ImGui::TextUnformatted("Values");
37 ImGui::Spring();
38 if (ImGui::Button("Reset to defaults"))
39 {
40 editorStyle = ed::Style();
41 }
42 ImGui::EndHorizontal();
43 ImGui::Spacing();
44 ImGui::DragFloat4("Node Padding", &editorStyle.NodePadding.x, 0.1F, 0.0F, 40.0F);
45 ImGui::DragFloat("Node Rounding", &editorStyle.NodeRounding, 0.1F, 0.0F, 40.0F);
46 ImGui::DragFloat("Node Border Width", &editorStyle.NodeBorderWidth, 0.1F, 0.0F, 15.0F);
47 ImGui::DragFloat("Hovered Node Border Width", &editorStyle.HoveredNodeBorderWidth, 0.1F, 0.0F, 15.0F);
48 ImGui::DragFloat("Selected Node Border Width", &editorStyle.SelectedNodeBorderWidth, 0.1F, 0.0F, 15.0F);
49 ImGui::DragFloat("Pin Rounding", &editorStyle.PinRounding, 0.1F, 0.0F, 40.0F);
50 ImGui::DragFloat("Pin Border Width", &editorStyle.PinBorderWidth, 0.1F, 0.0F, 15.0F);
51 ImGui::DragFloat("Link Strength", &editorStyle.LinkStrength, 1.0F, 0.0F, 500.0F);
52 // ImVec2 SourceDirection;
53 // ImVec2 TargetDirection;
54 ImGui::DragFloat("Scroll Duration", &editorStyle.ScrollDuration, 0.001F, 0.0F, 2.0F);
55 ImGui::DragFloat("Flow Marker Distance", &editorStyle.FlowMarkerDistance, 1.0F, 1.0F, 200.0F);
56 ImGui::DragFloat("Flow Speed", &editorStyle.FlowSpeed, 1.0F, 1.0F, 2000.0F);
57 ImGui::DragFloat("Flow Duration", &editorStyle.FlowDuration, 0.001F, 0.0F, 5.0F);
58 // ImVec2 PivotAlignment;
59 // ImVec2 PivotSize;
60 // ImVec2 PivotScale;
61 // float PinCorners;
62 // float PinRadius;
63 // float PinArrowSize;
64 // float PinArrowWidth;
65 ImGui::DragFloat("Group Rounding", &editorStyle.GroupRounding, 0.1F, 0.0F, 40.0F);
66 ImGui::DragFloat("Group Border Width", &editorStyle.GroupBorderWidth, 0.1F, 0.0F, 15.0F);
67
68 ImGui::Separator();
69
70 static ImGuiColorEditFlags edit_mode = ImGuiColorEditFlags_DisplayRGB;
71 ImGui::BeginHorizontal("Color Mode", ImVec2(paneWidth, 0), 1.0F);
72 ImGui::TextUnformatted("Filter Colors");
73 ImGui::Spring();
74 if (ImGui::Checkbox("Light mode", &nodeEditorLightMode)) { ApplyDarkLightMode(colors); }
75 ImGui::Spring(0);
76 ImGui::RadioButton("RGB", &edit_mode, ImGuiColorEditFlags_DisplayRGB);
77 ImGui::Spring(0);
78 ImGui::RadioButton("HSV", &edit_mode, ImGuiColorEditFlags_DisplayHSV);
79 ImGui::Spring(0);
80 ImGui::RadioButton("HEX", &edit_mode, ImGuiColorEditFlags_DisplayHex);
81 ImGui::EndHorizontal();
82
83 static ImGuiTextFilter filter;
84 filter.Draw("##NodeEditorStyleEditor", paneWidth);
85
86 ImGui::Spacing();
87
88 ImGui::PushItemWidth(-160);
89 for (int i = 0; i < ed::StyleColor_Count; i++)
90 {
91 const auto* name = ed::GetStyleColorName(static_cast<ed::StyleColor>(i));
92 if (!filter.PassFilter(name))
93 {
94 continue;
95 }
96
97 ImGui::ColorEdit4(name, &editorStyle.Colors[i].x, edit_mode); // NOLINT(cppcoreguidelines-pro-bounds-constant-array-index)
98 }
99
100 for (size_t i = 0; i < colors.size(); i++)
101 {
102 const auto* name = colorNames.at(i);
103 if (!filter.PassFilter(name))
104 {
105 continue;
106 }
107 ImGui::ColorEdit4(name, &colors.at(i).x, edit_mode); // NOLINT(cppcoreguidelines-pro-bounds-constant-array-index)
108 }
109 ImGui::PopItemWidth();
110
111 ImGui::End();
112}
113
114void NAV::gui::windows::ApplyDarkLightMode(std::vector<ImVec4>& colors)
115{
116 auto& editorStyle = ed::GetStyle();
118 {
119 editorStyle.Colors[ed::StyleColor_Bg] = ImColor(255, 255, 255, 255);
120 editorStyle.Colors[ed::StyleColor_Grid] = ImColor(120, 120, 120, 40);
121 editorStyle.Colors[ed::StyleColor_GroupBg] = ImColor(130, 130, 130, 160);
122
123 colors[NodeEditorApplication::COLOR_GROUP_HEADER_TEXT] = ImColor(0, 0, 0, 255);
124 colors[NodeEditorApplication::COLOR_GROUP_HEADER_BG] = ImColor(115, 115, 115, 0);
125 colors[NodeEditorApplication::COLOR_GROUP_OUTER_BORDER] = ImColor(255, 255, 255, 64);
126
127 ImGui::StyleColorsLight();
128 ImGui::GetStyle().Colors[ImGuiCol_WindowBg] = ImColor(255, 255, 255, 255);
129 ImGui::GetStyle().Colors[ImGuiCol_FrameBg] = ImColor(240, 240, 240, 255);
130 }
131 else
132 {
133 ed::Style defaultStyle{};
134 for (int i = 0; i < ed::StyleColor_Count; i++)
135 {
136 editorStyle.Colors[i] = defaultStyle.Colors[i]; // NOLINT(cppcoreguidelines-pro-bounds-constant-array-index)
137 }
138
139 colors[NodeEditorApplication::COLOR_GROUP_HEADER_TEXT] = ImColor(1.0F, 1.0F, 1.0F, 1.0F);
140 colors[NodeEditorApplication::COLOR_GROUP_HEADER_BG] = ImColor(1.0F, 1.0F, 1.0F, 0.25F);
141 colors[NodeEditorApplication::COLOR_GROUP_OUTER_BORDER] = ImColor(1.0F, 1.0F, 1.0F, 0.25F);
142
143 ImGui::StyleColorsDark();
144 }
145}
Style Editor window.
@ COLOR_GROUP_OUTER_BORDER
Color of the group outer border.
@ COLOR_GROUP_HEADER_BG
Color of the group header background.
@ COLOR_GROUP_HEADER_TEXT
Color of the group header text.
void ApplyDarkLightMode(std::vector< ImVec4 > &colors)
bool nodeEditorLightMode
If true, light mode is selected.
void ShowNodeEditorStyleEditor(bool *show, std::vector< ImVec4 > &colors, const std::vector< const char * > &colorNames)
Shows a window for editing the style of the Node Editor.