Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement EditBoxSlider #238

Merged
merged 1 commit into from
Apr 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
130 changes: 130 additions & 0 deletions gui-builder/include/WidgetProperties/EditBoxSliderProperties.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
// 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_EDIT_BOX_SLIDER_PROPERTIES_HPP
#define TGUI_GUI_BUILDER_EDIT_BOX_SLIDER_PROPERTIES_HPP

#include "WidgetProperties.hpp"

struct EditBoxSliderProperties : WidgetProperties
{
void updateProperty(const tgui::Widget::Ptr& widget, const tgui::String& property, const tgui::String& value) const override
{
auto editBoxSlider = widget->cast<tgui::EditBoxSlider>();
if (property == "Minimum")
editBoxSlider->setMinimum(value.toFloat());
else if (property == "Maximum")
editBoxSlider->setMaximum(value.toFloat());
else if (property == "Value")
editBoxSlider->setValue(value.toFloat());
else if (property == "Step")
editBoxSlider->setStep(value.toFloat());
else if (property == "DecimalPlaces")
editBoxSlider->setDecimalPlaces(value.toUInt());
else if (property == "TextAlignment")
editBoxSlider->setTextAlignment(deserializeTextAlignment(value));
else
WidgetProperties::updateProperty(widget, property, value);
}

TGUI_NODISCARD PropertyValueMapPair initProperties(const tgui::Widget::Ptr& widget) const override
{
auto pair = WidgetProperties::initProperties(widget);
auto editBoxSlider = widget->cast<tgui::EditBoxSlider>();
pair.first["Minimum"] = {"Float", tgui::String::fromNumber(editBoxSlider->getMinimum())};
pair.first["Maximum"] = {"Float", tgui::String::fromNumber(editBoxSlider->getMaximum())};
pair.first["Value"] = {"Float", tgui::String::fromNumber(editBoxSlider->getValue())};
pair.first["Step"] = {"Float", tgui::String::fromNumber(editBoxSlider->getStep())};
pair.first["Step"] = {"Float", tgui::String::fromNumber(editBoxSlider->getStep())};
pair.first["DecimalPlaces"] = {"UInt", tgui::String::fromNumber(editBoxSlider->getDecimalPlaces())};
pair.first["TextAlignment"] = {"Enum{Left,Center,Right}", serializeTextAlignment(editBoxSlider->getTextAlignment())};

const auto editBoxRenderer = editBoxSlider->getEditBoxSharedRenderer();
pair.second["EditBox.Padding"] = {"Outline", editBoxRenderer->getPadding().toString()};
pair.second["EditBox.CaretWidth"] = {"Float", tgui::String::fromNumber(editBoxRenderer->getCaretWidth())};
pair.second["EditBox.TextColor"] = {"Color", tgui::Serializer::serialize(editBoxRenderer->getTextColor())};
pair.second["EditBox.TextColorDisabled"] = {"Color", tgui::Serializer::serialize(editBoxRenderer->getTextColorDisabled())};
pair.second["EditBox.TextColorFocused"] = {"Color", tgui::Serializer::serialize(editBoxRenderer->getTextColorFocused())};
pair.second["EditBox.SelectedTextColor"] = {"Color", tgui::Serializer::serialize(editBoxRenderer->getSelectedTextColor())};
pair.second["EditBox.SelectedTextBackgroundColor"] = {"Color", tgui::Serializer::serialize(editBoxRenderer->getSelectedTextBackgroundColor())};
pair.second["EditBox.DefaultTextColor"] = {"Color", tgui::Serializer::serialize(editBoxRenderer->getDefaultTextColor())};
pair.second["EditBox.BackgroundColor"] = {"Color", tgui::Serializer::serialize(editBoxRenderer->getBackgroundColor())};
pair.second["EditBox.BackgroundColorHover"] = {"Color", tgui::Serializer::serialize(editBoxRenderer->getBackgroundColorHover())};
pair.second["EditBox.BackgroundColorDisabled"] = {"Color", tgui::Serializer::serialize(editBoxRenderer->getBackgroundColorDisabled())};
pair.second["EditBox.BackgroundColorFocused"] = {"Color", tgui::Serializer::serialize(editBoxRenderer->getBackgroundColorFocused())};
pair.second["EditBox.CaretColor"] = {"Color", tgui::Serializer::serialize(editBoxRenderer->getCaretColor())};
pair.second["EditBox.CaretColorHover"] = {"Color", tgui::Serializer::serialize(editBoxRenderer->getCaretColorHover())};
pair.second["EditBox.CaretColorFocused"] = {"Color", tgui::Serializer::serialize(editBoxRenderer->getCaretColorFocused())};
pair.second["EditBox.BorderColor"] = {"Color", tgui::Serializer::serialize(editBoxRenderer->getBorderColor())};
pair.second["EditBox.BorderColorHover"] = {"Color", tgui::Serializer::serialize(editBoxRenderer->getBorderColorHover())};
pair.second["EditBox.BorderColorDisabled"] = {"Color", tgui::Serializer::serialize(editBoxRenderer->getBorderColorDisabled())};
pair.second["EditBox.BorderColorFocused"] = {"Color", tgui::Serializer::serialize(editBoxRenderer->getBorderColorFocused())};
pair.second["EditBox.Texture"] = {"Texture", tgui::Serializer::serialize(editBoxRenderer->getTexture())};
pair.second["EditBox.TextureHover"] = {"Texture", tgui::Serializer::serialize(editBoxRenderer->getTextureHover())};
pair.second["EditBox.TextureDisabled"] = {"Texture", tgui::Serializer::serialize(editBoxRenderer->getTextureDisabled())};
pair.second["EditBox.TextureFocused"] = {"Texture", tgui::Serializer::serialize(editBoxRenderer->getTextureFocused())};
pair.second["EditBox.TextStyle"] = {"TextStyle", tgui::Serializer::serialize(editBoxRenderer->getTextStyle())};
pair.second["EditBox.DefaultTextStyle"] = {"TextStyle", tgui::Serializer::serialize(editBoxRenderer->getDefaultTextStyle())};

const auto sliderRenderer = editBoxSlider->getSliderSharedRenderer();
pair.second["Slider.Borders"] = {"Outline", tgui::Serializer::serialize(sliderRenderer->getBorders())};
pair.second["Slider.TrackColor"] = {"Color", tgui::Serializer::serialize(sliderRenderer->getTrackColor())};
pair.second["Slider.TrackColorHover"] = {"Color", tgui::Serializer::serialize(sliderRenderer->getTrackColorHover())};
pair.second["Slider.ThumbColor"] = {"Color", tgui::Serializer::serialize(sliderRenderer->getThumbColor())};
pair.second["Slider.ThumbColorHover"] = {"Color", tgui::Serializer::serialize(sliderRenderer->getThumbColorHover())};
pair.second["Slider.BorderColor"] = {"Color", tgui::Serializer::serialize(sliderRenderer->getBorderColor())};
pair.second["Slider.BorderColorHover"] = {"Color", tgui::Serializer::serialize(sliderRenderer->getBorderColorHover())};
pair.second["Slider.TextureTrack"] = {"Texture", tgui::Serializer::serialize(sliderRenderer->getTextureTrack())};
pair.second["Slider.TextureTrackHover"] = {"Texture", tgui::Serializer::serialize(sliderRenderer->getTextureTrackHover())};
pair.second["Slider.TextureThumb"] = {"Texture", tgui::Serializer::serialize(sliderRenderer->getTextureThumb())};
pair.second["Slider.TextureThumbHover"] = {"Texture", tgui::Serializer::serialize(sliderRenderer->getTextureThumbHover())};
return pair;
}

private:

TGUI_NODISCARD static tgui::EditBox::Alignment deserializeTextAlignment(tgui::String value)
{
value = value.trim().toLower();
if (value == "right")
return tgui::EditBox::Alignment::Right;
else if (value == "center")
return tgui::EditBox::Alignment::Center;
else
return tgui::EditBox::Alignment::Left;
}

TGUI_NODISCARD static tgui::String serializeTextAlignment(tgui::EditBox::Alignment alignment)
{
if (alignment == tgui::EditBox::Alignment::Center)
return "Center";
else if (alignment == tgui::EditBox::Alignment::Right)
return "Right";
else
return "Left";
}
};

