Skip to content

Commit

Permalink
Added new Orientation enum to replace VerticalScroll boolean used in …
Browse files Browse the repository at this point in the history
…Slider, Scrollbar and SpinButton
  • Loading branch information
texus committed Jun 30, 2024
1 parent 21d4f32 commit 1a607dc
Show file tree
Hide file tree
Showing 18 changed files with 251 additions and 129 deletions.
2 changes: 2 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ TGUI 1.4 (TBD)

- Added MaxValue getter to Scrollbar
- Added ScrollbarMaxValue getters to widgets with a scrollbar
- Added getPixelsPerPoint() to BackendRenderTarget
- Replace VerticalScroll with Orientation in Slider, Scrollbar and SpinButton
- Multiple fixes to EditBoxSlider widget


Expand Down
6 changes: 3 additions & 3 deletions gui-builder/include/WidgetProperties/ScrollbarProperties.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ struct ScrollbarProperties : WidgetProperties
scrollbar->setScrollAmount(value.toUInt());
else if (property == "AutoHide")
scrollbar->setAutoHide(parseBoolean(value, true));
else if (property == "VerticalScroll")
scrollbar->setVerticalScroll(parseBoolean(value, true));
else if (property == "Orientation")
scrollbar->setOrientation(deserializeOrientation(value));
else
WidgetProperties::updateProperty(widget, property, value);
}
Expand All @@ -58,7 +58,7 @@ struct ScrollbarProperties : WidgetProperties
pair.first["ViewportSize"] = {"UInt", tgui::String::fromNumber(scrollbar->getViewportSize())};
pair.first["ScrollAmount"] = {"UInt", tgui::String::fromNumber(scrollbar->getScrollAmount())};
pair.first["AutoHide"] = {"Bool", tgui::Serializer::serialize(scrollbar->getAutoHide())};
pair.first["VerticalScroll"] = {"Bool", tgui::Serializer::serialize(scrollbar->getVerticalScroll())};
pair.first["Orientation"] = {"Enum{Vertical,Horizontal}", serializeOrientation(scrollbar->getOrientation())};

const auto renderer = scrollbar->getSharedRenderer();
pair.second["TrackColor"] = {"Color", tgui::Serializer::serialize(renderer->getTrackColor())};
Expand Down
6 changes: 3 additions & 3 deletions gui-builder/include/WidgetProperties/SliderProperties.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ struct SliderProperties : WidgetProperties
slider->setStep(value.toFloat());
else if (property == "InvertedDirection")
slider->setInvertedDirection(parseBoolean(value, false));
else if (property == "VerticalScroll")
slider->setVerticalScroll(parseBoolean(value, true));
else if (property == "Orientation")
slider->setOrientation(deserializeOrientation(value));
else
WidgetProperties::updateProperty(widget, property, value);
}
Expand All @@ -58,7 +58,7 @@ struct SliderProperties : WidgetProperties
pair.first["Value"] = {"Float", tgui::String::fromNumber(slider->getValue())};
pair.first["Step"] = {"Float", tgui::String::fromNumber(slider->getStep())};
pair.first["InvertedDirection"] = {"Bool", tgui::Serializer::serialize(slider->getInvertedDirection())};
pair.first["VerticalScroll"] = {"Bool", tgui::Serializer::serialize(slider->getVerticalScroll())};
pair.first["Orientation"] = {"Enum{Vertical,Horizontal}", serializeOrientation(slider->getOrientation())};

const auto renderer = slider->getSharedRenderer();
pair.second["Borders"] = {"Outline", tgui::Serializer::serialize(renderer->getBorders())};
Expand Down
6 changes: 3 additions & 3 deletions gui-builder/include/WidgetProperties/SpinButtonProperties.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ struct SpinButtonProperties : WidgetProperties
spinButton->setValue(value.toFloat());
else if (property == "Step")
spinButton->setStep(value.toFloat());
else if (property == "VerticalScroll")
spinButton->setVerticalScroll(parseBoolean(value, true));
else if (property == "Orientation")
spinButton->setOrientation(deserializeOrientation(value));
else
WidgetProperties::updateProperty(widget, property, value);
}
Expand All @@ -55,7 +55,7 @@ struct SpinButtonProperties : WidgetProperties
pair.first["Maximum"] = {"Float", tgui::String::fromNumber(spinButton->getMaximum())};
pair.first["Value"] = {"Float", tgui::String::fromNumber(spinButton->getValue())};
pair.first["Step"] = {"Float", tgui::String::fromNumber(spinButton->getStep())};
pair.first["VerticalScroll"] = {"Bool", tgui::Serializer::serialize(spinButton->getVerticalScroll())};
pair.first["Orientation"] = {"Enum{Vertical,Horizontal}", serializeOrientation(spinButton->getOrientation())};

const auto renderer = spinButton->getSharedRenderer();
pair.second["Borders"] = {"Outline", tgui::Serializer::serialize(renderer->getBorders())};
Expand Down
17 changes: 17 additions & 0 deletions gui-builder/include/WidgetProperties/WidgetProperties.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,23 @@ struct WidgetProperties
else
return "Top";
}

