diff options
Diffstat (limited to 'src/ui/controls')
-rw-r--r-- | src/ui/controls/Button.cpp | 19 | ||||
-rw-r--r-- | src/ui/controls/Control.cpp | 7 | ||||
-rw-r--r-- | src/ui/controls/TextBox.cpp | 29 |
3 files changed, 13 insertions, 42 deletions
diff --git a/src/ui/controls/Button.cpp b/src/ui/controls/Button.cpp index 6f19e6b9..7858eadb 100644 --- a/src/ui/controls/Button.cpp +++ b/src/ui/controls/Button.cpp @@ -13,50 +13,37 @@ namespace cru::ui::controls { using cru::platform::gui::SystemCursorType; namespace { -void Set(render::BorderRenderObject* o, const ButtonStateStyle& s) { - o->SetBorderBrush(s.border_brush); - o->SetBorderThickness(s.border_thickness); - o->SetBorderRadius(s.border_radius); - o->SetForegroundBrush(s.foreground_brush); - o->SetBackgroundBrush(s.background_brush); -} - std::shared_ptr<platform::gui::ICursor> GetSystemCursor(SystemCursorType type) { return GetUiApplication()->GetCursorManager()->GetSystemCursor(type); } } // namespace Button::Button() : click_detector_(this) { - style_ = UiManager::GetInstance()->GetThemeResources()->button_style; - render_object_ = std::make_unique<render::BorderRenderObject>(); render_object_->SetAttachedControl(this); SetContainerRenderObject(render_object_.get()); - - Set(render_object_.get(), style_.normal); render_object_->SetBorderEnabled(true); click_detector_.StateChangeEvent()->AddHandler( [this](const helper::ClickState& state) { switch (state) { case helper::ClickState::None: - Set(render_object_.get(), style_.normal); SetCursor(GetSystemCursor(SystemCursorType::Arrow)); break; case helper::ClickState::Hover: - Set(render_object_.get(), style_.hover); SetCursor(GetSystemCursor(SystemCursorType::Hand)); break; case helper::ClickState::Press: - Set(render_object_.get(), style_.press); SetCursor(GetSystemCursor(SystemCursorType::Hand)); break; case helper::ClickState::PressInactive: - Set(render_object_.get(), style_.press_cancel); SetCursor(GetSystemCursor(SystemCursorType::Arrow)); break; } }); + + GetStyleRuleSet()->Set( + UiManager::GetInstance()->GetThemeResources()->button_style); } Button::~Button() = default; diff --git a/src/ui/controls/Control.cpp b/src/ui/controls/Control.cpp index c1316a62..1c4ffe51 100644 --- a/src/ui/controls/Control.cpp +++ b/src/ui/controls/Control.cpp @@ -6,6 +6,7 @@ #include "cru/ui/Base.hpp" #include "cru/ui/host/WindowHost.hpp" #include "cru/ui/render/RenderObject.hpp" +#include "cru/ui/style/StyleRuleSet.hpp" #include <memory> @@ -15,6 +16,8 @@ using platform::gui::IUiApplication; using platform::gui::SystemCursorType; Control::Control() { + style_rule_set_ = std::make_unique<style::StyleRuleSet>(this); + MouseEnterEvent()->Direct()->AddHandler([this](event::MouseEventArgs&) { this->is_mouse_over_ = true; this->OnMouseHoverChange(true); @@ -94,6 +97,10 @@ void Control::SetCursor(std::shared_ptr<ICursor> cursor) { } } +style::StyleRuleSet* Control::GetStyleRuleSet() { + return style_rule_set_.get(); +} + void Control::AddChild(Control* control, const Index position) { Expects(control->GetParent() == nullptr); // The control already has a parent. diff --git a/src/ui/controls/TextBox.cpp b/src/ui/controls/TextBox.cpp index 6ba6ecb2..031894c0 100644 --- a/src/ui/controls/TextBox.cpp +++ b/src/ui/controls/TextBox.cpp @@ -18,8 +18,6 @@ TextBox::TextBox() scroll_render_object_(new ScrollRenderObject()) { const auto theme_resources = UiManager::GetInstance()->GetThemeResources(); - border_style_ = theme_resources->text_box_border_style; - text_render_object_ = std::make_unique<TextRenderObject>( theme_resources->text_brush, theme_resources->default_font, theme_resources->text_selection_brush, theme_resources->caret_brush); @@ -38,17 +36,8 @@ TextBox::TextBox() service_->SetEditable(true); border_render_object_->SetBorderEnabled(true); - border_render_object_->SetBorderStyle(border_style_.normal); - - GainFocusEvent()->Direct()->AddHandler([this](event::FocusChangeEventArgs&) { - this->service_->SetCaretVisible(true); - this->UpdateBorderStyle(); - }); - LoseFocusEvent()->Direct()->AddHandler([this](event::FocusChangeEventArgs&) { - this->service_->SetCaretVisible(false); - this->UpdateBorderStyle(); - }); + GetStyleRuleSet()->Set(theme_resources->text_box_style); } TextBox::~TextBox() {} @@ -65,19 +54,7 @@ render::ScrollRenderObject* TextBox::GetScrollRenderObject() { return scroll_render_object_.get(); } -const TextBoxBorderStyle& TextBox::GetBorderStyle() { return border_style_; } - -void TextBox::SetBorderStyle(TextBoxBorderStyle border_style) { - border_style_ = std::move(border_style); -} - -void TextBox::OnMouseHoverChange(bool) { UpdateBorderStyle(); } - -void TextBox::UpdateBorderStyle() { - const auto focus = HasFocus(); - const auto hover = IsMouseOver(); - border_render_object_->SetBorderStyle( - focus ? (hover ? border_style_.focus_hover : border_style_.focus) - : (hover ? border_style_.hover : border_style_.normal)); +void TextBox::ApplyBorderStyle(const style::ApplyBorderStyleInfo& style) { + border_render_object_->ApplyBorderStyle(style); } } // namespace cru::ui::controls |