diff options
Diffstat (limited to 'src/theme_builder/components/styler/BorderStylerEditor.cpp')
-rw-r--r-- | src/theme_builder/components/styler/BorderStylerEditor.cpp | 73 |
1 files changed, 34 insertions, 39 deletions
diff --git a/src/theme_builder/components/styler/BorderStylerEditor.cpp b/src/theme_builder/components/styler/BorderStylerEditor.cpp index 6c87ad32..819e67c0 100644 --- a/src/theme_builder/components/styler/BorderStylerEditor.cpp +++ b/src/theme_builder/components/styler/BorderStylerEditor.cpp @@ -1,5 +1,4 @@ #include "BorderStylerEditor.h" -#include <memory> #include "cru/common/ClonablePtr.h" #include "cru/platform/graphics/Brush.h" #include "cru/platform/graphics/Factory.h" @@ -15,85 +14,81 @@ BorderStylerEditor::BorderStylerEditor() { container_.AddChild(foreground_brush_editor_.GetRootControl()); container_.AddChild(background_brush_editor_.GetRootControl()); - // TODO: Add change listener. + auto connect = [this](IEvent<std::nullptr_t>* event) { + event->AddHandler( + [this](std::nullptr_t) { this->change_event_.Raise(nullptr); }); + }; + + connect(corner_radius_editor_.ChangeEvent()); + connect(thickness_editor_.ChangeEvent()); + connect(brush_editor_.ChangeEvent()); + connect(foreground_brush_editor_.ChangeEvent()); + connect(background_brush_editor_.ChangeEvent()); } BorderStylerEditor::~BorderStylerEditor() { container_.RemoveFromParent(); } -ClonablePtr<ui::style::BorderStyler> BorderStylerEditor::GetStyler() { +ClonablePtr<ui::style::BorderStyler> BorderStylerEditor::GetValue() { auto graphics_factory = platform::gui::IUiApplication::GetInstance()->GetGraphicsFactory(); ui::style::ApplyBorderStyleInfo border_style; - if (corner_radius_editor_.IsEnabled()) { - border_style.border_radius = - corner_radius_editor_.GetEditor()->GetCornerRadius(); - } - - if (thickness_editor_.IsEnabled()) { - border_style.border_thickness = - thickness_editor_.GetEditor()->GetThickness(); - } + border_style.border_radius = corner_radius_editor_.GetValue(); + border_style.border_thickness = thickness_editor_.GetValue(); if (brush_editor_.IsEnabled()) { border_style.border_brush = graphics_factory->CreateSolidColorBrush( - brush_editor_.GetEditor()->GetColor()); + brush_editor_.GetEditor()->GetValue()); } if (foreground_brush_editor_.IsEnabled()) { border_style.foreground_brush = graphics_factory->CreateSolidColorBrush( - foreground_brush_editor_.GetEditor()->GetColor()); + foreground_brush_editor_.GetEditor()->GetValue()); } if (background_brush_editor_.IsEnabled()) { border_style.background_brush = graphics_factory->CreateSolidColorBrush( - background_brush_editor_.GetEditor()->GetColor()); + background_brush_editor_.GetEditor()->GetValue()); } return ui::style::BorderStyler::Create(border_style); } -void BorderStylerEditor::SetStyler( - const ClonablePtr<ui::style::BorderStyler> &styler) { +void BorderStylerEditor::SetValue( + const ClonablePtr<ui::style::BorderStyler>& styler) { Expects(styler); auto border_style = styler->GetBorderStyle(); - corner_radius_editor_.SetEnabled(border_style.border_radius.has_value()); - if (border_style.border_radius.has_value()) { - corner_radius_editor_.GetEditor()->SetCornerRadius( - *border_style.border_radius); - } - - thickness_editor_.SetEnabled(border_style.border_thickness.has_value()); - if (border_style.border_thickness.has_value()) { - thickness_editor_.GetEditor()->SetThickness(*border_style.border_thickness); - } + corner_radius_editor_.SetValue(border_style.border_radius, false); + thickness_editor_.SetValue(border_style.border_thickness, false); - brush_editor_.SetEnabled(border_style.border_brush.has_value()); + brush_editor_.SetEnabled(border_style.border_brush.has_value(), false); if (border_style.border_brush.has_value()) { - brush_editor_.GetEditor()->SetColor( + brush_editor_.GetEditor()->SetValue( std::dynamic_pointer_cast<platform::graphics::ISolidColorBrush>( border_style.border_brush.value()) - ->GetColor()); + ->GetColor(), + false); } - foreground_brush_editor_.SetEnabled( - border_style.foreground_brush.has_value()); + foreground_brush_editor_.SetEnabled(border_style.foreground_brush.has_value(), + false); if (border_style.foreground_brush.has_value()) { - foreground_brush_editor_.GetEditor()->SetColor( + foreground_brush_editor_.GetEditor()->SetValue( std::dynamic_pointer_cast<platform::graphics::ISolidColorBrush>( border_style.foreground_brush.value()) - ->GetColor()); + ->GetColor(), + false); } - background_brush_editor_.SetEnabled( - border_style.background_brush.has_value()); - + background_brush_editor_.SetEnabled(border_style.background_brush.has_value(), + false); if (border_style.background_brush.has_value()) { - background_brush_editor_.GetEditor()->SetColor( + background_brush_editor_.GetEditor()->SetValue( std::dynamic_pointer_cast<platform::graphics::ISolidColorBrush>( border_style.background_brush.value()) - ->GetColor()); + ->GetColor(), + false); } } |