1#ifndef YAZE_APP_GUI_CORE_STYLE_GUARD_H_
2#define YAZE_APP_GUI_CORE_STYLE_GUARD_H_
4#include <initializer_list>
9#include "imgui/imgui.h"
35 ImGui::PushStyleColor(idx, color);
39 ImGui::PushStyleColor(idx,
static_cast<ImVec4
>(color));
43 :
count_(static_cast<int>(entries.size())) {
44 for (
const auto& e : entries) {
45 ImGui::PushStyleColor(e.idx, e.color);
72 std::variant<float, ImVec2>
value;
76 ImGui::PushStyleVar(idx, val);
80 ImGui::PushStyleVar(idx, val);
84 :
count_(static_cast<int>(entries.size())) {
85 for (
const auto& e : entries) {
86 if (
auto* f = std::get_if<float>(&e.value)) {
87 ImGui::PushStyleVar(e.idx, *f);
89 ImGui::PushStyleVar(e.idx, std::get<ImVec2>(e.value));
116 std::optional<ImVec4>
bg;
138 bool* p_open =
nullptr, ImGuiWindowFlags flags = 0)
141 if (config.
bg.has_value()) {
142 ImGui::PushStyleColor(ImGuiCol_WindowBg, *config.
bg);
145 if (config.
border.has_value()) {
146 ImGui::PushStyleColor(ImGuiCol_Border, *config.
border);
151 if (config.
padding.x >= 0.0f) {
152 ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, config.
padding);
155 if (config.
spacing.x >= 0.0f) {
156 ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, config.
spacing);
160 ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, config.
border_size);
164 ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, config.
rounding);
168 is_open_ = ImGui::Begin(name, p_open, flags);
177 explicit operator bool()
const {
return is_open_; }
200 FixedPanel(
const char* name,
const ImVec2& pos,
const ImVec2& size,
202 ImGuiWindowFlags extra_flags = 0)
204 ImGui::SetNextWindowPos(pos);
205 ImGui::SetNextWindowSize(size);
207 constexpr ImGuiWindowFlags kFixedFlags =
208 ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoResize |
209 ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoCollapse |
210 ImGuiWindowFlags_NoDocking;
212 window_.emplace(name, config,
nullptr, kFixedFlags | extra_flags);
215 explicit operator bool()
const {
216 return window_.has_value() &&
static_cast<bool>(*window_);
237 std::optional<ImVec4>
bg;
257 bool has_border =
false, ImGuiWindowFlags flags = 0)
259 if (config.
bg.has_value()) {
260 ImGui::PushStyleColor(ImGuiCol_ChildBg, *config.
bg);
263 if (config.
border.has_value()) {
264 ImGui::PushStyleColor(ImGuiCol_Border, *config.
border);
268 ImGui::PushStyleVar(ImGuiStyleVar_ChildRounding, config.
rounding);
272 ImGui::PushStyleVar(ImGuiStyleVar_ChildBorderSize, config.
border_size);
275 is_open_ = ImGui::BeginChild(
id, size, has_border, flags);
284 explicit operator bool()
const {
return is_open_; }
RAII for fixed-position panels (activity bar, side panel, status bar).
FixedPanel(const FixedPanel &)=delete
FixedPanel(const char *name, const ImVec2 &pos, const ImVec2 &size, const StyledWindowConfig &config, ImGuiWindowFlags extra_flags=0)
FixedPanel & operator=(const FixedPanel &)=delete
std::optional< StyledWindow > window_
RAII guard for ImGui style colors.
StyleColorGuard(ImGuiCol idx, const Color &color)
StyleColorGuard(ImGuiCol idx, const ImVec4 &color)
StyleColorGuard(std::initializer_list< Entry > entries)
StyleColorGuard(const StyleColorGuard &)=delete
StyleColorGuard & operator=(const StyleColorGuard &)=delete
RAII guard for ImGui style vars.
StyleVarGuard(ImGuiStyleVar idx, float val)
StyleVarGuard(ImGuiStyleVar idx, const ImVec2 &val)
StyleVarGuard(const StyleVarGuard &)=delete
StyleVarGuard & operator=(const StyleVarGuard &)=delete
StyleVarGuard(std::initializer_list< Entry > entries)
RAII guard for ImGui child windows with optional styling.
StyledChild & operator=(const StyledChild &)=delete
StyledChild(const StyledChild &)=delete
StyledChild(const char *id, const ImVec2 &size, const StyledChildConfig &config, bool has_border=false, ImGuiWindowFlags flags=0)
RAII compound guard for window-level style setup.
StyledWindow & operator=(const StyledWindow &)=delete
StyledWindow(const char *name, const StyledWindowConfig &config, bool *p_open=nullptr, ImGuiWindowFlags flags=0)
StyledWindow(const StyledWindow &)=delete
std::variant< float, ImVec2 > value
Configuration for styled child windows.
std::optional< ImVec4 > border
std::optional< ImVec4 > bg
Configuration for styled windows and panels.
std::optional< ImVec4 > border
std::optional< ImVec4 > bg