diff --git a/data/dialogs/doc-new.xml b/data/dialogs/doc-new.xml index 29bafcc..1bb68c2 100644 --- a/data/dialogs/doc-new.xml +++ b/data/dialogs/doc-new.xml @@ -14,7 +14,7 @@ - + diff --git a/src/layout.cpp b/src/layout.cpp index ee29865..8d9bec2 100644 --- a/src/layout.cpp +++ b/src/layout.cpp @@ -92,16 +92,8 @@ bool LayoutManager::parse(const std::string& xml_string) noexcept if (p == m_layouts.end()) { auto& node = m_layouts[id]; - kWidget node_id = (kWidget)const_hash(current->Name()); - switch (node_id) - { - case kWidget::Border: - node.reset(new NodeBorder()); - break; - default: - node.reset(new Node()); - break; - } + std::string node_name = current->Name(); + node.reset(node_name == "border" ? new NodeBorder : new Node); node->set_manager(this); // try to copy the old size values if (old.count(id)) diff --git a/src/node.cpp b/src/node.cpp index 0e306df..b1b68ab 100644 --- a/src/node.cpp +++ b/src/node.cpp @@ -1401,50 +1401,18 @@ void Node::load_internal(const tinyxml2::XMLElement* x_node, bool skip_children } } - kWidget child_id = (kWidget)const_hash(x_child->Name()); - switch (child_id) + std::string node_name = x_child->Name(); + if (node_name == "ref") { -#define CASE(W,C) case W: { auto n = new C(); add_child(n); n->load_internal(x_child); break; } - CASE(kWidget::Node, Node); - CASE(kWidget::Border, NodeBorder); - CASE(kWidget::Image, NodeImage); - CASE(kWidget::ImageTexture, NodeImageTexture); - CASE(kWidget::Icon, NodeIcon); - CASE(kWidget::TextInput, NodeTextInput); - CASE(kWidget::Button, NodeButton); - CASE(kWidget::ButtonCustom, NodeButtonCustom); - CASE(kWidget::ComboBox, NodeComboBox); - CASE(kWidget::SliderH, NodeSliderH); - CASE(kWidget::SliderV, NodeSliderV); - CASE(kWidget::SliderHue, NodeSliderHue); - CASE(kWidget::PopupMenu, NodePopupMenu); - CASE(kWidget::Viewport, NodeViewport); - CASE(kWidget::CheckBox, NodeCheckBox); - CASE(kWidget::Layer, NodeLayer); - CASE(kWidget::PanelLayer, NodePanelLayer); - CASE(kWidget::PanelBrush, NodePanelBrush); - CASE(kWidget::PanelColor, NodePanelColor); - CASE(kWidget::PanelStroke, NodePanelStroke); - CASE(kWidget::PanelGrid, NodePanelGrid); - CASE(kWidget::PanelQuick, NodePanelQuick); - CASE(kWidget::ColorQuad, NodeColorQuad); - CASE(kWidget::StrokePreview, NodeStrokePreview); - CASE(kWidget::Canvas, NodeCanvas); - CASE(kWidget::Scroll, NodeScroll); - CASE(kWidget::DialogBrowse, NodeDialogBrowse); - CASE(kWidget::DialogBrowseItem, NodeDialogBrowseItem); - CASE(kWidget::DialogCloud, NodeDialogCloud); - CASE(kWidget::DialogCloudItem, NodeDialogCloudItem); - CASE(kWidget::ColorWheel, NodeColorWheel); - CASE(kWidget::ColorPicker, NodeColorPicker); - CASE(kWidget::About, NodeAbout); - CASE(kWidget::Changelog, NodeChangelog); - CASE(kWidget::UserManual, NodeUserManual); - CASE(kWidget::ToolBucket, NodeToolBucket); - CASE(kWidget::Timeline, NodeAnimationTimeline); - CASE(kWidget::Metadata, NodeMetadata); -#undef CASE - case kWidget::Text: + auto ids = x_child->Attribute("id"); + auto id = const_hash(ids); + auto& ref = (*m_manager)[id]->m_children[0]; + auto n = ref->clone(); + n->m_nodeID_s = ids; + n->m_nodeID = id; + add_child(n); + } + else if (node_name == "text") { auto n = new NodeText(); add_child(n); @@ -1466,27 +1434,37 @@ void Node::load_internal(const tinyxml2::XMLElement* x_node, bool skip_children } if (!text.empty()) n->set_text(text); - break; } - case kWidget::Ref: - { - auto ids = x_child->Attribute("id"); - auto id = const_hash(ids); - auto& ref = (*m_manager)[id]->m_children[0]; - auto n = ref->clone(); - n->m_nodeID_s = ids; - n->m_nodeID = id; - add_child(n); - break; - } - default: +#define CASE(W,C) else if (node_name == W) { auto n = new C(); add_child(n); n->load_internal(x_child); } + CASE("node", Node) + CASE("border", NodeBorder) + CASE("image", NodeImage) + CASE("image-texture", NodeImageTexture) + CASE("icon", NodeIcon) + CASE("text-input", NodeTextInput) + CASE("button", NodeButton) + CASE("button-custom", NodeButtonCustom) + CASE("combobox", NodeComboBox) + CASE("slider-h", NodeSliderH) + CASE("slider-v", NodeSliderV) + CASE("slider-hue", NodeSliderHue) + CASE("popup-menu", NodePopupMenu) + CASE("viewport", NodeViewport) + CASE("checkbox", NodeCheckBox) + CASE("stroke-preview", NodeStrokePreview) + CASE("canvas", NodeCanvas) + CASE("scroll", NodeScroll) + CASE("metadata", NodeMetadata) + CASE("panel-quick", NodePanelQuick) + CASE("colorwheel", NodeColorWheel) + CASE("color-quad", NodeColorQuad) +#undef CASE + else { LOG("instancing UNKNOWN node: %s", x_child->Name()); auto n = new Node(); add_child(n); n->load_internal(x_child); - break; - } } x_child = x_child->NextSiblingElement(); } diff --git a/src/node.h b/src/node.h index b9fc344..f90fb65 100644 --- a/src/node.h +++ b/src/node.h @@ -55,51 +55,6 @@ enum class kAttribute : uint16_t TextVerticalAlign = const_hash("text-vertical-align"), }; -enum class kWidget : uint16_t -{ - Node = const_hash("node"), - Border = const_hash("border"), - Shape = const_hash("shape"), - Text = const_hash("text"), - TextInput = const_hash("text-input"), - Image = const_hash("image"), - ImageTexture = const_hash("image-texture"), - Icon = const_hash("icon"), - Button = const_hash("button"), - ButtonCustom = const_hash("button-custom"), - ComboBox = const_hash("combobox"), - SliderH = const_hash("slider-h"), - SliderV = const_hash("slider-v"), - SliderHue = const_hash("slider-hue"), - PopupMenu = const_hash("popup-menu"), - Viewport = const_hash("viewport"), - Ref = const_hash("ref"), - CheckBox = const_hash("checkbox"), - Layer = const_hash("layer"), - PanelLayer = const_hash("panel-layer"), - PanelBrush = const_hash("panel-brush"), - PanelColor = const_hash("panel-color"), - PanelStroke = const_hash("panel-stroke"), - PanelGrid = const_hash("panel-grid"), - PanelQuick = const_hash("panel-quick"), - ColorQuad = const_hash("color-quad"), - StrokePreview = const_hash("stroke-preview"), - Canvas = const_hash("canvas"), - Scroll = const_hash("scroll"), - DialogBrowse = const_hash("dialog-browse"), - DialogBrowseItem = const_hash("dialog-browse-item"), - DialogCloud = const_hash("dialog-cloud"), - DialogCloudItem = const_hash("dialog-cloud-item"), - ColorWheel = const_hash("colorwheel"), - ColorPicker = const_hash("color-picker"), - About = const_hash("about"), - Changelog = const_hash("changelog"), - UserManual = const_hash("usermanual"), - ToolBucket = const_hash("tool-bucket"), - Timeline = const_hash("timeline"), - Metadata = const_hash("metadata"), -}; - class Node : public std::enable_shared_from_this { friend class LayoutManager;