LEL is working at a basic grid level, able to render boxes where I want.

This commit is contained in:
Zed A. Shaw 2025-02-15 01:31:57 -05:00
parent 846b7aaf16
commit 872cedc8e1
8 changed files with 127 additions and 99 deletions

54
lel.cpp
View file

@ -1,6 +1,6 @@
#include "lel.hpp"
#include <fmt/core.h>
#include "dbc.hpp"
#include "lel_parser.cpp"
LELParser::LELParser(int x, int y, int width, int height) :
@ -10,12 +10,10 @@ LELParser::LELParser(int x, int y, int width, int height) :
grid_h(height),
cur(0, 0)
{
}
void LELParser::ltab() {
cur.row = row_count;
fmt::println("ltab: rows {}", row_count);
cur.row = rows;
}
void LELParser::col() {
@ -23,60 +21,62 @@ void LELParser::col() {
void LELParser::valign(char dir) {
cur.top = dir == '^';
fmt::println("valign: {}", dir);
}
void LELParser::align(char dir) {
cur.left = dir == '<';
fmt::println("align {}", dir);
}
void LELParser::id(std::string name) {
fmt::println("id: {}", name);
dbc::check(!cells.contains(name),
fmt::format("duplicate cell name {}", name));
cells.insert_or_assign(name, cur);
cur = {cur.col + 1, cur.row};
}
void LELParser::row() {
row_count++;
max_columns = std::max(max_columns, cur.col);
rows++;
columns = std::max(columns, cur.col);
cur.col = 0;
fmt::println("row end: cols {}", cur.col);
}
void LELParser::setwidth(int width) {
fmt::println("setwidth: {}", width);
cur.w = width;
cur.max_w = width;
}
void LELParser::setheight(int height) {
fmt::println("setheight: {}", height);
cur.h = height;
cur.max_h = height;
}
void LELParser::expand() {
fmt::println("expand");
cur.expand = true;
}
void LELParser::finalize() {
int cell_width = grid_w / max_columns;
int cell_height = grid_h / row_count;
fmt::println("FINALIZE: cell w/h: {},{}", cell_width, cell_height);
dbc::check(columns > 0, "columns are 0");
dbc::check(rows > 0, "rows are 0");
int cell_width = grid_w / columns;
int cell_height = grid_h / rows;
dbc::check(cell_width > 0, "invalid cell width calc");
dbc::check(cell_height > 0, "invalid cell height calc");
for(auto [name, cell] : cells) {
cell.x = cell.col * cell_width;
cell.y = cell.row * cell_height;
if(cell.w == 0) cell.w = cell_width;
if(cell.x == 0) cell.h = cell_height;
for(auto& [name, cell] : cells) {
cell.x = grid_x + (cell.col * cell_width);
cell.y = grid_y + (cell.row * cell_height);
cell.max_w = cell.max_w == 0 ? cell_width : cell.max_w;
cell.max_h = cell.max_h == 0 ? cell_height : cell.max_h;
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);
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);
dbc::check(cell.h > 0, fmt::format("invalid height cell {}", name));
dbc::check(cell.w > 0, fmt::format("invalid width cell {}", name));
}
}
void LELParser::reset() {
row_count = 0;
max_columns = 0;
rows = 0;
columns = 0;
cur = {0, 0};
}