Skip to content

Commit

Permalink
Multiple fixes to EditBoxSlider widget
Browse files Browse the repository at this point in the history
- Properly defined a default size
- Slider is now slightly thicker
- Thumb of slider was clipped during drawing
- EditBoxSlider didn't inherit themes from EditBox and Slider widgets
  • Loading branch information
texus committed Jun 11, 2024
1 parent 730e6d7 commit 7c756a0
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 7 deletions.
10 changes: 8 additions & 2 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
TGUI 1.3 (10 June 2024)
------------------------
TGUI 1.4 (TBD)
---------------

- Multiple fixes to EditBoxSlider widget


TGUI 1.3.0 (10 June 2024)
--------------------------

- New backend: raylib
- New widget: EditBoxSlider ([PR #238](https://github.com/texus/TGUI/pull/238))
Expand Down
19 changes: 19 additions & 0 deletions include/TGUI/Widgets/EditBoxSlider.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,25 @@ TGUI_MODULE_EXPORT namespace tgui
void setSize(const Layout2d& size) override;
using SubwidgetContainer::setSize;

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// @brief Returns the full size of the combined edit box and slider
///
/// This size also takes the thumb of the slider into account as opposed to getSize which only includes the track size.
///
/// @return Full size of the combined edit box and slider
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
TGUI_NODISCARD Vector2f getFullSize() const override;

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// @brief Returns the distance between the position where the widget is drawn and where the widget is placed
///
/// This is a negative offset indicating the difference between the track and thumb position of the slider when the
/// value equals the minimum.
///
/// @return Offset of the widget
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
TGUI_NODISCARD Vector2f getWidgetOffset() const override;

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// @brief Sets a minimum value
///
Expand Down
1 change: 1 addition & 0 deletions src/Loading/Theme.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,7 @@ namespace tgui
{"ChildWindow", {{"CloseButton", "Button"}}},
{"ColorPicker", {{"Button", ""}, {"Label", ""}, {"Slider", ""}}},
{"ComboBox", {{"ListBox", ""}}},
{"EditBoxSlider", {{"EditBox", ""}, {"Slider", ""}}},
{"FileDialog", {{"Button", ""}, {"EditBox", ""}, {"ListView", ""}, {"FilenameLabel", "Label"}, {"FileTypeComboBox", "ComboBox"}}},
{"Label", {{"Scrollbar", ""}}},
{"ListBox", {{"Scrollbar", ""}}},
Expand Down
33 changes: 32 additions & 1 deletion src/SubwidgetContainer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,38 @@ namespace tgui

void SubwidgetContainer::draw(BackendRenderTarget& target, RenderStates states) const
{
m_container->draw(target, states);
const Outline padding = m_container->getSharedRenderer()->getPadding();
states.transform.translate({padding.getLeft(), padding.getTop()});

const Vector2f innerSize = {getFullSize().x - padding.getLeft() - padding.getRight(),
getFullSize().y - padding.getTop() - padding.getBottom()};

target.addClippingLayer(states, {getWidgetOffset(), innerSize});

for (const auto& widget : m_container->getWidgets())
{
if (!widget->isVisible())
continue;

const Vector2f origin{widget->getOrigin().x * widget->getSize().x, widget->getOrigin().y * widget->getSize().y};

RenderStates widgetStates = states;
widgetStates.transform.translate(widget->getPosition() - origin);
if (widget->getRotation() != 0)
{
const Vector2f rotOrigin{widget->getRotationOrigin().x * widget->getSize().x, widget->getRotationOrigin().y * widget->getSize().y};
widgetStates.transform.rotate(widget->getRotation(), rotOrigin);
}
if ((widget->getScale().x != 1) || (widget->getScale().y != 1))
{
const Vector2f scaleOrigin{widget->getScaleOrigin().x * widget->getSize().x, widget->getScaleOrigin().y * widget->getSize().y};
widgetStates.transform.scale(widget->getScale(), scaleOrigin);
}

target.drawWidget(widgetStates, widget);
}

target.removeClippingLayer();
}

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Expand Down
19 changes: 17 additions & 2 deletions src/Widgets/EditBoxSlider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ namespace tgui
m_container->add(m_editBox, "EditBox");
m_container->add(m_slider, "Slider");

m_slider->setSize(m_editBox->getSize().x, m_editBox->getSize().y / 3.f);
init();
}

Expand Down Expand Up @@ -176,8 +177,22 @@ namespace tgui
void EditBoxSlider::setSize(const Layout2d& size)
{
SubwidgetContainer::setSize(size);
m_editBox->setSize({getSize().x, getSize().y * 0.8f});
m_slider->setSize({getSize().x, getSize().y * 0.2f});
m_editBox->setSize({getSize().x, getSize().y * 0.75f});
m_slider->setSize({getSize().x, getSize().y * 0.25f});
}

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

Vector2f EditBoxSlider::getFullSize() const
{
return {m_slider->getFullSize().x, m_editBox->getSize().y + m_slider->getSize().y + ((m_slider->getFullSize().y - m_slider->getSize().y) / 2.f)};
}

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

Vector2f EditBoxSlider::getWidgetOffset() const
{
return {m_slider->getWidgetOffset().x, 0};
}

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Expand Down
6 changes: 4 additions & 2 deletions tests/Widgets/EditBoxSlider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,10 @@ TEST_CASE("[editBoxSlider]")

REQUIRE(editBoxSlider->getPosition() == tgui::Vector2f(40, 30));
REQUIRE(editBoxSlider->getSize() == tgui::Vector2f(25, 60));
REQUIRE(editBoxSlider->getFullSize() == editBoxSlider->getSize());
REQUIRE(editBoxSlider->getWidgetOffset() == tgui::Vector2f(0, 0));
REQUIRE(editBoxSlider->getFullSize().x >= editBoxSlider->getSize().x);
REQUIRE(editBoxSlider->getFullSize().y >= editBoxSlider->getSize().y);
REQUIRE(editBoxSlider->getWidgetOffset().x <= 0);
REQUIRE(editBoxSlider->getWidgetOffset().y == 0);
}

SECTION("Minimum")
Expand Down

0 comments on commit 7c756a0

Please sign in to comment.