Already better than CSS because I can center stuff.

This commit is contained in:
Zed A. Shaw 2025-02-15 12:13:58 -05:00
parent 1620a5420f
commit 60ed686eb0
6 changed files with 58 additions and 42 deletions

16
lel.cpp
View file

@ -1,6 +1,7 @@
#include "lel.hpp"
#include <fmt/core.h>
#include "dbc.hpp"
#include <numeric>
#include "lel_parser.cpp"
@ -58,6 +59,10 @@ namespace lel {
cur.expand = true;
}
void Parser::center() {
cur.center = true;
}
void Parser::finalize() {
dbc::check(columns > 0, "columns are 0");
dbc::check(rows > 0, "rows are 0");
@ -75,12 +80,11 @@ namespace lel {
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;
if(cell.right) cell.x += cell_width - cell.w;
if(cell.bottom) cell.y += cell_height - cell.h;
if(cell.center) {
cell.x = std::midpoint(cell.x, cell.x + cell_width) - cell.w / 2;
cell.y = std::midpoint(cell.y, cell.y + cell_height) - cell.h / 2;
}
dbc::check(cell.h > 0, fmt::format("invalid height cell {}", name));