#endif // TGUI_GUI_BUILDER_EDIT_BOX_SLIDER_PROPERTIES_HPP
16 changes: 0 additions & 16 deletions gui-builder/include/WidgetProperties/SpinControlProperties.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,22 +102,6 @@ struct SpinControlProperties : WidgetProperties
pair.second["SpinText.DefaultTextStyle"] = {"TextStyle", tgui::Serializer::serialize(textRenderer->getDefaultTextStyle())};
return pair;
}

private:

const std::set<tgui::String> m_buttonProperties = {
"ButtonsBorders", "BorderBetweenArrows", "ButtonsBackgroundColor", "ButtonsBackgroundColorHover", "ArrowColor",
"ArrowColorHover", "ButtonsBorderColor", "TextureArrowUp", "TextureArrowUpHover", "TextureArrowDown",
"TextureArrowDownHover"
};

const std::set<tgui::String> m_textProperties = {
"Padding", "CaretWidth", "TextColor", "TextColorDisabled", "TextColorFocused", "SelectedTextColor",
"SelectedTextBackgroundColor", "DefaultTextColor", "BackgroundColor", "BackgroundColorHover",
"BackgroundColorDisabled", "BackgroundColorFocused", "CaretColor", "CaretColorHover", "CaretColorFocused",
"BorderColor", "BorderColorHover", "BorderColorDisabled", "BorderColorFocused", "Texture", "TextureHover",
"TextureDisabled", "TextureFocused", "TextStyle", "DefaultTextStyle", "Borders"
};
};

