From d7dca1be0dd0814e30fa63924a20af3d924e974c Mon Sep 17 00:00:00 2001 From: crupest Date: Wed, 2 Dec 2020 19:38:25 +0800 Subject: ... --- include/cru/ui/style/ApplyBorderStyleInfo.hpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 include/cru/ui/style/ApplyBorderStyleInfo.hpp (limited to 'include/cru/ui/style/ApplyBorderStyleInfo.hpp') diff --git a/include/cru/ui/style/ApplyBorderStyleInfo.hpp b/include/cru/ui/style/ApplyBorderStyleInfo.hpp new file mode 100644 index 00000000..e9c4ca44 --- /dev/null +++ b/include/cru/ui/style/ApplyBorderStyleInfo.hpp @@ -0,0 +1,12 @@ +#pragma once +#include "../Base.hpp" + +namespace cru::ui::style { +struct ApplyBorderStyleInfo { + std::shared_ptr border_brush; + std::optional border_thickness; + std::optional border_radius; + std::shared_ptr foreground_brush; + std::shared_ptr background_brush; +}; +} // namespace cru::ui::style -- cgit v1.2.3 From c80808cf38b863f3bd84400eb7cf948d461238e0 Mon Sep 17 00:00:00 2001 From: crupest Date: Thu, 24 Dec 2020 23:51:15 +0800 Subject: ... --- include/cru/ui/style/ApplyBorderStyleInfo.hpp | 22 ++++++++++++--- src/ui/UiManager.cpp | 39 +++++++++++++++------------ src/ui/render/BorderRenderObject.cpp | 7 ++--- 3 files changed, 45 insertions(+), 23 deletions(-) (limited to 'include/cru/ui/style/ApplyBorderStyleInfo.hpp') diff --git a/include/cru/ui/style/ApplyBorderStyleInfo.hpp b/include/cru/ui/style/ApplyBorderStyleInfo.hpp index e9c4ca44..5058b51f 100644 --- a/include/cru/ui/style/ApplyBorderStyleInfo.hpp +++ b/include/cru/ui/style/ApplyBorderStyleInfo.hpp @@ -1,12 +1,28 @@ #pragma once +#include #include "../Base.hpp" namespace cru::ui::style { struct ApplyBorderStyleInfo { - std::shared_ptr border_brush; + explicit ApplyBorderStyleInfo( + std::optional> border_brush = + std::nullopt, + std::optional border_thickness = std::nullopt, + std::optional border_radius = std::nullopt, + std::optional> + foreground_brush = std::nullopt, + std::optional> + background_brush = std::nullopt) + : border_brush(std::move(border_brush)), + border_thickness(std::move(border_thickness)), + border_radius(std::move(border_radius)), + foreground_brush(std::move(foreground_brush)), + background_brush(std::move(background_brush)) {} + + std::optional> border_brush; std::optional border_thickness; std::optional border_radius; - std::shared_ptr foreground_brush; - std::shared_ptr background_brush; + std::optional> foreground_brush; + std::optional> background_brush; }; } // namespace cru::ui::style diff --git a/src/ui/UiManager.cpp b/src/ui/UiManager.cpp index bb7f5841..07812a96 100644 --- a/src/ui/UiManager.cpp +++ b/src/ui/UiManager.cpp @@ -1,10 +1,13 @@ #include "cru/ui/UiManager.hpp" +#include #include "Helper.hpp" +#include "cru/platform/GraphBase.hpp" #include "cru/platform/graphics/Brush.hpp" #include "cru/platform/graphics/Factory.hpp" #include "cru/platform/graphics/Font.hpp" #include "cru/platform/gui/UiApplication.hpp" +#include "cru/ui/Base.hpp" #include "cru/ui/style/ApplyBorderStyleInfo.hpp" #include "cru/ui/style/Condition.hpp" #include "cru/ui/style/Styler.hpp" @@ -48,51 +51,53 @@ UiManager::UiManager() { CreateSolidColorBrush(factory, colors::skyblue); theme_resource_.caret_brush = black_brush; + theme_resource_.button_style.AddStyleRule( + {NoCondition::Create(), + BorderStyler::Create(ApplyBorderStyleInfo{std::nullopt, Thickness(3), + CornerRadius(5), std::nullopt, + std::nullopt}), + u"DefaultButton"}); theme_resource_.button_style.AddStyleRule( {ClickStateCondition::Create(ClickState::None), BorderStyler::Create(ApplyBorderStyleInfo{ - CreateSolidColorBrush(factory, Color::FromHex(0x00bfff)), - Thickness(3), CornerRadius(5), nullptr, nullptr}), + CreateSolidColorBrush(factory, Color::FromHex(0x00bfff))}), u"DefaultButtonNormal"}); theme_resource_.button_style.AddStyleRule( {ClickStateCondition::Create(ClickState::Hover), BorderStyler::Create(ApplyBorderStyleInfo{ - CreateSolidColorBrush(factory, Color::FromHex(0x47d1ff)), - Thickness(3), CornerRadius(5), nullptr, nullptr}), + CreateSolidColorBrush(factory, Color::FromHex(0x47d1ff))}), u"DefaultButtonHover"}); theme_resource_.button_style.AddStyleRule( {ClickStateCondition::Create(ClickState::Press), BorderStyler::Create(ApplyBorderStyleInfo{ - CreateSolidColorBrush(factory, Color::FromHex(0x91e4ff)), - Thickness(3), CornerRadius(5), nullptr, nullptr}), + CreateSolidColorBrush(factory, Color::FromHex(0x91e4ff))}), u"DefaultButtonPress"}); theme_resource_.button_style.AddStyleRule( {ClickStateCondition::Create(ClickState::PressInactive), BorderStyler::Create(ApplyBorderStyleInfo{ - CreateSolidColorBrush(factory, Color::FromHex(0x91e4ff)), - Thickness(3), CornerRadius(5), nullptr, nullptr}), + CreateSolidColorBrush(factory, Color::FromHex(0x91e4ff))}), u"DefaultButtonPressInactive"}); + theme_resource_.text_box_style.AddStyleRule( + {NoCondition::Create(), + BorderStyler::Create( + ApplyBorderStyleInfo{std::nullopt, Thickness{1}, CornerRadius{5}}), + u"DefaultTextBox"}); theme_resource_.text_box_style.AddStyleRule( {HoverCondition::Create(false), BorderStyler::Create(ApplyBorderStyleInfo{ - CreateSolidColorBrush(factory, Color::FromHex(0xced4da)), - Thickness(1), CornerRadius(5), nullptr, nullptr}), + CreateSolidColorBrush(factory, Color::FromHex(0xced4da))}), u"DefaultTextBoxNormal"}); - theme_resource_.text_box_style.AddStyleRule( {HoverCondition::Create(true), BorderStyler::Create(ApplyBorderStyleInfo{ - CreateSolidColorBrush(factory, Color::FromHex(0xced4da)), - Thickness(1), CornerRadius(5), nullptr, nullptr}), + CreateSolidColorBrush(factory, Color::FromHex(0xced4da))}), u"DefaultTextBoxHover"}); - theme_resource_.text_box_style.AddStyleRule( {FocusCondition::Create(true), BorderStyler::Create(ApplyBorderStyleInfo{ - CreateSolidColorBrush(factory, Color::FromHex(0x495057)), - Thickness(1), CornerRadius(5), nullptr, nullptr}), - u"DefaultTextBoxHover"}); + CreateSolidColorBrush(factory, Color::FromHex(0x495057))}), + u"DefaultTextBoxFocus"}); } UiManager::~UiManager() = default; diff --git a/src/ui/render/BorderRenderObject.cpp b/src/ui/render/BorderRenderObject.cpp index c176e760..e2c40f0c 100644 --- a/src/ui/render/BorderRenderObject.cpp +++ b/src/ui/render/BorderRenderObject.cpp @@ -6,6 +6,7 @@ #include "cru/platform/graphics/Geometry.hpp" #include "cru/platform/graphics/util/Painter.hpp" #include "cru/ui/style/ApplyBorderStyleInfo.hpp" +#include "gsl/gsl_assert" #include @@ -19,11 +20,11 @@ BorderRenderObject::~BorderRenderObject() {} void BorderRenderObject::ApplyBorderStyle( const style::ApplyBorderStyleInfo& style) { - if (style.border_brush != nullptr) border_brush_ = style.border_brush; + if (style.border_brush) border_brush_ = *style.border_brush; if (style.border_thickness) border_thickness_ = *style.border_thickness; if (style.border_radius) border_radius_ = *style.border_radius; - if (style.foreground_brush) foreground_brush_ = style.foreground_brush; - if (style.background_brush) background_brush_ = style.background_brush; + if (style.foreground_brush) foreground_brush_ = *style.foreground_brush; + if (style.background_brush) background_brush_ = *style.background_brush; InvalidateLayout(); } -- cgit v1.2.3