diff options
author | 杨宇千 <crupest@outlook.com> | 2019-09-17 16:40:12 +0800 |
---|---|---|
committer | 杨宇千 <crupest@outlook.com> | 2019-09-17 16:40:12 +0800 |
commit | bea876a3b1a241e6127c06a14684a6dc9fcc9516 (patch) | |
tree | d06e40306671cb7c48290f65fdc5d39f219210c9 /src | |
parent | e8dd10eec26d26c3fb30f2712ccf58ac72edc8a2 (diff) | |
download | cru-bea876a3b1a241e6127c06a14684a6dc9fcc9516.tar.gz cru-bea876a3b1a241e6127c06a14684a6dc9fcc9516.tar.bz2 cru-bea876a3b1a241e6127c06a14684a6dc9fcc9516.zip |
...
Diffstat (limited to 'src')
-rw-r--r-- | src/ui/controls/button.cpp | 42 | ||||
-rw-r--r-- | src/ui/render/render_object.cpp | 4 | ||||
-rw-r--r-- | src/ui/ui_manager.cpp | 24 |
3 files changed, 41 insertions, 29 deletions
diff --git a/src/ui/controls/button.cpp b/src/ui/controls/button.cpp index 1a1f4286..2822f6db 100644 --- a/src/ui/controls/button.cpp +++ b/src/ui/controls/button.cpp @@ -14,33 +14,23 @@ namespace cru::ui::controls { using platform::native::GetSystemCursor; using platform::native::SystemCursor; -Button::Button() : click_detector_(this) { - // const auto predefined_resource = - // UiManager::GetInstance()->GetPredefineResources(); - - const auto factory = platform::graph::GraphFactory::GetInstance(); - border_style_.normal.brush = std::shared_ptr<platform::graph::Brush>( - factory->CreateSolidColorBrush(Color::FromHex(0x00bfff))); - border_style_.hover.brush = std::shared_ptr<platform::graph::Brush>( - factory->CreateSolidColorBrush(Color::FromHex(0x47d1ff))); - border_style_.press.brush = std::shared_ptr<platform::graph::Brush>( - factory->CreateSolidColorBrush(Color::FromHex(0x91e4ff))); - border_style_.press_cancel.brush = std::shared_ptr<platform::graph::Brush>( - factory->CreateSolidColorBrush(Color::FromHex(0x91e4ff))); - - border_style_.normal.thickness = border_style_.hover.thickness = - border_style_.press.thickness = border_style_.press_cancel.thickness = - Thickness{3}; +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); +} +} // namespace - border_style_.normal.corner_radius = border_style_.hover.corner_radius = - border_style_.press.corner_radius = - border_style_.press_cancel.corner_radius = - render::CornerRadius{Point{10, 5}}; +Button::Button() : click_detector_(this) { + style_ = UiManager::GetInstance()->GetThemeResources()->button_style; render_object_.reset(new render::BorderRenderObject); render_object_->SetAttachedControl(this); + Set(render_object_.get(), style_.normal); render_object_->SetBorderEnabled(true); - (*render_object_->GetBorderStyle()) = border_style_.normal; MouseEnterEvent()->Direct()->AddHandler([this](event::MouseEventArgs& args) { if (click_detector_.GetPressingButton() & trigger_button_) { @@ -84,19 +74,19 @@ void Button::OnChildChanged(Control* old_child, Control* new_child) { void Button::OnStateChange(ButtonState oldState, ButtonState newState) { switch (newState) { case ButtonState::Normal: - (*render_object_->GetBorderStyle()) = border_style_.normal; + Set(render_object_.get(), style_.normal); SetCursor(GetSystemCursor(SystemCursor::Arrow)); break; case ButtonState::Hover: - (*render_object_->GetBorderStyle()) = border_style_.hover; + Set(render_object_.get(), style_.hover); SetCursor(GetSystemCursor(SystemCursor::Hand)); break; case ButtonState::Press: - (*render_object_->GetBorderStyle()) = border_style_.press; + Set(render_object_.get(), style_.press); SetCursor(GetSystemCursor(SystemCursor::Hand)); break; case ButtonState::PressCancel: - (*render_object_->GetBorderStyle()) = border_style_.press_cancel; + Set(render_object_.get(), style_.press_cancel); SetCursor(GetSystemCursor(SystemCursor::Arrow)); break; } diff --git a/src/ui/render/render_object.cpp b/src/ui/render/render_object.cpp index 118c68c4..a28b4f03 100644 --- a/src/ui/render/render_object.cpp +++ b/src/ui/render/render_object.cpp @@ -7,8 +7,8 @@ namespace cru::ui::render { void RenderObject::AddChild(RenderObject* render_object, const int position) { - assert(child_mode_ == ChildMode::None); - assert(child_mode_ == ChildMode::Single && children_.size() > 0); + assert(child_mode_ != ChildMode::None); + assert(!(child_mode_ == ChildMode::Single && children_.size() > 0)); assert(render_object->GetParent() == nullptr); // Render object already has a parent. diff --git a/src/ui/ui_manager.cpp b/src/ui/ui_manager.cpp index fa3304fb..f60f6355 100644 --- a/src/ui/ui_manager.cpp +++ b/src/ui/ui_manager.cpp @@ -28,5 +28,27 @@ UiManager* UiManager::GetInstance() { return instance; } -UiManager::UiManager() : predefine_resources_(new PredefineResources()) {} +UiManager::UiManager() : predefine_resources_(new PredefineResources()) { + const auto factory = GraphFactory::GetInstance(); + theme_resource_.button_style.normal.border_brush = std::shared_ptr<platform::graph::Brush>( + factory->CreateSolidColorBrush(Color::FromHex(0x00bfff))); + theme_resource_.button_style.hover.border_brush = std::shared_ptr<platform::graph::Brush>( + factory->CreateSolidColorBrush(Color::FromHex(0x47d1ff))); + theme_resource_.button_style.press.border_brush = std::shared_ptr<platform::graph::Brush>( + factory->CreateSolidColorBrush(Color::FromHex(0x91e4ff))); + theme_resource_.button_style.press_cancel.border_brush = std::shared_ptr<platform::graph::Brush>( + factory->CreateSolidColorBrush(Color::FromHex(0x91e4ff))); + + theme_resource_.button_style.normal.border_thickness = + theme_resource_.button_style.hover.border_thickness = + theme_resource_.button_style.press.border_thickness = + theme_resource_.button_style.press_cancel.border_thickness = + Thickness(3); + + theme_resource_.button_style.normal.border_radius = + theme_resource_.button_style.hover.border_radius = + theme_resource_.button_style.press.border_radius = + theme_resource_.button_style.press_cancel.border_radius = + controls::CornerRadius({5, 5}); +} } // namespace cru::ui |