#endif // TGUI_GUI_BUILDER_SPIN_CONTROL_PROPERTIES_HPP
Binary file added gui-builder/resources/widget-icons/EditBoxSlider.png
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 @@ -32,6 +32,7 @@
#include "WidgetProperties/ClickableWidgetProperties.hpp"
#include "WidgetProperties/ComboBoxProperties.hpp"
#include "WidgetProperties/EditBoxProperties.hpp"
#include "WidgetProperties/EditBoxSliderProperties.hpp"
#include "WidgetProperties/GroupProperties.hpp"
#include "WidgetProperties/HorizontalLayoutProperties.hpp"
#include "WidgetProperties/HorizontalWrapProperties.hpp"
Expand Down Expand Up @@ -271,6 +272,7 @@ GuiBuilder::GuiBuilder(const tgui::String& programName) :
m_widgetProperties["ClickableWidget"] = std::make_unique<ClickableWidgetProperties>();
m_widgetProperties["ComboBox"] = std::make_unique<ComboBoxProperties>();
m_widgetProperties["EditBox"] = std::make_unique<EditBoxProperties>();
m_widgetProperties["EditBoxSlider"] = std::make_unique<EditBoxSliderProperties>();
m_widgetProperties["Group"] = std::make_unique<GroupProperties>();
m_widgetProperties["HorizontalLayout"] = std::make_unique<HorizontalLayoutProperties>();
m_widgetProperties["HorizontalWrap"] = std::make_unique<HorizontalWrapProperties>();
Expand Down Expand Up @@ -983,6 +985,7 @@ void GuiBuilder::loadToolbox()
{"ClickableWidget", []{ return tgui::ClickableWidget::create({150, 150}); }},
{"ComboBox", []{ return tgui::ComboBox::create(); }},
{"EditBox", []{ return tgui::EditBox::create(); }},
{"EditBoxSlider", []{ return tgui::EditBoxSlider::create(); }},
{"Group", []{ return tgui::Group::create({150, 150}); }},
{"HorizontalLayout", []{ return tgui::HorizontalLayout::create({150, 150}); }},
{"HorizontalWrap", []{ return tgui::HorizontalWrap::create({150, 150}); }},
Expand Down
1 change: 1 addition & 0 deletions include/TGUI/AllWidgets.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include <TGUI/Widgets/ColorPicker.hpp>
#include <TGUI/Widgets/ComboBox.hpp>
#include <TGUI/Widgets/EditBox.hpp>
#include <TGUI/Widgets/EditBoxSlider.hpp>
#include <TGUI/Widgets/FileDialog.hpp>
#include <TGUI/Widgets/Group.hpp>
#include <TGUI/Widgets/Grid.hpp>
Expand Down
Loading