diff options
Diffstat (limited to 'src/ui/mapper/style')
18 files changed, 236 insertions, 392 deletions
diff --git a/src/ui/mapper/style/AndConditionMapper.cpp b/src/ui/mapper/style/AndConditionMapper.cpp deleted file mode 100644 index ad996a4e..00000000 --- a/src/ui/mapper/style/AndConditionMapper.cpp +++ /dev/null @@ -1,31 +0,0 @@ -#include "cru/ui/mapper/style/AndConditionMapper.h" -#include "cru/base/ClonePtr.h" -#include "cru/ui/mapper/MapperRegistry.h" -#include "cru/ui/mapper/style/IConditionMapper.h" -#include "cru/ui/style/Condition.h" -#include "cru/base/xml/XmlNode.h" - -namespace cru::ui::mapper::style { -bool AndConditionMapper::XmlElementIsOfThisType(xml::XmlElementNode *node) { - return cru::string::CaseInsensitiveCompare(node->GetTag(), "AndCondition") == 0; -} - -ClonePtr<ui::style::AndCondition> AndConditionMapper::DoMapFromXml( - xml::XmlElementNode *node) { - std::vector<ClonePtr<ui::style::Condition>> conditions; - auto condition_mappers = - MapperRegistry::GetInstance()->GetMappersByInterface<IConditionMapper>(); - for (auto child : node->GetChildren()) { - if (child->GetType() == xml::XmlNode::Type::Element) { - auto c = child->AsElement(); - for (auto mapper : condition_mappers) { - if (mapper->XmlElementIsOfThisType(c)) { - conditions.push_back(mapper->MapConditionFromXml(c)); - break; - } - } - } - } - return ui::style::AndCondition::Create(std::move(conditions)); -} -} // namespace cru::ui::mapper::style diff --git a/src/ui/mapper/style/BorderStylerMapper.cpp b/src/ui/mapper/style/BorderStylerMapper.cpp deleted file mode 100644 index 33358b28..00000000 --- a/src/ui/mapper/style/BorderStylerMapper.cpp +++ /dev/null @@ -1,34 +0,0 @@ -#include "cru/ui/mapper/style/BorderStylerMapper.h" -#include "cru/base/ClonePtr.h" -#include "cru/ui/mapper/MapperRegistry.h" -#include "cru/ui/style/ApplyBorderStyleInfo.h" -#include "cru/ui/style/Styler.h" -#include "cru/base/xml/XmlNode.h" - -namespace cru::ui::mapper::style { -using cru::ui::style::ApplyBorderStyleInfo; -using cru::ui::style::BorderStyler; - -bool BorderStylerMapper::XmlElementIsOfThisType(xml::XmlElementNode* node) { - return cru::string::CaseInsensitiveCompare(node->GetTag(), "BorderStyler") == 0; -} - -ClonePtr<BorderStyler> BorderStylerMapper::DoMapFromXml( - xml::XmlElementNode* node) { - auto border_style_mapper = - MapperRegistry::GetInstance()->GetMapper<ApplyBorderStyleInfo>(); - - ApplyBorderStyleInfo border_style; - - for (auto child : node->GetChildren()) { - if (child->GetType() == xml::XmlElementNode::Type::Element) { - auto child_element = child->AsElement(); - if (border_style_mapper->XmlElementIsOfThisType(child_element)) { - border_style = border_style_mapper->MapFromXml(child_element); - } - } - } - - return BorderStyler::Create(std::move(border_style)); -} -} // namespace cru::ui::mapper::style diff --git a/src/ui/mapper/style/CheckedConditionMapper.cpp b/src/ui/mapper/style/CheckedConditionMapper.cpp deleted file mode 100644 index 9e93cbea..00000000 --- a/src/ui/mapper/style/CheckedConditionMapper.cpp +++ /dev/null @@ -1,24 +0,0 @@ -#include "cru/ui/mapper/style/CheckedConditionMapper.h" -#include "cru/base/ClonePtr.h" -#include "cru/base/StringUtil.h" -#include "cru/ui/style/Condition.h" -#include "cru/base/xml/XmlNode.h" - -namespace cru::ui::mapper::style { -bool CheckedConditionMapper::XmlElementIsOfThisType(xml::XmlElementNode* node) { - return cru::string::CaseInsensitiveCompare(node->GetTag(), - "CheckedCondition") == 0; -} - -ClonePtr<ui::style::CheckedCondition> CheckedConditionMapper::DoMapFromXml( - xml::XmlElementNode* node) { - auto value = node->GetAttributeValueCaseInsensitive("value"); - if (cru::string::CaseInsensitiveCompare(value, "true") == 0) { - return ui::style::CheckedCondition::Create(true); - } else if (cru::string::CaseInsensitiveCompare(value, "false") == 0) { - return ui::style::CheckedCondition::Create(false); - } else { - throw Exception("Invalid value for CheckedCondition: " + value); - } -} -} // namespace cru::ui::mapper::style diff --git a/src/ui/mapper/style/ClickStateConditionMapper.cpp b/src/ui/mapper/style/ClickStateConditionMapper.cpp deleted file mode 100644 index accfdf0a..00000000 --- a/src/ui/mapper/style/ClickStateConditionMapper.cpp +++ /dev/null @@ -1,35 +0,0 @@ -#include "cru/ui/mapper/style/ClickStateConditionMapper.h" -#include "cru/base/ClonePtr.h" -#include "cru/base/StringUtil.h" -#include "cru/ui/helper/ClickDetector.h" -#include "cru/ui/style/Condition.h" - -namespace cru::ui::mapper::style { -bool ClickStateConditionMapper::XmlElementIsOfThisType( - xml::XmlElementNode *node) { - return cru::string::CaseInsensitiveCompare(node->GetTag(), - "ClickStateCondition") == 0; -} - -ClonePtr<ui::style::ClickStateCondition> -ClickStateConditionMapper::DoMapFromXml(xml::XmlElementNode *node) { - auto state = helper::ClickState::None; - auto value_attr = node->GetOptionalAttributeValueCaseInsensitive("value"); - if (value_attr) { - if (cru::string::CaseInsensitiveCompare(*value_attr, "none") == 0) { - state = helper::ClickState::None; - } else if (cru::string::CaseInsensitiveCompare(*value_attr, "hover") == 0) { - state = helper::ClickState::Hover; - } else if (cru::string::CaseInsensitiveCompare(*value_attr, "press") == 0) { - state = helper::ClickState::Press; - } else if (cru::string::CaseInsensitiveCompare(*value_attr, - "pressinactive") == 0) { - state = helper::ClickState::PressInactive; - } else { - throw Exception("Unknown click state: " + *value_attr); - } - } - - return ui::style::ClickStateCondition::Create(state); -} -} // namespace cru::ui::mapper::style diff --git a/src/ui/mapper/style/ConditionMapper.cpp b/src/ui/mapper/style/ConditionMapper.cpp new file mode 100644 index 00000000..ce41a70a --- /dev/null +++ b/src/ui/mapper/style/ConditionMapper.cpp @@ -0,0 +1,107 @@ +#include "cru/ui/mapper/style/ConditionMapper.h" +#include "cru/base/ClonePtr.h" +#include "cru/base/xml/XmlNode.h" +#include "cru/ui/mapper/MapperRegistry.h" + +namespace cru::ui::mapper::style { +ClonePtr<NoCondition> NoConditionMapper::DoMapFromXml( + xml::XmlElementNode* node) { + return NoCondition::Create(); +} + +ClonePtr<AndCondition> AndConditionMapper::DoMapFromXml( + xml::XmlElementNode* node) { + std::vector<ClonePtr<Condition>> conditions; + auto condition_mappers = + MapperRegistry::GetInstance()->GetMappersByInterface<IConditionMapper>(); + for (auto child : node->GetChildren()) { + if (child->GetType() == xml::XmlNode::Type::Element) { + auto c = child->AsElement(); + for (auto mapper : condition_mappers) { + if (mapper->XmlElementIsOfThisType(c)) { + conditions.push_back(mapper->MapConditionFromXml(c)); + break; + } + } + } + } + return AndCondition::Create(std::move(conditions)); +} + +ClonePtr<OrCondition> OrConditionMapper::DoMapFromXml( + xml::XmlElementNode* node) { + std::vector<ClonePtr<Condition>> conditions; + auto condition_mappers = + MapperRegistry::GetInstance()->GetMappersByInterface<IConditionMapper>(); + for (auto child : node->GetChildren()) { + if (child->GetType() == xml::XmlNode::Type::Element) { + auto c = child->AsElement(); + for (auto mapper : condition_mappers) { + if (mapper->XmlElementIsOfThisType(c)) { + conditions.push_back(mapper->MapConditionFromXml(c)); + break; + } + } + } + } + return OrCondition::Create(std::move(conditions)); +} + +ClonePtr<ClickStateCondition> +ClickStateConditionMapper::DoMapFromXml(xml::XmlElementNode* node) { + auto state = helper::ClickState::None; + auto value_attr = node->GetOptionalAttributeValueCaseInsensitive("value"); + if (value_attr) { + if (cru::string::CaseInsensitiveCompare(*value_attr, "none") == 0) { + state = helper::ClickState::None; + } else if (cru::string::CaseInsensitiveCompare(*value_attr, "hover") == 0) { + state = helper::ClickState::Hover; + } else if (cru::string::CaseInsensitiveCompare(*value_attr, "press") == 0) { + state = helper::ClickState::Press; + } else if (cru::string::CaseInsensitiveCompare(*value_attr, + "pressinactive") == 0) { + state = helper::ClickState::PressInactive; + } else { + throw Exception("Unknown click state: " + *value_attr); + } + } + + return ClickStateCondition::Create(state); +} + +ClonePtr<CheckedCondition> CheckedConditionMapper::DoMapFromXml( + xml::XmlElementNode* node) { + auto value = node->GetAttributeValueCaseInsensitive("value"); + if (cru::string::CaseInsensitiveCompare(value, "true") == 0) { + return CheckedCondition::Create(true); + } else if (cru::string::CaseInsensitiveCompare(value, "false") == 0) { + return CheckedCondition::Create(false); + } else { + throw Exception("Invalid value for CheckedCondition: " + value); + } +} + +ClonePtr<FocusCondition> FocusConditionMapper::DoMapFromXml( + xml::XmlElementNode* node) { + auto value = node->GetAttributeValueCaseInsensitive("value"); + if (cru::string::CaseInsensitiveCompare(value, "true") == 0) { + return FocusCondition::Create(true); + } else if (cru::string::CaseInsensitiveCompare(value, "false") == 0) { + return FocusCondition::Create(false); + } else { + throw Exception("Invalid value for FocusCondition: " + value); + } +} + +ClonePtr<HoverCondition> HoverConditionMapper::DoMapFromXml( + xml::XmlElementNode* node) { + auto value = node->GetAttributeValueCaseInsensitive("value"); + if (cru::string::CaseInsensitiveCompare(value, "true") == 0) { + return HoverCondition::Create(true); + } else if (cru::string::CaseInsensitiveCompare(value, "false") == 0) { + return HoverCondition::Create(false); + } else { + throw Exception("Invalid value for HoverCondition: " + value); + } +} +} // namespace cru::ui::mapper::style diff --git a/src/ui/mapper/style/ContentBrushStylerMapper.cpp b/src/ui/mapper/style/ContentBrushStylerMapper.cpp deleted file mode 100644 index 1ab91be0..00000000 --- a/src/ui/mapper/style/ContentBrushStylerMapper.cpp +++ /dev/null @@ -1,30 +0,0 @@ -#include "cru/ui/mapper/style/ContentBrushStylerMapper.h" -#include "cru/base/ClonePtr.h" -#include "cru/platform/graphics/Brush.h" -#include "cru/ui/mapper/MapperRegistry.h" -#include "cru/ui/style/Styler.h" -#include "cru/base/xml/XmlNode.h" - -namespace cru::ui::mapper::style { -ContentBrushStylerMapper::ContentBrushStylerMapper() { - SetAllowedTags({"ContentBrushStyler"}); -} - -ContentBrushStylerMapper::~ContentBrushStylerMapper() {} - -ClonePtr<ui::style::ContentBrushStyler> -ContentBrushStylerMapper::DoMapFromXml(xml::XmlElementNode* node) { - auto brush_mapper = MapperRegistry::GetInstance() - ->GetSharedPtrMapper<platform::graphics::IBrush>(); - - std::shared_ptr<platform::graphics::IBrush> brush; - - for (auto child_node : node->GetChildren()) { - if (child_node->IsElementNode()) { - brush = brush_mapper->MapFromXml(child_node->AsElement()); - } - } - - return ui::style::ContentBrushStyler::Create(std::move(brush)); -} -} // namespace cru::ui::mapper::style diff --git a/src/ui/mapper/style/CursorStylerMapper.cpp b/src/ui/mapper/style/CursorStylerMapper.cpp deleted file mode 100644 index e5051ce0..00000000 --- a/src/ui/mapper/style/CursorStylerMapper.cpp +++ /dev/null @@ -1,27 +0,0 @@ -#include "cru/ui/mapper/style/CursorStylerMapper.h" -#include "cru/base/ClonePtr.h" -#include "cru/platform/gui/Cursor.h" -#include "cru/ui/mapper/MapperRegistry.h" -#include "cru/ui/style/Styler.h" - -namespace cru::ui::mapper::style { -bool CursorStylerMapper::XmlElementIsOfThisType(xml::XmlElementNode* node) { - return cru::string::CaseInsensitiveCompare(node->GetTag(), "CursorStyler") == 0; -} - -ClonePtr<ui::style::CursorStyler> CursorStylerMapper::DoMapFromXml( - xml::XmlElementNode* node) { - auto cursor_mapper = - MapperRegistry::GetInstance()->GetSharedPtrMapper<platform::gui::ICursor>(); - std::shared_ptr<platform::gui::ICursor> cursor; - - for (auto child : node->GetChildren()) { - if (child->GetType() == xml::XmlNode::Type::Element && - cursor_mapper->XmlElementIsOfThisType(child->AsElement())) { - cursor = cursor_mapper->MapFromXml(child->AsElement()); - } - } - - return ui::style::CursorStyler::Create(cursor); -} -} // namespace cru::ui::mapper::style diff --git a/src/ui/mapper/style/FocusConditionMapper.cpp b/src/ui/mapper/style/FocusConditionMapper.cpp deleted file mode 100644 index 08d0c992..00000000 --- a/src/ui/mapper/style/FocusConditionMapper.cpp +++ /dev/null @@ -1,24 +0,0 @@ -#include "cru/ui/mapper/style/FocusConditionMapper.h" -#include "cru/base/ClonePtr.h" -#include "cru/base/StringUtil.h" -#include "cru/ui/style/Condition.h" -#include "cru/base/xml/XmlNode.h" - -namespace cru::ui::mapper::style { -bool FocusConditionMapper::XmlElementIsOfThisType(xml::XmlElementNode* node) { - return cru::string::CaseInsensitiveCompare(node->GetTag(), - "FocusCondition") == 0; -} - -ClonePtr<ui::style::FocusCondition> FocusConditionMapper::DoMapFromXml( - xml::XmlElementNode* node) { - auto value = node->GetAttributeValueCaseInsensitive("value"); - if (cru::string::CaseInsensitiveCompare(value, "true") == 0) { - return ui::style::FocusCondition::Create(true); - } else if (cru::string::CaseInsensitiveCompare(value, "false") == 0) { - return ui::style::FocusCondition::Create(false); - } else { - throw Exception("Invalid value for FocusCondition: " + value); - } -} -} // namespace cru::ui::mapper::style diff --git a/src/ui/mapper/style/FontStylerMapper.cpp b/src/ui/mapper/style/FontStylerMapper.cpp deleted file mode 100644 index ac8051a3..00000000 --- a/src/ui/mapper/style/FontStylerMapper.cpp +++ /dev/null @@ -1,25 +0,0 @@ -#include "cru/ui/mapper/style/FontStylerMapper.h" -#include "cru/base/ClonePtr.h" -#include "cru/ui/mapper/MapperRegistry.h" - -namespace cru::ui::mapper::style { -FontStylerMapper::FontStylerMapper() { SetAllowedTags({"FontStyler"}); } - -FontStylerMapper::~FontStylerMapper() {} - -ClonePtr<ui::style::FontStyler> FontStylerMapper::DoMapFromXml( - xml::XmlElementNode* node) { - auto font_mapper = MapperRegistry::GetInstance() - ->GetSharedPtrMapper<platform::graphics::IFont>(); - - std::shared_ptr<platform::graphics::IFont> font; - - for (auto child_node : node->GetChildren()) { - if (child_node->IsElementNode()) { - font = font_mapper->MapFromXml(child_node->AsElement()); - } - } - - return ui::style::FontStyler::Create(std::move(font)); -} -} // namespace cru::ui::mapper::style diff --git a/src/ui/mapper/style/HoverConditionMapper.cpp b/src/ui/mapper/style/HoverConditionMapper.cpp deleted file mode 100644 index 7797ad7c..00000000 --- a/src/ui/mapper/style/HoverConditionMapper.cpp +++ /dev/null @@ -1,25 +0,0 @@ -#include "cru/ui/mapper/style/HoverConditionMapper.h" -#include "cru/base/ClonePtr.h" -#include "cru/base/StringUtil.h" -#include "cru/ui/style/Condition.h" - -namespace cru::ui::mapper::style { -using namespace cru::ui::style; - -bool HoverConditionMapper::XmlElementIsOfThisType(xml::XmlElementNode* node) { - return cru::string::CaseInsensitiveCompare(node->GetTag(), - "HoverCondition") == 0; -} - -ClonePtr<HoverCondition> HoverConditionMapper::DoMapFromXml( - xml::XmlElementNode* node) { - auto value = node->GetAttributeValueCaseInsensitive("value"); - if (cru::string::CaseInsensitiveCompare(value, "true") == 0) { - return ui::style::HoverCondition::Create(true); - } else if (cru::string::CaseInsensitiveCompare(value, "false") == 0) { - return ui::style::HoverCondition::Create(false); - } else { - throw Exception("Invalid value for HoverCondition: " + value); - } -} -} // namespace cru::ui::mapper::style diff --git a/src/ui/mapper/style/MarginStylerMapper.cpp b/src/ui/mapper/style/MarginStylerMapper.cpp deleted file mode 100644 index 2343dd3e..00000000 --- a/src/ui/mapper/style/MarginStylerMapper.cpp +++ /dev/null @@ -1,24 +0,0 @@ -#include "cru/ui/mapper/style/MarginStylerMapper.h" -#include "cru/ui/mapper/MapperRegistry.h" -#include "cru/ui/render/MeasureRequirement.h" -#include "cru/ui/style/Styler.h" - -namespace cru::ui::mapper::style { -MarginStylerMapper::MarginStylerMapper() { SetAllowedTags({"MarginStyler"}); } - -MarginStylerMapper::~MarginStylerMapper() {} - -ClonePtr<ui::style::MarginStyler> MarginStylerMapper::DoMapFromXml( - xml::XmlElementNode* node) { - Thickness thickness; - - auto thickness_mapper = MapperRegistry::GetInstance()->GetMapper<Thickness>(); - - auto value_attribute = node->GetOptionalAttributeValueCaseInsensitive("value"); - if (value_attribute) { - thickness = thickness_mapper->MapFromString(*value_attribute); - } - - return ui::style::MarginStyler::Create(thickness); -} -} // namespace cru::ui::mapper::style diff --git a/src/ui/mapper/style/NoConditionMapper.cpp b/src/ui/mapper/style/NoConditionMapper.cpp deleted file mode 100644 index 3ee9981e..00000000 --- a/src/ui/mapper/style/NoConditionMapper.cpp +++ /dev/null @@ -1,14 +0,0 @@ -#include "cru/ui/mapper/style/NoConditionMapper.h" -#include "cru/base/ClonePtr.h" -#include "cru/base/xml/XmlNode.h" - -namespace cru::ui::mapper::style { -bool NoConditionMapper::XmlElementIsOfThisType(xml::XmlElementNode* node) { - return cru::string::CaseInsensitiveCompare(node->GetTag(), "NoCondition") == 0; -} - -ClonePtr<ui::style::NoCondition> NoConditionMapper::DoMapFromXml( - xml::XmlElementNode* node) { - return ui::style::NoCondition::Create(); -} -} // namespace cru::ui::mapper::style diff --git a/src/ui/mapper/style/OrConditionMapper.cpp b/src/ui/mapper/style/OrConditionMapper.cpp deleted file mode 100644 index 5591bab0..00000000 --- a/src/ui/mapper/style/OrConditionMapper.cpp +++ /dev/null @@ -1,31 +0,0 @@ -#include "cru/ui/mapper/style/OrConditionMapper.h" -#include "cru/base/ClonePtr.h" -#include "cru/ui/mapper/MapperRegistry.h" -#include "cru/ui/mapper/style/IConditionMapper.h" -#include "cru/ui/style/Condition.h" -#include "cru/base/xml/XmlNode.h" - -namespace cru::ui::mapper::style { -bool OrConditionMapper::XmlElementIsOfThisType(xml::XmlElementNode *node) { - return cru::string::CaseInsensitiveCompare(node->GetTag(), "OrCondition") == 0; -} - -ClonePtr<ui::style::OrCondition> OrConditionMapper::DoMapFromXml( - xml::XmlElementNode *node) { - std::vector<ClonePtr<ui::style::Condition>> conditions; - auto condition_mappers = - MapperRegistry::GetInstance()->GetMappersByInterface<IConditionMapper>(); - for (auto child : node->GetChildren()) { - if (child->GetType() == xml::XmlNode::Type::Element) { - auto c = child->AsElement(); - for (auto mapper : condition_mappers) { - if (mapper->XmlElementIsOfThisType(c)) { - conditions.push_back(mapper->MapConditionFromXml(c)); - break; - } - } - } - } - return ui::style::OrCondition::Create(std::move(conditions)); -} -} // namespace cru::ui::mapper::style diff --git a/src/ui/mapper/style/PaddingStylerMapper.cpp b/src/ui/mapper/style/PaddingStylerMapper.cpp deleted file mode 100644 index 60c40c3d..00000000 --- a/src/ui/mapper/style/PaddingStylerMapper.cpp +++ /dev/null @@ -1,27 +0,0 @@ -#include "cru/ui/mapper/style/PaddingStylerMapper.h" -#include "cru/ui/mapper/MapperRegistry.h" -#include "cru/ui/render/MeasureRequirement.h" -#include "cru/ui/style/Styler.h" - -namespace cru::ui::mapper::style { -PaddingStylerMapper::PaddingStylerMapper() { - SetAllowedTags({"PaddingStyler"}); -} - -PaddingStylerMapper::~PaddingStylerMapper() {} - -ClonePtr<ui::style::PaddingStyler> PaddingStylerMapper::DoMapFromXml( - xml::XmlElementNode* node) { - Thickness thickness; - - auto thickness_mapper = MapperRegistry::GetInstance()->GetMapper<Thickness>(); - - auto value_attribute = - node->GetOptionalAttributeValueCaseInsensitive("value"); - if (value_attribute) { - thickness = thickness_mapper->MapFromString(*value_attribute); - } - - return ui::style::PaddingStyler::Create(thickness); -} -} // namespace cru::ui::mapper::style diff --git a/src/ui/mapper/style/PreferredSizeStylerMapper.cpp b/src/ui/mapper/style/PreferredSizeStylerMapper.cpp deleted file mode 100644 index 0603f5c4..00000000 --- a/src/ui/mapper/style/PreferredSizeStylerMapper.cpp +++ /dev/null @@ -1,31 +0,0 @@ -#include "cru/ui/mapper/style/PreferredSizeStylerMapper.h" -#include "cru/ui/mapper/MapperRegistry.h" -#include "cru/ui/render/MeasureRequirement.h" -#include "cru/ui/style/Styler.h" - -namespace cru::ui::mapper::style { -bool PreferredSizeStylerMapper::XmlElementIsOfThisType( - xml::XmlElementNode* node) { - return cru::string::CaseInsensitiveCompare(node->GetTag(), "PreferredSizeStyler") == 0; -} - -ClonePtr<ui::style::PreferredSizeStyler> -PreferredSizeStylerMapper::DoMapFromXml(xml::XmlElementNode* node) { - render::MeasureSize size; - - auto measure_length_mapper = - MapperRegistry::GetInstance()->GetMapper<render::MeasureLength>(); - - auto width_attribute = node->GetOptionalAttributeValueCaseInsensitive("width"); - if (width_attribute) { - size.width = measure_length_mapper->MapFromString(*width_attribute); - } - - auto height_attribute = node->GetOptionalAttributeValueCaseInsensitive("height"); - if (height_attribute) { - size.height = measure_length_mapper->MapFromString(*height_attribute); - } - - return ui::style::PreferredSizeStyler::Create(size); -} -} // namespace cru::ui::mapper::style diff --git a/src/ui/mapper/style/StyleRuleMapper.cpp b/src/ui/mapper/style/StyleRuleMapper.cpp index 30fedb16..3c1819a1 100644 --- a/src/ui/mapper/style/StyleRuleMapper.cpp +++ b/src/ui/mapper/style/StyleRuleMapper.cpp @@ -1,17 +1,13 @@ #include "cru/ui/mapper/style/StyleRuleMapper.h" #include "cru/base/ClonePtr.h" #include "cru/ui/mapper/MapperRegistry.h" -#include "cru/ui/mapper/style/IConditionMapper.h" -#include "cru/ui/mapper/style/IStylerMapper.h" -#include "cru/ui/style/Condition.h" +#include "cru/ui/mapper/style/ConditionMapper.h" +#include "cru/ui/mapper/style/StylerMapper.h" #include "cru/ui/style/StyleRule.h" #include "cru/ui/style/Styler.h" namespace cru::ui::mapper::style { using namespace ui::style; -bool StyleRuleMapper::XmlElementIsOfThisType(xml::XmlElementNode* node) { - return cru::string::CaseInsensitiveCompare(node->GetTag(), "StyleRule") == 0; -} ClonePtr<ui::style::StyleRule> StyleRuleMapper::DoMapFromXml( xml::XmlElementNode* node) { diff --git a/src/ui/mapper/style/StyleRuleSetMapper.cpp b/src/ui/mapper/style/StyleRuleSetMapper.cpp index 19a628ad..f4fd957b 100644 --- a/src/ui/mapper/style/StyleRuleSetMapper.cpp +++ b/src/ui/mapper/style/StyleRuleSetMapper.cpp @@ -7,10 +7,6 @@ namespace cru::ui::mapper::style { using namespace cru::ui::style; -bool StyleRuleSetMapper::XmlElementIsOfThisType(xml::XmlElementNode* node) { - return cru::string::CaseInsensitiveCompare(node->GetTag(), "StyleRuleSet") == 0; -} - std::shared_ptr<ui::style::StyleRuleSet> StyleRuleSetMapper::DoMapFromXml( xml::XmlElementNode* node) { auto style_rule_mapper = diff --git a/src/ui/mapper/style/StylerMapper.cpp b/src/ui/mapper/style/StylerMapper.cpp new file mode 100644 index 00000000..f48b4d61 --- /dev/null +++ b/src/ui/mapper/style/StylerMapper.cpp @@ -0,0 +1,127 @@ +#include "cru/ui/mapper/style/StylerMapper.h" +#include "cru/base/ClonePtr.h" +#include "cru/base/xml/XmlNode.h" +#include "cru/ui/mapper/MapperRegistry.h" +#include "cru/ui/style/ApplyBorderStyleInfo.h" +#include "cru/ui/style/Styler.h" + +namespace cru::ui::mapper::style { +ClonePtr<BorderStyler> BorderStylerMapper::DoMapFromXml( + xml::XmlElementNode* node) { + auto border_style_mapper = + MapperRegistry::GetInstance()->GetMapper<ApplyBorderStyleInfo>(); + + ApplyBorderStyleInfo border_style; + + for (auto child : node->GetChildren()) { + if (child->GetType() == xml::XmlElementNode::Type::Element) { + auto child_element = child->AsElement(); + if (border_style_mapper->XmlElementIsOfThisType(child_element)) { + border_style = border_style_mapper->MapFromXml(child_element); + } + } + } + + return BorderStyler::Create(std::move(border_style)); +} + +ClonePtr<ui::style::ContentBrushStyler> ContentBrushStylerMapper::DoMapFromXml( + xml::XmlElementNode* node) { + auto brush_mapper = MapperRegistry::GetInstance() + ->GetSharedPtrMapper<platform::graphics::IBrush>(); + + std::shared_ptr<platform::graphics::IBrush> brush; + + for (auto child_node : node->GetChildren()) { + if (child_node->IsElementNode()) { + brush = brush_mapper->MapFromXml(child_node->AsElement()); + } + } + + return ui::style::ContentBrushStyler::Create(std::move(brush)); +} + +ClonePtr<ui::style::CursorStyler> CursorStylerMapper::DoMapFromXml( + xml::XmlElementNode* node) { + auto cursor_mapper = MapperRegistry::GetInstance() + ->GetSharedPtrMapper<platform::gui::ICursor>(); + std::shared_ptr<platform::gui::ICursor> cursor; + + for (auto child : node->GetChildren()) { + if (child->GetType() == xml::XmlNode::Type::Element && + cursor_mapper->XmlElementIsOfThisType(child->AsElement())) { + cursor = cursor_mapper->MapFromXml(child->AsElement()); + } + } + + return ui::style::CursorStyler::Create(cursor); +} + +ClonePtr<ui::style::FontStyler> FontStylerMapper::DoMapFromXml( + xml::XmlElementNode* node) { + auto font_mapper = MapperRegistry::GetInstance() + ->GetSharedPtrMapper<platform::graphics::IFont>(); + + std::shared_ptr<platform::graphics::IFont> font; + + for (auto child_node : node->GetChildren()) { + if (child_node->IsElementNode()) { + font = font_mapper->MapFromXml(child_node->AsElement()); + } + } + + return ui::style::FontStyler::Create(std::move(font)); +} + +ClonePtr<ui::style::MarginStyler> MarginStylerMapper::DoMapFromXml( + xml::XmlElementNode* node) { + Thickness thickness; + + auto thickness_mapper = MapperRegistry::GetInstance()->GetMapper<Thickness>(); + + auto value_attribute = + node->GetOptionalAttributeValueCaseInsensitive("value"); + if (value_attribute) { + thickness = thickness_mapper->MapFromString(*value_attribute); + } + + return ui::style::MarginStyler::Create(thickness); +} + +ClonePtr<ui::style::PaddingStyler> PaddingStylerMapper::DoMapFromXml( + xml::XmlElementNode* node) { + Thickness thickness; + + auto thickness_mapper = MapperRegistry::GetInstance()->GetMapper<Thickness>(); + + auto value_attribute = + node->GetOptionalAttributeValueCaseInsensitive("value"); + if (value_attribute) { + thickness = thickness_mapper->MapFromString(*value_attribute); + } + + return ui::style::PaddingStyler::Create(thickness); +} + +ClonePtr<ui::style::PreferredSizeStyler> +PreferredSizeStylerMapper::DoMapFromXml(xml::XmlElementNode* node) { + render::MeasureSize size; + + auto measure_length_mapper = + MapperRegistry::GetInstance()->GetMapper<render::MeasureLength>(); + + auto width_attribute = + node->GetOptionalAttributeValueCaseInsensitive("width"); + if (width_attribute) { + size.width = measure_length_mapper->MapFromString(*width_attribute); + } + + auto height_attribute = + node->GetOptionalAttributeValueCaseInsensitive("height"); + if (height_attribute) { + size.height = measure_length_mapper->MapFromString(*height_attribute); + } + + return ui::style::PreferredSizeStyler::Create(size); +} +} // namespace cru::ui::mapper::style |