TGUI_NODISCARD static tgui::String serializeOrientation(tgui::Orientation orientation)
{
if (orientation == tgui::Orientation::Horizontal)
return "Horizontal";
else
return "Vertical";
}

TGUI_NODISCARD static tgui::Orientation deserializeOrientation(tgui::String value)
{
value = value.trim().toLower();
if (value == "horizontal")
return tgui::Orientation::Horizontal;
else
return tgui::Orientation::Vertical;
}
};

#endif // TGUI_GUI_BUILDER_WIDGET_PROPERTIES_HPP
10 changes: 10 additions & 0 deletions include/TGUI/Layout.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,16 @@ TGUI_MODULE_EXPORT namespace tgui
class Widget;
class Container;

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// @brief Orientation of the object
/// @since TGUI 1.4
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
enum class Orientation
{
Vertical, //!< Vertical orientation
Horizontal //!< Horizontal orientation
};

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// @brief The horizontal alignment
/// @since TGUI 1.3
Expand Down
7 changes: 2 additions & 5 deletions include/TGUI/Widgets/RangeSlider.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -305,11 +305,8 @@ TGUI_MODULE_EXPORT namespace tgui
float m_selectionEnd = 0;
float m_step = 1;

// Is the slider drawn vertically?
bool m_verticalScroll = false;

// Does the image lie vertically?
bool m_verticalImage = false;
Orientation m_orientation = Orientation::Horizontal; // Is the slider drawn horizontally or vertically?
Orientation m_imageOrientation = Orientation::Horizontal; // Does the loaded image lie horizontally or vertically?

Sprite m_spriteTrack;
Sprite m_spriteTrackHover;
Expand Down
32 changes: 24 additions & 8 deletions include/TGUI/Widgets/Scrollbar.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ TGUI_MODULE_EXPORT namespace tgui
///
/// @param size The new size of the scrollbar
///
/// Note that the VerticalScroll propery is changed by this function based on the given width and height.
/// Note that the Orientation propery is changed by this function based on the given width and height.
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void setSize(const Layout2d& size) override;
using Widget::setSize;
Expand Down Expand Up @@ -202,19 +202,38 @@ TGUI_MODULE_EXPORT namespace tgui
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
TGUI_NODISCARD bool getAutoHide() const;

#ifndef TGUI_REMOVE_DEPRECATED_CODE
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// @brief Changes whether the scrollbar lies horizontally or vertically
/// @param vertical Should the scrollbar lie vertically?
///
/// This function will swap the width and height of the scrollbar if it didn't lie in the wanted direction.
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void setVerticalScroll(bool vertical);
TGUI_DEPRECATED("Use setOrientation instead") void setVerticalScroll(bool vertical);

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// @brief Returns whether the scrollbar lies horizontally or vertically
/// @return Does the scrollbar lie vertically?
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
TGUI_NODISCARD bool getVerticalScroll() const;
TGUI_DEPRECATED("Use getOrientation instead") TGUI_NODISCARD bool getVerticalScroll() const;
#endif

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// @brief Changes whether the scrollbar lies horizontally or vertically
/// @param orientation Orientation of the scrollbar
///
/// This function will swap the width and height of the scrollbar if it didn't lie in the wanted direction.
///
/// @since TGUI 1.4
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void setOrientation(Orientation orientation);

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// @brief Returns whether the scrollbar lies horizontally or vertically
/// @return Orientation of the scrollbar
/// @since TGUI 1.4
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
TGUI_NODISCARD Orientation getOrientation() const;

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// @brief Returns the default width of the scrollbar
Expand Down Expand Up @@ -339,11 +358,8 @@ TGUI_MODULE_EXPORT namespace tgui
// Maximum should be above this value before the scrollbar is needed
unsigned int m_viewportSize = 1;

// Is the scrollbar draw vertically?
bool m_verticalScroll = true;

// Does the image lie vertically?
bool m_verticalImage = true;
Orientation m_orientation = Orientation::Vertical; // Is the scrollbar drawn horizontally or vertically?
Orientation m_imageOrientation = Orientation::Vertical; // Does the loaded image lie horizontally or vertically?

// How far should the value change when pressing one of the arrows?
unsigned int m_scrollAmount = 1;
Expand Down
30 changes: 25 additions & 5 deletions include/TGUI/Widgets/Slider.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ TGUI_MODULE_EXPORT namespace tgui
///
/// @param size The new size of the slider
///
/// Note that the VerticalScroll propery is changed by this function based on the given width and height.
/// Note that the Orientation propery is changed by this function based on the given width and height.
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void setSize(const Layout2d& size) override;
using Widget::setSize;
Expand Down Expand Up @@ -191,19 +191,38 @@ TGUI_MODULE_EXPORT namespace tgui
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
TGUI_NODISCARD float getStep() const;

