replace kWidget enum with string

This commit is contained in:
2019-12-01 21:42:40 +01:00
parent 94cf227704
commit afb26e8321
4 changed files with 39 additions and 114 deletions

View File

@@ -14,7 +14,7 @@
<text text="Note: resolution is measured in K-pixels, so a 2K document produces\na 2048x1024 equirectangular output." margin="0 5 10 5"/>
<border dir="row" align="center" height="30" color=".2 .2 .2 1">
<text text="Project name: " margin="0 5 0 5"/>
<text-input id="txt-input" margin="0 1 0 0" align="center" pad="5" grow="1" height="30" color=".3"/>
<text-input id="txt-input" margin="0 2 0 0" align="center" pad="5" grow="1" height="30" color=".3"/>
<combobox id="resolution" width="100" height="30" text="2K" combo-list="2K,4K,6K,8K,16K,32K" default="1"/>
</border>
<text os="win,osx" id="path" text="Workind dir: path" text-wrap-width="470" margin="10 5 10 5"/>

View File

@@ -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))

View File

@@ -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();
}

View File

@@ -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<Node>
{
friend class LayoutManager;