2015-08-07 05:03:22 -07:00
|
|
|
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
2016-07-10 15:01:18 -07:00
|
|
|
// TGUI - Texus' Graphical User Interface
|
2018-03-22 11:57:45 -07:00
|
|
|
// Copyright (C) 2012-2018 Bruno Van de Velde (vdv_b@tgui.eu)
|
2015-08-07 05:03:22 -07:00
|
|
|
//
|
|
|
|
// This software is provided 'as-is', without any express or implied warranty.
|
|
|
|
// In no event will the authors be held liable for any damages arising from the use of this software.
|
|
|
|
//
|
|
|
|
// Permission is granted to anyone to use this software for any purpose,
|
|
|
|
// including commercial applications, and to alter it and redistribute it freely,
|
|
|
|
// subject to the following restrictions:
|
|
|
|
//
|
|
|
|
// 1. The origin of this software must not be misrepresented;
|
|
|
|
// you must not claim that you wrote the original software.
|
|
|
|
// If you use this software in a product, an acknowledgment
|
|
|
|
// in the product documentation would be appreciated but is not required.
|
|
|
|
//
|
|
|
|
// 2. Altered source versions must be plainly marked as such,
|
|
|
|
// and must not be misrepresented as being the original software.
|
|
|
|
//
|
|
|
|
// 3. This notice may not be removed or altered from any source distribution.
|
|
|
|
//
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2017-11-01 05:19:47 -07:00
|
|
|
#include "Tests.hpp"
|
2015-08-07 05:03:22 -07:00
|
|
|
#include <TGUI/Widgets/Label.hpp>
|
2016-03-17 02:25:39 -07:00
|
|
|
#include <TGUI/Widgets/Panel.hpp>
|
2016-03-10 15:03:09 -08:00
|
|
|
#include <TGUI/Gui.hpp>
|
2015-08-07 05:03:22 -07:00
|
|
|
|
2016-07-10 15:01:18 -07:00
|
|
|
TEST_CASE("[Label]")
|
|
|
|
{
|
2016-09-14 11:11:20 -07:00
|
|
|
tgui::Label::Ptr label = tgui::Label::create();
|
2017-02-09 15:35:24 -08:00
|
|
|
label->getRenderer()->setFont("resources/DejaVuSans.ttf");
|
2015-08-07 05:03:22 -07:00
|
|
|
|
2016-03-10 15:03:09 -08:00
|
|
|
SECTION("Signals")
|
|
|
|
{
|
2015-08-07 05:03:22 -07:00
|
|
|
REQUIRE_NOTHROW(label->connect("DoubleClicked", [](){}));
|
2017-08-30 09:51:21 -07:00
|
|
|
REQUIRE_NOTHROW(label->connect("DoubleClicked", [](sf::String){}));
|
|
|
|
REQUIRE_NOTHROW(label->connect("DoubleClicked", [](std::string){}));
|
2017-07-10 04:29:36 -07:00
|
|
|
REQUIRE_NOTHROW(label->connect("DoubleClicked", [](tgui::Widget::Ptr, std::string){}));
|
2017-08-30 09:51:21 -07:00
|
|
|
REQUIRE_NOTHROW(label->connect("DoubleClicked", [](tgui::Widget::Ptr, std::string, sf::String){}));
|
|
|
|
REQUIRE_NOTHROW(label->connect("DoubleClicked", [](tgui::Widget::Ptr, std::string, std::string){}));
|
2015-08-07 05:03:22 -07:00
|
|
|
}
|
|
|
|
|
2016-03-10 15:03:09 -08:00
|
|
|
SECTION("WidgetType")
|
|
|
|
{
|
2015-08-07 05:03:22 -07:00
|
|
|
REQUIRE(label->getWidgetType() == "Label");
|
|
|
|
}
|
|
|
|
|
2016-03-16 09:08:30 -07:00
|
|
|
SECTION("Position and Size")
|
|
|
|
{
|
|
|
|
label->setPosition(40, 30);
|
|
|
|
label->setSize(150, 100);
|
|
|
|
label->getRenderer()->setBorders(2);
|
|
|
|
|
|
|
|
REQUIRE(label->getPosition() == sf::Vector2f(40, 30));
|
|
|
|
REQUIRE(label->getSize() == sf::Vector2f(150, 100));
|
|
|
|
REQUIRE(label->getFullSize() == label->getSize());
|
|
|
|
REQUIRE(label->getWidgetOffset() == sf::Vector2f(0, 0));
|
|
|
|
}
|
|
|
|
|
2016-03-10 15:03:09 -08:00
|
|
|
SECTION("Text")
|
|
|
|
{
|
2015-08-07 05:03:22 -07:00
|
|
|
REQUIRE(label->getText() == "");
|
|
|
|
label->setText("SomeText");
|
|
|
|
REQUIRE(label->getText() == "SomeText");
|
|
|
|
}
|
|
|
|
|
2016-03-10 15:03:09 -08:00
|
|
|
SECTION("TextSize")
|
|
|
|
{
|
2015-08-07 05:03:22 -07:00
|
|
|
label->setTextSize(25);
|
|
|
|
REQUIRE(label->getTextSize() == 25);
|
|
|
|
}
|
|
|
|
|
2016-03-10 15:03:09 -08:00
|
|
|
SECTION("Alignment")
|
|
|
|
{
|
2016-01-30 04:48:52 -08:00
|
|
|
REQUIRE(label->getHorizontalAlignment() == tgui::Label::HorizontalAlignment::Left);
|
|
|
|
REQUIRE(label->getVerticalAlignment() == tgui::Label::VerticalAlignment::Top);
|
|
|
|
|
|
|
|
label->setHorizontalAlignment(tgui::Label::HorizontalAlignment::Center);
|
|
|
|
REQUIRE(label->getHorizontalAlignment() == tgui::Label::HorizontalAlignment::Center);
|
|
|
|
REQUIRE(label->getVerticalAlignment() == tgui::Label::VerticalAlignment::Top);
|
|
|
|
|
|
|
|
label->setHorizontalAlignment(tgui::Label::HorizontalAlignment::Right);
|
|
|
|
REQUIRE(label->getHorizontalAlignment() == tgui::Label::HorizontalAlignment::Right);
|
|
|
|
|
|
|
|
label->setHorizontalAlignment(tgui::Label::HorizontalAlignment::Left);
|
|
|
|
REQUIRE(label->getHorizontalAlignment() == tgui::Label::HorizontalAlignment::Left);
|
|
|
|
|
|
|
|
label->setVerticalAlignment(tgui::Label::VerticalAlignment::Center);
|
|
|
|
REQUIRE(label->getHorizontalAlignment() == tgui::Label::HorizontalAlignment::Left);
|
|
|
|
REQUIRE(label->getVerticalAlignment() == tgui::Label::VerticalAlignment::Center);
|
|
|
|
|
|
|
|
label->setVerticalAlignment(tgui::Label::VerticalAlignment::Bottom);
|
|
|
|
REQUIRE(label->getVerticalAlignment() == tgui::Label::VerticalAlignment::Bottom);
|
|
|
|
|
|
|
|
label->setVerticalAlignment(tgui::Label::VerticalAlignment::Top);
|
|
|
|
REQUIRE(label->getVerticalAlignment() == tgui::Label::VerticalAlignment::Top);
|
|
|
|
}
|
|
|
|
|
2016-03-10 15:03:09 -08:00
|
|
|
SECTION("AutoSize")
|
|
|
|
{
|
2015-08-07 05:03:22 -07:00
|
|
|
REQUIRE(label->getAutoSize());
|
|
|
|
label->setAutoSize(false);
|
|
|
|
REQUIRE(!label->getAutoSize());
|
|
|
|
label->setAutoSize(true);
|
|
|
|
REQUIRE(label->getAutoSize());
|
|
|
|
label->setSize(200, 100);
|
|
|
|
REQUIRE(!label->getAutoSize());
|
|
|
|
}
|
|
|
|
|
2016-03-10 15:03:09 -08:00
|
|
|
SECTION("MaximumTextWidth")
|
|
|
|
{
|
2015-08-07 05:03:22 -07:00
|
|
|
REQUIRE(label->getMaximumTextWidth() == 0);
|
|
|
|
label->setMaximumTextWidth(300);
|
|
|
|
REQUIRE(label->getMaximumTextWidth() == 300);
|
2016-03-10 15:03:09 -08:00
|
|
|
|
|
|
|
label->setSize(200, 50);
|
|
|
|
REQUIRE(label->getMaximumTextWidth() == 200);
|
|
|
|
|
|
|
|
label->setSize(400, 50);
|
|
|
|
REQUIRE(label->getMaximumTextWidth() == 400);
|
|
|
|
|
|
|
|
label->setMaximumTextWidth(500);
|
|
|
|
REQUIRE(label->getMaximumTextWidth() == 400);
|
|
|
|
|
|
|
|
label->setAutoSize(true);
|
|
|
|
REQUIRE(label->getMaximumTextWidth() == 500);
|
2015-08-07 05:03:22 -07:00
|
|
|
}
|
2016-03-02 10:52:40 -08:00
|
|
|
|
2017-09-05 14:28:21 -07:00
|
|
|
SECTION("IgnoreMouseEvents")
|
|
|
|
{
|
|
|
|
REQUIRE(!label->isIgnoringMouseEvents());
|
|
|
|
label->ignoreMouseEvents(true);
|
|
|
|
REQUIRE(label->isIgnoringMouseEvents());
|
|
|
|
label->ignoreMouseEvents(false);
|
|
|
|
REQUIRE(!label->isIgnoringMouseEvents());
|
|
|
|
}
|
|
|
|
|
2016-07-28 07:06:13 -07:00
|
|
|
SECTION("Events / Signals")
|
2016-03-10 15:03:09 -08:00
|
|
|
{
|
2016-07-17 11:19:30 -07:00
|
|
|
SECTION("ClickableWidget")
|
2016-03-17 02:25:39 -07:00
|
|
|
{
|
2016-07-17 11:19:30 -07:00
|
|
|
testClickableWidgetSignals(label);
|
2016-03-17 02:25:39 -07:00
|
|
|
}
|
|
|
|
|
2016-07-28 07:06:13 -07:00
|
|
|
SECTION("Double click")
|
2016-03-10 15:03:09 -08:00
|
|
|
{
|
2016-07-17 11:19:30 -07:00
|
|
|
unsigned int doubleClickedCount = 0;
|
2018-05-11 05:24:12 -07:00
|
|
|
label->connect("DoubleClicked", &genericCallback, std::ref(doubleClickedCount));
|
2016-03-10 15:03:09 -08:00
|
|
|
|
2016-07-17 11:19:30 -07:00
|
|
|
label->setPosition(40, 30);
|
|
|
|
label->setSize(150, 100);
|
2016-03-10 15:03:09 -08:00
|
|
|
|
2016-09-08 06:30:41 -07:00
|
|
|
label->leftMousePressed({115, 80});
|
|
|
|
label->leftMouseReleased({115, 80});
|
2016-03-10 15:03:09 -08:00
|
|
|
|
|
|
|
tgui::Gui gui;
|
|
|
|
gui.add(label);
|
2016-06-30 07:12:43 -07:00
|
|
|
gui.updateTime(DOUBLE_CLICK_TIMEOUT);
|
2016-03-10 15:03:09 -08:00
|
|
|
|
2016-09-08 06:30:41 -07:00
|
|
|
label->leftMousePressed({115, 80});
|
|
|
|
label->leftMouseReleased({115, 80});
|
2016-03-10 15:03:09 -08:00
|
|
|
REQUIRE(doubleClickedCount == 0);
|
|
|
|
|
2016-06-30 07:12:43 -07:00
|
|
|
gui.updateTime(DOUBLE_CLICK_TIMEOUT / 2.f);
|
2016-03-10 15:03:09 -08:00
|
|
|
|
2016-09-08 06:30:41 -07:00
|
|
|
label->leftMousePressed({115, 80});
|
|
|
|
label->leftMouseReleased({115, 80});
|
2016-03-10 15:03:09 -08:00
|
|
|
REQUIRE(doubleClickedCount == 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-17 10:33:14 -07:00
|
|
|
testWidgetRenderer(label->getRenderer());
|
2016-03-10 15:03:09 -08:00
|
|
|
SECTION("Renderer")
|
|
|
|
{
|
2015-08-07 05:03:22 -07:00
|
|
|
auto renderer = label->getRenderer();
|
|
|
|
|
2016-03-10 15:03:09 -08:00
|
|
|
SECTION("set serialized property")
|
|
|
|
{
|
2015-08-07 05:03:22 -07:00
|
|
|
REQUIRE_NOTHROW(renderer->setProperty("TextColor", "rgb(100, 50, 150)"));
|
|
|
|
REQUIRE_NOTHROW(renderer->setProperty("BackgroundColor", "rgb(150, 100, 50)"));
|
|
|
|
REQUIRE_NOTHROW(renderer->setProperty("BorderColor", "rgb(50, 150, 100)"));
|
|
|
|
REQUIRE_NOTHROW(renderer->setProperty("Borders", "(1, 2, 3, 4)"));
|
|
|
|
REQUIRE_NOTHROW(renderer->setProperty("Padding", "(5, 6, 7, 8)"));
|
2016-07-10 15:01:18 -07:00
|
|
|
REQUIRE_NOTHROW(renderer->setProperty("TextStyle", "Bold | Italic"));
|
2015-08-07 05:03:22 -07:00
|
|
|
}
|
2016-03-10 15:03:09 -08:00
|
|
|
|
|
|
|
SECTION("set object property")
|
|
|
|
{
|
2015-08-07 05:03:22 -07:00
|
|
|
REQUIRE_NOTHROW(renderer->setProperty("TextColor", sf::Color{100, 50, 150}));
|
|
|
|
REQUIRE_NOTHROW(renderer->setProperty("BackgroundColor", sf::Color{150, 100, 50}));
|
|
|
|
REQUIRE_NOTHROW(renderer->setProperty("BorderColor", sf::Color{50, 150, 100}));
|
|
|
|
REQUIRE_NOTHROW(renderer->setProperty("Borders", tgui::Borders{1, 2, 3, 4}));
|
|
|
|
REQUIRE_NOTHROW(renderer->setProperty("Padding", tgui::Borders{5, 6, 7, 8}));
|
2016-07-10 15:01:18 -07:00
|
|
|
REQUIRE_NOTHROW(renderer->setProperty("TextStyle", tgui::TextStyle{sf::Text::Bold | sf::Text::Italic}));
|
2015-08-07 05:03:22 -07:00
|
|
|
}
|
2016-03-10 15:03:09 -08:00
|
|
|
|
|
|
|
SECTION("functions")
|
|
|
|
{
|
2015-08-07 05:03:22 -07:00
|
|
|
renderer->setTextColor({100, 50, 150});
|
|
|
|
renderer->setBackgroundColor({150, 100, 50});
|
|
|
|
renderer->setBorderColor({50, 150, 100});
|
|
|
|
renderer->setBorders({1, 2, 3, 4});
|
|
|
|
renderer->setPadding({5, 6, 7, 8});
|
2016-07-10 15:01:18 -07:00
|
|
|
renderer->setTextStyle(sf::Text::Bold | sf::Text::Italic);
|
2015-08-07 05:03:22 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
REQUIRE(renderer->getProperty("TextColor").getColor() == sf::Color(100, 50, 150));
|
|
|
|
REQUIRE(renderer->getProperty("BackgroundColor").getColor() == sf::Color(150, 100, 50));
|
|
|
|
REQUIRE(renderer->getProperty("BorderColor").getColor() == sf::Color(50, 150, 100));
|
2016-06-30 07:12:43 -07:00
|
|
|
REQUIRE(renderer->getProperty("Borders").getOutline() == tgui::Borders(1, 2, 3, 4));
|
|
|
|
REQUIRE(renderer->getProperty("Padding").getOutline() == tgui::Padding(5, 6, 7, 8));
|
2016-07-10 15:01:18 -07:00
|
|
|
REQUIRE(renderer->getProperty("TextStyle").getTextStyle() == (sf::Text::Bold | sf::Text::Italic));
|
2016-03-17 02:25:39 -07:00
|
|
|
|
2016-06-30 07:12:43 -07:00
|
|
|
REQUIRE(renderer->getTextColor() == sf::Color(100, 50, 150));
|
|
|
|
REQUIRE(renderer->getBackgroundColor() == sf::Color(150, 100, 50));
|
|
|
|
REQUIRE(renderer->getBorderColor() == sf::Color(50, 150, 100));
|
|
|
|
REQUIRE(renderer->getBorders() == tgui::Borders(1, 2, 3, 4));
|
|
|
|
REQUIRE(renderer->getPadding() == tgui::Padding(5, 6, 7, 8));
|
2016-07-10 15:01:18 -07:00
|
|
|
REQUIRE(renderer->getTextStyle() == (sf::Text::Bold | sf::Text::Italic));
|
2015-08-07 05:03:22 -07:00
|
|
|
}
|
2016-03-02 10:52:40 -08:00
|
|
|
|
2016-03-10 15:03:09 -08:00
|
|
|
SECTION("Saving and loading from file")
|
|
|
|
{
|
2015-08-07 05:03:22 -07:00
|
|
|
label->setText("SomeText");
|
|
|
|
label->setTextSize(25);
|
2016-01-30 04:48:52 -08:00
|
|
|
label->setHorizontalAlignment(tgui::Label::HorizontalAlignment::Center);
|
|
|
|
label->setVerticalAlignment(tgui::Label::VerticalAlignment::Bottom);
|
2015-08-07 05:03:22 -07:00
|
|
|
label->setMaximumTextWidth(300);
|
2017-09-05 14:28:21 -07:00
|
|
|
label->ignoreMouseEvents(true);
|
2015-08-07 05:03:22 -07:00
|
|
|
|
2016-07-28 07:06:13 -07:00
|
|
|
testSavingWidget("Label", label);
|
2016-03-02 10:52:40 -08:00
|
|
|
}
|
2017-02-09 15:36:29 -08:00
|
|
|
|
|
|
|
SECTION("Draw")
|
|
|
|
{
|
|
|
|
label->setPosition(10, 5);
|
|
|
|
label->getRenderer()->setTextColor(sf::Color::Red);
|
|
|
|
|
|
|
|
SECTION("Simple")
|
|
|
|
{
|
|
|
|
TEST_DRAW_INIT(110, 40, label)
|
|
|
|
label->setText(L"Test gÊ");
|
|
|
|
label->setTextSize(24);
|
|
|
|
label->getRenderer()->setTextStyle(sf::Text::Style::Italic);
|
|
|
|
TEST_DRAW("Label_Simple.png")
|
|
|
|
}
|
|
|
|
|
|
|
|
SECTION("Complex")
|
|
|
|
{
|
|
|
|
TEST_DRAW_INIT(420, 215, label)
|
|
|
|
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);
|
|
|
|
label->getRenderer()->setBackgroundColor(sf::Color::Blue);
|
|
|
|
label->getRenderer()->setBorderColor(sf::Color::Yellow);
|
|
|
|
label->getRenderer()->setBorders({1, 2, 3, 4});
|
|
|
|
label->getRenderer()->setPadding({4, 3, 2, 1});
|
2017-02-12 17:01:20 -08:00
|
|
|
label->getRenderer()->setOpacity(0.7f);
|
2017-02-09 15:36:29 -08:00
|
|
|
TEST_DRAW("Label_Complex.png")
|
|
|
|
}
|
|
|
|
}
|
2015-08-07 05:03:22 -07:00
|
|
|
}
|