aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2022-01-27 20:07:15 +0800
committercrupest <crupest@outlook.com>2022-01-27 20:07:15 +0800
commit56633dab8c1bf9d25a6367a651b5b054055a2130 (patch)
treed372843e3f6f91604a077ed15c353bedd5ef7e1b
parentd3aa43d9ea0dfc32935767cf60a89af2736dc339 (diff)
downloadcru-56633dab8c1bf9d25a6367a651b5b054055a2130.tar.gz
cru-56633dab8c1bf9d25a6367a651b5b054055a2130.tar.bz2
cru-56633dab8c1bf9d25a6367a651b5b054055a2130.zip
...
-rw-r--r--assets/cru/ui/DefaultResources.xml4
-rw-r--r--include/cru/ui/mapper/BrushMapper.hpp20
-rw-r--r--include/cru/xml/XmlNode.hpp3
-rw-r--r--src/ui/CMakeLists.txt1
-rw-r--r--src/ui/mapper/BorderStyleMapper.cpp9
-rw-r--r--src/ui/mapper/BrushMapper.cpp40
6 files changed, 73 insertions, 4 deletions
diff --git a/assets/cru/ui/DefaultResources.xml b/assets/cru/ui/DefaultResources.xml
index fbe48182..b831be2c 100644
--- a/assets/cru/ui/DefaultResources.xml
+++ b/assets/cru/ui/DefaultResources.xml
@@ -1,4 +1,8 @@
<Theme>
+ <Resource key="scrollbar.collapse-thumb.color">
+ <Color value="gray" />
+ </Resource>
+
<Resource key="button-style">
<StyleRuleSet>
<StyleRule>
diff --git a/include/cru/ui/mapper/BrushMapper.hpp b/include/cru/ui/mapper/BrushMapper.hpp
new file mode 100644
index 00000000..b2021076
--- /dev/null
+++ b/include/cru/ui/mapper/BrushMapper.hpp
@@ -0,0 +1,20 @@
+#pragma once
+#include "Mapper.hpp"
+#include "cru/common/Base.hpp"
+#include "cru/platform/graphics/Brush.hpp"
+#include "cru/xml/XmlNode.hpp"
+
+namespace cru::ui::mapper {
+class BrushMapper : public BasicRefMapper<platform::graphics::IBrush> {
+ public:
+ CRU_DEFAULT_CONSTRUCTOR_DESTRUCTOR(BrushMapper)
+
+ public:
+ bool SupportMapFromXml() override { return true; }
+ bool XmlElementIsOfThisType(xml::XmlElementNode* node) override;
+
+ protected:
+ std::shared_ptr<platform::graphics::IBrush> DoMapFromXml(
+ xml::XmlElementNode* node) override;
+};
+} // namespace cru::ui::mapper
diff --git a/include/cru/xml/XmlNode.hpp b/include/cru/xml/XmlNode.hpp
index f308c9de..d1cb9430 100644
--- a/include/cru/xml/XmlNode.hpp
+++ b/include/cru/xml/XmlNode.hpp
@@ -33,6 +33,9 @@ class CRU_XML_API XmlNode {
virtual XmlNode* Clone() const = 0;
+ bool IsTextNode() const { return type_ == Type::Text; }
+ bool IsElementNode() const { return type_ == Type::Element; }
+
XmlElementNode* AsElement();
XmlTextNode* AsText();
const XmlElementNode* AsElement() const;
diff --git a/src/ui/CMakeLists.txt b/src/ui/CMakeLists.txt
index a86e24c0..d19784b2 100644
--- a/src/ui/CMakeLists.txt
+++ b/src/ui/CMakeLists.txt
@@ -25,6 +25,7 @@ add_library(cru_ui SHARED
host/LayoutPaintCycler.cpp
host/WindowHost.cpp
mapper/BorderStyleMapper.cpp
+ mapper/BrushMapper.cpp
mapper/ColorMapper.cpp
mapper/CornerRadiusMapper.cpp
mapper/CursorMapper.cpp
diff --git a/src/ui/mapper/BorderStyleMapper.cpp b/src/ui/mapper/BorderStyleMapper.cpp
index 691f091d..1209df07 100644
--- a/src/ui/mapper/BorderStyleMapper.cpp
+++ b/src/ui/mapper/BorderStyleMapper.cpp
@@ -1,6 +1,7 @@
#include "cru/ui/mapper/BorderStyleMapper.hpp"
#include "../Helper.hpp"
#include "cru/common/Logger.hpp"
+#include "cru/platform/graphics/Brush.hpp"
#include "cru/platform/graphics/Factory.hpp"
#include "cru/ui/mapper/MapperRegistry.hpp"
#include "cru/ui/style/ApplyBorderStyleInfo.hpp"
@@ -27,14 +28,14 @@ ApplyBorderStyleInfo BorderStyleMapper::DoMapFromXml(
MapperRegistry::GetInstance()->GetMapper<Thickness>();
auto corner_radius_mapper =
MapperRegistry::GetInstance()->GetMapper<CornerRadius>();
- auto color_mapper = MapperRegistry::GetInstance()->GetMapper<Color>();
+ auto brush_mapper = MapperRegistry::GetInstance()
+ ->GetRefMapper<platform::graphics::IBrush>();
if (thickness_mapper->XmlElementIsOfThisType(c)) {
result.border_thickness = thickness_mapper->MapFromXml(c);
} else if (corner_radius_mapper->XmlElementIsOfThisType(c)) {
result.border_radius = corner_radius_mapper->MapFromXml(c);
- } else if (color_mapper->XmlElementIsOfThisType(c)) {
- auto brush = GetGraphicsFactory()->CreateSolidColorBrush(
- color_mapper->MapFromXml(c));
+ } else if (brush_mapper->XmlElementIsOfThisType(c)) {
+ auto brush = brush_mapper->MapFromXml(c);
auto name = c->GetOptionalAttributeCaseInsensitive(u"name");
if (name) {
if (name->CaseInsensitiveCompare(u"foreground") == 0) {
diff --git a/src/ui/mapper/BrushMapper.cpp b/src/ui/mapper/BrushMapper.cpp
new file mode 100644
index 00000000..bfaef507
--- /dev/null
+++ b/src/ui/mapper/BrushMapper.cpp
@@ -0,0 +1,40 @@
+#include "cru/ui/mapper/BrushMapper.hpp"
+#include "../Helper.hpp"
+#include "cru/platform/Color.hpp"
+#include "cru/platform/graphics/Brush.hpp"
+#include "cru/platform/graphics/Factory.hpp"
+#include "cru/ui/mapper/ColorMapper.hpp"
+#include "cru/ui/mapper/MapperRegistry.hpp"
+#include "cru/xml/XmlNode.hpp"
+
+#include <memory>
+
+namespace cru::ui::mapper {
+bool BrushMapper::XmlElementIsOfThisType(xml::XmlElementNode* node) {
+ auto color_mapper = MapperRegistry::GetInstance()->GetMapper<Color>();
+ return color_mapper->XmlElementIsOfThisType(node) ||
+ node->GetTag().CaseInsensitiveEqual(u"Brush");
+}
+
+std::shared_ptr<platform::graphics::IBrush> BrushMapper::DoMapFromXml(
+ xml::XmlElementNode* node) {
+ auto color_mapper = MapperRegistry::GetInstance()->GetMapper<Color>();
+
+ Color color = colors::transparent;
+
+ if (color_mapper->XmlElementIsOfThisType(node)) {
+ color = color_mapper->MapFromXml(node);
+ } else {
+ for (auto child : node->GetChildren()) {
+ if (child->IsElementNode()) {
+ auto c = child->AsElement();
+ if (color_mapper->XmlElementIsOfThisType(node)) {
+ color = color_mapper->MapFromXml(node);
+ }
+ }
+ }
+ }
+
+ return GetGraphicsFactory()->CreateSolidColorBrush(color);
+}
+} // namespace cru::ui::mapper