LEL is able to position right/left/top/bottom and expand out too.

Zed A. Shaw 3 weeks ago
parent 872cedc8e1
commit cebf61a794
  1. 3
      combat_ui.cpp
  2. 24
      lel.cpp
  3. 4
      lel.hpp
  4. 14
      tests/lel.cpp

@ -10,7 +10,6 @@ namespace gui {
{
bool good = $layout.parse(
"[attack1 | attack2 | attack3 | heal]"
"[move1 | move2 | move3 | move4]"
);
dbc::check(good, "failed to parse combat layout");
@ -19,7 +18,7 @@ namespace gui {
sf::RectangleShape button;
button.setPosition({float(cell.x + 10), float(cell.y + 10)});
button.setSize({float(cell.w - 20), float(cell.h - 20)});
button.setFillColor({uint8_t(cell.col * 75), 100, 100});
button.setFillColor({100, 100, 100});
button.setOutlineColor({200, 200, 200});
button.setOutlineThickness(5);
$shapes[name] = button;

@ -20,18 +20,20 @@ void LELParser::col() {
}
void LELParser::valign(char dir) {
cur.top = dir == '^';
cur.bottom = dir == '.';
}
void LELParser::align(char dir) {
cur.left = dir == '<';
cur.right = dir == '>';
}
void LELParser::id(std::string name) {
dbc::check(!cells.contains(name),
fmt::format("duplicate cell name {}", name));
if(name != "_") {
dbc::check(!cells.contains(name),
fmt::format("duplicate cell name {}", name));
cells.insert_or_assign(name, cur);
}
cells.insert_or_assign(name, cur);
cur = {cur.col + 1, cur.row};
}
@ -67,8 +69,16 @@ void LELParser::finalize() {
cell.max_w = cell.max_w == 0 ? cell_width : cell.max_w;
cell.max_h = cell.max_h == 0 ? cell_height : cell.max_h;
cell.w = cell.expand ? cell.max_w : std::min(cell_width, cell.max_w);
cell.h = cell.expand ? cell.max_h : std::min(cell_height, cell.max_h);
cell.w = cell.expand ? std::min(cell.max_w, grid_w) : std::min(cell_width, cell.max_w);
cell.h = cell.expand ? std::min(cell.max_h, grid_h) : std::min(cell_height, cell.max_h);
if(cell.right) {
cell.x += cell_width - cell.w;
}
if(cell.bottom) {
cell.y += cell_height - cell.h;
}
dbc::check(cell.h > 0, fmt::format("invalid height cell {}", name));
dbc::check(cell.w > 0, fmt::format("invalid width cell {}", name));

@ -11,8 +11,8 @@ struct Cell {
int max_h = 0;
int col = 0;
int row = 0;
bool left = true;
bool top = true;
bool right = false;
bool bottom = false;
bool expand = false;
Cell(int col, int row) : col(col), row(row) {}

@ -11,20 +11,20 @@ TEST_CASE("test basic ops", "[lel]") {
LELParser parser(0, 0, 500, 500);
std::vector<std::string> labels{
"label_1", "label3", "text1", "people",
"label2", "_", "message", "buttons"};
"label2", "message", "buttons"};
bool good = parser.parse(
"[ label_1 | label3 | test1]"
"[ *(300,300)text1 | (150)people | test2]"
"[ >label2 | _ | test3]"
"[ *(300,300)text1 | (150)people | ^test2]"
"[ >label2 | _ | .test3]"
"[ message | buttons | test4]");
REQUIRE(good);
REQUIRE(parser.rows == 4);
REQUIRE(parser.columns == 3);
REQUIRE(parser.cells.size() == 12);
REQUIRE(parser.cells.at("label2").left == false);
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);
@ -34,8 +34,8 @@ TEST_CASE("test basic ops", "[lel]") {
for(auto name : labels) {
auto& cell = parser.cells.at(name);
fmt::println("name={}; col/row={},{}; x/y={},{} w/h={},{}; left={}, top={}, expand={}",
name, cell.col, cell.row, cell.x, cell.y, cell.w, cell.h, cell.left, cell.top, cell.expand);
fmt::println("name={}; col/row={},{}; x/y={},{} w/h={},{}; right={}, bottom={}, expand={}",
name, cell.col, cell.row, cell.x, cell.y, cell.w, cell.h, cell.right, cell.bottom, cell.expand);
REQUIRE(cell.w > 0);
REQUIRE(cell.h > 0);

Loading…
Cancel
Save