Brought over a bunch of stuff to get started, but only lel.cpp compiles.
This commit is contained in:
parent
26685279ce
commit
103793204d
33 changed files with 2746 additions and 0 deletions
32
tests/guecs.cpp
Normal file
32
tests/guecs.cpp
Normal file
|
@ -0,0 +1,32 @@
|
|||
#include <catch2/catch_test_macros.hpp>
|
||||
#include <fmt/core.h>
|
||||
#include "constants.hpp"
|
||||
#include "guecs.hpp"
|
||||
#include "textures.hpp"
|
||||
#include <fmt/xchar.h>
|
||||
|
||||
using namespace guecs;
|
||||
|
||||
TEST_CASE("prototype one gui", "[ecs-gui]") {
|
||||
guecs::UI gui;
|
||||
textures::init();
|
||||
|
||||
gui.position(0, 0, 1000, 500);
|
||||
gui.layout("[test1|test2|test3][test4|_|test5]");
|
||||
|
||||
for(auto& [name, cell] : gui.cells()) {
|
||||
auto button = gui.entity(name);
|
||||
gui.set<lel::Cell>(button, cell);
|
||||
gui.set<Rectangle>(button, {});
|
||||
gui.set<Clickable>(button, {});
|
||||
gui.set<Textual>(button, {L"whatever"});
|
||||
}
|
||||
|
||||
gui.init();
|
||||
|
||||
// at this point it's mostly ready but I'd need to render it to a window real quick
|
||||
sf::RenderWindow window;
|
||||
window.setSize({SCREEN_WIDTH, SCREEN_HEIGHT});
|
||||
gui.render(window);
|
||||
window.display();
|
||||
}
|
52
tests/lel.cpp
Normal file
52
tests/lel.cpp
Normal file
|
@ -0,0 +1,52 @@
|
|||
#include "lel.hpp"
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
#include <fmt/core.h>
|
||||
#include <string>
|
||||
|
||||
TEST_CASE("test basic ops", "[lel]") {
|
||||
lel::Parser parser(0, 0, 500, 500);
|
||||
|
||||
bool good = parser.parse(
|
||||
"[ label_1 | label3 | test1]"
|
||||
"[ *(300,300)text1 | %(150)people | ^test2]"
|
||||
"[ >label2 | _ | .test3]"
|
||||
"[ =message | buttons | test4]");
|
||||
|
||||
REQUIRE(good);
|
||||
|
||||
for(size_t rowcount = 0; rowcount < parser.grid.size(); rowcount++) {
|
||||
auto& row = parser.grid[rowcount];
|
||||
|
||||
for(size_t colcount = 0; colcount < row.size(); colcount++) {
|
||||
auto &name = row[colcount];
|
||||
if(name == "_") {
|
||||
REQUIRE(!parser.cells.contains(name));
|
||||
} else {
|
||||
auto &cell = parser.cells.at(name);
|
||||
REQUIRE(cell.row == int(rowcount));
|
||||
REQUIRE(cell.col == int(colcount));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
REQUIRE(parser.cells.size() == 11);
|
||||
REQUIRE(parser.cells.at("label2").right == true);
|
||||
REQUIRE(parser.cells.at("text1").expand == true);
|
||||
REQUIRE(parser.cells.at("text1").w == 300);
|
||||
REQUIRE(parser.cells.at("text1").h == 300);
|
||||
REQUIRE(parser.cells.at("people").expand == false);
|
||||
REQUIRE(parser.cells.at("message").expand == false);
|
||||
REQUIRE(parser.cells.at("message").center == true);
|
||||
|
||||
for(auto& [name, cell] : parser.cells) {
|
||||
REQUIRE(cell.w > 0);
|
||||
REQUIRE(cell.h > 0);
|
||||
}
|
||||
|
||||
auto hit = parser.hit(10, 10);
|
||||
REQUIRE(*hit == "label_1");
|
||||
|
||||
auto nohit = parser.hit(1000, 1000);
|
||||
REQUIRE(!nohit);
|
||||
REQUIRE(nohit == std::nullopt);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue