From d7d6c5aea66842bb09ff53f2da0502df6ba43f77 Mon Sep 17 00:00:00 2001 From: John Cosker Date: Mon, 6 Feb 2023 08:55:46 -0500 Subject: [PATCH] Backwards options for cycle hotkey working --- library/lua/gui/widgets.lua | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/library/lua/gui/widgets.lua b/library/lua/gui/widgets.lua index 342ece201..cc71df9bf 100644 --- a/library/lua/gui/widgets.lua +++ b/library/lua/gui/widgets.lua @@ -1440,6 +1440,7 @@ CycleHotkeyLabel = defclass(CycleHotkeyLabel, Label) CycleHotkeyLabel.ATTRS{ key=DEFAULT_NIL, + key_back=DEFAULT_NIL, label=DEFAULT_NIL, label_width=DEFAULT_NIL, options=DEFAULT_NIL, @@ -1451,7 +1452,8 @@ function CycleHotkeyLabel:init() self:setOption(self.initial_option) self:setText{ - {key=self.key, key_sep=': ', text=self.label, width=self.label_width, + {key=self.key_back, key_sep='', width=0, on_activate=self.key_back and self:callback('cycle', true)}, + {key=self.key, key_sep=self.key_back and '' or ': ', text=self.label, width=self.key_back and 0 or self.label_width, on_activate=self:callback('cycle')}, ' ', {text=self:callback('getOptionLabel'), @@ -1459,12 +1461,14 @@ function CycleHotkeyLabel:init() } end -function CycleHotkeyLabel:cycle() +function CycleHotkeyLabel:cycle(backwards) local old_option_idx = self.option_idx - if self.option_idx == #self.options then + if self.option_idx == #self.options and not backwards then self.option_idx = 1 + elseif self.option_idx == 1 and backwards then + self.option_idx = #self.options else - self.option_idx = self.option_idx + 1 + self.option_idx = self.option_idx + (not backwards and 1 or -1) end if self.on_change then self.on_change(self:getOptionValue(),