diff --git a/changelog.md b/changelog.md index 90b028cfd..16b33803f 100644 --- a/changelog.md +++ b/changelog.md @@ -1,3 +1,9 @@ +TGUI 1.7 (TBD) +--------------- + +- New widgets: GrowHorizontalLayout and GrowVerticalLayout + + TGUI 1.6.1 (8 October 2024) ---------------------------- diff --git a/include/TGUI/AllWidgets.hpp b/include/TGUI/AllWidgets.hpp index 108eeb5b8..d5d25b27e 100644 --- a/include/TGUI/AllWidgets.hpp +++ b/include/TGUI/AllWidgets.hpp @@ -40,6 +40,8 @@ #include #include #include +#include +#include #include #include #include diff --git a/include/TGUI/String.hpp b/include/TGUI/String.hpp index 26be30d0a..8c745939a 100644 --- a/include/TGUI/String.hpp +++ b/include/TGUI/String.hpp @@ -441,7 +441,11 @@ TGUI_MODULE_EXPORT namespace tgui #if TGUI_HAS_WINDOW_BACKEND_SFML // This constructor has to be explicit or it will cause MSVC to no longer compile code that performs sf::String + std::string explicit String(const sf::String& str) + #if SFML_VERSION_MAJOR >= 3 + : m_string{str.toUtf32()} + #else : m_string{reinterpret_cast(str.toUtf32().c_str())} + #endif { } diff --git a/include/TGUI/Widgets/GrowHorizontalLayout.hpp b/include/TGUI/Widgets/GrowHorizontalLayout.hpp new file mode 100644 index 000000000..179e9c353 --- /dev/null +++ b/include/TGUI/Widgets/GrowHorizontalLayout.hpp @@ -0,0 +1,144 @@ +///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// +// TGUI - Texus' Graphical User Interface +// Copyright (C) 2012-2024 Bruno Van de Velde (vdv_b@tgui.eu) +// +// This software is provided 'as-is', without any express or implied warranty. +// In no event will the authors be held liable for any damages arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it freely, +// subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; +// you must not claim that you wrote the original software. +// If you use this software in a product, an acknowledgment +// in the product documentation would be appreciated but is not required. +// +// 2. Altered source versions must be plainly marked as such, +// and must not be misrepresented as being the original software. +// +// 3. This notice may not be removed or altered from any source distribution. +// +///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +#ifndef TGUI_GROW_HORIZONTAL_LAYOUT_HPP +#define TGUI_GROW_HORIZONTAL_LAYOUT_HPP + +#include + +///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +TGUI_MODULE_EXPORT namespace tgui +{ + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + /// @brief Container that automatically positions children beside each other. + /// + /// The width of child widgets isn't altered, while the height is changed to match that of the horizontal layout. + /// With each widget that gets added, the width of the horizontal layout increases to fit the new widget. + /// + /// If you want the layout to have a fixed size and want children resized to fill the area then check HorizontalLayout instead. + /// + /// @since TGUI 1.7 + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + class TGUI_API GrowHorizontalLayout : public BoxLayout + { + public: + using Ptr = std::shared_ptr; //!< Shared widget pointer + using ConstPtr = std::shared_ptr; //!< Shared constant widget pointer + + static constexpr const char StaticWidgetType[] = "GrowHorizontalLayout"; //!< Type name of the widget + + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + /// @internal + /// @brief Constructor + /// @param typeName Type of the widget + /// @param initRenderer Should the renderer be initialized? Should be true unless a derived class initializes it. + /// @see create + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + GrowHorizontalLayout(const char* typeName = StaticWidgetType, bool initRenderer = true); + + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + /// @brief Copy constructor + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + GrowHorizontalLayout(const GrowHorizontalLayout&); + + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + /// @brief Move constructor + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + GrowHorizontalLayout(GrowHorizontalLayout&&) noexcept; + + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + /// @brief Overload of copy assignment operator + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + GrowHorizontalLayout& operator=(const GrowHorizontalLayout&); + + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + /// @brief Move assignment + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + GrowHorizontalLayout& operator=(GrowHorizontalLayout&&) noexcept; + + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + /// @brief Destructor + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + ~GrowHorizontalLayout() = default; + + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + /// @brief Creates a new horizontal layout widget + /// + /// @param height Height of the horizontal layout + /// + /// @return The new horizontal layout + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + TGUI_NODISCARD static GrowHorizontalLayout::Ptr create(const Layout& width = {RelativeValue(1)}); + + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + /// @brief Makes a copy of another layout + /// + /// @param layout The other layout + /// + /// @return The new layout + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + TGUI_NODISCARD static GrowHorizontalLayout::Ptr copy(const GrowHorizontalLayout::ConstPtr& layout); + + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + /// @brief Returns the space available for widgets inside the container + /// @return Size of the container + /// + /// @warning The width returned by this function is always 0. This is to prevent child widgets from depending on the + /// width of the horizontal layout (which isn't allowed as the width of the layout depends on its children). + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + TGUI_NODISCARD Vector2f getInnerSize() const override; + + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + /// @brief Removes all widgets that were added to the container + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + void removeAllWidgets() override; + + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + protected: + + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + // @brief Repositions and resize the widgets + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + void updateWidgets() override; + + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + // @brief Makes a copy of the widget + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + TGUI_NODISCARD Widget::Ptr clone() const override; + + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + protected: + + std::vector m_widgetLayouts; + + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + }; + + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +} + +///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +#endif // TGUI_GROW_HORIZONTAL_LAYOUT_HPP diff --git a/include/TGUI/Widgets/GrowVerticalLayout.hpp b/include/TGUI/Widgets/GrowVerticalLayout.hpp new file mode 100644 index 000000000..b3e3217c1 --- /dev/null +++ b/include/TGUI/Widgets/GrowVerticalLayout.hpp @@ -0,0 +1,144 @@ +///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// +// TGUI - Texus' Graphical User Interface +// Copyright (C) 2012-2024 Bruno Van de Velde (vdv_b@tgui.eu) +// +// This software is provided 'as-is', without any express or implied warranty. +// In no event will the authors be held liable for any damages arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it freely, +// subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; +// you must not claim that you wrote the original software. +// If you use this software in a product, an acknowledgment +// in the product documentation would be appreciated but is not required. +// +// 2. Altered source versions must be plainly marked as such, +// and must not be misrepresented as being the original software. +// +// 3. This notice may not be removed or altered from any source distribution. +// +///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +#ifndef TGUI_GROW_VERTICAL_LAYOUT_HPP +#define TGUI_GROW_VERTICAL_LAYOUT_HPP + +#include + +///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +TGUI_MODULE_EXPORT namespace tgui +{ + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + /// @brief Container that automatically positions children below each other. + /// + /// The height of child widgets isn't altered, while the width is changed to match that of the vertical layout. + /// With each widget that gets added, the height of the vertical layout increases to fit the new widget. + /// + /// If you want the layout to have a fixed size and want children resized to fill the area then check VerticalLayout instead. + /// + /// @since TGUI 1.7 + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + class TGUI_API GrowVerticalLayout : public BoxLayout + { + public: + using Ptr = std::shared_ptr; //!< Shared widget pointer + using ConstPtr = std::shared_ptr; //!< Shared constant widget pointer + + static constexpr const char StaticWidgetType[] = "GrowVerticalLayout"; //!< Type name of the widget + + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + /// @internal + /// @brief Constructor + /// @param typeName Type of the widget + /// @param initRenderer Should the renderer be initialized? Should be true unless a derived class initializes it. + /// @see create + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + GrowVerticalLayout(const char* typeName = StaticWidgetType, bool initRenderer = true); + + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + /// @brief Copy constructor + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + GrowVerticalLayout(const GrowVerticalLayout&); + + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + /// @brief Move constructor + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + GrowVerticalLayout(GrowVerticalLayout&&) noexcept; + + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + /// @brief Overload of copy assignment operator + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + GrowVerticalLayout& operator=(const GrowVerticalLayout&); + + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + /// @brief Move assignment + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + GrowVerticalLayout& operator=(GrowVerticalLayout&&) noexcept; + + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + /// @brief Destructor + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + ~GrowVerticalLayout() = default; + + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + /// @brief Creates a new vertical layout widget + /// + /// @param width Width of the vertical layout + /// + /// @return The new vertical layout + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + TGUI_NODISCARD static GrowVerticalLayout::Ptr create(const Layout& width = {RelativeValue(1)}); + + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + /// @brief Makes a copy of another layout + /// + /// @param layout The other layout + /// + /// @return The new layout + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + TGUI_NODISCARD static GrowVerticalLayout::Ptr copy(const GrowVerticalLayout::ConstPtr& layout); + + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + /// @brief Returns the space available for widgets inside the container + /// @return Size of the container + /// + /// @warning The height returned by this function is always 0. This is to prevent child widgets from depending on the + /// height of the vertical layout (which isn't allowed as the height of the layout depends on its children). + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + TGUI_NODISCARD Vector2f getInnerSize() const override; + + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + /// @brief Removes all widgets that were added to the container + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + void removeAllWidgets() override; + + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + protected: + + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + // @brief Repositions and resize the widgets + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + void updateWidgets() override; + + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + // @brief Makes a copy of the widget + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + TGUI_NODISCARD Widget::Ptr clone() const override; + + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + protected: + + std::vector m_widgetLayouts; + + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + }; + + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +} + +///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +#endif // TGUI_GROW_VERTICAL_LAYOUT_HPP diff --git a/include/TGUI/Widgets/HorizontalLayout.hpp b/include/TGUI/Widgets/HorizontalLayout.hpp index 38074620d..e65ae21b3 100644 --- a/include/TGUI/Widgets/HorizontalLayout.hpp +++ b/include/TGUI/Widgets/HorizontalLayout.hpp @@ -35,6 +35,9 @@ TGUI_MODULE_EXPORT namespace tgui /// @brief Container that automatically resizes children to fit the entire available space between children. /// /// The children are positioned side by side. + /// + /// If you don't want the width of child widgets to be altered and instead want the horizontal layout to grow in size as new + /// widgets are added, then check out the GrowHorizontalLayout instead. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// class TGUI_API HorizontalLayout : public BoxLayoutRatios { diff --git a/include/TGUI/Widgets/VerticalLayout.hpp b/include/TGUI/Widgets/VerticalLayout.hpp index 1af33d390..4dcb6a2b5 100644 --- a/include/TGUI/Widgets/VerticalLayout.hpp +++ b/include/TGUI/Widgets/VerticalLayout.hpp @@ -35,6 +35,9 @@ TGUI_MODULE_EXPORT namespace tgui /// @brief Container that automatically resizes children to fit the entire available space between children /// /// The children are stacked vertically. + /// + /// If you don't want the height of child widgets to be altered and instead want the vertical layout to grow in size as new + /// widgets are added, then check out the GrowVerticalLayout instead. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// class TGUI_API VerticalLayout : public BoxLayoutRatios { diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 2bf062699..38ab6daeb 100755 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -111,6 +111,8 @@ set(TGUI_SRC Widgets/FileDialog.cpp Widgets/Group.cpp Widgets/Grid.cpp + Widgets/GrowHorizontalLayout.cpp + Widgets/GrowVerticalLayout.cpp Widgets/HorizontalLayout.cpp Widgets/HorizontalWrap.cpp Widgets/Knob.cpp @@ -248,97 +250,100 @@ set(TGUI_HEADERS "${PROJECT_SOURCE_DIR}/include/TGUI/Backend/Font/SFML-Graphics/BackendFontSFML.hpp" "${PROJECT_SOURCE_DIR}/include/TGUI/Backend/Font/Raylib/BackendFontRaylib.hpp" "${PROJECT_SOURCE_DIR}/include/TGUI/Backend/Font/FreeType/BackendFontFreeType.hpp" + "${PROJECT_SOURCE_DIR}/include/TGUI/Loading/DataIO.hpp" + "${PROJECT_SOURCE_DIR}/include/TGUI/Loading/Deserializer.hpp" "${PROJECT_SOURCE_DIR}/include/TGUI/Loading/ImageLoader.hpp" "${PROJECT_SOURCE_DIR}/include/TGUI/Loading/Serializer.hpp" - "${PROJECT_SOURCE_DIR}/include/TGUI/Loading/ThemeLoader.hpp" "${PROJECT_SOURCE_DIR}/include/TGUI/Loading/Theme.hpp" - "${PROJECT_SOURCE_DIR}/include/TGUI/Loading/DataIO.hpp" - "${PROJECT_SOURCE_DIR}/include/TGUI/Loading/Deserializer.hpp" + "${PROJECT_SOURCE_DIR}/include/TGUI/Loading/ThemeLoader.hpp" "${PROJECT_SOURCE_DIR}/include/TGUI/Loading/WidgetFactory.hpp" + "${PROJECT_SOURCE_DIR}/include/TGUI/Renderers/BoxLayoutRenderer.hpp" + "${PROJECT_SOURCE_DIR}/include/TGUI/Renderers/ButtonRenderer.hpp" + "${PROJECT_SOURCE_DIR}/include/TGUI/Renderers/ChatBoxRenderer.hpp" + "${PROJECT_SOURCE_DIR}/include/TGUI/Renderers/CheckBoxRenderer.hpp" "${PROJECT_SOURCE_DIR}/include/TGUI/Renderers/ChildWindowRenderer.hpp" + "${PROJECT_SOURCE_DIR}/include/TGUI/Renderers/ColorPickerRenderer.hpp" + "${PROJECT_SOURCE_DIR}/include/TGUI/Renderers/ComboBoxRenderer.hpp" + "${PROJECT_SOURCE_DIR}/include/TGUI/Renderers/EditBoxRenderer.hpp" + "${PROJECT_SOURCE_DIR}/include/TGUI/Renderers/FileDialogRenderer.hpp" + "${PROJECT_SOURCE_DIR}/include/TGUI/Renderers/GroupRenderer.hpp" + "${PROJECT_SOURCE_DIR}/include/TGUI/Renderers/KnobRenderer.hpp" + "${PROJECT_SOURCE_DIR}/include/TGUI/Renderers/LabelRenderer.hpp" + "${PROJECT_SOURCE_DIR}/include/TGUI/Renderers/ListBoxRenderer.hpp" "${PROJECT_SOURCE_DIR}/include/TGUI/Renderers/ListViewRenderer.hpp" - "${PROJECT_SOURCE_DIR}/include/TGUI/Renderers/ProgressBarRenderer.hpp" + "${PROJECT_SOURCE_DIR}/include/TGUI/Renderers/MenuBarRenderer.hpp" "${PROJECT_SOURCE_DIR}/include/TGUI/Renderers/MessageBoxRenderer.hpp" - "${PROJECT_SOURCE_DIR}/include/TGUI/Renderers/PictureRenderer.hpp" - "${PROJECT_SOURCE_DIR}/include/TGUI/Renderers/ChatBoxRenderer.hpp" - "${PROJECT_SOURCE_DIR}/include/TGUI/Renderers/KnobRenderer.hpp" - "${PROJECT_SOURCE_DIR}/include/TGUI/Renderers/ButtonRenderer.hpp" - "${PROJECT_SOURCE_DIR}/include/TGUI/Renderers/ComboBoxRenderer.hpp" - "${PROJECT_SOURCE_DIR}/include/TGUI/Renderers/TextAreaRenderer.hpp" "${PROJECT_SOURCE_DIR}/include/TGUI/Renderers/PanelListBoxRenderer.hpp" "${PROJECT_SOURCE_DIR}/include/TGUI/Renderers/PanelRenderer.hpp" - "${PROJECT_SOURCE_DIR}/include/TGUI/Renderers/BoxLayoutRenderer.hpp" - "${PROJECT_SOURCE_DIR}/include/TGUI/Renderers/TreeViewRenderer.hpp" - "${PROJECT_SOURCE_DIR}/include/TGUI/Renderers/LabelRenderer.hpp" - "${PROJECT_SOURCE_DIR}/include/TGUI/Renderers/WidgetRenderer.hpp" - "${PROJECT_SOURCE_DIR}/include/TGUI/Renderers/GroupRenderer.hpp" - "${PROJECT_SOURCE_DIR}/include/TGUI/Renderers/EditBoxRenderer.hpp" - "${PROJECT_SOURCE_DIR}/include/TGUI/Renderers/RangeSliderRenderer.hpp" - "${PROJECT_SOURCE_DIR}/include/TGUI/Renderers/SplitContainerRenderer.hpp" - "${PROJECT_SOURCE_DIR}/include/TGUI/Renderers/FileDialogRenderer.hpp" + "${PROJECT_SOURCE_DIR}/include/TGUI/Renderers/PictureRenderer.hpp" + "${PROJECT_SOURCE_DIR}/include/TGUI/Renderers/ProgressBarRenderer.hpp" "${PROJECT_SOURCE_DIR}/include/TGUI/Renderers/RadioButtonRenderer.hpp" + "${PROJECT_SOURCE_DIR}/include/TGUI/Renderers/RangeSliderRenderer.hpp" + "${PROJECT_SOURCE_DIR}/include/TGUI/Renderers/ScrollablePanelRenderer.hpp" "${PROJECT_SOURCE_DIR}/include/TGUI/Renderers/ScrollbarRenderer.hpp" - "${PROJECT_SOURCE_DIR}/include/TGUI/Renderers/TabsRenderer.hpp" "${PROJECT_SOURCE_DIR}/include/TGUI/Renderers/SeparatorLineRenderer.hpp" "${PROJECT_SOURCE_DIR}/include/TGUI/Renderers/SliderRenderer.hpp" "${PROJECT_SOURCE_DIR}/include/TGUI/Renderers/SpinButtonRenderer.hpp" + "${PROJECT_SOURCE_DIR}/include/TGUI/Renderers/SplitContainerRenderer.hpp" + "${PROJECT_SOURCE_DIR}/include/TGUI/Renderers/TabsRenderer.hpp" + "${PROJECT_SOURCE_DIR}/include/TGUI/Renderers/TextAreaRenderer.hpp" "${PROJECT_SOURCE_DIR}/include/TGUI/Renderers/TextBoxRenderer.hpp" - "${PROJECT_SOURCE_DIR}/include/TGUI/Renderers/CheckBoxRenderer.hpp" - "${PROJECT_SOURCE_DIR}/include/TGUI/Renderers/ColorPickerRenderer.hpp" - "${PROJECT_SOURCE_DIR}/include/TGUI/Renderers/ListBoxRenderer.hpp" - "${PROJECT_SOURCE_DIR}/include/TGUI/Renderers/MenuBarRenderer.hpp" - "${PROJECT_SOURCE_DIR}/include/TGUI/Renderers/ScrollablePanelRenderer.hpp" - "${PROJECT_SOURCE_DIR}/include/TGUI/Widgets/ComboBox.hpp" - "${PROJECT_SOURCE_DIR}/include/TGUI/Widgets/VerticalLayout.hpp" - "${PROJECT_SOURCE_DIR}/include/TGUI/Widgets/MessageBox.hpp" - "${PROJECT_SOURCE_DIR}/include/TGUI/Widgets/Group.hpp" - "${PROJECT_SOURCE_DIR}/include/TGUI/Widgets/FileDialog.hpp" - "${PROJECT_SOURCE_DIR}/include/TGUI/Widgets/Knob.hpp" - "${PROJECT_SOURCE_DIR}/include/TGUI/Widgets/ButtonBase.hpp" + "${PROJECT_SOURCE_DIR}/include/TGUI/Renderers/TreeViewRenderer.hpp" + "${PROJECT_SOURCE_DIR}/include/TGUI/Renderers/WidgetRenderer.hpp" "${PROJECT_SOURCE_DIR}/include/TGUI/Widgets/BitmapButton.hpp" - "${PROJECT_SOURCE_DIR}/include/TGUI/Widgets/RangeSlider.hpp" + "${PROJECT_SOURCE_DIR}/include/TGUI/Widgets/BoxLayout.hpp" + "${PROJECT_SOURCE_DIR}/include/TGUI/Widgets/BoxLayoutRatios.hpp" + "${PROJECT_SOURCE_DIR}/include/TGUI/Widgets/ButtonBase.hpp" "${PROJECT_SOURCE_DIR}/include/TGUI/Widgets/Button.hpp" - "${PROJECT_SOURCE_DIR}/include/TGUI/Widgets/SpinControl.hpp" "${PROJECT_SOURCE_DIR}/include/TGUI/Widgets/CanvasBase.hpp" - "${PROJECT_SOURCE_DIR}/include/TGUI/Widgets/RadioButtonGroup.hpp" - "${PROJECT_SOURCE_DIR}/include/TGUI/Widgets/ToggleButton.hpp" + "${PROJECT_SOURCE_DIR}/include/TGUI/Widgets/ChatBox.hpp" + "${PROJECT_SOURCE_DIR}/include/TGUI/Widgets/CheckBox.hpp" + "${PROJECT_SOURCE_DIR}/include/TGUI/Widgets/ChildWindow.hpp" + "${PROJECT_SOURCE_DIR}/include/TGUI/Widgets/ClickableWidget.hpp" + "${PROJECT_SOURCE_DIR}/include/TGUI/Widgets/ColorPicker.hpp" + "${PROJECT_SOURCE_DIR}/include/TGUI/Widgets/ComboBox.hpp" + "${PROJECT_SOURCE_DIR}/include/TGUI/Widgets/EditBox.hpp" + "${PROJECT_SOURCE_DIR}/include/TGUI/Widgets/EditBoxSlider.hpp" + "${PROJECT_SOURCE_DIR}/include/TGUI/Widgets/FileDialog.hpp" "${PROJECT_SOURCE_DIR}/include/TGUI/Widgets/Grid.hpp" + "${PROJECT_SOURCE_DIR}/include/TGUI/Widgets/Group.hpp" + "${PROJECT_SOURCE_DIR}/include/TGUI/Widgets/GrowHorizontalLayout.hpp" + "${PROJECT_SOURCE_DIR}/include/TGUI/Widgets/GrowVerticalLayout.hpp" + "${PROJECT_SOURCE_DIR}/include/TGUI/Widgets/HorizontalLayout.hpp" + "${PROJECT_SOURCE_DIR}/include/TGUI/Widgets/HorizontalWrap.hpp" + "${PROJECT_SOURCE_DIR}/include/TGUI/Widgets/Knob.hpp" + "${PROJECT_SOURCE_DIR}/include/TGUI/Widgets/Label.hpp" "${PROJECT_SOURCE_DIR}/include/TGUI/Widgets/ListBox.hpp" "${PROJECT_SOURCE_DIR}/include/TGUI/Widgets/ListView.hpp" - "${PROJECT_SOURCE_DIR}/include/TGUI/Widgets/HorizontalWrap.hpp" - "${PROJECT_SOURCE_DIR}/include/TGUI/Widgets/ClickableWidget.hpp" "${PROJECT_SOURCE_DIR}/include/TGUI/Widgets/MenuBar.hpp" - "${PROJECT_SOURCE_DIR}/include/TGUI/Widgets/SeparatorLine.hpp" - "${PROJECT_SOURCE_DIR}/include/TGUI/Widgets/ColorPicker.hpp" - "${PROJECT_SOURCE_DIR}/include/TGUI/Widgets/CheckBox.hpp" - "${PROJECT_SOURCE_DIR}/include/TGUI/Widgets/Scrollbar.hpp" - "${PROJECT_SOURCE_DIR}/include/TGUI/Widgets/PanelListBox.hpp" - "${PROJECT_SOURCE_DIR}/include/TGUI/Widgets/TreeView.hpp" - "${PROJECT_SOURCE_DIR}/include/TGUI/Widgets/Label.hpp" + "${PROJECT_SOURCE_DIR}/include/TGUI/Widgets/MessageBox.hpp" "${PROJECT_SOURCE_DIR}/include/TGUI/Widgets/Panel.hpp" - "${PROJECT_SOURCE_DIR}/include/TGUI/Widgets/BoxLayoutRatios.hpp" + "${PROJECT_SOURCE_DIR}/include/TGUI/Widgets/PanelListBox.hpp" "${PROJECT_SOURCE_DIR}/include/TGUI/Widgets/Picture.hpp" - "${PROJECT_SOURCE_DIR}/include/TGUI/Widgets/SpinButton.hpp" - "${PROJECT_SOURCE_DIR}/include/TGUI/Widgets/SplitContainer.hpp" - "${PROJECT_SOURCE_DIR}/include/TGUI/Widgets/EditBox.hpp" - "${PROJECT_SOURCE_DIR}/include/TGUI/Widgets/ChatBox.hpp" + "${PROJECT_SOURCE_DIR}/include/TGUI/Widgets/ProgressBar.hpp" + "${PROJECT_SOURCE_DIR}/include/TGUI/Widgets/RadioButtonGroup.hpp" "${PROJECT_SOURCE_DIR}/include/TGUI/Widgets/RadioButton.hpp" - "${PROJECT_SOURCE_DIR}/include/TGUI/Widgets/Slider.hpp" + "${PROJECT_SOURCE_DIR}/include/TGUI/Widgets/RangeSlider.hpp" + "${PROJECT_SOURCE_DIR}/include/TGUI/Widgets/RichTextLabel.hpp" "${PROJECT_SOURCE_DIR}/include/TGUI/Widgets/ScrollablePanel.hpp" + "${PROJECT_SOURCE_DIR}/include/TGUI/Widgets/Scrollbar.hpp" + "${PROJECT_SOURCE_DIR}/include/TGUI/Widgets/SeparatorLine.hpp" + "${PROJECT_SOURCE_DIR}/include/TGUI/Widgets/Slider.hpp" + "${PROJECT_SOURCE_DIR}/include/TGUI/Widgets/SpinButton.hpp" + "${PROJECT_SOURCE_DIR}/include/TGUI/Widgets/SpinControl.hpp" + "${PROJECT_SOURCE_DIR}/include/TGUI/Widgets/SplitContainer.hpp" + "${PROJECT_SOURCE_DIR}/include/TGUI/Widgets/TabContainer.hpp" "${PROJECT_SOURCE_DIR}/include/TGUI/Widgets/Tabs.hpp" - "${PROJECT_SOURCE_DIR}/include/TGUI/Widgets/BoxLayout.hpp" - "${PROJECT_SOURCE_DIR}/include/TGUI/Widgets/HorizontalLayout.hpp" "${PROJECT_SOURCE_DIR}/include/TGUI/Widgets/TextArea.hpp" - "${PROJECT_SOURCE_DIR}/include/TGUI/Widgets/TabContainer.hpp" - "${PROJECT_SOURCE_DIR}/include/TGUI/Widgets/ChildWindow.hpp" - "${PROJECT_SOURCE_DIR}/include/TGUI/Widgets/RichTextLabel.hpp" - "${PROJECT_SOURCE_DIR}/include/TGUI/Widgets/ProgressBar.hpp" - "${PROJECT_SOURCE_DIR}/include/TGUI/Widgets/EditBoxSlider.hpp" - "${PROJECT_SOURCE_DIR}/include/TGUI/extlibs/IncludeWindows.hpp" + "${PROJECT_SOURCE_DIR}/include/TGUI/Widgets/ToggleButton.hpp" + "${PROJECT_SOURCE_DIR}/include/TGUI/Widgets/TreeView.hpp" + "${PROJECT_SOURCE_DIR}/include/TGUI/Widgets/VerticalLayout.hpp" + "${PROJECT_SOURCE_DIR}/include/TGUI/extlibs/IncludeNanoSVG.hpp" "${PROJECT_SOURCE_DIR}/include/TGUI/extlibs/IncludeSDL.hpp" "${PROJECT_SOURCE_DIR}/include/TGUI/extlibs/IncludeStbImage.hpp" - "${PROJECT_SOURCE_DIR}/include/TGUI/extlibs/IncludeNanoSVG.hpp" "${PROJECT_SOURCE_DIR}/include/TGUI/extlibs/IncludeStbImageWrite.hpp" + "${PROJECT_SOURCE_DIR}/include/TGUI/extlibs/IncludeWindows.hpp" + ) if(TGUI_OS_WINDOWS) diff --git a/src/FileDialogIconLoaderLinux.cpp b/src/FileDialogIconLoaderLinux.cpp index f31e51a30..df9865ce3 100644 --- a/src/FileDialogIconLoaderLinux.cpp +++ b/src/FileDialogIconLoaderLinux.cpp @@ -425,7 +425,7 @@ namespace tgui Filesystem::Path("/usr/share/icons/hicolor/48x48/places/"), }; - std::map> foundIcons; + std::map> foundIcons; for (std::size_t i = 0; i < potentialIconPaths.size(); ++i) { const Filesystem::Path& iconDir = potentialIconPaths[i]; @@ -449,7 +449,7 @@ namespace tgui continue; // If both an SVG and a PNG file exist then we will select the svg file - int themeIconPriority = 10 * themePriority; + std::size_t themeIconPriority = 10 * themePriority; if (isSvg) themeIconPriority += 2; else if (isPng) diff --git a/src/Loading/ThemeLoader.cpp b/src/Loading/ThemeLoader.cpp index aa38ff75e..262045ec9 100644 --- a/src/Loading/ThemeLoader.cpp +++ b/src/Loading/ThemeLoader.cpp @@ -269,7 +269,7 @@ namespace tgui throw Exception{U"Failed to open theme file '" + fullFilename + U"'."}; std::stringstream stream; - stream.write(reinterpret_cast(fileContents.get()), static_cast(fileSize)); + stream.write(reinterpret_cast(fileContents.get()), static_cast(fileSize)); std::unique_ptr root = DataIO::parse(stream); diff --git a/src/Loading/WidgetFactory.cpp b/src/Loading/WidgetFactory.cpp index cf37a0e8b..340454024 100644 --- a/src/Loading/WidgetFactory.cpp +++ b/src/Loading/WidgetFactory.cpp @@ -44,6 +44,8 @@ namespace tgui {"FileDialog", std::make_shared}, {"Grid", std::make_shared}, {"Group", std::make_shared}, + {"GrowHorizontalLayout", std::make_shared}, + {"GrowVerticalLayout", std::make_shared}, {"HorizontalLayout", std::make_shared}, {"HorizontalWrap", std::make_shared}, {"Knob", std::make_shared}, diff --git a/src/Widgets/ButtonBase.cpp b/src/Widgets/ButtonBase.cpp index 820a21394..89d9893e1 100644 --- a/src/Widgets/ButtonBase.cpp +++ b/src/Widgets/ButtonBase.cpp @@ -138,7 +138,7 @@ namespace tgui { text.style.disconnectCallback(m_textStyleChangedCallbackId); - ClickableWidget::operator=(other); + ClickableWidget::operator=(std::move(other)); m_string = std::move(other.m_string); m_down = std::move(other.m_down); m_state = std::move(other.m_state); diff --git a/src/Widgets/GrowHorizontalLayout.cpp b/src/Widgets/GrowHorizontalLayout.cpp new file mode 100644 index 000000000..97124e1ef --- /dev/null +++ b/src/Widgets/GrowHorizontalLayout.cpp @@ -0,0 +1,184 @@ +///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// +// TGUI - Texus' Graphical User Interface +// Copyright (C) 2012-2024 Bruno Van de Velde (vdv_b@tgui.eu) +// +// This software is provided 'as-is', without any express or implied warranty. +// In no event will the authors be held liable for any damages arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it freely, +// subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; +// you must not claim that you wrote the original software. +// If you use this software in a product, an acknowledgment +// in the product documentation would be appreciated but is not required. +// +// 2. Altered source versions must be plainly marked as such, +// and must not be misrepresented as being the original software. +// +// 3. This notice may not be removed or altered from any source distribution. +// +///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +#include + +///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +namespace tgui +{ +#if TGUI_COMPILED_WITH_CPP_VER < 17 + constexpr const char GrowHorizontalLayout::StaticWidgetType[]; +#endif + + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + + GrowHorizontalLayout::GrowHorizontalLayout(const char* typeName, bool initRenderer) : + BoxLayout{typeName, false} + { + if (initRenderer) + { + m_renderer = aurora::makeCopied(); + setRenderer(Theme::getDefault()->getRendererNoThrow(m_type)); + } + } + + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + + GrowHorizontalLayout::GrowHorizontalLayout(const GrowHorizontalLayout& other) : + BoxLayout {other}, + m_widgetLayouts{} + { + GrowHorizontalLayout::updateWidgets(); + } + + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + + GrowHorizontalLayout::GrowHorizontalLayout(GrowHorizontalLayout&& other) noexcept : + BoxLayout {std::move(other)}, + m_widgetLayouts{} + { + GrowHorizontalLayout::updateWidgets(); + } + + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + + GrowHorizontalLayout& GrowHorizontalLayout::operator=(const GrowHorizontalLayout& other) + { + if (&other != this) + { + BoxLayout::operator=(other); + m_widgetLayouts = {}; + + GrowHorizontalLayout::updateWidgets(); + } + + return *this; + } + + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + + GrowHorizontalLayout& GrowHorizontalLayout::operator=(GrowHorizontalLayout&& other) noexcept + { + if (&other != this) + { + BoxLayout::operator=(std::move(other)); + m_widgetLayouts = {}; + + GrowHorizontalLayout::updateWidgets(); + } + + return *this; + } + + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + + GrowHorizontalLayout::Ptr GrowHorizontalLayout::create(const Layout& width) + { + auto layout = std::make_shared(); + layout->setWidth(width); + return layout; + } + + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + + GrowHorizontalLayout::Ptr GrowHorizontalLayout::copy(const GrowHorizontalLayout::ConstPtr& layout) + { + if (layout) + return std::static_pointer_cast(layout->clone()); + else + return nullptr; + } + + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + + void GrowHorizontalLayout::updateWidgets() + { + m_widgetLayouts.clear(); + + const float contentHeight = std::max(0.f, getSize().y - m_paddingCached.getTop() - m_paddingCached.getBottom()); + + float currentOffset = 0; + for (const auto& widget : m_widgets) + { + widget->setPosition({currentOffset, 0}); + widget->setHeight(contentHeight); + + // Correct the size for widgets that are bigger than what you set (e.g. have borders around it or a text next to them) + if (widget->getFullSize() != widget->getSize()) + { + const float newHeight = widget->getSize().y - (widget->getFullSize().y - widget->getSize().y); + if (newHeight > 0) + { + widget->setHeight(newHeight); + widget->setPosition(widget->getPosition() - widget->getWidgetOffset()); + } + } + + currentOffset += widget->getFullSize().x + m_spaceBetweenWidgetsCached; + } + + float layoutWidth = currentOffset + m_paddingCached.getLeft() + m_paddingCached.getRight(); + if (!m_widgets.empty()) + layoutWidth -= m_spaceBetweenWidgetsCached; // There is no padding below the last widget + + // Call the function from Widget instead of BoxLayout to prevent an infinite loop + // NOLINTNEXTLINE(bugprone-parent-virtual-call) + Widget::setSize({layoutWidth, getSizeLayout().y}); + + // Bind layouts to the child widgets so that we can recalculate the positions when the width of one of them changes + m_widgetLayouts.reserve(m_widgets.size()); + for (const auto& widget : m_widgets) + { + m_widgetLayouts.push_back(bindWidth(widget)); + m_widgetLayouts.back().connectWidget(this, true, [this]{ updateWidgets(); }); + } + } + + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + + Widget::Ptr GrowHorizontalLayout::clone() const + { + return std::make_shared(*this); + } + + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + + Vector2f GrowHorizontalLayout::getInnerSize() const + { + return {0.f, BoxLayout::getInnerSize().y}; + } + + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + + void GrowHorizontalLayout::removeAllWidgets() + { + BoxLayout::removeAllWidgets(); + updateWidgets(); + } + + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +} + +///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/src/Widgets/GrowVerticalLayout.cpp b/src/Widgets/GrowVerticalLayout.cpp new file mode 100644 index 000000000..20731ed49 --- /dev/null +++ b/src/Widgets/GrowVerticalLayout.cpp @@ -0,0 +1,184 @@ +///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// +// TGUI - Texus' Graphical User Interface +// Copyright (C) 2012-2024 Bruno Van de Velde (vdv_b@tgui.eu) +// +// This software is provided 'as-is', without any express or implied warranty. +// In no event will the authors be held liable for any damages arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it freely, +// subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; +// you must not claim that you wrote the original software. +// If you use this software in a product, an acknowledgment +// in the product documentation would be appreciated but is not required. +// +// 2. Altered source versions must be plainly marked as such, +// and must not be misrepresented as being the original software. +// +// 3. This notice may not be removed or altered from any source distribution. +// +///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +#include + +///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +namespace tgui +{ +#if TGUI_COMPILED_WITH_CPP_VER < 17 + constexpr const char GrowVerticalLayout::StaticWidgetType[]; +#endif + + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + + GrowVerticalLayout::GrowVerticalLayout(const char* typeName, bool initRenderer) : + BoxLayout{typeName, false} + { + if (initRenderer) + { + m_renderer = aurora::makeCopied(); + setRenderer(Theme::getDefault()->getRendererNoThrow(m_type)); + } + } + + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + + GrowVerticalLayout::GrowVerticalLayout(const GrowVerticalLayout& other) : + BoxLayout {other}, + m_widgetLayouts{} + { + GrowVerticalLayout::updateWidgets(); + } + + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + + GrowVerticalLayout::GrowVerticalLayout(GrowVerticalLayout&& other) noexcept : + BoxLayout {std::move(other)}, + m_widgetLayouts{} + { + GrowVerticalLayout::updateWidgets(); + } + + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + + GrowVerticalLayout& GrowVerticalLayout::operator=(const GrowVerticalLayout& other) + { + if (&other != this) + { + BoxLayout::operator=(other); + m_widgetLayouts = {}; + + GrowVerticalLayout::updateWidgets(); + } + + return *this; + } + + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + + GrowVerticalLayout& GrowVerticalLayout::operator=(GrowVerticalLayout&& other) noexcept + { + if (&other != this) + { + BoxLayout::operator=(std::move(other)); + m_widgetLayouts = {}; + + GrowVerticalLayout::updateWidgets(); + } + + return *this; + } + + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + + GrowVerticalLayout::Ptr GrowVerticalLayout::create(const Layout& width) + { + auto layout = std::make_shared(); + layout->setWidth(width); + return layout; + } + + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + + GrowVerticalLayout::Ptr GrowVerticalLayout::copy(const GrowVerticalLayout::ConstPtr& layout) + { + if (layout) + return std::static_pointer_cast(layout->clone()); + else + return nullptr; + } + + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + + void GrowVerticalLayout::updateWidgets() + { + m_widgetLayouts.clear(); + + const float contentWidth = std::max(0.f, getSize().x - m_paddingCached.getLeft() - m_paddingCached.getRight()); + + float currentOffset = 0; + for (const auto& widget : m_widgets) + { + widget->setPosition({0, currentOffset}); + widget->setWidth(contentWidth); + + // Correct the size for widgets that are bigger than what you set (e.g. have borders around it or a text next to them) + if (widget->getFullSize().x != widget->getSize().x) + { + const float newWidth = widget->getSize().x - (widget->getFullSize().x - widget->getSize().x); + if (newWidth > 0) + { + widget->setWidth(newWidth); + widget->setPosition(widget->getPosition() - widget->getWidgetOffset()); + } + } + + currentOffset += widget->getFullSize().y + m_spaceBetweenWidgetsCached; + } + + float layoutHeight = currentOffset + m_paddingCached.getTop() + m_paddingCached.getBottom(); + if (!m_widgets.empty()) + layoutHeight -= m_spaceBetweenWidgetsCached; // There is no padding below the last widget + + // Call the function from Widget instead of BoxLayout to prevent an infinite loop + // NOLINTNEXTLINE(bugprone-parent-virtual-call) + Widget::setSize({getSizeLayout().x, layoutHeight}); + + // Bind layouts to the child widgets so that we can recalculate the positions when the height of one of them changes + m_widgetLayouts.reserve(m_widgets.size()); + for (const auto& widget : m_widgets) + { + m_widgetLayouts.push_back(bindHeight(widget)); + m_widgetLayouts.back().connectWidget(this, false, [this]{ updateWidgets(); }); + } + } + + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + + Widget::Ptr GrowVerticalLayout::clone() const + { + return std::make_shared(*this); + } + + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + + Vector2f GrowVerticalLayout::getInnerSize() const + { + return {BoxLayout::getInnerSize().x, 0.f}; + } + + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + + void GrowVerticalLayout::removeAllWidgets() + { + BoxLayout::removeAllWidgets(); + updateWidgets(); + } + + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +} + +///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 77462242c..e5700a37a 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -71,6 +71,8 @@ set(TEST_SOURCES Widgets/FileDialog.cpp Widgets/Group.cpp Widgets/Grid.cpp + Widgets/GrowHorizontalLayout.cpp + Widgets/GrowVerticalLayout.cpp Widgets/HorizontalLayout.cpp Widgets/HorizontalWrap.cpp Widgets/Knob.cpp diff --git a/tests/Widgets/GrowHorizontalLayout.cpp b/tests/Widgets/GrowHorizontalLayout.cpp new file mode 100644 index 000000000..31b042590 --- /dev/null +++ b/tests/Widgets/GrowHorizontalLayout.cpp @@ -0,0 +1,89 @@ +///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// +// TGUI - Texus' Graphical User Interface +// Copyright (C) 2012-2024 Bruno Van de Velde (vdv_b@tgui.eu) +// +// This software is provided 'as-is', without any express or implied warranty. +// In no event will the authors be held liable for any damages arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it freely, +// subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; +// you must not claim that you wrote the original software. +// If you use this software in a product, an acknowledgment +// in the product documentation would be appreciated but is not required. +// +// 2. Altered source versions must be plainly marked as such, +// and must not be misrepresented as being the original software. +// +// 3. This notice may not be removed or altered from any source distribution. +// +///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +#include "Tests.hpp" + +TEST_CASE("[GrowHorizontalLayout]") +{ + auto layout = tgui::GrowHorizontalLayout::create(); + layout->setHeight(300); + layout->setPosition(50, 40); + + SECTION("Positions and sizes") + { + REQUIRE(layout->getSize() == tgui::Vector2f{0, 300}); + + layout->getRenderer()->setSpaceBetweenWidgets(10); + layout->setSize(300, 300); + REQUIRE(layout->getSize() == tgui::Vector2f{0, 300}); + + auto button = tgui::Button::create("Hello"); + button->setWidth(50); + layout->add(button, "Btn"); + + REQUIRE(layout->getSize() == tgui::Vector2f{50, 300}); + + auto panel = tgui::Panel::create(); + layout->add(panel); + panel->setWidth(30); + + REQUIRE(layout->getSize() == tgui::Vector2f{90, 300}); + + auto button2 = tgui::Button::create("World"); + button2->setWidth("height * 0.4"); + layout->add(button2); + + REQUIRE(layout->getSize() == tgui::Vector2f{220, 300}); + + auto editBox = tgui::EditBox::create(); + editBox->setWidth(20); + layout->insert(1, editBox); + + REQUIRE(layout->getSize() == tgui::Vector2f{250, 300}); + + layout->remove(panel); + + REQUIRE(layout->getSize() == tgui::Vector2f{210, 300}); + + layout->setHeight(350); + REQUIRE(layout->getSize() == tgui::Vector2f{230, 350}); + + auto layout2 = tgui::GrowHorizontalLayout::copy(layout); + + layout2->get("Btn")->setWidth(100); + REQUIRE(layout->getSize() == tgui::Vector2f{230, 350}); + REQUIRE(layout2->getSize() == tgui::Vector2f{280, 350}); + + layout->removeAllWidgets(); + REQUIRE(layout->getSize() == tgui::Vector2f{0, 350}); + REQUIRE(layout2->getSize() == tgui::Vector2f{280, 350}); + } + + SECTION("Saving and loading from file") + { + layout->add(tgui::Button::create("Hello")); + layout->add(tgui::Button::create("World")); + testSavingWidget("GrowHorizontalLayout", layout, false); + } +} diff --git a/tests/Widgets/GrowVerticalLayout.cpp b/tests/Widgets/GrowVerticalLayout.cpp new file mode 100644 index 000000000..5cf16acab --- /dev/null +++ b/tests/Widgets/GrowVerticalLayout.cpp @@ -0,0 +1,89 @@ +///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// +// TGUI - Texus' Graphical User Interface +// Copyright (C) 2012-2024 Bruno Van de Velde (vdv_b@tgui.eu) +// +// This software is provided 'as-is', without any express or implied warranty. +// In no event will the authors be held liable for any damages arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it freely, +// subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; +// you must not claim that you wrote the original software. +// If you use this software in a product, an acknowledgment +// in the product documentation would be appreciated but is not required. +// +// 2. Altered source versions must be plainly marked as such, +// and must not be misrepresented as being the original software. +// +// 3. This notice may not be removed or altered from any source distribution. +// +///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +#include "Tests.hpp" + +TEST_CASE("[GrowVerticalLayout]") +{ + auto layout = tgui::GrowVerticalLayout::create(); + layout->setWidth(300); + layout->setPosition(50, 40); + + SECTION("Positions and sizes") + { + REQUIRE(layout->getSize() == tgui::Vector2f{300, 0}); + + layout->getRenderer()->setSpaceBetweenWidgets(10); + layout->setSize(300, 300); + REQUIRE(layout->getSize() == tgui::Vector2f{300, 0}); + + auto button = tgui::Button::create("Hello"); + button->setHeight(50); + layout->add(button, "Btn"); + + REQUIRE(layout->getSize() == tgui::Vector2f{300, 50}); + + auto panel = tgui::Panel::create(); + layout->add(panel); + panel->setHeight(30); + + REQUIRE(layout->getSize() == tgui::Vector2f{300, 90}); + + auto button2 = tgui::Button::create("World"); + button2->setHeight("width * 0.4"); + layout->add(button2); + + REQUIRE(layout->getSize() == tgui::Vector2f{300, 220}); + + auto editBox = tgui::EditBox::create(); + editBox->setHeight(20); + layout->insert(1, editBox); + + REQUIRE(layout->getSize() == tgui::Vector2f{300, 250}); + + layout->remove(panel); + + REQUIRE(layout->getSize() == tgui::Vector2f{300, 210}); + + layout->setWidth(350); + REQUIRE(layout->getSize() == tgui::Vector2f{350, 230}); + + auto layout2 = tgui::GrowVerticalLayout::copy(layout); + + layout2->get("Btn")->setHeight(100); + REQUIRE(layout->getSize() == tgui::Vector2f{350, 230}); + REQUIRE(layout2->getSize() == tgui::Vector2f{350, 280}); + + layout->removeAllWidgets(); + REQUIRE(layout->getSize() == tgui::Vector2f{350, 0}); + REQUIRE(layout2->getSize() == tgui::Vector2f{350, 280}); + } + + SECTION("Saving and loading from file") + { + layout->add(tgui::Button::create("Hello")); + layout->add(tgui::Button::create("World")); + testSavingWidget("GrowVerticalLayout", layout, false); + } +}