You can now prefix a size with % and it will do percentage for the size, even over 100.

Zed A. Shaw 3 weeks ago
parent d558da1620
commit c03a384372
  1. 2
      combat_ui.cpp
  2. 5
      lel.cpp
  3. 1
      lel.hpp
  4. 92
      lel_parser.cpp
  5. 4
      lel_parser.rl
  6. 2
      tests/lel.cpp

@ -9,7 +9,7 @@ namespace gui {
$level(level)
{
bool good = $layout.parse(
"[attack1 | =(90)attack2 | attack3 | heal]"
"[attack1 | attack2 | attack3 | heal]"
);
dbc::check(good, "failed to parse combat layout");

@ -40,6 +40,11 @@ namespace lel {
cell.max_w = cell.max_w == 0 ? cell_width : cell.max_w;
cell.max_h = cell.max_h == 0 ? cell_height : cell.max_h;
if(cell.percent) {
cell.max_w = cell.max_w * 0.01 * cell_width;
cell.max_h = cell.max_h * 0.01 * 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);

@ -17,6 +17,7 @@ namespace lel {
bool bottom = false;
bool expand = false;
bool center = false;
bool percent = false;
Cell(int col, int row) : col(col), row(row) {}
};

@ -7,7 +7,7 @@
namespace lel {
#line 42 "lel_parser.rl"
#line 44 "lel_parser.rl"
@ -15,64 +15,66 @@ namespace lel {
static const char _Parser_actions[] = {
0, 1, 1, 1, 2, 1, 3, 1,
4, 1, 5, 1, 6, 1, 9, 1,
10, 1, 11, 1, 12, 2, 0, 7,
2, 0, 8, 2, 4, 1, 2, 4,
5
10, 1, 11, 1, 12, 1, 13, 2,
0, 7, 2, 0, 8, 2, 4, 1,
2, 4, 5
};
static const char _Parser_key_offsets[] = {
0, 0, 4, 19, 21, 25, 37, 49,
54, 56, 59
0, 0, 4, 20, 33, 35, 39, 41,
44, 56, 61
};
static const char _Parser_trans_keys[] = {
32, 91, 9, 13, 32, 40, 42, 46,
61, 94, 95, 9, 13, 60, 62, 65,
90, 97, 122, 48, 57, 41, 44, 48,
57, 40, 42, 46, 61, 94, 95, 60,
62, 65, 90, 97, 122, 32, 93, 95,
124, 9, 13, 48, 57, 65, 90, 97,
122, 32, 93, 124, 9, 13, 48, 57,
41, 48, 57, 32, 91, 9, 13, 0
32, 91, 9, 13, 32, 37, 40, 42,
46, 61, 94, 95, 9, 13, 60, 62,
65, 90, 97, 122, 37, 40, 42, 46,
61, 94, 95, 60, 62, 65, 90, 97,
122, 48, 57, 41, 44, 48, 57, 48,
57, 41, 48, 57, 32, 93, 95, 124,
9, 13, 48, 57, 65, 90, 97, 122,
32, 93, 124, 9, 13, 32, 91, 9,
13, 0
};
static const char _Parser_single_lengths[] = {
0, 2, 7, 0, 2, 6, 4, 3,
0, 1, 2
0, 2, 8, 7, 0, 2, 0, 1,
4, 3, 2
};
static const char _Parser_range_lengths[] = {
0, 1, 4, 1, 1, 3, 4, 1,
1, 1, 1
0, 1, 4, 3, 1, 1, 1, 1,
4, 1, 1
};
static const char _Parser_index_offsets[] = {
0, 0, 4, 16, 18, 22, 32, 41,
46, 48, 51
0, 0, 4, 17, 28, 30, 34, 36,
39, 48, 53
};
static const char _Parser_indicies[] = {
0, 2, 0, 1, 3, 4, 5, 6,
8, 6, 9, 3, 7, 9, 9, 1,
10, 1, 11, 12, 13, 1, 4, 5,
6, 8, 6, 9, 7, 9, 9, 1,
14, 16, 15, 17, 14, 15, 15, 15,
1, 18, 19, 20, 18, 1, 21, 1,
22, 23, 1, 24, 2, 24, 1, 0
7, 9, 7, 10, 3, 8, 10, 10,
1, 4, 5, 6, 7, 9, 7, 10,
8, 10, 10, 1, 11, 1, 12, 13,
14, 1, 15, 1, 16, 17, 1, 18,
20, 19, 21, 18, 19, 19, 19, 1,
22, 23, 24, 22, 1, 25, 2, 25,
1, 0
};
static const char _Parser_trans_targs[] = {
1, 0, 2, 2, 3, 5, 5, 5,
5, 6, 4, 5, 8, 4, 7, 6,
10, 2, 7, 10, 2, 9, 5, 9,
10
1, 0, 2, 2, 3, 4, 3, 3,
3, 3, 8, 5, 3, 6, 5, 7,
3, 7, 9, 8, 10, 2, 9, 10,
2, 10
};
static const char _Parser_trans_actions[] = {
0, 0, 3, 0, 0, 13, 5, 11,
15, 19, 17, 21, 21, 0, 7, 0,
30, 27, 0, 9, 1, 17, 24, 0,
0
0, 0, 3, 0, 17, 0, 13, 5,
11, 15, 21, 19, 23, 23, 0, 19,
26, 0, 7, 0, 32, 29, 0, 9,
1, 0
};
static const int Parser_start = 1;
@ -82,7 +84,7 @@ static const int Parser_error = 0;
static const int Parser_en_main = 1;
#line 45 "lel_parser.rl"
#line 47 "lel_parser.rl"
bool Parser::parse(std::string input) {
reset();
@ -94,14 +96,14 @@ bool Parser::parse(std::string input) {
std::string tk;
#line 89 "lel_parser.cpp"
#line 91 "lel_parser.cpp"
{
cs = Parser_start;
}
#line 56 "lel_parser.rl"
#line 58 "lel_parser.rl"
#line 92 "lel_parser.cpp"
#line 94 "lel_parser.cpp"
{
int _klen;
unsigned int _trans;
@ -224,14 +226,18 @@ _match:
{ cur.center = true; }
break;
case 11:
#line 35 "lel_parser.rl"
{ start = p; }
#line 27 "lel_parser.rl"
{ cur.percent = true; }
break;
case 12:
#line 38 "lel_parser.rl"
#line 37 "lel_parser.rl"
{ start = p; }
break;
case 13:
#line 40 "lel_parser.rl"
{start = p;}
break;
#line 208 "lel_parser.cpp"
#line 213 "lel_parser.cpp"
}
}
@ -244,7 +250,7 @@ _again:
_out: {}
}
#line 57 "lel_parser.rl"
#line 59 "lel_parser.rl"
bool good = pe - p == 0;
if(good) {

@ -24,6 +24,7 @@ namespace lel {
action setheight { cur.max_h = std::stoi(tk); }
action expand { cur.expand = true; }
action center { cur.center = true; }
action percent { cur.percent = true; }
col = "|" $col;
ltab = "[" $ltab;
@ -31,10 +32,11 @@ namespace lel {
valign = ("^" | ".") $valign;
expand = "*" $expand;
center = "=" $center;
percent = "%" $percent;
halign = ("<" | ">") $align;
number = digit+ >{ start = fpc; } %token;
setw = ("(" number %setwidth ("," number %setheight)? ")") ;
modifiers = (center | expand | valign | halign | setw);
modifiers = (percent | center | expand | valign | halign | setw);
id = modifiers* ((alpha | '_')+ :>> (alnum | '_')*) >{start = fpc;} %id;
row = space* ltab space* id space* (col space* id space*)* space* rtab space*;

@ -12,7 +12,7 @@ TEST_CASE("test basic ops", "[lel]") {
bool good = parser.parse(
"[ label_1 | label3 | test1]"
"[ *(300,300)text1 | (150)people | ^test2]"
"[ *(300,300)text1 | %(150)people | ^test2]"
"[ >label2 | _ | .test3]"
"[ =message | buttons | test4]");

Loading…
Cancel
Save