Labels can now have a scrollbar (disabled by default for backwards compatibility)

0.8
Bruno Van de Velde 2018-12-22 18:38:18 +01:00
parent e56acc278d
commit 10a02dbd8f
15 changed files with 381 additions and 62 deletions

View File

@ -1,6 +1,9 @@
TGUI 0.8.3 (TBD)
-----------------
- Label can now have a vertical scrollbar
- Default scrollbar width wasn't always taken from texture size in widgets containing scrollbars
- Scrollbar wasn't drawn correctly when Maximum equaled ViewportSize with AutoHide disabled
- Default icons in TreeView didn't change color when item was selected
- Rounded icon position in TreeView to avoid bad icon alignment
@ -11,7 +14,7 @@ TGUI 0.8.2 (16 December 2018)
- TreeView widget added
- Text styles of lines in ChatBox can now be changed
- Clipping was broken when using multiple windows
- ScrollbablePanel didn't fully scroll to right with both scrollbars visible
- ScrollbablePanel didn't fully scroll to the right with both scrollbars visible
TGUI 0.8.1 (15 October 2018)

View File

@ -98,4 +98,9 @@
#define TGUI_PRINT_WARNING(msg)
#endif
#ifdef TGUI_NEXT
#define TGUI_REMOVE_DEPRECATED_CODE
#define TGUI_USE_CPP17
#endif
#endif // TGUI_CONFIG_HPP

View File

