sm::AUTO_VALUES to automatically assign option widths

This commit is contained in:
Zeno Rogue 2022-10-21 18:50:30 +02:00
parent 5c507e58fd
commit caa4ac5bb4
3 changed files with 15 additions and 5 deletions

View File

@ -394,6 +394,11 @@ EX namespace dialog {
innerwidth = 0;
int N = items.size();
list_starts_at = list_ends_at = list_actual_size = 0;
bool autoval = cmode & sm::AUTO_VALUES;
rightwidth = 0;
if(!autoval) rightwidth = textwidth(dfsize, "MMMMMMMM") + dfsize/2;
for(int i=0; i<N; i++) {
if(items[i].type == diListStart)
list_starts_at = tothei;
@ -409,13 +414,14 @@ EX namespace dialog {
tothei += dfspace * items[i].scale / 100;
if(among(items[i].type, diItem, diColorItem))
innerwidth = max(innerwidth, textwidth(dfsize * items[i].scale / 100, items[i].body));
if(among(items[i].type, diItem))
rightwidth = max(rightwidth, textwidth(dfsize * items[i].scale / 100, items[i].value) + dfsize);
if(items[i].type == diTitle || items[i].type == diInfo || items[i].type == diBigItem)
dialogwidth = max(dialogwidth, textwidth(dfsize * items[i].scale / 100, items[i].body) * 10/9);
}
}
leftwidth = ISMOBILE ? 0 : textwidth(dfsize, "MMMMM") + dfsize/2;
rightwidth = textwidth(dfsize, "MMMMMMMM") + dfsize/2;
fwidth = innerwidth + leftwidth + rightwidth;
if(list_actual_size) fwidth += dfsize;

View File

@ -711,7 +711,7 @@ void expansion_analyzer::view_distances_dialog() {
dynamicval<color_t> dv(distcolors[0], forecolor);
dialog::init("");
cmode |= sm::DIALOG_STRICT_X | sm::EXPANSION;
cmode |= sm::DIALOG_STRICT_X | sm::EXPANSION | sm::AUTO_VALUES;
int maxlen = last_distance;
vector<bignum> qty(maxlen);
@ -753,9 +753,12 @@ void expansion_analyzer::view_distances_dialog() {
#endif
}
dialog::start_list(1600, 1600);
for(int i=0; i<maxlen; i++) if(!qty[i].digits.empty())
dialog::addInfo(its(i) + ": " + qty[i].get_str(100), distcolors[i]);
dialog::start_list(1600, 1600, 'a');
for(int i=0; i<maxlen; i++) if(!qty[i].digits.empty()) {
dialog::addSelItem(qty[i].get_str(100), " " + its(i), dialog::list_fake_key);
auto& last = dialog::lastItem();
last.color = last.colorv = distcolors[i];
}
dialog::end_list();
if(sizes_known() || bt::in()) {

View File

@ -5688,6 +5688,7 @@ namespace sm {
static const int PANNING = (1<<20); // smooth scrolling works
static const int DARKEN = (1<<21); // darken the game background
static const int NOSCR = (1<<22); // do not show the game background
static const int AUTO_VALUES = (1<<23); // automatic place for values
}
#endif