mirror of
https://github.com/obsqrbtz/clrsync.git
synced 2026-04-09 12:37:41 +03:00
chore: refactor
This commit is contained in:
@@ -17,7 +17,7 @@ void action_buttons::clear()
|
||||
m_buttons.clear();
|
||||
}
|
||||
|
||||
void action_buttons::render(const core::palette &theme_palette)
|
||||
void action_buttons::render(const core::palette &)
|
||||
{
|
||||
if (m_buttons.empty())
|
||||
return;
|
||||
@@ -37,30 +37,16 @@ void action_buttons::render(const core::palette &theme_palette)
|
||||
ImGui::SameLine();
|
||||
first = false;
|
||||
|
||||
int style_colors_pushed = 0;
|
||||
bool has_style = false;
|
||||
if (button.use_error_style)
|
||||
{
|
||||
auto error = palette_color(theme_palette, "error");
|
||||
auto error_hover = ImVec4(error.x * 1.1f, error.y * 1.1f, error.z * 1.1f, error.w);
|
||||
auto error_active = ImVec4(error.x * 0.8f, error.y * 0.8f, error.z * 0.8f, error.w);
|
||||
auto on_error = palette_color(theme_palette, "on_error");
|
||||
ImGui::PushStyleColor(ImGuiCol_Button, error);
|
||||
ImGui::PushStyleColor(ImGuiCol_ButtonHovered, error_hover);
|
||||
ImGui::PushStyleColor(ImGuiCol_ButtonActive, error_active);
|
||||
ImGui::PushStyleColor(ImGuiCol_Text, on_error);
|
||||
style_colors_pushed = 4;
|
||||
push_error_button_style();
|
||||
has_style = true;
|
||||
}
|
||||
else if (button.use_success_style)
|
||||
{
|
||||
auto success = palette_color(theme_palette, "success", "accent");
|
||||
auto success_hover = ImVec4(success.x * 1.1f, success.y * 1.1f, success.z * 1.1f, success.w);
|
||||
auto success_active = ImVec4(success.x * 0.8f, success.y * 0.8f, success.z * 0.8f, success.w);
|
||||
auto on_success = palette_color(theme_palette, "on_success", "on_surface");
|
||||
ImGui::PushStyleColor(ImGuiCol_Button, success);
|
||||
ImGui::PushStyleColor(ImGuiCol_ButtonHovered, success_hover);
|
||||
ImGui::PushStyleColor(ImGuiCol_ButtonActive, success_active);
|
||||
ImGui::PushStyleColor(ImGuiCol_Text, on_success);
|
||||
style_colors_pushed = 4;
|
||||
push_success_button_style();
|
||||
has_style = true;
|
||||
}
|
||||
|
||||
bool disabled = !button.enabled;
|
||||
@@ -70,21 +56,17 @@ void action_buttons::render(const core::palette &theme_palette)
|
||||
if (ImGui::Button(button.label.c_str()))
|
||||
{
|
||||
if (button.on_click)
|
||||
{
|
||||
button.on_click();
|
||||
}
|
||||
}
|
||||
|
||||
if (disabled)
|
||||
ImGui::EndDisabled();
|
||||
|
||||
if (style_colors_pushed > 0)
|
||||
ImGui::PopStyleColor(style_colors_pushed);
|
||||
if (has_style)
|
||||
pop_button_style();
|
||||
|
||||
if (!button.tooltip.empty() && ImGui::IsItemHovered())
|
||||
{
|
||||
ImGui::SetTooltip("%s", button.tooltip.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
ImGui::PopStyleVar();
|
||||
|
||||
@@ -12,20 +12,11 @@ ImVec4 palette_color(const core::palette &pal, const std::string &key,
|
||||
|
||||
auto it = colors.find(key);
|
||||
if (it == colors.end() && !fallback.empty())
|
||||
{
|
||||
it = colors.find(fallback);
|
||||
}
|
||||
|
||||
if (it != colors.end())
|
||||
{
|
||||
const auto &col = it->second;
|
||||
const uint32_t hex = col.hex();
|
||||
const float r = ((hex >> 24) & 0xFF) / 255.0f;
|
||||
const float g = ((hex >> 16) & 0xFF) / 255.0f;
|
||||
const float b = ((hex >> 8) & 0xFF) / 255.0f;
|
||||
const float a = (hex & 0xFF) / 255.0f;
|
||||
return ImVec4(r, g, b, a);
|
||||
}
|
||||
return theme::color_utils::from_hex(it->second.hex());
|
||||
|
||||
return ImVec4(1.0f, 1.0f, 1.0f, 1.0f);
|
||||
}
|
||||
|
||||
@@ -38,21 +29,53 @@ uint32_t palette_color_u32(const core::palette &pal, const std::string &key,
|
||||
|
||||
auto it = colors.find(key);
|
||||
if (it == colors.end() && !fallback.empty())
|
||||
{
|
||||
it = colors.find(fallback);
|
||||
}
|
||||
|
||||
if (it != colors.end())
|
||||
{
|
||||
const auto &col = it->second;
|
||||
const uint32_t hex = col.hex();
|
||||
const uint32_t r = (hex >> 24) & 0xFF;
|
||||
const uint32_t g = (hex >> 16) & 0xFF;
|
||||
const uint32_t b = (hex >> 8) & 0xFF;
|
||||
const uint32_t a = hex & 0xFF;
|
||||
return (a << 24) | (b << 16) | (g << 8) | r;
|
||||
}
|
||||
return theme::color_utils::to_imgui_u32(it->second.hex());
|
||||
|
||||
return 0xFFFFFFFF;
|
||||
}
|
||||
|
||||
void push_success_button_style()
|
||||
{
|
||||
const auto &t = theme::current_theme();
|
||||
ImGui::PushStyleColor(ImGuiCol_Button, t.success());
|
||||
ImGui::PushStyleColor(ImGuiCol_ButtonHovered, t.success_hovered());
|
||||
ImGui::PushStyleColor(ImGuiCol_ButtonActive, t.success_active());
|
||||
ImGui::PushStyleColor(ImGuiCol_Text, t.on_success());
|
||||
}
|
||||
|
||||
void push_error_button_style()
|
||||
{
|
||||
const auto &t = theme::current_theme();
|
||||
ImGui::PushStyleColor(ImGuiCol_Button, t.error());
|
||||
ImGui::PushStyleColor(ImGuiCol_ButtonHovered, t.error_hovered());
|
||||
ImGui::PushStyleColor(ImGuiCol_ButtonActive, t.error_active());
|
||||
ImGui::PushStyleColor(ImGuiCol_Text, t.on_error());
|
||||
}
|
||||
|
||||
void push_warning_button_style()
|
||||
{
|
||||
const auto &t = theme::current_theme();
|
||||
ImGui::PushStyleColor(ImGuiCol_Button, t.warning());
|
||||
ImGui::PushStyleColor(ImGuiCol_ButtonHovered, t.warning_hovered());
|
||||
ImGui::PushStyleColor(ImGuiCol_ButtonActive, t.warning_active());
|
||||
ImGui::PushStyleColor(ImGuiCol_Text, t.on_warning());
|
||||
}
|
||||
|
||||
void push_info_button_style()
|
||||
{
|
||||
const auto &t = theme::current_theme();
|
||||
ImGui::PushStyleColor(ImGuiCol_Button, t.info());
|
||||
ImGui::PushStyleColor(ImGuiCol_ButtonHovered, t.info_hovered());
|
||||
ImGui::PushStyleColor(ImGuiCol_ButtonActive, t.info_active());
|
||||
ImGui::PushStyleColor(ImGuiCol_Text, t.on_info());
|
||||
}
|
||||
|
||||
void pop_button_style()
|
||||
{
|
||||
ImGui::PopStyleColor(4);
|
||||
}
|
||||
|
||||
} // namespace clrsync::gui::widgets
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#define CLRSYNC_GUI_WIDGETS_COLORS_HPP
|
||||
|
||||
#include "core/palette/palette.hpp"
|
||||
#include "gui/theme/app_theme.hpp"
|
||||
#include "imgui.h"
|
||||
#include <string>
|
||||
|
||||
@@ -14,6 +15,18 @@ ImVec4 palette_color(const core::palette &pal, const std::string &key,
|
||||
uint32_t palette_color_u32(const core::palette &pal, const std::string &key,
|
||||
const std::string &fallback = "");
|
||||
|
||||
inline const theme::app_theme &theme() { return theme::current_theme(); }
|
||||
|
||||
void push_success_button_style();
|
||||
|
||||
void push_error_button_style();
|
||||
|
||||
void push_warning_button_style();
|
||||
|
||||
void push_info_button_style();
|
||||
|
||||
void pop_button_style();
|
||||
|
||||
} // namespace clrsync::gui::widgets
|
||||
|
||||
#endif // CLRSYNC_GUI_WIDGETS_COLORS_HPP
|
||||
|
||||
@@ -5,11 +5,10 @@
|
||||
namespace clrsync::gui::widgets
|
||||
{
|
||||
|
||||
void section_header(const std::string& title, const core::palette& palette)
|
||||
void section_header(const std::string &title, const core::palette &)
|
||||
{
|
||||
ImGui::Spacing();
|
||||
auto accent_color = palette_color(palette, "accent");
|
||||
ImGui::TextColored(accent_color, "%s", title.c_str());
|
||||
ImGui::TextColored(theme().accent(), "%s", title.c_str());
|
||||
ImGui::Separator();
|
||||
ImGui::Spacing();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user