From 952f020fb5fb45782fc1dde37912e900e03c38b0 Mon Sep 17 00:00:00 2001 From: scorpion-26 Date: Wed, 29 Nov 2023 23:27:41 +0100 Subject: [PATCH] Allow AddClass before widget creation This is necessary for multiple layout classes. --- src/Widget.cpp | 5 +++++ src/Widget.h | 2 ++ 2 files changed, 7 insertions(+) diff --git a/src/Widget.cpp b/src/Widget.cpp index d79f560..c1c7a10 100644 --- a/src/Widget.cpp +++ b/src/Widget.cpp @@ -87,6 +87,7 @@ void Widget::AddClass(const std::string& cssClass) auto style = gtk_widget_get_style_context(m_Widget); gtk_style_context_add_class(style, cssClass.c_str()); } + m_AdditionalClasses.insert(cssClass); } void Widget::RemoveClass(const std::string& cssClass) { @@ -95,6 +96,7 @@ void Widget::RemoveClass(const std::string& cssClass) auto style = gtk_widget_get_style_context(m_Widget); gtk_style_context_remove_class(style, cssClass.c_str()); } + m_AdditionalClasses.erase(cssClass); } void Widget::SetVerticalTransform(const Transform& transform) @@ -176,6 +178,9 @@ void Widget::ApplyPropertiesToWidget() // Apply style auto style = gtk_widget_get_style_context(m_Widget); gtk_style_context_add_class(style, m_CssClass.c_str()); + for (auto& cssClass : m_AdditionalClasses) { + gtk_style_context_add_class(style, cssClass.c_str()); + } gtk_widget_set_tooltip_text(m_Widget, m_Tooltip.c_str()); diff --git a/src/Widget.h b/src/Widget.h index 7e30315..e58c232 100644 --- a/src/Widget.h +++ b/src/Widget.h @@ -6,6 +6,7 @@ #include #include #include +#include enum class Alignment { @@ -175,6 +176,7 @@ protected: std::vector> m_Childs; std::string m_CssClass; + std::unordered_set m_AdditionalClasses; std::string m_Tooltip; Transform m_HorizontalTransform; // X Transform m_VerticalTransform; // Y