Fixing more bugs related to percentages and then prototype a more complex UI.

This commit is contained in:
Zed A. Shaw 2025-02-15 22:14:19 -05:00
parent e106ad4be7
commit a7991a8f06
5 changed files with 45 additions and 20 deletions

18
lel.cpp
View file

@ -35,21 +35,27 @@ namespace lel {
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 = 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;
// ZED: getting a bit hairy but this should work
if(cell.percent) {
cell.max_w = cell.max_w * 0.01 * cell_width;
cell.max_h = cell.max_h * 0.01 * cell_height;
// when percent mode we have to take unset to 100%
if(cell.max_w == 0) cell.max_w = 100;
if(cell.max_h == 0) cell.max_h = 100;
cell.max_w *= cell_width * 0.01;
cell.max_h *= cell_height * 0.01;
} else {
if(cell.max_w == 0) cell.max_w = cell_width;
if(cell.max_h == 0) cell.max_h = cell_height;
}
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);
cell.mid_x = std::midpoint(cell.x, cell.x + cell_width);
cell.mid_y = std::midpoint(cell.y, cell.y + cell_height);
cell.mid_x = std::midpoint(cell.x, cell.x + cell.w);
cell.mid_y = std::midpoint(cell.y, cell.y + cell.h);
if(cell.right) cell.x += cell_width - cell.w;
if(cell.bottom) cell.y += cell_height - cell.h;