-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathstyle.hpp
More file actions
118 lines (102 loc) · 4.6 KB
/
style.hpp
File metadata and controls
118 lines (102 loc) · 4.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
/*
* Copyright (c) 2014-2025, NVIDIA CORPORATION. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* SPDX-FileCopyrightText: Copyright (c) 2014-2025, NVIDIA CORPORATION.
* SPDX-License-Identifier: Apache-2.0
*/
#pragma once
#include <cmath>
#include <vector>
#include <imgui/imgui.h>
namespace nvgui {
//--------------------------------------------------------------------------------------------------
// Setting a dark style for the GUI
// The colors were coded in sRGB color space, set the useLinearColor
// flag to convert to linear color space.
inline void setStyle(bool useLinearColor)
{
typedef ImVec4 (*srgbFunction)(float, float, float, float);
srgbFunction passthrough = [](float r, float g, float b, float a) -> ImVec4 { return ImVec4(r, g, b, a); };
srgbFunction toLinear = [](float r, float g, float b, float a) -> ImVec4 {
auto toLinearScalar = [](float u) -> float {
return u <= 0.04045 ? 25 * u / 323.f : powf((200 * u + 11) / 211.f, 2.4f);
};
return ImVec4(toLinearScalar(r), toLinearScalar(g), toLinearScalar(b), a);
};
srgbFunction srgb = useLinearColor ? toLinear : passthrough;
ImGui::StyleColorsDark();
ImGuiStyle& style = ImGui::GetStyle();
style.WindowRounding = 0.0f;
style.WindowBorderSize = 0.0f;
style.ColorButtonPosition = ImGuiDir_Right;
style.FrameRounding = 2.0f;
style.FrameBorderSize = 1.0f;
style.GrabRounding = 4.0f;
style.IndentSpacing = 12.0f;
style.Colors[ImGuiCol_WindowBg] = srgb(0.2f, 0.2f, 0.2f, 1.0f);
style.Colors[ImGuiCol_MenuBarBg] = srgb(0.2f, 0.2f, 0.2f, 1.0f);
style.Colors[ImGuiCol_ScrollbarBg] = srgb(0.2f, 0.2f, 0.2f, 1.0f);
style.Colors[ImGuiCol_PopupBg] = srgb(0.135f, 0.135f, 0.135f, 1.0f);
style.Colors[ImGuiCol_Border] = srgb(0.4f, 0.4f, 0.4f, 0.5f);
style.Colors[ImGuiCol_FrameBg] = srgb(0.05f, 0.05f, 0.05f, 0.5f);
// Normal
ImVec4 normal_color = srgb(0.465f, 0.465f, 0.525f, 1.0f);
std::vector<ImGuiCol> to_change_nrm;
to_change_nrm.push_back(ImGuiCol_Header);
to_change_nrm.push_back(ImGuiCol_SliderGrab);
to_change_nrm.push_back(ImGuiCol_Button);
to_change_nrm.push_back(ImGuiCol_CheckMark);
to_change_nrm.push_back(ImGuiCol_ResizeGrip);
to_change_nrm.push_back(ImGuiCol_TextSelectedBg);
to_change_nrm.push_back(ImGuiCol_Separator);
to_change_nrm.push_back(ImGuiCol_FrameBgActive);
for(auto c : to_change_nrm)
{
style.Colors[c] = normal_color;
}
// Active
ImVec4 active_color = srgb(0.365f, 0.365f, 0.425f, 1.0f);
std::vector<ImGuiCol> to_change_act;
to_change_act.push_back(ImGuiCol_HeaderActive);
to_change_act.push_back(ImGuiCol_SliderGrabActive);
to_change_act.push_back(ImGuiCol_ButtonActive);
to_change_act.push_back(ImGuiCol_ResizeGripActive);
to_change_act.push_back(ImGuiCol_SeparatorActive);
for(auto c : to_change_act)
{
style.Colors[c] = active_color;
}
// Hovered
ImVec4 hovered_color = srgb(0.565f, 0.565f, 0.625f, 1.0f);
std::vector<ImGuiCol> to_change_hover;
to_change_hover.push_back(ImGuiCol_HeaderHovered);
to_change_hover.push_back(ImGuiCol_ButtonHovered);
to_change_hover.push_back(ImGuiCol_FrameBgHovered);
to_change_hover.push_back(ImGuiCol_ResizeGripHovered);
to_change_hover.push_back(ImGuiCol_SeparatorHovered);
for(auto c : to_change_hover)
{
style.Colors[c] = hovered_color;
}
style.Colors[ImGuiCol_TitleBgActive] = srgb(0.465f, 0.465f, 0.465f, 1.0f);
style.Colors[ImGuiCol_TitleBg] = srgb(0.125f, 0.125f, 0.125f, 1.0f);
style.Colors[ImGuiCol_Tab] = srgb(0.05f, 0.05f, 0.05f, 0.5f);
style.Colors[ImGuiCol_TabHovered] = srgb(0.465f, 0.495f, 0.525f, 1.0f);
style.Colors[ImGuiCol_TabActive] = srgb(0.282f, 0.290f, 0.302f, 1.0f);
style.Colors[ImGuiCol_ModalWindowDimBg] = srgb(0.465f, 0.465f, 0.465f, 0.350f);
//Colors_ext[ImGuiColExt_Warning] = srgb (1.0f, 0.43f, 0.35f, 1.0f);
ImGui::SetColorEditOptions(ImGuiColorEditFlags_Float | ImGuiColorEditFlags_PickerHueWheel);
}
} // namespace nvgui