Skip to content

Commit d39e15d

Browse files
committed
Expand widget clauses: Add conditional functions to phrases
1 parent 460c0c8 commit d39e15d

File tree

5 files changed

+377
-141
lines changed

5 files changed

+377
-141
lines changed

data/mods/TEST_DATA/widgets.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@
122122
"type": "widget",
123123
"style": "text",
124124
"var": "compass_legend_text",
125+
"width": 0,
125126
"text_align": "left",
126127
"flags": [ "W_DYNAMIC_HEIGHT" ]
127128
},
@@ -131,6 +132,7 @@
131132
"style": "text",
132133
"var": "compass_legend_text",
133134
"height": 3,
135+
"width": 0,
134136
"text_align": "left",
135137
"flags": [ "W_DYNAMIC_HEIGHT" ]
136138
},
@@ -140,6 +142,7 @@
140142
"style": "text",
141143
"var": "compass_legend_text",
142144
"height": 5,
145+
"width": 0,
143146
"text_align": "left",
144147
"flags": [ "W_DYNAMIC_HEIGHT" ]
145148
},

src/display.cpp

Lines changed: 2 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1150,36 +1150,7 @@ std::string display::colorized_bodypart_status_legend_text( const Character &u,
11501150
}
11511151
}
11521152
}
1153-
// Split legend keys into X lines, where X = height.
1154-
// Lines use the provided width.
1155-
// This effectively limits the text to a 'width'x'height' box.
1156-
std::string ret;
1157-
height = 0;
1158-
const int h_max = max_height == 0 ? INT_MAX : max_height;
1159-
const int nsize = keys.size();
1160-
for( int row = 0, nidx = 0; row < h_max && nidx < nsize; row++ ) {
1161-
int wavail = width;
1162-
int nwidth = utf8_width( keys[nidx], true );
1163-
bool startofline = true;
1164-
while( nidx < nsize && ( wavail > nwidth || startofline ) ) {
1165-
startofline = false;
1166-
wavail -= nwidth;
1167-
ret += keys[nidx];
1168-
nidx++;
1169-
if( nidx < nsize ) {
1170-
nwidth = utf8_width( keys[nidx], true );
1171-
if( wavail > nwidth ) {
1172-
ret += " ";
1173-
wavail -= 2;
1174-
}
1175-
}
1176-
}
1177-
if( row < h_max - 1 ) {
1178-
ret += "\n";
1179-
}
1180-
height++;
1181-
}
1182-
return ret;
1153+
return format_widget_multiline( keys, max_height, width, height );
11831154
}
11841155

11851156
std::string display::colorized_bodypart_outer_armor( const Character &u, const bodypart_id &bp )
@@ -1586,36 +1557,7 @@ std::string display::colorized_compass_legend_text( int width, int max_height, i
15861557
name = string_format( "%s %s", colorize( m.first->sym, m.first->color ), colorize( name, danger ) );
15871558
names.emplace_back( name );
15881559
}
1589-
// Split names into X lines, where X = height.
1590-
// Lines use the provided width.
1591-
// This effectively limits the text to a 'width'x'height' box.
1592-
std::string ret;
1593-
height = 0;
1594-
const int h_max = max_height == 0 ? INT_MAX : max_height;
1595-
const int nsize = names.size();
1596-
for( int row = 0, nidx = 0; row < h_max && nidx < nsize; row++ ) {
1597-
int wavail = width;
1598-
int nwidth = utf8_width( names[nidx], true );
1599-
bool startofline = true;
1600-
while( nidx < nsize && ( wavail > nwidth || startofline ) ) {
1601-
startofline = false;
1602-
wavail -= nwidth;
1603-
ret += names[nidx];
1604-
nidx++;
1605-
if( nidx < nsize ) {
1606-
nwidth = utf8_width( names[nidx], true );
1607-
if( wavail > nwidth ) {
1608-
ret += " ";
1609-
wavail -= 2;
1610-
}
1611-
}
1612-
}
1613-
if( row < h_max - 1 ) {
1614-
ret += "\n";
1615-
}
1616-
height++;
1617-
}
1618-
return ret;
1560+
return format_widget_multiline( names, max_height, width, height );
16191561
}
16201562

16211563
// Print monster info to the given window

0 commit comments

Comments
 (0)