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"/> <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"> <border dir="row" align="center" height="30" color=".2 .2 .2 1">
<text text="Project name: " margin="0 5 0 5"/> <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"/> <combobox id="resolution" width="100" height="30" text="2K" combo-list="2K,4K,6K,8K,16K,32K" default="1"/>
</border> </border>
<text os="win,osx" id="path" text="Workind dir: path" text-wrap-width="470" margin="10 5 10 5"/> <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()) if (p == m_layouts.end())
{ {
auto& node = m_layouts[id]; auto& node = m_layouts[id];
kWidget node_id = (kWidget)const_hash(current->Name()); std::string node_name = current->Name();
switch (node_id) node.reset(node_name == "border" ? new NodeBorder : new Node);
{
case kWidget::Border:
node.reset(new NodeBorder());
break;
default:
node.reset(new Node());
break;
}
node->set_manager(this); node->set_manager(this);
// try to copy the old size values // try to copy the old size values
if (old.count(id)) 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()); std::string node_name = x_child->Name();
switch (child_id) if (node_name == "ref")
{ {
#define CASE(W,C) case W: { auto n = new C(); add_child(n); n->load_internal(x_child); break; } auto ids = x_child->Attribute("id");
CASE(kWidget::Node, Node); auto id = const_hash(ids);
CASE(kWidget::Border, NodeBorder); auto& ref = (*m_manager)[id]->m_children[0];
CASE(kWidget::Image, NodeImage); auto n = ref->clone();
CASE(kWidget::ImageTexture, NodeImageTexture); n->m_nodeID_s = ids;
CASE(kWidget::Icon, NodeIcon); n->m_nodeID = id;
CASE(kWidget::TextInput, NodeTextInput); add_child(n);
CASE(kWidget::Button, NodeButton); }
CASE(kWidget::ButtonCustom, NodeButtonCustom); else if (node_name == "text")
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 n = new NodeText(); auto n = new NodeText();
add_child(n); add_child(n);
@@ -1466,27 +1434,37 @@ void Node::load_internal(const tinyxml2::XMLElement* x_node, bool skip_children
} }
if (!text.empty()) if (!text.empty())
n->set_text(text); n->set_text(text);
break;
} }
case kWidget::Ref: #define CASE(W,C) else if (node_name == W) { auto n = new C(); add_child(n); n->load_internal(x_child); }
{ CASE("node", Node)
auto ids = x_child->Attribute("id"); CASE("border", NodeBorder)
auto id = const_hash(ids); CASE("image", NodeImage)
auto& ref = (*m_manager)[id]->m_children[0]; CASE("image-texture", NodeImageTexture)
auto n = ref->clone(); CASE("icon", NodeIcon)
n->m_nodeID_s = ids; CASE("text-input", NodeTextInput)
n->m_nodeID = id; CASE("button", NodeButton)
add_child(n); CASE("button-custom", NodeButtonCustom)
break; CASE("combobox", NodeComboBox)
} CASE("slider-h", NodeSliderH)
default: 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()); LOG("instancing UNKNOWN node: %s", x_child->Name());
auto n = new Node(); auto n = new Node();
add_child(n); add_child(n);
n->load_internal(x_child); n->load_internal(x_child);
break;
}
} }
x_child = x_child->NextSiblingElement(); x_child = x_child->NextSiblingElement();
} }

View File

@@ -55,51 +55,6 @@ enum class kAttribute : uint16_t
TextVerticalAlign = const_hash("text-vertical-align"), 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> class Node : public std::enable_shared_from_this<Node>
{ {
friend class LayoutManager; friend class LayoutManager;