Renamed LowValue to ViewportSize in ScrollBar
This commit is contained in:
parent
1fc9cd57bc
commit
bc251ddcca
@ -163,7 +163,7 @@ int main()
|
||||
scrollbar->setPosition(380, 40);
|
||||
scrollbar->setSize(18, 540);
|
||||
scrollbar->setMaximum(100);
|
||||
scrollbar->setLowValue(70);
|
||||
scrollbar->setViewportSize(70);
|
||||
gui.add(scrollbar);
|
||||
|
||||
auto comboBox = tgui::ComboBox::create();
|
||||
|
@ -38,8 +38,8 @@ struct ScrollbarProperties : WidgetProperties
|
||||
scrollbar->setMaximum(static_cast<unsigned int>(tgui::stoi(value)));
|
||||
else if (property == "Value")
|
||||
scrollbar->setValue(static_cast<unsigned int>(tgui::stoi(value)));
|
||||
else if (property == "LowValue")
|
||||
scrollbar->setLowValue(static_cast<unsigned int>(tgui::stoi(value)));
|
||||
else if (property == "ViewportSize")
|
||||
scrollbar->setViewportSize(static_cast<unsigned int>(tgui::stoi(value)));
|
||||
else if (property == "ScrollAmount")
|
||||
scrollbar->setScrollAmount(static_cast<unsigned int>(tgui::stoi(value)));
|
||||
else if (property == "AutoHide")
|
||||
@ -54,7 +54,7 @@ struct ScrollbarProperties : WidgetProperties
|
||||
auto scrollbar = std::dynamic_pointer_cast<tgui::Scrollbar>(widget);
|
||||
pair.first["Maximum"] = {"UInt", tgui::to_string(scrollbar->getMaximum())};
|
||||
pair.first["Value"] = {"UInt", tgui::to_string(scrollbar->getValue())};
|
||||
pair.first["LowValue"] = {"UInt", tgui::to_string(scrollbar->getLowValue())};
|
||||
pair.first["ViewportSize"] = {"UInt", tgui::to_string(scrollbar->getViewportSize())};
|
||||
pair.first["ScrollAmount"] = {"UInt", tgui::to_string(scrollbar->getScrollAmount())};
|
||||
pair.first["AutoHide"] = {"Bool", tgui::Serializer::serialize(scrollbar->getAutoHide())};
|
||||
|
||||
|
@ -99,12 +99,11 @@ namespace tgui
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief Sets a maximum value
|
||||
///
|
||||
/// @param maximum The new maximum value
|
||||
///
|
||||
/// When the value is bigger than (maximum - low value), the value is set to maximum - low value.
|
||||
/// When the value is bigger than (maximum - viewportSize), the value is set to maximum - viewportSize.
|
||||
/// The default maximum value is 10.
|
||||
///
|
||||
/// @see setViewportSize
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
void setMaximum(unsigned int maximum);
|
||||
|
||||
@ -122,11 +121,10 @@ namespace tgui
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief Changes the current value
|
||||
///
|
||||
/// @param value The new value
|
||||
///
|
||||
/// The value has to be smaller than maximum - low value.
|
||||
///
|
||||
/// The value has to be smaller than maximum - viewportSize.
|
||||
/// @see setViewportSize
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
void setValue(unsigned int value);
|
||||
|
||||
@ -143,26 +141,25 @@ namespace tgui
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief Changes the 'low value'
|
||||
/// @brief Changes the viewport size
|
||||
///
|
||||
/// @param lowValue The new low value.
|
||||
/// In e.g. a list box, this value is the amount of items that fit inside the list box
|
||||
/// @param viewport The new viewport size
|
||||
///
|
||||
/// If the contents through which the scrollbar can scroll is 600 pixels of which only 200 pixels are visible on the
|
||||
/// screen then the viewport size should be set to 200 and the maximum should be set to 600. The thumb will occupy
|
||||
/// one third of the scrollbar track in this case. The possible scrollbar values are in the range [0, 400] in this case.
|
||||
///
|
||||
/// Until the maximum is bigger than this value, no scrollbar will be drawn.
|
||||
/// You can however choose to always draw the scrollbar by calling setAutoHide(false).
|
||||
/// The default low value is 6.
|
||||
///
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
void setLowValue(unsigned int lowValue);
|
||||
void setViewportSize(unsigned int viewport);
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief Returns the low value
|
||||
///
|
||||
/// @see setLowValue
|
||||
///
|
||||
/// @brief Returns the viewport size
|
||||
/// @see setViewportSize
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
unsigned int getLowValue() const;
|
||||
unsigned int getViewportSize() const;
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
@ -185,11 +182,10 @@ namespace tgui
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief Changes whether the scrollbar should hide automatically or not
|
||||
///
|
||||
/// When true (default), the scrollbar will not be drawn when the maximum is smaller than the low value.
|
||||
///
|
||||
/// @param autoHide Should the scrollbar be invisible when you can't scroll?
|
||||
///
|
||||
/// When true (default), the scrollbar will not be drawn when the maximum is smaller than the viewportSize.
|
||||
/// @see setViewportSize
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
void setAutoHide(bool autoHide);
|
||||
|
||||
@ -197,9 +193,8 @@ namespace tgui
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief Returns whether the scrollbar is hiding automatically or not
|
||||
///
|
||||
/// When true (default), the scrollbar will not be drawn when the maximum is smaller than the low value.
|
||||
/// So when you can't scroll, the scrollbar won't be drawn.
|
||||
///
|
||||
/// When true (default), the scrollbar will not be drawn when the maximum is smaller than the viewportSize.
|
||||
/// @see setViewportSize
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
bool getAutoHide() const;
|
||||
|
||||
@ -327,7 +322,7 @@ namespace tgui
|
||||
unsigned int m_value = 0;
|
||||
|
||||
// Maximum should be above this value before the scrollbar is needed
|
||||
unsigned int m_lowValue = 6;
|
||||
unsigned int m_viewportSize = 1;
|
||||
|
||||
// Is the scrollbar draw vertically?
|
||||
bool m_verticalScroll = true;
|
||||
@ -396,11 +391,9 @@ namespace tgui
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief Returns whether the scrollbar is currently visible
|
||||
///
|
||||
/// The scrollbar is visible when auto hide is disabled or when the maximum is higher than the low value
|
||||
///
|
||||
/// @return Is the scrollbar visible?
|
||||
///
|
||||
/// The scrollbar is visible when auto hide is disabled or when the maximum is higher than the viewport size
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
bool isShown() const;
|
||||
|
||||
|
@ -106,7 +106,7 @@ namespace tgui
|
||||
|
||||
m_scroll->setPosition(getSize().x - m_bordersCached.getRight() - m_scroll->getSize().x, m_bordersCached.getTop());
|
||||
m_scroll->setSize({m_scroll->getSize().x, getInnerSize().y});
|
||||
m_scroll->setLowValue(static_cast<unsigned int>(getInnerSize().y - m_paddingCached.getTop() - m_paddingCached.getBottom()));
|
||||
m_scroll->setViewportSize(static_cast<unsigned int>(getInnerSize().y - m_paddingCached.getTop() - m_paddingCached.getBottom()));
|
||||
|
||||
recalculateAllLines();
|
||||
}
|
||||
@ -353,7 +353,7 @@ namespace tgui
|
||||
|
||||
void ChatBox::mouseWheelScrolled(float delta, Vector2f pos)
|
||||
{
|
||||
if (m_scroll->getLowValue() < m_scroll->getMaximum())
|
||||
if (m_scroll->getViewportSize() < m_scroll->getMaximum())
|
||||
m_scroll->mouseWheelScrolled(delta, pos - getPosition());
|
||||
}
|
||||
|
||||
@ -396,10 +396,10 @@ namespace tgui
|
||||
// Scroll down to the last item when there is a scrollbar and it is at the bottom
|
||||
if (m_newLinesBelowOthers)
|
||||
{
|
||||
if (((oldMaximum >= m_scroll->getLowValue()) && (m_scroll->getValue() == oldMaximum - m_scroll->getLowValue()))
|
||||
|| ((oldMaximum <= m_scroll->getLowValue()) && (m_scroll->getMaximum() > m_scroll->getLowValue())))
|
||||
if (((oldMaximum >= m_scroll->getViewportSize()) && (m_scroll->getValue() == oldMaximum - m_scroll->getViewportSize()))
|
||||
|| ((oldMaximum <= m_scroll->getViewportSize()) && (m_scroll->getMaximum() > m_scroll->getViewportSize())))
|
||||
{
|
||||
m_scroll->setValue(m_scroll->getMaximum() - m_scroll->getLowValue());
|
||||
m_scroll->setValue(m_scroll->getMaximum() - m_scroll->getViewportSize());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -116,7 +116,7 @@ namespace tgui
|
||||
m_spriteBackground.setSize(getInnerSize());
|
||||
|
||||
m_scroll->setSize({m_scroll->getSize().x, std::max(0.f, getInnerSize().y)});
|
||||
m_scroll->setLowValue(static_cast<unsigned int>(getInnerSize().y - m_paddingCached.getTop() - m_paddingCached.getBottom()));
|
||||
m_scroll->setViewportSize(static_cast<unsigned int>(getInnerSize().y - m_paddingCached.getTop() - m_paddingCached.getBottom()));
|
||||
|
||||
setPosition(m_position);
|
||||
}
|
||||
@ -131,8 +131,8 @@ namespace tgui
|
||||
m_scroll->setMaximum(static_cast<unsigned int>((m_items.size() + 1) * m_itemHeight));
|
||||
|
||||
// Scroll down when auto-scrolling is enabled
|
||||
if (m_autoScroll && (m_scroll->getLowValue() < m_scroll->getMaximum()))
|
||||
m_scroll->setValue(m_scroll->getMaximum() - m_scroll->getLowValue());
|
||||
if (m_autoScroll && (m_scroll->getViewportSize() < m_scroll->getMaximum()))
|
||||
m_scroll->setValue(m_scroll->getMaximum() - m_scroll->getViewportSize());
|
||||
|
||||
// Create the new item
|
||||
Text newItem;
|
||||
@ -198,8 +198,8 @@ namespace tgui
|
||||
// Move the scrollbar
|
||||
if (m_selectedItem * getItemHeight() < m_scroll->getValue())
|
||||
m_scroll->setValue(m_selectedItem * getItemHeight());
|
||||
else if ((m_selectedItem + 1) * getItemHeight() > m_scroll->getValue() + m_scroll->getLowValue())
|
||||
m_scroll->setValue((m_selectedItem + 1) * getItemHeight() - m_scroll->getLowValue());
|
||||
else if ((m_selectedItem + 1) * getItemHeight() > m_scroll->getValue() + m_scroll->getViewportSize())
|
||||
m_scroll->setValue((m_selectedItem + 1) * getItemHeight() - m_scroll->getViewportSize());
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -986,13 +986,13 @@ namespace tgui
|
||||
// Find out which items are visible
|
||||
std::size_t firstItem = 0;
|
||||
std::size_t lastItem = m_items.size();
|
||||
if (m_scroll->getLowValue() < m_scroll->getMaximum())
|
||||
if (m_scroll->getViewportSize() < m_scroll->getMaximum())
|
||||
{
|
||||
firstItem = m_scroll->getValue() / m_itemHeight;
|
||||
lastItem = (m_scroll->getValue() + m_scroll->getLowValue()) / m_itemHeight;
|
||||
lastItem = (m_scroll->getValue() + m_scroll->getViewportSize()) / m_itemHeight;
|
||||
|
||||
// Show another item when the scrollbar is standing between two items
|
||||
if ((m_scroll->getValue() + m_scroll->getLowValue()) % m_itemHeight != 0)
|
||||
if ((m_scroll->getValue() + m_scroll->getViewportSize()) % m_itemHeight != 0)
|
||||
++lastItem;
|
||||
}
|
||||
|
||||
|
@ -490,9 +490,9 @@ namespace tgui
|
||||
Vector2f contentSize = {innerSize.x - m_paddingCached.getLeft() - m_paddingCached.getRight(),
|
||||
innerSize.y - m_paddingCached.getTop() - m_paddingCached.getBottom()};
|
||||
|
||||
if (m_verticalScrollbar->isVisible() && (m_verticalScrollbar->getMaximum() > m_verticalScrollbar->getLowValue()))
|
||||
if (m_verticalScrollbar->isVisible() && (m_verticalScrollbar->getMaximum() > m_verticalScrollbar->getViewportSize()))
|
||||
contentSize.x -= m_verticalScrollbar->getSize().x;
|
||||
if (m_horizontalScrollbar->isVisible() && (m_horizontalScrollbar->getMaximum() > m_horizontalScrollbar->getLowValue()))
|
||||
if (m_horizontalScrollbar->isVisible() && (m_horizontalScrollbar->getMaximum() > m_horizontalScrollbar->getViewportSize()))
|
||||
contentSize.y -= m_horizontalScrollbar->getSize().y;
|
||||
|
||||
// If the content size is manually specified and smaller than the panel itself, then use it for clipping
|
||||
@ -600,20 +600,20 @@ namespace tgui
|
||||
getSize().y - m_bordersCached.getTop() - m_bordersCached.getBottom()};
|
||||
|
||||
const Vector2f visibleSize = getInnerSize();
|
||||
m_horizontalScrollbar->setLowValue(static_cast<unsigned int>(visibleSize.x));
|
||||
m_verticalScrollbar->setLowValue(static_cast<unsigned int>(visibleSize.y));
|
||||
m_horizontalScrollbar->setViewportSize(static_cast<unsigned int>(visibleSize.x));
|
||||
m_verticalScrollbar->setViewportSize(static_cast<unsigned int>(visibleSize.y));
|
||||
|
||||
const Vector2f contentSize = getContentSize();
|
||||
m_horizontalScrollbar->setMaximum(static_cast<unsigned int>(contentSize.x));
|
||||
m_verticalScrollbar->setMaximum(static_cast<unsigned int>(contentSize.y));
|
||||
|
||||
const bool horizontalScrollbarVisible = m_horizontalScrollbar->isVisible() && (!m_horizontalScrollbar->getAutoHide() || (m_horizontalScrollbar->getMaximum() > m_horizontalScrollbar->getLowValue()));
|
||||
const bool horizontalScrollbarVisible = m_horizontalScrollbar->isVisible() && (!m_horizontalScrollbar->getAutoHide() || (m_horizontalScrollbar->getMaximum() > m_horizontalScrollbar->getViewportSize()));
|
||||
if (horizontalScrollbarVisible)
|
||||
{
|
||||
m_verticalScrollbar->setSize(m_verticalScrollbar->getSize().x, scrollbarSpace.y - m_horizontalScrollbar->getSize().y);
|
||||
m_verticalScrollbar->setLowValue(static_cast<unsigned int>(m_verticalScrollbar->getLowValue() - m_horizontalScrollbar->getSize().y));
|
||||
m_verticalScrollbar->setViewportSize(static_cast<unsigned int>(m_verticalScrollbar->getViewportSize() - m_horizontalScrollbar->getSize().y));
|
||||
|
||||
const bool verticalScrollbarVisible = m_verticalScrollbar->isVisible() && (!m_verticalScrollbar->getAutoHide() || (m_verticalScrollbar->getMaximum() > m_verticalScrollbar->getLowValue()));
|
||||
const bool verticalScrollbarVisible = m_verticalScrollbar->isVisible() && (!m_verticalScrollbar->getAutoHide() || (m_verticalScrollbar->getMaximum() > m_verticalScrollbar->getViewportSize()));
|
||||
if (verticalScrollbarVisible)
|
||||
m_horizontalScrollbar->setSize(scrollbarSpace.x - m_verticalScrollbar->getSize().x, m_horizontalScrollbar->getSize().y);
|
||||
else
|
||||
@ -623,13 +623,13 @@ namespace tgui
|
||||
{
|
||||
m_verticalScrollbar->setSize(m_verticalScrollbar->getSize().x, scrollbarSpace.y);
|
||||
|
||||
const bool verticalScrollbarVisible = m_verticalScrollbar->isVisible() && (!m_verticalScrollbar->getAutoHide() || (m_verticalScrollbar->getMaximum() > m_verticalScrollbar->getLowValue()));
|
||||
const bool verticalScrollbarVisible = m_verticalScrollbar->isVisible() && (!m_verticalScrollbar->getAutoHide() || (m_verticalScrollbar->getMaximum() > m_verticalScrollbar->getViewportSize()));
|
||||
if (verticalScrollbarVisible)
|
||||
{
|
||||
m_horizontalScrollbar->setSize(scrollbarSpace.x - m_verticalScrollbar->getSize().x, m_horizontalScrollbar->getSize().y);
|
||||
m_horizontalScrollbar->setLowValue(static_cast<unsigned int>(m_horizontalScrollbar->getLowValue() - m_verticalScrollbar->getSize().x));
|
||||
m_horizontalScrollbar->setViewportSize(static_cast<unsigned int>(m_horizontalScrollbar->getViewportSize() - m_verticalScrollbar->getSize().x));
|
||||
|
||||
if (m_horizontalScrollbar->isVisible() && (!m_horizontalScrollbar->getAutoHide() || (m_horizontalScrollbar->getMaximum() > m_horizontalScrollbar->getLowValue())))
|
||||
if (m_horizontalScrollbar->isVisible() && (!m_horizontalScrollbar->getAutoHide() || (m_horizontalScrollbar->getMaximum() > m_horizontalScrollbar->getViewportSize())))
|
||||
m_verticalScrollbar->setSize(m_verticalScrollbar->getSize().x, scrollbarSpace.y - m_horizontalScrollbar->getSize().y);
|
||||
}
|
||||
else
|
||||
@ -639,10 +639,10 @@ namespace tgui
|
||||
m_verticalScrollbar->setPosition(m_bordersCached.getLeft() + scrollbarSpace.x - m_verticalScrollbar->getSize().x, m_bordersCached.getTop());
|
||||
m_horizontalScrollbar->setPosition(m_bordersCached.getLeft(), m_bordersCached.getTop() + scrollbarSpace.y - m_horizontalScrollbar->getSize().y);
|
||||
|
||||
const float verticalSpeed = 40.f * (static_cast<float>(m_verticalScrollbar->getMaximum() - m_verticalScrollbar->getLowValue()) / m_verticalScrollbar->getLowValue());
|
||||
const float verticalSpeed = 40.f * (static_cast<float>(m_verticalScrollbar->getMaximum() - m_verticalScrollbar->getViewportSize()) / m_verticalScrollbar->getViewportSize());
|
||||
m_verticalScrollbar->setScrollAmount(static_cast<unsigned int>(std::ceil(std::sqrt(verticalSpeed))));
|
||||
|
||||
const float horizontalSpeed = 40.f * (static_cast<float>(m_horizontalScrollbar->getMaximum() - m_horizontalScrollbar->getLowValue()) / m_horizontalScrollbar->getLowValue());
|
||||
const float horizontalSpeed = 40.f * (static_cast<float>(m_horizontalScrollbar->getMaximum() - m_horizontalScrollbar->getViewportSize()) / m_horizontalScrollbar->getViewportSize());
|
||||
m_horizontalScrollbar->setScrollAmount(static_cast<unsigned int>(std::ceil(std::sqrt(horizontalSpeed))));
|
||||
}
|
||||
|
||||
|
@ -124,8 +124,8 @@ namespace tgui
|
||||
m_track.height = std::max(0.f, getSize().y - m_arrowUp.height - m_arrowDown.height);
|
||||
|
||||
m_thumb.width = getSize().x;
|
||||
if (m_maximum > m_lowValue)
|
||||
m_thumb.height = m_track.height * m_lowValue / m_maximum;
|
||||
if (m_maximum > m_viewportSize)
|
||||
m_thumb.height = m_track.height * m_viewportSize / m_maximum;
|
||||
else
|
||||
m_thumb.height = m_track.height;
|
||||
}
|
||||
@ -149,8 +149,8 @@ namespace tgui
|
||||
m_track.height = getSize().y;
|
||||
|
||||
m_thumb.height = getSize().y;
|
||||
if (m_maximum > m_lowValue)
|
||||
m_thumb.width = m_track.width * m_lowValue / m_maximum;
|
||||
if (m_maximum > m_viewportSize)
|
||||
m_thumb.width = m_track.width * m_viewportSize / m_maximum;
|
||||
else
|
||||
m_thumb.width = m_track.width;
|
||||
}
|
||||
@ -235,10 +235,10 @@ namespace tgui
|
||||
m_maximum = 1;
|
||||
|
||||
// When the value is above the maximum then adjust it
|
||||
if (m_maximum < m_lowValue)
|
||||
if (m_maximum < m_viewportSize)
|
||||
setValue(0);
|
||||
else if (m_value > m_maximum - m_lowValue)
|
||||
setValue(m_maximum - m_lowValue);
|
||||
else if (m_value > m_maximum - m_viewportSize)
|
||||
setValue(m_maximum - m_viewportSize);
|
||||
|
||||
// Recalculate the size and position of the thumb image
|
||||
setSize(m_size);
|
||||
@ -256,10 +256,10 @@ namespace tgui
|
||||
void Scrollbar::setValue(unsigned int value)
|
||||
{
|
||||
// When the value is above the maximum then adjust it
|
||||
if (m_maximum < m_lowValue)
|
||||
if (m_maximum < m_viewportSize)
|
||||
value = 0;
|
||||
else if (value > m_maximum - m_lowValue)
|
||||
value = m_maximum - m_lowValue;
|
||||
else if (value > m_maximum - m_viewportSize)
|
||||
value = m_maximum - m_viewportSize;
|
||||
|
||||
if (m_value != value)
|
||||
{
|
||||
@ -281,16 +281,16 @@ namespace tgui
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void Scrollbar::setLowValue(unsigned int lowValue)
|
||||
void Scrollbar::setViewportSize(unsigned int viewportSize)
|
||||
{
|
||||
// Set the new value
|
||||
m_lowValue = lowValue;
|
||||
m_viewportSize = viewportSize;
|
||||
|
||||
// When the value is above the maximum then adjust it
|
||||
if (m_maximum < m_lowValue)
|
||||
if (m_maximum < m_viewportSize)
|
||||
setValue(0);
|
||||
else if (m_value > m_maximum - m_lowValue)
|
||||
setValue(m_maximum - m_lowValue);
|
||||
else if (m_value > m_maximum - m_viewportSize)
|
||||
setValue(m_maximum - m_viewportSize);
|
||||
|
||||
// Recalculate the size and position of the thumb image
|
||||
setSize(m_size);
|
||||
@ -298,9 +298,9 @@ namespace tgui
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
unsigned int Scrollbar::getLowValue() const
|
||||
unsigned int Scrollbar::getViewportSize() const
|
||||
{
|
||||
return m_lowValue;
|
||||
return m_viewportSize;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
@ -336,7 +336,7 @@ namespace tgui
|
||||
bool Scrollbar::mouseOnWidget(Vector2f pos) const
|
||||
{
|
||||
// Don't make any calculations when no scrollbar is needed
|
||||
if (m_autoHide && (m_maximum <= m_lowValue))
|
||||
if (m_autoHide && (m_maximum <= m_viewportSize))
|
||||
return false;
|
||||
|
||||
return FloatRect{getPosition().x, getPosition().y, getSize().x, getSize().y}.contains(pos);
|
||||
@ -400,7 +400,7 @@ namespace tgui
|
||||
if (m_mouseDown && m_mouseDownOnArrow)
|
||||
{
|
||||
// Only continue when the calculations can be made
|
||||
if (m_maximum > m_lowValue)
|
||||
if (m_maximum > m_viewportSize)
|
||||
{
|
||||
bool valueDown = false;
|
||||
bool valueUp = false;
|
||||
@ -467,7 +467,7 @@ namespace tgui
|
||||
}
|
||||
else if (valueUp)
|
||||
{
|
||||
if (m_value + m_scrollAmount < m_maximum - m_lowValue + 1)
|
||||
if (m_value + m_scrollAmount < m_maximum - m_viewportSize + 1)
|
||||
{
|
||||
if (m_value % m_scrollAmount)
|
||||
setValue(m_value + (m_scrollAmount - (m_value % m_scrollAmount)));
|
||||
@ -475,7 +475,7 @@ namespace tgui
|
||||
setValue(m_value + m_scrollAmount);
|
||||
}
|
||||
else
|
||||
setValue(m_maximum - m_lowValue);
|
||||
setValue(m_maximum - m_viewportSize);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -498,7 +498,7 @@ namespace tgui
|
||||
if (m_mouseDown && !m_mouseDownOnArrow)
|
||||
{
|
||||
// Don't continue if the calculations can't be made
|
||||
if (!m_autoHide && (m_maximum <= m_lowValue))
|
||||
if (!m_autoHide && (m_maximum <= m_viewportSize))
|
||||
return;
|
||||
|
||||
// Check in which direction the scrollbar lies
|
||||
@ -515,10 +515,10 @@ namespace tgui
|
||||
/ (getSize().y - m_arrowUp.height - m_arrowDown.height)) * m_maximum) + 0.5f);
|
||||
|
||||
// If the value isn't too high then change it
|
||||
if (value <= (m_maximum - m_lowValue))
|
||||
if (value <= (m_maximum - m_viewportSize))
|
||||
setValue(value);
|
||||
else
|
||||
setValue(m_maximum - m_lowValue);
|
||||
setValue(m_maximum - m_viewportSize);
|
||||
}
|
||||
else // The mouse was above the scrollbar
|
||||
setValue(0);
|
||||
@ -528,7 +528,7 @@ namespace tgui
|
||||
if ((thumbTop - m_arrowUp.height > 0) && (thumbTop + m_thumb.height + m_arrowDown.height < getSize().y))
|
||||
m_thumb.top = thumbTop;
|
||||
else // Prevent the thumb from going outside the scrollbar
|
||||
m_thumb.top = m_track.top + ((m_track.height - m_thumb.height) * m_value / (m_maximum - m_lowValue));
|
||||
m_thumb.top = m_track.top + ((m_track.height - m_thumb.height) * m_value / (m_maximum - m_viewportSize));
|
||||
}
|
||||
else // The click occurred on the track
|
||||
{
|
||||
@ -544,7 +544,7 @@ namespace tgui
|
||||
// Check if you clicked above the thumb
|
||||
if (value <= m_value)
|
||||
{
|
||||
const float subtractValue = m_lowValue / 3.0f;
|
||||
const float subtractValue = m_viewportSize / 3.0f;
|
||||
|
||||
// Try to place the thumb on 2/3 of the clicked position
|
||||
if (value >= subtractValue)
|
||||
@ -554,13 +554,13 @@ namespace tgui
|
||||
}
|
||||
else // The click occurred below the thumb
|
||||
{
|
||||
const float subtractValue = m_lowValue * 2.0f / 3.0f;
|
||||
const float subtractValue = m_viewportSize * 2.0f / 3.0f;
|
||||
|
||||
// Try to place the thumb on 2/3 of the clicked position
|
||||
if (value <= (m_maximum - m_lowValue + subtractValue))
|
||||
if (value <= (m_maximum - m_viewportSize + subtractValue))
|
||||
setValue(static_cast<unsigned int>(value - subtractValue + 0.5f));
|
||||
else
|
||||
setValue(m_maximum - m_lowValue);
|
||||
setValue(m_maximum - m_viewportSize);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -582,10 +582,10 @@ namespace tgui
|
||||
const unsigned int value = static_cast<unsigned int>((((pos.x - m_mouseDownOnThumbPos.x - m_arrowUp.width)
|
||||
/ (getSize().x - m_arrowUp.width - m_arrowDown.width)) * m_maximum) + 0.5f);
|
||||
// If the value isn't too high then change it
|
||||
if (value <= (m_maximum - m_lowValue))
|
||||
if (value <= (m_maximum - m_viewportSize))
|
||||
setValue(value);
|
||||
else
|
||||
setValue(m_maximum - m_lowValue);
|
||||
setValue(m_maximum - m_viewportSize);
|
||||
}
|
||||
else // The mouse was to the left of the thumb
|
||||
setValue(0);
|
||||
@ -595,7 +595,7 @@ namespace tgui
|
||||
if ((thumbLeft - m_arrowUp.width > 0) && (thumbLeft + m_thumb.width + m_arrowDown.width < getSize().x))
|
||||
m_thumb.left = thumbLeft;
|
||||
else // Prevent the thumb from going outside the scrollbar
|
||||
m_thumb.left = m_track.left + ((m_track.width - m_thumb.width) * m_value / (m_maximum - m_lowValue));
|
||||
m_thumb.left = m_track.left + ((m_track.width - m_thumb.width) * m_value / (m_maximum - m_viewportSize));
|
||||
}
|
||||
else // The click occurred on the track
|
||||
{
|
||||
@ -611,7 +611,7 @@ namespace tgui
|
||||
// Check if you clicked to the left of the thumb
|
||||
if (value <= m_value)
|
||||
{
|
||||
const float subtractValue = m_lowValue / 3.0f;
|
||||
const float subtractValue = m_viewportSize / 3.0f;
|
||||
|
||||
// Try to place the thumb on 2/3 of the clicked position
|
||||
if (value >= subtractValue)
|
||||
@ -621,13 +621,13 @@ namespace tgui
|
||||
}
|
||||
else // The click occurred to the right of the thumb
|
||||
{
|
||||
const float subtractValue = m_lowValue * 2.0f / 3.0f;
|
||||
const float subtractValue = m_viewportSize * 2.0f / 3.0f;
|
||||
|
||||
// Try to place the thumb on 2/3 of the clicked position
|
||||
if (value <= (m_maximum - m_lowValue + subtractValue))
|
||||
if (value <= (m_maximum - m_viewportSize + subtractValue))
|
||||
setValue(static_cast<unsigned int>(value - subtractValue + 0.5f));
|
||||
else
|
||||
setValue(m_maximum - m_lowValue);
|
||||
setValue(m_maximum - m_viewportSize);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -779,7 +779,7 @@ namespace tgui
|
||||
auto node = Widget::save(renderers);
|
||||
|
||||
node->propertyValuePairs["AutoHide"] = std::make_unique<DataIO::ValueNode>(Serializer::serialize(m_autoHide));
|
||||
node->propertyValuePairs["LowValue"] = std::make_unique<DataIO::ValueNode>(to_string(m_lowValue));
|
||||
node->propertyValuePairs["ViewportSize"] = std::make_unique<DataIO::ValueNode>(to_string(m_viewportSize));
|
||||
node->propertyValuePairs["Maximum"] = std::make_unique<DataIO::ValueNode>(to_string(m_maximum));
|
||||
node->propertyValuePairs["Value"] = std::make_unique<DataIO::ValueNode>(to_string(m_value));
|
||||
node->propertyValuePairs["ScrollAmount"] = std::make_unique<DataIO::ValueNode>(to_string(m_scrollAmount));
|
||||
@ -793,8 +793,8 @@ namespace tgui
|
||||
{
|
||||
Widget::load(node, renderers);
|
||||
|
||||
if (node->propertyValuePairs["lowvalue"])
|
||||
setLowValue(tgui::stoi(node->propertyValuePairs["lowvalue"]->value));
|
||||
if (node->propertyValuePairs["viewportsize"])
|
||||
setViewportSize(tgui::stoi(node->propertyValuePairs["viewportsize"]->value));
|
||||
if (node->propertyValuePairs["maximum"])
|
||||
setMaximum(tgui::stoi(node->propertyValuePairs["maximum"]->value));
|
||||
if (node->propertyValuePairs["value"])
|
||||
@ -812,11 +812,11 @@ namespace tgui
|
||||
if (m_verticalScroll)
|
||||
{
|
||||
m_thumb.left = 0;
|
||||
m_thumb.top = m_track.top + ((m_track.height - m_thumb.height) * m_value / (m_maximum - m_lowValue));
|
||||
m_thumb.top = m_track.top + ((m_track.height - m_thumb.height) * m_value / (m_maximum - m_viewportSize));
|
||||
}
|
||||
else
|
||||
{
|
||||
m_thumb.left = m_track.left + ((m_track.width - m_thumb.width) * m_value / (m_maximum - m_lowValue));
|
||||
m_thumb.left = m_track.left + ((m_track.width - m_thumb.width) * m_value / (m_maximum - m_viewportSize));
|
||||
m_thumb.top = 0;
|
||||
}
|
||||
}
|
||||
@ -826,7 +826,7 @@ namespace tgui
|
||||
void Scrollbar::draw(sf::RenderTarget& target, sf::RenderStates states) const
|
||||
{
|
||||
// Don't draw the scrollbar when it is not needed
|
||||
if (m_autoHide && (m_maximum <= m_lowValue))
|
||||
if (m_autoHide && (m_maximum <= m_viewportSize))
|
||||
return;
|
||||
|
||||
states.transform.translate(getPosition());
|
||||
@ -966,7 +966,7 @@ namespace tgui
|
||||
|
||||
bool ScrollbarChildWidget::isShown() const
|
||||
{
|
||||
return m_visible && (!m_autoHide || (m_maximum > m_lowValue));
|
||||
return m_visible && (!m_autoHide || (m_maximum > m_viewportSize));
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -118,7 +118,7 @@ namespace tgui
|
||||
// If there is a scrollbar then reinitialize it
|
||||
if (isVerticalScrollbarPresent())
|
||||
{
|
||||
m_verticalScroll->setLowValue(static_cast<unsigned int>(getInnerSize().y - m_paddingCached.getTop() - m_paddingCached.getBottom()));
|
||||
m_verticalScroll->setViewportSize(static_cast<unsigned int>(getInnerSize().y - m_paddingCached.getTop() - m_paddingCached.getBottom()));
|
||||
m_verticalScroll->setSize({m_verticalScroll->getSize().x, getInnerSize().y});
|
||||
}
|
||||
|
||||
@ -469,7 +469,7 @@ namespace tgui
|
||||
if (m_selEnd.y <= m_topLine)
|
||||
m_verticalScroll->setValue(static_cast<unsigned int>(m_selEnd.y * m_lineHeight));
|
||||
else if (m_selEnd.y + 1 >= m_topLine + m_visibleLines)
|
||||
m_verticalScroll->setValue(static_cast<unsigned int>(((m_selEnd.y + 1) * m_lineHeight) - m_verticalScroll->getLowValue()));
|
||||
m_verticalScroll->setValue(static_cast<unsigned int>(((m_selEnd.y + 1) * m_lineHeight) - m_verticalScroll->getViewportSize()));
|
||||
|
||||
recalculateVisibleLines();
|
||||
}
|
||||
@ -1279,7 +1279,7 @@ namespace tgui
|
||||
m_verticalScroll->setValue(static_cast<unsigned int>(((m_selEnd.y + 1) * m_lineHeight)
|
||||
+ Text::calculateExtraVerticalSpace(m_fontCached, m_textSize)
|
||||
+ Text::getExtraVerticalPadding(m_textSize)
|
||||
- m_verticalScroll->getLowValue()));
|
||||
- m_verticalScroll->getViewportSize()));
|
||||
}
|
||||
|
||||
recalculatePositions();
|
||||
|
@ -30,7 +30,7 @@ TEST_CASE("[Scrollbar]")
|
||||
tgui::Scrollbar::Ptr scrollbar = tgui::Scrollbar::create();
|
||||
scrollbar->getRenderer()->setFont("resources/DejaVuSans.ttf");
|
||||
scrollbar->setMaximum(20);
|
||||
scrollbar->setLowValue(5);
|
||||
scrollbar->setViewportSize(5);
|
||||
scrollbar->setValue(10);
|
||||
|
||||
SECTION("Signals")
|
||||
@ -57,22 +57,22 @@ TEST_CASE("[Scrollbar]")
|
||||
REQUIRE(scrollbar->getWidgetOffset() == sf::Vector2f(0, 0));
|
||||
}
|
||||
|
||||
SECTION("LowValue")
|
||||
SECTION("ViewportSize")
|
||||
{
|
||||
REQUIRE(scrollbar->getLowValue() == 5);
|
||||
REQUIRE(scrollbar->getViewportSize() == 5);
|
||||
|
||||
scrollbar->setLowValue(7);
|
||||
REQUIRE(scrollbar->getLowValue() == 7);
|
||||
scrollbar->setViewportSize(7);
|
||||
REQUIRE(scrollbar->getViewportSize() == 7);
|
||||
REQUIRE(scrollbar->getValue() == 10);
|
||||
REQUIRE(scrollbar->getMaximum() == 20);
|
||||
|
||||
scrollbar->setLowValue(16);
|
||||
REQUIRE(scrollbar->getLowValue() == 16);
|
||||
scrollbar->setViewportSize(16);
|
||||
REQUIRE(scrollbar->getViewportSize() == 16);
|
||||
REQUIRE(scrollbar->getValue() == 4);
|
||||
REQUIRE(scrollbar->getMaximum() == 20);
|
||||
|
||||
scrollbar->setLowValue(22);
|
||||
REQUIRE(scrollbar->getLowValue() == 22);
|
||||
scrollbar->setViewportSize(22);
|
||||
REQUIRE(scrollbar->getViewportSize() == 22);
|
||||
REQUIRE(scrollbar->getValue() == 0);
|
||||
REQUIRE(scrollbar->getMaximum() == 20);
|
||||
}
|
||||
@ -82,17 +82,17 @@ TEST_CASE("[Scrollbar]")
|
||||
REQUIRE(scrollbar->getMaximum() == 20);
|
||||
|
||||
scrollbar->setMaximum(17);
|
||||
REQUIRE(scrollbar->getLowValue() == 5);
|
||||
REQUIRE(scrollbar->getViewportSize() == 5);
|
||||
REQUIRE(scrollbar->getValue() == 10);
|
||||
REQUIRE(scrollbar->getMaximum() == 17);
|
||||
|
||||
scrollbar->setMaximum(12);
|
||||
REQUIRE(scrollbar->getLowValue() == 5);
|
||||
REQUIRE(scrollbar->getViewportSize() == 5);
|
||||
REQUIRE(scrollbar->getValue() == 7);
|
||||
REQUIRE(scrollbar->getMaximum() == 12);
|
||||
|
||||
scrollbar->setMaximum(4);
|
||||
REQUIRE(scrollbar->getLowValue() == 5);
|
||||
REQUIRE(scrollbar->getViewportSize() == 5);
|
||||
REQUIRE(scrollbar->getValue() == 0);
|
||||
REQUIRE(scrollbar->getMaximum() == 4);
|
||||
}
|
||||
@ -266,7 +266,7 @@ TEST_CASE("[Scrollbar]")
|
||||
SECTION("Saving and loading from file")
|
||||
{
|
||||
scrollbar->setMaximum(50);
|
||||
scrollbar->setLowValue(10);
|
||||
scrollbar->setViewportSize(10);
|
||||
scrollbar->setValue(20);
|
||||
scrollbar->setScrollAmount(5);
|
||||
scrollbar->setAutoHide(false);
|
||||
@ -281,7 +281,7 @@ TEST_CASE("[Scrollbar]")
|
||||
scrollbar->setEnabled(true);
|
||||
scrollbar->setPosition({10, 15});
|
||||
scrollbar->setSize({100, 30});
|
||||
scrollbar->setLowValue(120);
|
||||
scrollbar->setViewportSize(120);
|
||||
scrollbar->setMaximum(200);
|
||||
scrollbar->setValue(30);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user