diff options
-rw-r--r-- | assets/cru/ui/DefaultResources.xml | 4 | ||||
-rw-r--r-- | include/cru/ui/mapper/BrushMapper.hpp | 20 | ||||
-rw-r--r-- | include/cru/xml/XmlNode.hpp | 3 | ||||
-rw-r--r-- | src/ui/CMakeLists.txt | 1 | ||||
-rw-r--r-- | src/ui/mapper/BorderStyleMapper.cpp | 9 | ||||
-rw-r--r-- | src/ui/mapper/BrushMapper.cpp | 40 |
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 |