From 18a9a7d1fae4a2410e28383d37a3a409ae7ee0b4 Mon Sep 17 00:00:00 2001 From: Myk Taylor Date: Thu, 29 Jun 2023 18:13:16 -0700 Subject: [PATCH] allow invalid options to default to the first option and make the range slider move the other slider if it would become invalid --- library/lua/gui/widgets.lua | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/library/lua/gui/widgets.lua b/library/lua/gui/widgets.lua index a58ac228c..7a3201f28 100644 --- a/library/lua/gui/widgets.lua +++ b/library/lua/gui/widgets.lua @@ -1552,8 +1552,7 @@ function CycleHotkeyLabel:setOption(value_or_index, call_on_change) end end if not option_idx then - error(('cannot find option with value or index: "%s"') - :format(value_or_index)) + option_idx = 1 end local old_option_idx = self.option_idx self.option_idx = option_idx @@ -2392,9 +2391,15 @@ local function rangeslider_do_drag(self, width_per_idx) end end if new_left_idx and new_left_idx ~= self.get_left_idx_fn() then + if not new_right_idx and new_left_idx > self.get_right_idx_fn() then + self.on_right_change(new_left_idx) + end self.on_left_change(new_left_idx) end if new_right_idx and new_right_idx ~= self.get_right_idx_fn() then + if new_right_idx < self.get_left_idx_fn() then + self.on_left_change(new_right_idx) + end self.on_right_change(new_right_idx) end end