Add support to "visible" attribute

This commit is contained in:
Martín Capello 2021-09-06 13:20:20 -03:00
parent 05dfd75743
commit 495623d6b2
6 changed files with 63 additions and 59 deletions

View File

@ -379,13 +379,13 @@ void AppBrushes::load(const std::string& filename)
// Pixel-perfect // Pixel-perfect
if (TiXmlElement* pixelPerfectElem = brushElem->FirstChildElement("pixelperfect")) { if (TiXmlElement* pixelPerfectElem = brushElem->FirstChildElement("pixelperfect")) {
pixelPerfect = bool_attr_is_true(pixelPerfectElem, "value"); pixelPerfect = bool_attr(pixelPerfectElem, "value", false);
flags |= int(BrushSlot::Flags::PixelPerfect); flags |= int(BrushSlot::Flags::PixelPerfect);
} }
// Image color (enabled by default for backward compatibility) // Image color (enabled by default for backward compatibility)
if (!brushElem->Attribute("imagecolor") || if (!brushElem->Attribute("imagecolor") ||
bool_attr_is_true(brushElem, "imagecolor")) bool_attr(brushElem, "imagecolor", false))
flags |= int(BrushSlot::Flags::ImageColor); flags |= int(BrushSlot::Flags::ImageColor);
if (flags != 0) if (flags != 0)

View File

