aboutsummaryrefslogtreecommitdiff
path: root/src/ui
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2020-12-24 23:51:15 +0800
committercrupest <crupest@outlook.com>2020-12-24 23:51:15 +0800
commitc80808cf38b863f3bd84400eb7cf948d461238e0 (patch)
treee2f16c02a8bd085d040bbb1392c1021c5a1fc8bc /src/ui
parent253fcf881d04d0c86236e4cf0067f08eea39f051 (diff)
downloadcru-c80808cf38b863f3bd84400eb7cf948d461238e0.tar.gz
cru-c80808cf38b863f3bd84400eb7cf948d461238e0.tar.bz2
cru-c80808cf38b863f3bd84400eb7cf948d461238e0.zip
...
Diffstat (limited to 'src/ui')
-rw-r--r--src/ui/UiManager.cpp39
-rw-r--r--src/ui/render/BorderRenderObject.cpp7
2 files changed, 26 insertions, 20 deletions
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 <optional>
#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"
@@ -49,50 +52,52 @@ UiManager::UiManager() {
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 <algorithm>
@@ -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();
}