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"
11#include "imgui/imgui_internal.h"
37 ImGui::PushStyleColor(idx, color);
41 ImGui::PushStyleColor(idx,
static_cast<ImVec4
>(color));
45 :
count_(static_cast<int>(entries.size())) {
46 for (
const auto& e : entries) {
47 ImGui::PushStyleColor(e.idx, e.color);
53 ImGui::PopStyleColor(
count_);
75 std::variant<float, ImVec2>
value;
79 ImGui::PushStyleVar(idx, val);
83 ImGui::PushStyleVar(idx, val);
87 :
count_(static_cast<int>(entries.size())) {
88 for (
const auto& e : entries) {
89 if (
auto* f = std::get_if<float>(&e.value)) {
90 ImGui::PushStyleVar(e.idx, *f);
92 ImGui::PushStyleVar(e.idx, std::get<ImVec2>(e.value));
99 ImGui::PopStyleVar(
count_);
127 explicit IdScope(
const char* str_id) { ImGui::PushID(str_id); }
128 explicit IdScope(
int int_id) { ImGui::PushID(int_id); }
129 explicit IdScope(
const void* ptr_id) { ImGui::PushID(ptr_id); }
152 ImGui::BeginDisabled(disabled);
171 ImGui::PushItemFlag(option, enabled);
196 ImGui::PushItemFlag(ImGuiItemFlags_ReadOnly, read_only);
216 std::optional<ImVec4>
bg;
238 bool* p_open =
nullptr, ImGuiWindowFlags flags = 0)
241 if (config.
bg.has_value()) {
242 ImGui::PushStyleColor(ImGuiCol_WindowBg, *config.
bg);
245 if (config.
border.has_value()) {
246 ImGui::PushStyleColor(ImGuiCol_Border, *config.
border);
251 if (config.
padding.x >= 0.0f) {
252 ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, config.
padding);
255 if (config.
spacing.x >= 0.0f) {
256 ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, config.
spacing);
260 ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, config.
border_size);
264 ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, config.
rounding);
268 is_open_ = ImGui::Begin(name, p_open, flags);
279 explicit operator bool()
const {
return is_open_; }
302 FixedPanel(
const char* name,
const ImVec2& pos,
const ImVec2& size,
305 ImGui::SetNextWindowPos(pos);
306 ImGui::SetNextWindowSize(size);
308 constexpr ImGuiWindowFlags kFixedFlags =
309 ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoResize |
310 ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoCollapse |
311 ImGuiWindowFlags_NoDocking;
313 window_.emplace(name, config,
nullptr, kFixedFlags | extra_flags);
316 explicit operator bool()
const {
317 return window_.has_value() &&
static_cast<bool>(*window_);
338 std::optional<ImVec4>
bg;
358 ImGuiWindowFlags flags = 0)
360 if (config.
bg.has_value()) {
361 ImGui::PushStyleColor(ImGuiCol_ChildBg, *config.
bg);
364 if (config.
border.has_value()) {
365 ImGui::PushStyleColor(ImGuiCol_Border, *config.
border);
369 ImGui::PushStyleVar(ImGuiStyleVar_ChildRounding, config.
rounding);
373 ImGui::PushStyleVar(ImGuiStyleVar_ChildBorderSize, config.
border_size);
376 is_open_ = ImGui::BeginChild(
id, size, has_border, flags);
387 explicit operator bool()
const {
return is_open_; }
RAII guard for ImGui::BeginDisabled / ImGui::EndDisabled.
DisabledScope & operator=(const DisabledScope &)=delete
DisabledScope(const DisabledScope &)=delete
DisabledScope(bool disabled=true)
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::PushID / ImGui::PopID.
IdScope(const char *str_id)
IdScope & operator=(const IdScope &)=delete
IdScope(const IdScope &)=delete
IdScope(const void *ptr_id)
RAII guard for ImGui::PushItemFlag / ImGui::PopItemFlag.
ItemFlagScope & operator=(const ItemFlagScope &)=delete
ItemFlagScope(const ItemFlagScope &)=delete
ItemFlagScope(ImGuiItemFlags option, bool enabled)
RAII guard that pushes ImGuiItemFlags_ReadOnly.
ReadOnlyScope(const ReadOnlyScope &)=delete
ReadOnlyScope & operator=(const ReadOnlyScope &)=delete
ReadOnlyScope(bool read_only=true)
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