Skip to content

Commit

Permalink
Changed method of storing names of widgets
Browse files Browse the repository at this point in the history
Fixed adding the same widget to multiple containers
Added possibility to connect signals before creating widget
Update .gitignore
Now UserData property will be saved as string if possible
  • Loading branch information
1aam2am1 committed Jan 12, 2020
1 parent a49b770 commit 72caf05
Show file tree
Hide file tree
Showing 27 changed files with 926 additions and 116 deletions.
11 changes: 11 additions & 0 deletions gui-builder/include/WidgetProperties/WidgetProperties.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ struct WidgetProperties
widget->setVisible(parseBoolean(value, true));
else if (property == "Enabled")
widget->setEnabled(parseBoolean(value, true));
else if (property == "UserData")
widget->setUserData(value.toAnsiString());
else // Renderer property
widget->getRenderer()->setProperty(property, value);
}
Expand All @@ -67,6 +69,15 @@ struct WidgetProperties
pairs["Height"] = {"String", widget->getSizeLayout().y.toString()};
pairs["Visible"] = {"Bool", tgui::Serializer::serialize(widget->isVisible())};
pairs["Enabled"] = {"Bool", tgui::Serializer::serialize(widget->isEnabled())};
try
{
pairs["UserData"] = {"String", widget->getUserData<std::string>()};
}
catch(const std::bad_cast&)
{
pairs["UserData"] = {"String", ""};
}


PropertyValueMap rendererPairs;
const auto renderer = widget->getSharedRenderer();
Expand Down
5 changes: 2 additions & 3 deletions gui-builder/src/Form.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ bool Form::setSelectedWidgetName(const std::string& name)
}
}

m_selectedWidget->ptr->getParent()->setWidgetName(m_selectedWidget->ptr, name);
m_selectedWidget->ptr->Widget::setWidgetName(name);
m_selectedWidget->name = name;
return true;
}
Expand Down Expand Up @@ -575,12 +575,11 @@ void Form::drawExtra(sf::RenderWindow& window) const
void Form::importLoadedWidgets(tgui::Container::Ptr parent)
{
const auto& widgets = parent->getWidgets();
const auto& widgetNames = parent->getWidgetNames();
for (std::size_t i = 0; i < widgets.size(); ++i)
{
const std::string id = tgui::to_string(widgets[i].get());
m_widgets[id] = std::make_shared<WidgetInfo>(widgets[i]);
m_widgets[id]->name = widgetNames[i];
m_widgets[id]->name = widgets[i]->getWidgetName();
m_widgets[id]->theme = "Custom";

if (widgets[i]->isContainer())
Expand Down
2 changes: 1 addition & 1 deletion gui-builder/src/GuiBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2218,7 +2218,7 @@ void GuiBuilder::fillWidgetHierarchyTreeRecursively(std::vector<sf::String>& hie
const size_t widgetCount = asContainer->getWidgets().size();
for (size_t i = 0; i < widgetCount; ++i)
{
hierarchy.push_back(asContainer->getWidgetNames()[i]);
hierarchy.push_back(asContainer->getWidgets()[i]->getWidgetName());
fillWidgetHierarchyTreeRecursively(hierarchy, asContainer->getWidgets()[i]);
hierarchy.pop_back();
}
Expand Down
25 changes: 16 additions & 9 deletions include/TGUI/Container.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,18 +107,26 @@ namespace tgui
return m_widgets;
}


#ifndef TGUI_REMOVE_DEPRECATED_CODE
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// @brief Returns a list of the names of all the widgets in this container
///
/// @return Vector of all widget names
///
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
const std::vector<sf::String>& getWidgetNames() const
TGUI_DEPRECATED("Use getWidgets() and Widget::getWidgetName instead") const std::vector<sf::String> getWidgetNames() const
{
std::vector<sf::String> m_widgetNames;
m_widgetNames.reserve(m_widgets.size());

for (std::size_t i = 0; i < m_widgets.size(); ++i)
{
m_widgetNames.emplace_back(m_widgets[i]->getWidgetName());
}

return m_widgetNames;
}

#endif

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// @brief Adds a widget to the container
Expand Down Expand Up @@ -186,7 +194,7 @@ namespace tgui
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
virtual void removeAllWidgets();


#ifndef TGUI_REMOVE_DEPRECATED_CODE
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// @brief Changes the name of a widget
///
Expand All @@ -196,19 +204,19 @@ namespace tgui
/// @return True when the name was changed, false when the widget wasn't part of this container.
///
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
bool setWidgetName(const Widget::Ptr& widget, const std::string& name);
TGUI_DEPRECATED("Use Widget::setWidgetName instead") bool setWidgetName(const Widget::Ptr& widget, const std::string& name);


/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// @brief Returns the name of a widget
///
/// @param widget Widget of which the name should be retrieved
///
/// @return Name of the widget or an empty string when the widget didn't exist or wasn't given a name
/// @return Name of the widget or an empty string when the widget wasn't part of this container or wasn't given a name
///
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
std::string getWidgetName(const Widget::ConstPtr& widget) const;

TGUI_DEPRECATED("Use Widget::getWidgetName instead") std::string getWidgetName(const Widget::ConstPtr& widget) const;
#endif

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// @brief Unchecks all the radio buttons
Expand Down Expand Up @@ -465,7 +473,6 @@ namespace tgui
protected:

std::vector<Widget::Ptr> m_widgets;
std::vector<sf::String> m_widgetNames;

Widget::Ptr m_widgetBelowMouse;
Widget::Ptr m_focusedWidget;
Expand Down
14 changes: 7 additions & 7 deletions include/TGUI/Gui.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -217,15 +217,15 @@ namespace tgui
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
const std::vector<Widget::Ptr>& getWidgets() const;


#ifndef TGUI_REMOVE_DEPRECATED_CODE
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// @brief Returns a list of the names of all the widgets
///
/// @return Vector of all widget names
///
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
const std::vector<sf::String>& getWidgetNames() const;

TGUI_DEPRECATED("Use getWidgets() and Widget::getWidgetName instead") const std::vector<sf::String> getWidgetNames() const;
#endif

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// @brief Adds a widget to the container
Expand Down Expand Up @@ -291,7 +291,7 @@ namespace tgui
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void removeAllWidgets();


#ifndef TGUI_REMOVE_DEPRECATED_CODE
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// @brief Changes the name of a widget
///
Expand All @@ -301,7 +301,7 @@ namespace tgui
/// @return True when the name was changed, false when the widget wasn't part of this container
///
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
bool setWidgetName(const Widget::Ptr& widget, const std::string& name);
TGUI_DEPRECATED("Use Widget::setWidgetName instead") bool setWidgetName(const Widget::Ptr& widget, const std::string& name);


/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Expand All @@ -312,8 +312,8 @@ namespace tgui
/// @return Name of the widget or an empty string when the widget didn't exist or wasn't given a name
///
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
std::string getWidgetName(const Widget::Ptr& widget) const;

TGUI_DEPRECATED("Use Widget::getWidgetName instead") std::string getWidgetName(const Widget::Ptr& widget) const;
#endif

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// @brief Focuses the next widget
Expand Down
Loading

0 comments on commit 72caf05

Please sign in to comment.