#ifndef TGUI_REMOVE_DEPRECATED_CODE
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// @brief Changes whether the slider lies horizontally or vertically
/// @param vertical Should the slider lie vertically?
///
/// This function will swap the width and height of the slider if it didn't lie in the wanted direction.
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void setVerticalScroll(bool vertical);
TGUI_DEPRECATED("Use setOrientation instead") void setVerticalScroll(bool vertical);

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// @brief Returns whether the slider lies horizontally or vertically
/// @return Does the slider lie vertically?
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
TGUI_NODISCARD bool getVerticalScroll() const;
TGUI_DEPRECATED("Use getOrientation instead") TGUI_NODISCARD bool getVerticalScroll() const;
#endif

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// @brief Changes whether the slider lies horizontally or vertically
/// @param orientation Orientation of the slider
///
/// This function will swap the width and height of the slider if it didn't lie in the wanted direction.
///
/// @since TGUI 1.4
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void setOrientation(Orientation orientation);

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// @brief Returns whether the slider lies horizontally or vertically
/// @return Orientation of the slider
/// @since TGUI 1.4
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
TGUI_NODISCARD Orientation getOrientation() const;

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// @brief Changes whether the side of the slider that is the minimum and maximum should be inverted
Expand Down Expand Up @@ -339,10 +358,11 @@ TGUI_MODULE_EXPORT namespace tgui
float m_step = 1;

bool m_invertedDirection = false; // Are min and max swapped?
bool m_verticalScroll = false; // Is the slider drawn vertically?
bool m_verticalImage = false; // Does the image lie vertically?
bool m_changeValueOnScroll = true; // Does mouseScroll event change slider value?

Orientation m_orientation = Orientation::Horizontal; // Is the slider drawn horizontally or vertically?
Orientation m_imageOrientation = Orientation::Horizontal; // Does the loaded image lie horizontally or vertically?

Sprite m_spriteTrack;
Sprite m_spriteTrackHover;
Sprite m_spriteThumb;
Expand Down
28 changes: 23 additions & 5 deletions include/TGUI/Widgets/SpinButton.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ TGUI_MODULE_EXPORT namespace tgui
///
/// @param size The new size of the spin button
///
/// Note that the VerticalScroll property is changed by this function based on the given width and height.
/// Note that the Orientation property is changed by this function based on the given width and height.
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void setSize(const Layout2d& size) override;
using Widget::setSize;
Expand Down Expand Up @@ -168,19 +168,38 @@ TGUI_MODULE_EXPORT namespace tgui
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
TGUI_NODISCARD float getStep() const;

#ifndef TGUI_REMOVE_DEPRECATED_CODE
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// @brief Changes whether the spin button lies horizontally or vertically
/// @param vertical Should the spin button lie vertically?
///
/// This function will swap the width and height of the spin button if it didn't lie in the wanted direction.
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void setVerticalScroll(bool vertical);
TGUI_DEPRECATED("Use setOrientation instead")void setVerticalScroll(bool vertical);

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// @brief Returns whether the spin button lies horizontally or vertically
/// @return Does the spin button lie vertically?
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
TGUI_NODISCARD bool getVerticalScroll() const;
TGUI_DEPRECATED("Use getOrientation instead")TGUI_NODISCARD bool getVerticalScroll() const;
#endif

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// @brief Changes whether the spin button lies horizontally or vertically
/// @param orientation Orientation of the spin button
///
/// This function will swap the width and height of the spin button if it didn't lie in the wanted direction.
///
/// @since TGUI 1.4
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void setOrientation(Orientation orientation);

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// @brief Returns whether the spin button lies horizontally or vertically
/// @return Orientation of the spin button
/// @since TGUI 1.4
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
TGUI_NODISCARD Orientation getOrientation() const;

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// @internal
Expand Down Expand Up @@ -262,8 +281,7 @@ TGUI_MODULE_EXPORT namespace tgui
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
protected:

// Is the spin button draw vertically (arrows on top of each other)?
bool m_verticalScroll = true;
Orientation m_orientation = Orientation::Vertical; // Is the spin button draw horizontally (arrows next to each other) or vertically (arrows on top of each other)?
std::chrono::time_point<std::chrono::steady_clock> m_PressedAt;

float m_minimum = 0;
Expand Down
10 changes: 5 additions & 5 deletions src/Widgets/ColorPicker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,10 +179,10 @@ namespace tgui
m_colorWheelSprite.setTexture(m_colorWheelTexture);
pixels = nullptr;

m_red->setVerticalScroll(false);
m_green->setVerticalScroll(false);
m_blue->setVerticalScroll(false);
m_alpha->setVerticalScroll(false);
m_red->setOrientation(Orientation::Horizontal);
m_green->setOrientation(Orientation::Horizontal);
m_blue->setOrientation(Orientation::Horizontal);
m_alpha->setOrientation(Orientation::Horizontal);
m_red->setWidth(200);
m_green->setWidth(200);
m_blue->setWidth(200);
Expand Down Expand Up @@ -218,7 +218,7 @@ namespace tgui

add(m_value, "#TGUI_INTERNAL$ColorPickerValue#");
m_value->setValue(m_value->getMaximum());
m_value->setVerticalScroll(true);
m_value->setOrientation(Orientation::Vertical);
m_value->setHeight(200);

add(Label::create("Last:"), "#TGUI_INTERNAL$ColorPickerLabelLast#");
Expand Down
Loading

0 comments on commit 1a607dc

Please sign in to comment.