Skip to content

Commit c577892

Browse files
committed
fix: a couple crashes/dialog oddities
1 parent 3fa51c3 commit c577892

File tree

2 files changed

+23
-10
lines changed

2 files changed

+23
-10
lines changed

src/base/containers.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ class bounded_map : public bounded_container<Sz,T>
8787
{
8888
cont = other.cont;
8989
this->true_sz = other.true_sz;
90+
this->default_val = other.default_val;
9091
normalize();
9192
return *this;
9293
}
@@ -219,6 +220,7 @@ class bounded_vec : public bounded_container<Sz,T>
219220
{
220221
cont = other.cont;
221222
this->true_sz = other.true_sz;
223+
this->default_val = other.default_val;
222224
normalize();
223225
return *this;
224226
}

src/dialog/numpick.cpp

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,8 @@ std::shared_ptr<GUI::Widget> MapPickDialog<Sz>::view()
177177
using namespace GUI::Key;
178178
using namespace GUI::Props;
179179

180+
if(local_map.empty()) return nullptr;
181+
180182
std::shared_ptr<GUI::Grid> wingrid, sgrid, cmdrow;
181183

182184
sgrid = GUI::Internal::makeRows(4);
@@ -187,7 +189,7 @@ std::shared_ptr<GUI::Widget> MapPickDialog<Sz>::view()
187189
info = "Select a set of numbers.",
188190
onClose = message::CANCEL,
189191
Column(
190-
wingrid = Column(padding=0_px),
192+
wingrid = Column(padding = 0_px),
191193
Row(
192194
vAlign = 1.0,
193195
spacing = 2_em,
@@ -201,7 +203,7 @@ std::shared_ptr<GUI::Widget> MapPickDialog<Sz>::view()
201203
}),
202204
Button(
203205
text = "Fill",
204-
disabled = local_map.capacity() == local_map.size(),
206+
disabled = local_map.capacity() == local_map.size(),
205207
onPressFunc = [&]()
206208
{
207209
for(Sz q = 0; q < local_map.size(); ++q)
@@ -215,7 +217,7 @@ std::shared_ptr<GUI::Widget> MapPickDialog<Sz>::view()
215217
{
216218
if(!local_map.contains(q))
217219
{
218-
if(auto v = call_get_num("Add at what index?",q,local_map.size()))
220+
if(auto v = call_get_num("Add at what index?", q, local_map.size()-1, 0))
219221
{
220222
local_map[*v] = local_map.defval();
221223
this->refresh_dlg();
@@ -284,6 +286,9 @@ std::shared_ptr<GUI::Widget> MapPickDialog<Sz>::view()
284286
));
285287
sgrid->add(row);
286288
}
289+
if (local_map.inner_empty()) sgrid->add(DummyWidget()); //prevent crash on empty map
290+
auto curpg_start = pg*pglimit;
291+
auto curpg_end = zc_min(local_map.size()-1,((pg+1)*pglimit)-1);
287292
wingrid->add(Row(
288293
Button(type = GUI::Button::type::ICON, icon = BTNICON_ARROW_LEFT2,
289294
disabled = !pg,
@@ -305,7 +310,7 @@ std::shared_ptr<GUI::Widget> MapPickDialog<Sz>::view()
305310
this->refresh_dlg();
306311
}
307312
}),
308-
Label(text = fmt::format("Page {} ({}-{})",pg,pg*pglimit,((pg+1)*pglimit)-1),
313+
Label(text = fmt::format("Page {} ({}-{})",pg,curpg_start,curpg_end),
309314
minwidth = 8_em, textAlign = 1),
310315
Button(type = GUI::Button::type::ICON, icon = BTNICON_ARROW_RIGHT,
311316
disabled = (local_map.capacity() <= (pg+1)*pglimit),
@@ -372,7 +377,7 @@ std::shared_ptr<GUI::Widget> NumPickDialog::view()
372377
if(zsint)
373378
{
374379
tf = TextField(
375-
maxwidth = 8_em, hPadding = 0_px,
380+
width = 8_em, hPadding = 0_px,
376381
type = GUI::TextField::type::SWAP_ZSINT2,
377382
val = local_val, low = min, high = max,
378383
onValChangedFunc = [&](GUI::TextField::type,std::string_view,int32_t val)
@@ -383,22 +388,26 @@ std::shared_ptr<GUI::Widget> NumPickDialog::view()
383388
else
384389
{
385390
tf = TextField(
386-
maxwidth = 8_em, hPadding = 0_px,
391+
width = 8_em, hPadding = 0_px,
387392
type = GUI::TextField::type::SWAP_ZSINT_NO_DEC,
388-
val = local_val*10000, low = min, high = max,
393+
val = local_val*10000, low = min*10000, high = max*10000,
389394
onValChangedFunc = [&](GUI::TextField::type,std::string_view,int32_t val)
390395
{
391396
local_val = val/10000;
392397
});
393398
}
399+
std::shared_ptr<GUI::Widget> w;
400+
if(max < min)
401+
w = DummyWidget(padding = 0_px);
402+
else w = Label(text = fmt::format("({} <= x <= {})",min,max));
394403
window = Window(
395404
title = "Number Picker",
396405
minwidth = 30_em,
397406
info = "Select a number.",
398407
onClose = message::CANCEL,
399408
Column(
400409
Label(text = labeltext),
401-
tf,
410+
w, tf,
402411
Row(
403412
vAlign = 1.0,
404413
spacing = 2_em,
@@ -426,6 +435,8 @@ bool NumPickDialog::handleMessage(const GUI::DialogMessage<message>& msg)
426435
rerun_dlg = true;
427436
return true;
428437
case message::OK:
438+
if(max > min)
439+
local_val = vbound(local_val,max,min);
429440
retv = local_val;
430441
return true;
431442
case message::CANCEL:
@@ -437,13 +448,13 @@ bool NumPickDialog::handleMessage(const GUI::DialogMessage<message>& msg)
437448
optional<int32_t> call_get_num(std::string const& lbl, int32_t dv, int32_t max, int32_t min)
438449
{
439450
optional<int32_t> ret = nullopt;
440-
NumPickDialog(lbl,ret,dv,false,min,max).show();
451+
NumPickDialog(lbl,ret,dv,false,max,min).show();
441452
return ret;
442453
}
443454
optional<zfix> call_get_zfix(std::string const& lbl, zfix dv, zfix max, zfix min)
444455
{
445456
optional<int32_t> ret = nullopt;
446-
NumPickDialog(lbl,ret,dv.getZLong(),true,min.getZLong(),max.getZLong()).show();
457+
NumPickDialog(lbl,ret,dv.getZLong(),true,max.getZLong(),min.getZLong()).show();
447458
if(ret)
448459
return zslongToFix(*ret);
449460
return ret;

0 commit comments

Comments
 (0)