Allow AddClass before widget creation

This is necessary for multiple layout classes.
This commit is contained in:
scorpion-26 2023-11-29 23:27:41 +01:00
parent 1279d3e2fb
commit 952f020fb5
2 changed files with 7 additions and 0 deletions

View file

@ -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());

View file

@ -6,6 +6,7 @@
#include <memory>
#include <string>
#include <functional>
#include <unordered_set>
enum class Alignment
{
@ -175,6 +176,7 @@ protected:
std::vector<std::unique_ptr<Widget>> m_Childs;
std::string m_CssClass;
std::unordered_set<std::string> m_AdditionalClasses;
std::string m_Tooltip;
Transform m_HorizontalTransform; // X
Transform m_VerticalTransform; // Y