Added MinimumResizableBorderWidth to ChildWindow renderer to allow having an invisible area next to the borders to make resizing easier on child windows with small borders
parent
5368fc0a4e
commit
06665e6d8d
|
@ -200,6 +200,26 @@ namespace tgui
|
|||
float getPaddingBetweenButtons() const;
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief Changes the minimum width of the area where you can drag to resize the child window
|
||||
/// @param minimumBoderWidth Minimum amount of pixels where the child window can be dragged to resize it
|
||||
///
|
||||
/// If the border is larger than minimumBoderWidth then this function has no effect. If the borders are smaller,
|
||||
/// several invisible pixels next to the border can also be used to resize the child window.
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
void setMinimumResizableBorderWidth(float minimumBoderWidth);
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief Returns the minimum width of the area where you can drag to resize the child window
|
||||
/// @return Minimum amount of pixels where the child window can be dragged to resize it
|
||||
///
|
||||
/// If the border is larger than this value then it has no effect. If the borders are smaller, several invisible
|
||||
/// pixels next to the border can also be used to resize the child window.
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
float getMinimumResizableBorderWidth() const;
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief Changes whether characters are rendered on top of the title buttons
|
||||
/// @param showText Should text be shown on the title buttons?
|
||||
|
|
|
@ -490,6 +490,7 @@ namespace tgui
|
|||
float m_borderBelowTitleBarCached = 0;
|
||||
float m_distanceToSideCached = 0;
|
||||
float m_paddingBetweenButtonsCached = 0;
|
||||
float m_MinimumResizableBorderWidthCached = 5;
|
||||
bool m_showTextOnTitleButtonsCached = false;
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
|
|
@ -46,6 +46,7 @@ namespace tgui
|
|||
TGUI_RENDERER_PROPERTY_NUMBER(ChildWindowRenderer, BorderBelowTitleBar, 0)
|
||||
TGUI_RENDERER_PROPERTY_NUMBER(ChildWindowRenderer, DistanceToSide, 3)
|
||||
TGUI_RENDERER_PROPERTY_NUMBER(ChildWindowRenderer, PaddingBetweenButtons, 1)
|
||||
TGUI_RENDERER_PROPERTY_NUMBER(ChildWindowRenderer, MinimumResizableBorderWidth, 5)
|
||||
|
||||
TGUI_RENDERER_PROPERTY_BOOL(ChildWindowRenderer, ShowTextOnTitleButtons, false)
|
||||
|
||||
|
|
|
@ -413,7 +413,20 @@ namespace tgui
|
|||
|
||||
bool ChildWindow::mouseOnWidget(Vector2f pos) const
|
||||
{
|
||||
if (FloatRect{getPosition(), getFullSize()}.contains(pos))
|
||||
FloatRect region{getPosition(), getFullSize()};
|
||||
|
||||
// Expand the region if the child window is resizable (to make the borders easier to click on)
|
||||
if (m_resizable)
|
||||
{
|
||||
region.left -= std::max(0.f, m_MinimumResizableBorderWidthCached - m_bordersCached.getLeft());
|
||||
region.top -= std::max(0.f, m_MinimumResizableBorderWidthCached - m_bordersCached.getTop());
|
||||
region.width += std::max(0.f, m_MinimumResizableBorderWidthCached - m_bordersCached.getLeft())
|
||||
+ std::max(0.f, m_MinimumResizableBorderWidthCached - m_bordersCached.getRight());
|
||||
region.height += std::max(0.f, m_MinimumResizableBorderWidthCached - m_bordersCached.getTop())
|
||||
+ std::max(0.f, m_MinimumResizableBorderWidthCached - m_bordersCached.getBottom());
|
||||
}
|
||||
|
||||
if (region.contains(pos))
|
||||
{
|
||||
// If the mouse enters the border or title bar then then none of the widgets can still be under the mouse
|
||||
if (m_widgetBelowMouse && !FloatRect{getPosition() + getChildWidgetsOffset(), getSize()}.contains(pos))
|
||||
|
@ -450,13 +463,13 @@ namespace tgui
|
|||
{
|
||||
// Check on which border the mouse is standing
|
||||
m_resizeDirection = ResizeNone;
|
||||
if (FloatRect{0, 0, m_bordersCached.getLeft(), getFullSize().y}.contains(pos))
|
||||
if (pos.x < m_bordersCached.getLeft())
|
||||
m_resizeDirection |= ResizeLeft;
|
||||
if (FloatRect{0, 0, getFullSize().x, m_bordersCached.getTop()}.contains(pos))
|
||||
if (pos.y < m_bordersCached.getTop())
|
||||
m_resizeDirection |= ResizeTop;
|
||||
if (FloatRect{getFullSize().x - m_bordersCached.getRight(), 0, m_bordersCached.getRight(), getFullSize().y}.contains(pos))
|
||||
if (pos.x >= getFullSize().x - m_bordersCached.getRight())
|
||||
m_resizeDirection |= ResizeRight;
|
||||
if (FloatRect{0, getFullSize().y - m_bordersCached.getBottom(), getFullSize().x, m_bordersCached.getBottom()}.contains(pos))
|
||||
if (pos.y >= getFullSize().y - m_bordersCached.getBottom())
|
||||
m_resizeDirection |= ResizeBottom;
|
||||
}
|
||||
|
||||
|
@ -734,6 +747,10 @@ namespace tgui
|
|||
m_paddingBetweenButtonsCached = getSharedRenderer()->getPaddingBetweenButtons();
|
||||
setPosition(m_position);
|
||||
}
|
||||
else if (property == "minimumresizableborderwidth")
|
||||
{
|
||||
m_MinimumResizableBorderWidthCached = getSharedRenderer()->getMinimumResizableBorderWidth();
|
||||
}
|
||||
else if (property == "showtextontitlebuttons")
|
||||
{
|
||||
m_showTextOnTitleButtonsCached = getSharedRenderer()->getShowTextOnTitleButtons();
|
||||
|
|
|
@ -250,6 +250,7 @@ TEST_CASE("[ChildWindow]")
|
|||
REQUIRE_NOTHROW(renderer->setProperty("DistanceToSide", "2"));
|
||||
REQUIRE_NOTHROW(renderer->setProperty("PaddingBetweenButtons", "1"));
|
||||
REQUIRE_NOTHROW(renderer->setProperty("TitleBarHeight", "25"));
|
||||
REQUIRE_NOTHROW(renderer->setProperty("MinimumResizableBorderWidth", "4"));
|
||||
REQUIRE_NOTHROW(renderer->setProperty("CloseButton", "{ BackgroundColor = Red; }"));
|
||||
REQUIRE_NOTHROW(renderer->setProperty("MaximizeButton", "{ BackgroundColor = Green; }"));
|
||||
REQUIRE_NOTHROW(renderer->setProperty("MinimizeButton", "{ BackgroundColor = Blue; }"));
|
||||
|
@ -266,6 +267,7 @@ TEST_CASE("[ChildWindow]")
|
|||
REQUIRE_NOTHROW(renderer->setProperty("DistanceToSide", 2));
|
||||
REQUIRE_NOTHROW(renderer->setProperty("PaddingBetweenButtons", 1));
|
||||
REQUIRE_NOTHROW(renderer->setProperty("TitleBarHeight", 25));
|
||||
REQUIRE_NOTHROW(renderer->setProperty("MinimumResizableBorderWidth", 4));
|
||||
REQUIRE_NOTHROW(renderer->setProperty("CloseButton", closeButtonRenderer.getData()));
|
||||
REQUIRE_NOTHROW(renderer->setProperty("MaximizeButton", maximizeButtonRenderer.getData()));
|
||||
REQUIRE_NOTHROW(renderer->setProperty("MinimizeButton", minimizeButtonRenderer.getData()));
|
||||
|
@ -282,6 +284,7 @@ TEST_CASE("[ChildWindow]")
|
|||
renderer->setDistanceToSide(2);
|
||||
renderer->setPaddingBetweenButtons(1);
|
||||
renderer->setTitleBarHeight(25);
|
||||
renderer->setMinimumResizableBorderWidth(4);
|
||||
|
||||
renderer->setCloseButton(closeButtonRenderer.getData());
|
||||
renderer->setMaximizeButton(maximizeButtonRenderer.getData());
|
||||
|
@ -297,6 +300,7 @@ TEST_CASE("[ChildWindow]")
|
|||
REQUIRE(renderer->getProperty("DistanceToSide").getNumber() == 2);
|
||||
REQUIRE(renderer->getProperty("PaddingBetweenButtons").getNumber() == 1);
|
||||
REQUIRE(renderer->getProperty("TitleBarHeight").getNumber() == 25);
|
||||
REQUIRE(renderer->getProperty("MinimumResizableBorderWidth").getNumber() == 4);
|
||||
|
||||
REQUIRE(renderer->getCloseButton()->propertyValuePairs["backgroundcolor"].getColor() == sf::Color::Red);
|
||||
REQUIRE(renderer->getMaximizeButton()->propertyValuePairs["backgroundcolor"].getColor() == sf::Color::Green);
|
||||
|
|
Loading…
Reference in New Issue