Skip to content

Commit

Permalink
Add PanelListBox to GUI builder
Browse files Browse the repository at this point in the history
  • Loading branch information
Schweini07 committed May 8, 2024
1 parent 31b1902 commit ebf0291
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 0 deletions.
58 changes: 58 additions & 0 deletions gui-builder/include/WidgetProperties/PanelListBoxProperties.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
// 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_GUI_BUILDER_PANEL_LIST_BOX_PROPERTIES_HPP
#define TGUI_GUI_BUILDER_PANEL_LIST_BOX_PROPERTIES_HPP

#include "ScrollablePanelProperties.hpp"

struct PanelListBoxProperties : ScrollablePanelProperties
{
void updateProperty(const tgui::Widget::Ptr& widget, const tgui::String& property, const tgui::String& value) const override
{
auto panel = widget->cast<tgui::PanelListBox>();
if (property == "ItemsWidth")
panel->setItemsWidth(value);
else if (property == "ItemsHeight")
panel->setItemsHeight(value);
else if (property == "MaximumItems")
panel->setMaximumItems(value.toUInt()); // conversion to size_t not possible with tgui::String
else
WidgetProperties::updateProperty(widget, property, value);
}

TGUI_NODISCARD PropertyValueMapPair initProperties(const tgui::Widget::Ptr& widget) const override
{
auto pair = ScrollablePanelProperties::initProperties(widget);
auto panel = widget->cast<tgui::PanelListBox>();

pair.first["ItemsWidth"] = {"Layout", panel->getItemsWidth().toString()};
pair.first["ItemsHeight"] = {"Layout", panel->getItemsHeight().toString()};
pair.first["MaximumItems"] = {"size_t", tgui::String::fromNumber(panel->getMaximumItems())};
return pair;
}
};

#endif // TGUI_GUI_BUILDER_PANEL_LIST_BOX_PROPERTIES_HPP
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions gui-builder/src/GuiBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
#include "WidgetProperties/ListBoxProperties.hpp"
#include "WidgetProperties/ListViewProperties.hpp"
#include "WidgetProperties/PanelProperties.hpp"
#include "WidgetProperties/PanelListBoxProperties.hpp"
#include "WidgetProperties/PictureProperties.hpp"
#include "WidgetProperties/ProgressBarProperties.hpp"
#include "WidgetProperties/RadioButtonProperties.hpp"
Expand Down Expand Up @@ -284,6 +285,7 @@ GuiBuilder::GuiBuilder(const tgui::String& programName) :
m_widgetProperties["ListBox"] = std::make_unique<ListBoxProperties>();
m_widgetProperties["ListView"] = std::make_unique<ListViewProperties>();
m_widgetProperties["Panel"] = std::make_unique<PanelProperties>();
m_widgetProperties["PanelListBox"] = std::make_unique<PanelListBoxProperties>();
m_widgetProperties["Picture"] = std::make_unique<PictureProperties>();
m_widgetProperties["ProgressBar"] = std::make_unique<ProgressBarProperties>();
m_widgetProperties["RadioButton"] = std::make_unique<RadioButtonProperties>();
Expand Down Expand Up @@ -999,6 +1001,7 @@ void GuiBuilder::loadToolbox()
{"ListBox", []{ return tgui::ListBox::create(); }},
{"ListView", []{ return tgui::ListView::create(); }},
{"Panel", []{ return tgui::Panel::create({150, 150}); }},
{"PanelListBox", []{ return tgui::PanelListBox::create(); }},
{"Picture", []{ return tgui::Picture::create((tgui::getResourcePath() / "resources/DefaultPicture.png").asString()); }},
{"ProgressBar", []{ return tgui::ProgressBar::create(); }},
{"RadioButton", []{ return tgui::RadioButton::create(); }},
Expand Down

0 comments on commit ebf0291

Please sign in to comment.