@ -144,7 +144,7 @@
return it->second.getRenderer(); \
else \
{ \
auto renderer = Theme::getDefault()->getRendererNoThrow(RENDERER); \
const auto& renderer = Theme::getDefault()->getRendererNoThrow(RENDERER); \
m_data->propertyValuePairs[toLower(#NAME)] = {renderer ? renderer : RendererData::create()}; \
return renderer; \
} \

View File

@ -159,6 +159,34 @@ namespace tgui
TextStyle getTextStyle() const;
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// @brief Sets the renderer data of the scrollbars
/// @param scrollbarRendererData Data about how the scrollbars should look
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void setScrollbar(std::shared_ptr<RendererData> scrollbarRendererData);
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// @brief Returns the renderer data of the scrollbars
/// @return Data about how the scrollbars looks
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
std::shared_ptr<RendererData> getScrollbar() const;
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// @brief Sets the wanted width of the scrollbar
/// @param scrollbarWidth Requested scrollbar width or 0 to use the default width (texture size if using textures)
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void setScrollbarWidth(float scrollbarWidth);
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// @brief Returns the wanted width of the scrollbar
/// @return Requested scrollbar width or 0 if no width was set (texture width or default value will be used)
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
float getScrollbarWidth() const;
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
};

View File

@ -59,14 +59,14 @@ namespace tgui
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// @brief Sets the wanted width scrollbar
/// @brief Sets the wanted width of the scrollbar
/// @param scrollbarWidth Requested scrollbar width or 0 to use the default width (texture size if using textures)
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void setScrollbarWidth(float scrollbarWidth);
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// @brief Returns the wanted width scrollbar
/// @brief Returns the wanted width of the scrollbar
/// @return Requested scrollbar width or 0 if no width was set (texture width or default value will be used)
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
float getScrollbarWidth() const;

View File

@ -29,6 +29,8 @@
#include <TGUI/Widgets/ClickableWidget.hpp>
#include <TGUI/Renderers/LabelRenderer.hpp>
#include <TGUI/CopiedSharedPtr.hpp>
#include <TGUI/Widgets/Scrollbar.hpp>
#include <TGUI/Text.hpp>
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@ -46,6 +48,15 @@ namespace tgui
typedef std::shared_ptr<const Label> ConstPtr; ///< Shared constant widget pointer
/// @brief Defines when the scrollbar shows up
enum class ScrollbarPolicy
{
Automatic, ///< Show the scrollbar only when needed (default)
Always, ///< Always show the scrollbar (except for auto-sized labels), even when the text fits inside the label
Never ///< Never show the scrollbar, even if the text does not fit inside the label
};
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// @brief The horizontal text alignment
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@ -211,6 +222,20 @@ namespace tgui
VerticalAlignment getVerticalAlignment() const;
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// @brief Changes when the vertical scrollbar should be displayed
/// @param policy The policy for displaying the vertical scrollbar
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void setScrollbarPolicy(ScrollbarPolicy policy);
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// @brief Returns when the vertical scrollbar should be displayed
/// @return The policy for displaying the vertical scrollbar
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
ScrollbarPolicy getScrollbarPolicy() const;
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// @brief Changes whether the label is auto-sized or not
///
@ -296,11 +321,24 @@ namespace tgui
bool canGainFocus() const override;
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// @internal
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void leftMousePressed(Vector2f pos) override;
/// @internal
void leftMouseReleased(Vector2f pos) override;
/// @internal
void mouseMoved(Vector2f pos) override;
/// @internal
bool mouseWheelScrolled(float delta, Vector2f pos) override;
/// @internal
void mouseNoLongerOnWidget() override;
/// @internal
void mouseNoLongerDown() override;
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// @brief Draw the widget to a render target
@ -394,6 +432,13 @@ namespace tgui
// Will be set to true after the first click, but gets reset to false when the second click does not occur soon after
bool m_possibleDoubleClick = false;
CopiedSharedPtr<ScrollbarChildWidget> m_scrollbar;
#ifdef TGUI_NEXT
ScrollbarPolicy m_scrollbarPolicy = ScrollbarPolicy::Automatic;
#else
ScrollbarPolicy m_scrollbarPolicy = ScrollbarPolicy::Never;
#endif
// Cached renderer properties
Borders m_bordersCached;
Padding m_paddingCached;

View File

@ -38,6 +38,9 @@ namespace tgui
TGUI_RENDERER_PROPERTY_COLOR(LabelRenderer, BorderColor, Color::Black)
TGUI_RENDERER_PROPERTY_TEXT_STYLE(LabelRenderer, TextStyle, sf::Text::Regular)
TGUI_RENDERER_PROPERTY_RENDERER(LabelRenderer, Scrollbar, "scrollbar")
TGUI_RENDERER_PROPERTY_NUMBER(LabelRenderer, ScrollbarWidth, 0)
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

View File

@ -28,10 +28,6 @@
#include <cmath>
#ifdef TGUI_USE_CPP17
#include <optional>
#endif
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
namespace tgui
@ -41,10 +37,12 @@ namespace tgui
Label::Label()
{
m_type = "Label";
m_draggableWidget = true;
m_renderer = aurora::makeCopied<LabelRenderer>();
setRenderer(Theme::getDefault()->getRendererNoThrow(m_type));
m_scrollbar->setVisible(false);
setTextSize(getGlobalTextSize());
}
@ -177,13 +175,31 @@ namespace tgui
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void Label::setScrollbarPolicy(ScrollbarPolicy policy)
{
m_scrollbarPolicy = policy;
// The policy only has an effect when not auto-sizing
if (!m_autoSize)
rearrangeText();
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Label::ScrollbarPolicy Label::getScrollbarPolicy() const
{
return m_scrollbarPolicy;
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void Label::setAutoSize(bool autoSize)
{
if (m_autoSize != autoSize)
{
m_autoSize = autoSize;
rearrangeText();
}
if (m_autoSize == autoSize)
return;
m_autoSize = autoSize;
rearrangeText();
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@ -197,11 +213,11 @@ namespace tgui
void Label::setMaximumTextWidth(float maximumWidth)
{
if (m_maximumTextWidth != maximumWidth)
{
m_maximumTextWidth = maximumWidth;
rearrangeText();
}
if (m_maximumTextWidth == maximumWidth)
return;
m_maximumTextWidth = maximumWidth;
rearrangeText();
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@ -246,26 +262,93 @@ namespace tgui
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void Label::leftMousePressed(Vector2f pos)
{
if (m_scrollbar->isShown() && m_scrollbar->mouseOnWidget(pos - getPosition()))
{
m_mouseDown = true;
m_scrollbar->leftMousePressed(pos - getPosition());
}
else
ClickableWidget::leftMousePressed(pos);
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void Label::leftMouseReleased(Vector2f pos)
{
const bool mouseDown = m_mouseDown;
ClickableWidget::leftMouseReleased(pos);
if (mouseDown)
if (!m_scrollbar->isShown() || !m_scrollbar->isMouseDown())
{
// Check if you double-clicked
if (m_possibleDoubleClick)
const bool mouseDown = m_mouseDown;
ClickableWidget::leftMouseReleased(pos);
if (mouseDown)
{
// Check if you double-clicked
if (m_possibleDoubleClick)
{
m_possibleDoubleClick = false;
onDoubleClick.emit(this, m_string);
}
else // This is the first click
{
m_animationTimeElapsed = {};
m_possibleDoubleClick = true;
}
}
else // Mouse didn't go down on the label, so this isn't considered a click
m_possibleDoubleClick = false;
onDoubleClick.emit(this, m_string);
}
else // This is the first click
{
m_animationTimeElapsed = {};
m_possibleDoubleClick = true;
}
}
else
m_mouseDown = false;
if (m_scrollbar->isShown())
m_scrollbar->leftMouseReleased(pos - getPosition());
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void Label::mouseMoved(Vector2f pos)
{
if (m_scrollbar->isShown() && ((m_scrollbar->isMouseDown() && m_scrollbar->isMouseDownOnThumb()) || m_scrollbar->mouseOnWidget(pos - getPosition())))
m_scrollbar->mouseMoved(pos - getPosition());
else
{
ClickableWidget::mouseMoved(pos);
if (m_scrollbar->isShown())
m_scrollbar->mouseNoLongerOnWidget();
}
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
bool Label::mouseWheelScrolled(float delta, Vector2f pos)
{
if (!m_autoSize && m_scrollbar->isShown())
{
m_scrollbar->mouseWheelScrolled(delta, pos - getPosition());
return true;
}
return false;
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void Label::mouseNoLongerOnWidget()
{
ClickableWidget::mouseNoLongerOnWidget();
m_scrollbar->mouseNoLongerOnWidget();
m_possibleDoubleClick = false;
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void Label::mouseNoLongerDown()
{
ClickableWidget::mouseNoLongerDown();
m_scrollbar->mouseNoLongerDown();
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@ -313,6 +396,23 @@ namespace tgui
{
m_backgroundColorCached = getSharedRenderer()->getBackgroundColor();
}
else if (property == "scrollbar")
{
m_scrollbar->setRenderer(getSharedRenderer()->getScrollbar());
// If no scrollbar width was set then we may need to use the one from the texture
if (!getSharedRenderer()->getScrollbarWidth())
{
m_scrollbar->setSize({m_scrollbar->getDefaultWidth(), m_scrollbar->getSize().y});
rearrangeText();
}
}
else if (property == "scrollbarwidth")
{
const float width = getSharedRenderer()->getScrollbarWidth() ? getSharedRenderer()->getScrollbarWidth() : m_scrollbar->getDefaultWidth();
m_scrollbar->setSize({width, m_scrollbar->getSize().y});
rearrangeText();
}
else if (property == "font")
{
Widget::rendererChanged(property);
@ -354,6 +454,14 @@ namespace tgui
if (m_ignoringMouseEvents)
node->propertyValuePairs["IgnoreMouseEvents"] = std::make_unique<DataIO::ValueNode>(Serializer::serialize(m_ignoringMouseEvents));
if (m_scrollbarPolicy != ScrollbarPolicy::Automatic)
{
if (m_scrollbarPolicy == ScrollbarPolicy::Always)
node->propertyValuePairs["ScrollbarPolicy"] = std::make_unique<DataIO::ValueNode>("Always");
else if (m_scrollbarPolicy == ScrollbarPolicy::Never)
node->propertyValuePairs["ScrollbarPolicy"] = std::make_unique<DataIO::ValueNode>("Never");
}
node->propertyValuePairs["TextSize"] = std::make_unique<DataIO::ValueNode>(to_string(m_textSize));
return node;
}
@ -386,6 +494,19 @@ namespace tgui
throw Exception{"Failed to parse VerticalAlignment property, found unknown value."};
}
if (node->propertyValuePairs["scrollbarpolicy"])
{
std::string policy = toLower(trim(node->propertyValuePairs["scrollbarpolicy"]->value));
if (policy == "automatic")
setScrollbarPolicy(ScrollbarPolicy::Automatic);
else if (policy == "always")
setScrollbarPolicy(ScrollbarPolicy::Always);
else if (policy == "never")
setScrollbarPolicy(ScrollbarPolicy::Never);
else
throw Exception{"Failed to parse ScrollbarPolicy property, found unknown value."};
}
if (node->propertyValuePairs["text"])
setText(Deserializer::deserialize(ObjectConverter::Type::String, node->propertyValuePairs["text"]->value).getString());
if (node->propertyValuePairs["textsize"])
@ -423,6 +544,27 @@ namespace tgui
const float textOffset = Text::getExtraHorizontalPadding(m_fontCached, m_textSize, m_textStyleCached);
// Show or hide the scrollbar
if (m_autoSize)
m_scrollbar->setVisible(false);
else
{
if (m_scrollbarPolicy == ScrollbarPolicy::Always)
{
m_scrollbar->setVisible(true);
m_scrollbar->setAutoHide(false);
}
else if (m_scrollbarPolicy == ScrollbarPolicy::Never)
{
m_scrollbar->setVisible(false);
}
else // ScrollbarPolicy::Automatic
{
m_scrollbar->setVisible(true);
m_scrollbar->setAutoHide(true);
}
}
// Find the maximum width of one line
float maxWidth;
if (m_autoSize)
@ -430,12 +572,52 @@ namespace tgui
else
{
maxWidth = getSize().x - m_bordersCached.getLeft() - m_bordersCached.getRight() - m_paddingCached.getLeft() - m_paddingCached.getRight() - 2*textOffset;
// If the scrollbar is always visible then we take it into account, otherwise we assume there is no scrollbar
if (m_scrollbarPolicy == ScrollbarPolicy::Always)
maxWidth -= m_scrollbar->getSize().x;
if (maxWidth <= 0)
return;
}
// Fit the text in the available space
const sf::String string = Text::wordWrap(maxWidth, m_string, m_fontCached, m_textSize, m_textStyleCached & sf::Text::Bold);
sf::String string = Text::wordWrap(maxWidth, m_string, m_fontCached, m_textSize, m_textStyleCached & sf::Text::Bold);
const Outline outline = {m_paddingCached.getLeft() + m_bordersCached.getLeft(),
m_paddingCached.getTop() + m_bordersCached.getTop(),
m_paddingCached.getRight() + m_bordersCached.getRight(),
m_paddingCached.getBottom() + m_bordersCached.getBottom()};
const auto lineCount = std::count(string.begin(), string.end(), '\n') + 1;
float requiredTextHeight = lineCount * m_fontCached.getLineSpacing(m_textSize)
+ Text::calculateExtraVerticalSpace(m_fontCached, m_textSize, m_textStyleCached)
+ Text::getExtraVerticalPadding(m_textSize);
// Check if a scrollbar should be added
if (!m_autoSize)
{
// If the text doesn't fit in the label then we need to run the word-wrap again, but this time taking the scrollbar into account
if ((m_scrollbarPolicy == ScrollbarPolicy::Automatic) && (requiredTextHeight > getSize().y - outline.getTop() - outline.getBottom()))
{
maxWidth -= m_scrollbar->getSize().x;
if (maxWidth <= 0)
return;
string = Text::wordWrap(maxWidth, m_string, m_fontCached, m_textSize, m_textStyleCached & sf::Text::Bold);
const auto newLineCount = std::count(string.begin(), string.end(), '\n') + 1;
requiredTextHeight = newLineCount * m_fontCached.getLineSpacing(m_textSize)
+ Text::calculateExtraVerticalSpace(m_fontCached, m_textSize, m_textStyleCached)
+ Text::getExtraVerticalPadding(m_textSize);
}
m_scrollbar->setSize(m_scrollbar->getSize().x, static_cast<unsigned int>(getSize().y - m_bordersCached.getTop() - m_bordersCached.getBottom()));
m_scrollbar->setViewportSize(static_cast<unsigned int>(getSize().y - outline.getTop() - outline.getBottom()));
m_scrollbar->setMaximum(static_cast<unsigned int>(requiredTextHeight));
m_scrollbar->setPosition({getSize().x - m_bordersCached.getRight() - m_scrollbar->getSize().x, m_bordersCached.getTop()});
m_scrollbar->setScrollAmount(m_textSize);
}
// Split the string in multiple lines
float width = 0;
@ -463,19 +645,10 @@ namespace tgui
searchPosStart = newLinePos + 1;
}
const Outline outline = {m_paddingCached.getLeft() + m_bordersCached.getLeft(),
m_paddingCached.getTop() + m_bordersCached.getTop(),
m_paddingCached.getRight() + m_bordersCached.getRight(),
m_paddingCached.getBottom() + m_bordersCached.getBottom()};
// Update the size of the label
if (m_autoSize)
{
Widget::setSize({std::max(width, maxWidth) + outline.getLeft() + outline.getRight() + 2*textOffset,
(std::max<std::size_t>(m_lines.size(), 1) * m_fontCached.getLineSpacing(m_textSize))
+ Text::calculateExtraVerticalSpace(m_fontCached, m_textSize, m_textStyleCached)
+ Text::getExtraVerticalPadding(m_textSize) + outline.getTop() + outline.getBottom()});
Widget::setSize({std::max(width, maxWidth) + outline.getLeft() + outline.getRight() + 2*textOffset, requiredTextHeight + outline.getTop() + outline.getBottom()});
m_bordersCached.updateParentSize(getSize());
m_paddingCached.updateParentSize(getSize());
}
@ -535,6 +708,7 @@ namespace tgui
void Label::draw(sf::RenderTarget& target, sf::RenderStates states) const
{
states.transform.translate(std::round(getPosition().x), std::round(getPosition().y));
const sf::RenderStates statesForScrollbar = states;
Vector2f innerSize = {getSize().x - m_bordersCached.getLeft() - m_bordersCached.getRight(),
getSize().y - m_bordersCached.getTop() - m_bordersCached.getBottom()};
@ -550,27 +724,29 @@ namespace tgui
if (m_backgroundColorCached.isSet() && (m_backgroundColorCached != Color::Transparent))
drawRectangleShape(target, states, innerSize, m_backgroundColorCached);
// Apply clipping when needed
#ifdef TGUI_USE_CPP17
std::optional<Clipping> clipping;
#else
std::unique_ptr<Clipping> clipping;
#endif
if (!m_autoSize)
// Draw the scrollbar
if (m_scrollbar->isVisible())
m_scrollbar->draw(target, statesForScrollbar);
// Draw the text
if (m_autoSize)
{
for (const auto& line : m_lines)
line.draw(target, states);
}
else
{
innerSize.x -= m_paddingCached.getLeft() + m_paddingCached.getRight();
innerSize.y -= m_paddingCached.getTop() + m_paddingCached.getBottom();
#ifdef TGUI_USE_CPP17
clipping.emplace(target, states, Vector2f{m_paddingCached.getLeft(), m_paddingCached.getTop()}, innerSize);
#else
clipping = std::make_unique<Clipping>(target, states, Vector2f{m_paddingCached.getLeft(), m_paddingCached.getTop()}, innerSize);
#endif
}
const Clipping clipping{target, states, Vector2f{m_paddingCached.getLeft(), m_paddingCached.getTop()}, innerSize};
// Draw the text
for (const auto& line : m_lines)
line.draw(target, states);
if (m_scrollbar->isShown())
states.transform.translate({0, -static_cast<float>(m_scrollbar->getValue())});
for (const auto& line : m_lines)
line.draw(target, states);
}
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

View File

@ -102,7 +102,7 @@ TEST_CASE("[Clipping]")
auto group = tgui::Group::create();
panel->add(group);
auto layout = tgui::HorizontalLayout::create({150, 25});
auto layout = tgui::HorizontalLayout::create({150, 30});
layout->setPosition({-30, -15});
group->add(layout);

View File

@ -128,6 +128,17 @@ TEST_CASE("[Label]")
REQUIRE(label->getMaximumTextWidth() == 500);
}
SECTION("ScrollbarPolicy")
{
REQUIRE(label->getScrollbarPolicy() == tgui::Label::ScrollbarPolicy::Never);
label->setScrollbarPolicy(tgui::Label::ScrollbarPolicy::Always);
REQUIRE(label->getScrollbarPolicy() == tgui::Label::ScrollbarPolicy::Always);
label->setScrollbarPolicy(tgui::Label::ScrollbarPolicy::Automatic);
REQUIRE(label->getScrollbarPolicy() == tgui::Label::ScrollbarPolicy::Automatic);
label->setScrollbarPolicy(tgui::Label::ScrollbarPolicy::Never);
REQUIRE(label->getScrollbarPolicy() == tgui::Label::ScrollbarPolicy::Never);
}
SECTION("IgnoreMouseEvents")
{
REQUIRE(!label->isIgnoringMouseEvents());
@ -176,6 +187,10 @@ TEST_CASE("[Label]")
{
auto renderer = label->getRenderer();
tgui::ScrollbarRenderer scrollbarRenderer;
scrollbarRenderer.setTrackColor(sf::Color::Red);
scrollbarRenderer.setThumbColor(sf::Color::Blue);
SECTION("set serialized property")
{
REQUIRE_NOTHROW(renderer->setProperty("TextColor", "rgb(100, 50, 150)"));
@ -184,6 +199,8 @@ TEST_CASE("[Label]")
REQUIRE_NOTHROW(renderer->setProperty("Borders", "(1, 2, 3, 4)"));
REQUIRE_NOTHROW(renderer->setProperty("Padding", "(5, 6, 7, 8)"));
REQUIRE_NOTHROW(renderer->setProperty("TextStyle", "Bold | Italic"));
REQUIRE_NOTHROW(renderer->setProperty("Scrollbar", "{ TrackColor = Red; ThumbColor = Blue; }"));
REQUIRE_NOTHROW(renderer->setProperty("ScrollbarWidth", "15"));
}
SECTION("set object property")
@ -194,6 +211,8 @@ TEST_CASE("[Label]")
REQUIRE_NOTHROW(renderer->setProperty("Borders", tgui::Borders{1, 2, 3, 4}));
REQUIRE_NOTHROW(renderer->setProperty("Padding", tgui::Borders{5, 6, 7, 8}));
REQUIRE_NOTHROW(renderer->setProperty("TextStyle", tgui::TextStyle{sf::Text::Bold | sf::Text::Italic}));
REQUIRE_NOTHROW(renderer->setProperty("Scrollbar", scrollbarRenderer.getData()));
REQUIRE_NOTHROW(renderer->setProperty("ScrollbarWidth", 15));
}
SECTION("functions")
@ -204,6 +223,8 @@ TEST_CASE("[Label]")
renderer->setBorders({1, 2, 3, 4});
renderer->setPadding({5, 6, 7, 8});
renderer->setTextStyle(sf::Text::Bold | sf::Text::Italic);
renderer->setScrollbar(scrollbarRenderer.getData());
renderer->setScrollbarWidth(15);
}
REQUIRE(renderer->getProperty("TextColor").getColor() == sf::Color(100, 50, 150));
@ -212,6 +233,7 @@ TEST_CASE("[Label]")
REQUIRE(renderer->getProperty("Borders").getOutline() == tgui::Borders(1, 2, 3, 4));
REQUIRE(renderer->getProperty("Padding").getOutline() == tgui::Padding(5, 6, 7, 8));
REQUIRE(renderer->getProperty("TextStyle").getTextStyle() == (sf::Text::Bold | sf::Text::Italic));
REQUIRE(renderer->getProperty("ScrollbarWidth").getNumber() == 15);
REQUIRE(renderer->getTextColor() == sf::Color(100, 50, 150));
REQUIRE(renderer->getBackgroundColor() == sf::Color(150, 100, 50));
@ -219,6 +241,10 @@ TEST_CASE("[Label]")
REQUIRE(renderer->getBorders() == tgui::Borders(1, 2, 3, 4));
REQUIRE(renderer->getPadding() == tgui::Padding(5, 6, 7, 8));
REQUIRE(renderer->getTextStyle() == (sf::Text::Bold | sf::Text::Italic));
REQUIRE(renderer->getScrollbar()->propertyValuePairs.size() == 2);
REQUIRE(renderer->getScrollbar()->propertyValuePairs["trackcolor"].getColor() == sf::Color::Red);
REQUIRE(renderer->getScrollbar()->propertyValuePairs["thumbcolor"].getColor() == sf::Color::Blue);
}
SECTION("Saving and loading from file")
@ -227,6 +253,7 @@ TEST_CASE("[Label]")
label->setTextSize(25);
label->setHorizontalAlignment(tgui::Label::HorizontalAlignment::Center);
label->setVerticalAlignment(tgui::Label::VerticalAlignment::Bottom);
label->setScrollbarPolicy(tgui::Label::ScrollbarPolicy::Never);
label->setMaximumTextWidth(300);
label->ignoreMouseEvents(true);
@ -250,6 +277,7 @@ TEST_CASE("[Label]")
SECTION("Complex")
{
TEST_DRAW_INIT(420, 215, label)
label->setScrollbarPolicy(tgui::Label::ScrollbarPolicy::Automatic);
label->setText("Bacon ipsum dolor amet alcatra jerky turkey ball tip jowl beef. Shank landjaeger frankfurter, doner burgdoggen strip steak chicken pancetta jowl. Pork loin leberkas meatloaf ham shoulder cow hamburger pancetta. Rump turducken ribeye salami pork chop sirloin. Leberkas alcatra filet mignon jerky pork belly.");
label->setTextSize(18);
label->setSize(400, 205);
@ -259,6 +287,12 @@ TEST_CASE("[Label]")
label->getRenderer()->setPadding({4, 3, 2, 1});
label->getRenderer()->setOpacity(0.7f);
TEST_DRAW("Label_Complex.png")
SECTION("With scrollbar")
{
label->setText(label->getText() + "\n" + label->getText());
TEST_DRAW("Label_Complex_WithScrollbar.png")
}
}
}
}

View File

@ -78,6 +78,28 @@ TEST_CASE("[ScrollablePanel]")
}
}
SECTION("VerticalScrollbarPolicy")
{
REQUIRE(panel->getVerticalScrollbarPolicy() == tgui::ScrollablePanel::ScrollbarPolicy::Automatic);
panel->setVerticalScrollbarPolicy(tgui::ScrollablePanel::ScrollbarPolicy::Always);
REQUIRE(panel->getVerticalScrollbarPolicy() == tgui::ScrollablePanel::ScrollbarPolicy::Always);
panel->setVerticalScrollbarPolicy(tgui::ScrollablePanel::ScrollbarPolicy::Automatic);
REQUIRE(panel->getVerticalScrollbarPolicy() == tgui::ScrollablePanel::ScrollbarPolicy::Automatic);
panel->setVerticalScrollbarPolicy(tgui::ScrollablePanel::ScrollbarPolicy::Never);
REQUIRE(panel->getVerticalScrollbarPolicy() == tgui::ScrollablePanel::ScrollbarPolicy::Never);
}
SECTION("HorizontalScrollbarPolicy")
{
REQUIRE(panel->getHorizontalScrollbarPolicy() == tgui::ScrollablePanel::ScrollbarPolicy::Automatic);
panel->setHorizontalScrollbarPolicy(tgui::ScrollablePanel::ScrollbarPolicy::Always);
REQUIRE(panel->getHorizontalScrollbarPolicy() == tgui::ScrollablePanel::ScrollbarPolicy::Always);
panel->setHorizontalScrollbarPolicy(tgui::ScrollablePanel::ScrollbarPolicy::Automatic);
REQUIRE(panel->getHorizontalScrollbarPolicy() == tgui::ScrollablePanel::ScrollbarPolicy::Automatic);
panel->setHorizontalScrollbarPolicy(tgui::ScrollablePanel::ScrollbarPolicy::Never);
REQUIRE(panel->getHorizontalScrollbarPolicy() == tgui::ScrollablePanel::ScrollbarPolicy::Never);
}
SECTION("Events / Signals")
{
unsigned int mousePressedCount = 0;

Binary file not shown.

After

Width:  |  Height:  |  Size: 30 KiB

View File

@ -70,6 +70,7 @@ EditBox {
Label {
TextColor = rgb(100, 100, 100);
Scrollbar = &Scrollbar;
}
ListBox {

View File

@ -74,6 +74,7 @@ EditBox {
Label {
TextColor = rgb(190, 190, 190);
Scrollbar = &Scrollbar;
}
ListBox {

View File

@ -67,6 +67,7 @@ EditBox {
Label {
TextColor = rgba(255, 255, 255, 215);
Scrollbar = &Scrollbar;
}
ListBox {