@ -418,7 +418,7 @@ void KeyboardShortcuts::importFile(TiXmlElement* rootElement, KeySource source)
while (xmlKey) { while (xmlKey) {
const char* command_name = xmlKey->Attribute("command"); const char* command_name = xmlKey->Attribute("command");
const char* command_key = get_shortcut(xmlKey); const char* command_key = get_shortcut(xmlKey);
bool removed = bool_attr_is_true(xmlKey, "removed"); bool removed = bool_attr(xmlKey, "removed", false);
if (command_name) { if (command_name) {
Command* command = Commands::instance()->byId(command_name); Command* command = Commands::instance()->byId(command_name);
@ -481,7 +481,7 @@ void KeyboardShortcuts::importFile(TiXmlElement* rootElement, KeySource source)
while (xmlKey) { while (xmlKey) {
const char* tool_id = xmlKey->Attribute("tool"); const char* tool_id = xmlKey->Attribute("tool");
const char* tool_key = get_shortcut(xmlKey); const char* tool_key = get_shortcut(xmlKey);
bool removed = bool_attr_is_true(xmlKey, "removed"); bool removed = bool_attr(xmlKey, "removed", false);
if (tool_id) { if (tool_id) {
tools::Tool* tool = App::instance()->toolBox()->getToolById(tool_id); tools::Tool* tool = App::instance()->toolBox()->getToolById(tool_id);
@ -509,7 +509,7 @@ void KeyboardShortcuts::importFile(TiXmlElement* rootElement, KeySource source)
while (xmlKey) { while (xmlKey) {
const char* tool_id = xmlKey->Attribute("tool"); const char* tool_id = xmlKey->Attribute("tool");
const char* tool_key = get_shortcut(xmlKey); const char* tool_key = get_shortcut(xmlKey);
bool removed = bool_attr_is_true(xmlKey, "removed"); bool removed = bool_attr(xmlKey, "removed", false);
if (tool_id) { if (tool_id) {
tools::Tool* tool = App::instance()->toolBox()->getToolById(tool_id); tools::Tool* tool = App::instance()->toolBox()->getToolById(tool_id);
@ -537,7 +537,7 @@ void KeyboardShortcuts::importFile(TiXmlElement* rootElement, KeySource source)
while (xmlKey) { while (xmlKey) {
const char* action_id = xmlKey->Attribute("action"); const char* action_id = xmlKey->Attribute("action");
const char* action_key = get_shortcut(xmlKey); const char* action_key = get_shortcut(xmlKey);
bool removed = bool_attr_is_true(xmlKey, "removed"); bool removed = bool_attr(xmlKey, "removed", false);
if (action_id) { if (action_id) {
KeyAction action = base::convert_to<KeyAction, std::string>(action_id); KeyAction action = base::convert_to<KeyAction, std::string>(action_id);
@ -565,7 +565,7 @@ void KeyboardShortcuts::importFile(TiXmlElement* rootElement, KeySource source)
while (xmlKey) { while (xmlKey) {
const char* action_id = xmlKey->Attribute("action"); const char* action_id = xmlKey->Attribute("action");
const char* action_key = get_shortcut(xmlKey); const char* action_key = get_shortcut(xmlKey);
bool removed = bool_attr_is_true(xmlKey, "removed"); bool removed = bool_attr(xmlKey, "removed", false);
if (action_id) { if (action_id) {
WheelAction action = base::convert_to<WheelAction, std::string>(action_id); WheelAction action = base::convert_to<WheelAction, std::string>(action_id);

View File

@ -168,7 +168,7 @@ static FontData* load_font(std::map<std::string, FontData*>& fonts,
const char* fileStr = xmlFont->Attribute("file"); const char* fileStr = xmlFont->Attribute("file");
bool antialias = true; bool antialias = true;
if (xmlFont->Attribute("antialias")) if (xmlFont->Attribute("antialias"))
antialias = bool_attr_is_true(xmlFont, "antialias"); antialias = bool_attr(xmlFont, "antialias", false);
std::string fontFilename; std::string fontFilename;
if (platformFileStr) if (platformFileStr)

View File

@ -135,8 +135,8 @@ Widget* WidgetLoader::convertXmlElementToWidget(const TiXmlElement* elem, Widget
widget = new Panel(); widget = new Panel();
} }
else if (elem_name == "box") { else if (elem_name == "box") {
bool horizontal = bool_attr_is_true(elem, "horizontal"); bool horizontal = bool_attr(elem, "horizontal", false);
bool vertical = bool_attr_is_true(elem, "vertical"); bool vertical = bool_attr(elem, "vertical", false);
int align = (horizontal ? HORIZONTAL: vertical ? VERTICAL: 0); int align = (horizontal ? HORIZONTAL: vertical ? VERTICAL: 0);
if (!widget) if (!widget)
@ -173,11 +173,11 @@ Widget* WidgetLoader::convertXmlElementToWidget(const TiXmlElement* elem, Widget
} }
} }
bool left = bool_attr_is_true(elem, "left"); bool left = bool_attr(elem, "left", false);
bool right = bool_attr_is_true(elem, "right"); bool right = bool_attr(elem, "right", false);
bool top = bool_attr_is_true(elem, "top"); bool top = bool_attr(elem, "top", false);
bool bottom = bool_attr_is_true(elem, "bottom"); bool bottom = bool_attr(elem, "bottom", false);
bool closewindow = bool_attr_is_true(elem, "closewindow"); bool closewindow = bool_attr(elem, "closewindow", false);
widget->setAlign((left ? LEFT: (right ? RIGHT: CENTER)) | widget->setAlign((left ? LEFT: (right ? RIGHT: CENTER)) |
(top ? TOP: (bottom ? BOTTOM: MIDDLE))); (top ? TOP: (bottom ? BOTTOM: MIDDLE)));
@ -214,10 +214,10 @@ Widget* WidgetLoader::convertXmlElementToWidget(const TiXmlElement* elem, Widget
} }
} }
bool center = bool_attr_is_true(elem, "center"); bool center = bool_attr(elem, "center", false);
bool right = bool_attr_is_true(elem, "right"); bool right = bool_attr(elem, "right", false);
bool top = bool_attr_is_true(elem, "top"); bool top = bool_attr(elem, "top", false);
bool bottom = bool_attr_is_true(elem, "bottom"); bool bottom = bool_attr(elem, "bottom", false);
widget->setAlign((center ? CENTER: widget->setAlign((center ? CENTER:
(right ? RIGHT: LEFT)) | (right ? RIGHT: LEFT)) |
@ -228,7 +228,7 @@ Widget* WidgetLoader::convertXmlElementToWidget(const TiXmlElement* elem, Widget
if (!widget) if (!widget)
widget = new ComboBox(); widget = new ComboBox();
bool editable = bool_attr_is_true(elem, "editable"); bool editable = bool_attr(elem, "editable", false);
if (editable) if (editable)
((ComboBox*)widget)->setEditable(true); ((ComboBox*)widget)->setEditable(true);
} }
@ -240,7 +240,7 @@ Widget* WidgetLoader::convertXmlElementToWidget(const TiXmlElement* elem, Widget
const char* suffix = elem->Attribute("suffix"); const char* suffix = elem->Attribute("suffix");
const char* decimals = elem->Attribute("decimals"); const char* decimals = elem->Attribute("decimals");
const bool readonly = bool_attr_is_true(elem, "readonly"); const bool readonly = bool_attr(elem, "readonly", false);
widget = (elem_name == "expr" ? widget = (elem_name == "expr" ?
new ExprEntry: new ExprEntry:
@ -257,7 +257,7 @@ Widget* WidgetLoader::convertXmlElementToWidget(const TiXmlElement* elem, Widget
} }
else if (elem_name == "grid") { else if (elem_name == "grid") {
const char *columns = elem->Attribute("columns"); const char *columns = elem->Attribute("columns");
bool same_width_columns = bool_attr_is_true(elem, "same_width_columns"); bool same_width_columns = bool_attr(elem, "same_width_columns", false);
if (columns != NULL) { if (columns != NULL) {
widget = new Grid(strtol(columns, NULL, 10), widget = new Grid(strtol(columns, NULL, 10),
@ -268,10 +268,10 @@ Widget* WidgetLoader::convertXmlElementToWidget(const TiXmlElement* elem, Widget
if (!widget) if (!widget)
widget = new Label(""); widget = new Label("");
bool center = bool_attr_is_true(elem, "center"); bool center = bool_attr(elem, "center", false);
bool right = bool_attr_is_true(elem, "right"); bool right = bool_attr(elem, "right", false);
bool top = bool_attr_is_true(elem, "top"); bool top = bool_attr(elem, "top", false);
bool bottom = bool_attr_is_true(elem, "bottom"); bool bottom = bool_attr(elem, "bottom", false);
widget->setAlign((center ? CENTER: widget->setAlign((center ? CENTER:
(right ? RIGHT: LEFT)) | (right ? RIGHT: LEFT)) |
@ -290,10 +290,10 @@ Widget* WidgetLoader::convertXmlElementToWidget(const TiXmlElement* elem, Widget
link->setUrl(url); link->setUrl(url);
} }
bool center = bool_attr_is_true(elem, "center"); bool center = bool_attr(elem, "center", false);
bool right = bool_attr_is_true(elem, "right"); bool right = bool_attr(elem, "right", false);
bool top = bool_attr_is_true(elem, "top"); bool top = bool_attr(elem, "top", false);
bool bottom = bool_attr_is_true(elem, "bottom"); bool bottom = bool_attr(elem, "bottom", false);
widget->setAlign( widget->setAlign(
(center ? CENTER: (right ? RIGHT: LEFT)) | (center ? CENTER: (right ? RIGHT: LEFT)) |
@ -303,7 +303,7 @@ Widget* WidgetLoader::convertXmlElementToWidget(const TiXmlElement* elem, Widget
if (!widget) if (!widget)
widget = new ListBox(); widget = new ListBox();
bool multiselect = bool_attr_is_true(elem, "multiselect"); bool multiselect = bool_attr(elem, "multiselect", false);
if (multiselect) if (multiselect)
static_cast<ListBox*>(widget)->setMultiselect(multiselect); static_cast<ListBox*>(widget)->setMultiselect(multiselect);
} }
@ -323,8 +323,8 @@ Widget* WidgetLoader::convertXmlElementToWidget(const TiXmlElement* elem, Widget
listitem->setValue(value); listitem->setValue(value);
} }
else if (elem_name == "splitter") { else if (elem_name == "splitter") {
bool horizontal = bool_attr_is_true(elem, "horizontal"); bool horizontal = bool_attr(elem, "horizontal", false);
bool vertical = bool_attr_is_true(elem, "vertical"); bool vertical = bool_attr(elem, "vertical", false);
const char* by = elem->Attribute("by"); const char* by = elem->Attribute("by");
const char* position = elem->Attribute("position"); const char* position = elem->Attribute("position");
Splitter::Type type = (by && strcmp(by, "pixel") == 0 ? Splitter::Type type = (by && strcmp(by, "pixel") == 0 ?
@ -361,10 +361,10 @@ Widget* WidgetLoader::convertXmlElementToWidget(const TiXmlElement* elem, Widget
radio->setRadioGroup(radio_group); radio->setRadioGroup(radio_group);
} }
bool center = bool_attr_is_true(elem, "center"); bool center = bool_attr(elem, "center", false);
bool right = bool_attr_is_true(elem, "right"); bool right = bool_attr(elem, "right", false);
bool top = bool_attr_is_true(elem, "top"); bool top = bool_attr(elem, "top", false);
bool bottom = bool_attr_is_true(elem, "bottom"); bool bottom = bool_attr(elem, "bottom", false);
widget->setAlign( widget->setAlign(
(center ? CENTER: (center ? CENTER:
@ -373,12 +373,12 @@ Widget* WidgetLoader::convertXmlElementToWidget(const TiXmlElement* elem, Widget
(bottom ? BOTTOM: MIDDLE))); (bottom ? BOTTOM: MIDDLE)));
} }
else if (elem_name == "separator") { else if (elem_name == "separator") {
bool center = bool_attr_is_true(elem, "center"); bool center = bool_attr(elem, "center", false);
bool right = bool_attr_is_true(elem, "right"); bool right = bool_attr(elem, "right", false);
bool middle = bool_attr_is_true(elem, "middle"); bool middle = bool_attr(elem, "middle", false);
bool bottom = bool_attr_is_true(elem, "bottom"); bool bottom = bool_attr(elem, "bottom", false);
bool horizontal = bool_attr_is_true(elem, "horizontal"); bool horizontal = bool_attr(elem, "horizontal", false);
bool vertical = bool_attr_is_true(elem, "vertical"); bool vertical = bool_attr(elem, "vertical", false);
int align = int align =
(horizontal ? HORIZONTAL: 0) | (horizontal ? HORIZONTAL: 0) |
(vertical ? VERTICAL: 0) | (vertical ? VERTICAL: 0) |
@ -400,7 +400,7 @@ Widget* WidgetLoader::convertXmlElementToWidget(const TiXmlElement* elem, Widget
widget = new Slider(min_value, max_value, min_value); widget = new Slider(min_value, max_value, min_value);
} }
else if (elem_name == "textbox") { else if (elem_name == "textbox") {
bool wordwrap = bool_attr_is_true(elem, "wordwrap"); bool wordwrap = bool_attr(elem, "wordwrap", false);
if (!widget) if (!widget)
widget = new TextBox(elem->GetText(), 0); widget = new TextBox(elem->GetText(), 0);
@ -416,7 +416,7 @@ Widget* WidgetLoader::convertXmlElementToWidget(const TiXmlElement* elem, Widget
} }
else if (elem_name == "window") { else if (elem_name == "window") {
if (!widget) { if (!widget) {
bool desktop = bool_attr_is_true(elem, "desktop"); bool desktop = bool_attr(elem, "desktop", false);
if (desktop) if (desktop)
widget = new Window(Window::DesktopWindow); widget = new Window(Window::DesktopWindow);
@ -427,8 +427,8 @@ Widget* WidgetLoader::convertXmlElementToWidget(const TiXmlElement* elem, Widget
} }
} }
else if (elem_name == "colorpicker") { else if (elem_name == "colorpicker") {
const bool rgba = bool_attr_is_true(elem, "rgba"); const bool rgba = bool_attr(elem, "rgba", false);
const bool simple = bool_attr_is_true(elem, "simple"); const bool simple = bool_attr(elem, "simple", false);
if (!widget) { if (!widget) {
ColorButtonOptions options; ColorButtonOptions options;
@ -453,9 +453,9 @@ Widget* WidgetLoader::convertXmlElementToWidget(const TiXmlElement* elem, Widget
widget = new ButtonSet(strtol(columns, NULL, 10)); widget = new ButtonSet(strtol(columns, NULL, 10));
if (ButtonSet* buttonset = dynamic_cast<ButtonSet*>(widget)) { if (ButtonSet* buttonset = dynamic_cast<ButtonSet*>(widget)) {
if (bool_attr_is_true(elem, "multiple")) if (bool_attr(elem, "multiple", false))
buttonset->setMultiMode(ButtonSet::MultiMode::Set); buttonset->setMultiMode(ButtonSet::MultiMode::Set);
if (bool_attr_is_true(elem, "oneormore")) if (bool_attr(elem, "oneormore", false))
buttonset->setMultiMode(ButtonSet::MultiMode::OneOrMore); buttonset->setMultiMode(ButtonSet::MultiMode::OneOrMore);
} }
} }
@ -529,12 +529,13 @@ void WidgetLoader::fillWidgetWithXmlElementAttributes(const TiXmlElement* elem,
{ {
const char* id = elem->Attribute("id"); const char* id = elem->Attribute("id");
const char* tooltip_dir = elem->Attribute("tooltip_dir"); const char* tooltip_dir = elem->Attribute("tooltip_dir");
bool selected = bool_attr_is_true(elem, "selected"); bool selected = bool_attr(elem, "selected", false);
bool disabled = bool_attr_is_true(elem, "disabled"); bool disabled = bool_attr(elem, "disabled", false);
bool expansive = bool_attr_is_true(elem, "expansive"); bool expansive = bool_attr(elem, "expansive", false);
bool homogeneous = bool_attr_is_true(elem, "homogeneous"); bool homogeneous = bool_attr(elem, "homogeneous", false);
bool magnet = bool_attr_is_true(elem, "magnet"); bool magnet = bool_attr(elem, "magnet", false);
bool noborders = bool_attr_is_true(elem, "noborders"); bool noborders = bool_attr(elem, "noborders", false);
bool visible = bool_attr(elem, "visible", true);
const char* width = elem->Attribute("width"); const char* width = elem->Attribute("width");
const char* height = elem->Attribute("height"); const char* height = elem->Attribute("height");
const char* minwidth = elem->Attribute("minwidth"); const char* minwidth = elem->Attribute("minwidth");
@ -592,6 +593,9 @@ void WidgetLoader::fillWidgetWithXmlElementAttributes(const TiXmlElement* elem,
if (expansive) if (expansive)
widget->setExpansive(true); widget->setExpansive(true);
if (!visible)
widget->setVisible(false);
if (homogeneous) if (homogeneous)
widget->setAlign(widget->align() | HOMOGENEOUS); widget->setAlign(widget->align() | HOMOGENEOUS);
@ -706,7 +710,7 @@ void WidgetLoader::fillWidgetWithXmlElementAttributesWithChildren(const TiXmlEle
} }
if (widget->type() == kViewWidget) { if (widget->type() == kViewWidget) {
bool maxsize = bool_attr_is_true(elem, "maxsize"); bool maxsize = bool_attr(elem, "maxsize", false);
if (maxsize) if (maxsize)
static_cast<View*>(widget)->makeVisibleAllScrollableArea(); static_cast<View*>(widget)->makeVisibleAllScrollableArea();
} }

View File

@ -45,11 +45,11 @@ void save_xml(XmlDocumentRef doc, const std::string& filename)
throw XmlException(doc.get()); throw XmlException(doc.get());
} }
bool bool_attr_is_true(const TiXmlElement* elem, const char* attrName) bool bool_attr(const TiXmlElement* elem, const char* attrName, bool defaultVal)
{ {
const char* value = elem->Attribute(attrName); const char* value = elem->Attribute(attrName);
return (value != NULL) && (strcmp(value, "true") == 0); return value == NULL ? defaultVal : strcmp(value, "true") == 0;
} }
} // namespace app } // namespace app

View File

@ -23,7 +23,7 @@ namespace app {
XmlDocumentRef open_xml(const std::string& filename); XmlDocumentRef open_xml(const std::string& filename);
void save_xml(XmlDocumentRef doc, const std::string& filename); void save_xml(XmlDocumentRef doc, const std::string& filename);
bool bool_attr_is_true(const TiXmlElement* elem, const char* attrName); bool bool_attr(const TiXmlElement* elem, const char* attrName, bool defaultVal);
} // namespace app } // namespace app