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

This commit is contained in:
Zed A. Shaw 2025-02-15 10:59:51 -05:00
parent 872cedc8e1
commit cebf61a794
4 changed files with 27 additions and 18 deletions

24
lel.cpp
View file

@ -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));