Skip to content

Commit

Permalink
Widget tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dancazarin committed Feb 19, 2025
1 parent 9b3e3f1 commit f123a7e
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
Binary file added src/graphics/testdata/widget-text.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions src/widgets/Text.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ namespace Brisk {

Text::Text(Construction construction, std::string text, ArgumentsView<Text> args)
: Widget{ construction, nullptr }, m_text(std::move(text)) {
registerBuiltinFonts();
args.apply(this);
onChanged();
enableCustomMeasure();
Expand Down
24 changes: 23 additions & 1 deletion src/widgets/WIdgets_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@
* If you do not wish to be bound by the GPL-2.0+ license, you must purchase a commercial
* license. For commercial licensing options, please visit: https://brisklib.com
*/
#include <brisk/widgets/Text.hpp>
#include <brisk/widgets/Widgets.hpp>
#include <catch2/catch_all.hpp>
#include <brisk/graphics/Palette.hpp>
#include "Catch2Utils.hpp"
#include "../graphics/VisualTests.hpp"

namespace Brisk {

Expand All @@ -31,4 +33,24 @@ TEST_CASE("Text") {

CHECK(w->text.get() == "Initialize");
}

TEST_CASE("WidgetRendering") {
WidgetTree tree;
tree.setViewportRectangle({ 0, 0, 128, 64 });
tree.setRoot(rcnew Widget{
backgroundColor = Palette::Standard::red,
margin = { 8_apx },
justifyContent = Justify::Center,
alignContent = Align::Center,
rcnew Text{
"Text",
color = Palette::white,
fontSize = 40.f,
},
});
renderTest("widget-text", tree.viewportRectangle().size(), [&](RenderContext& context) {
Canvas canvas(context);
tree.updateAndPaint(canvas, Palette::black, true);
});
}
} // namespace Brisk

0 comments on commit f123a7e

Please sign in to comment.