From 88a68d2f98bda0b28ebd527b75bb300159d5712e Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Sat, 28 Aug 2021 21:15:01 +0200 Subject: [PATCH] fix: propagate cancel widget --- .../birb/modules/gui/menus/model/init.lua | 4 ++-- .../birb/modules/gui/menus/model/page.lua | 17 ++++++++++++----- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/sonic-radiance.love/birb/modules/gui/menus/model/init.lua b/sonic-radiance.love/birb/modules/gui/menus/model/init.lua index 2aba865..e6979a1 100644 --- a/sonic-radiance.love/birb/modules/gui/menus/model/init.lua +++ b/sonic-radiance.love/birb/modules/gui/menus/model/init.lua @@ -142,9 +142,9 @@ end -- CANCEL FUNCTIONS -- Add a widget as a "cancel" function -function MenuModel:setCancelWidget() +function MenuModel:setCancelWidget(id) local page = self:getCurrentPage() - page:setCancelWidget() + page:setCancelWidget(id) end function MenuModel:getCancelWidget() diff --git a/sonic-radiance.love/birb/modules/gui/menus/model/page.lua b/sonic-radiance.love/birb/modules/gui/menus/model/page.lua index e2c13e0..326b76f 100644 --- a/sonic-radiance.love/birb/modules/gui/menus/model/page.lua +++ b/sonic-radiance.love/birb/modules/gui/menus/model/page.lua @@ -66,8 +66,8 @@ end -- All the actions callback used by the widgets function Page:cancelAction() - if (self.cancel ~= 0) then - self:action(self.cancel, "key") + if (self:getCancelWidget() ~= 0) then + self:action(self:getCancelWidget(), "key") end end @@ -134,11 +134,18 @@ end -- Add a widget as a "cancel" function function Page:setCancelWidget(id) - self.cancel = #self.widgets + if (id == nil) then + id = #self.widgets + end + self.cancel = id end -function Page:getCancelWidget(id) - return self.cancel +function Page:getCancelWidget() + if (self.cancel == "last") then + return #self.widgets + else + return self.cancel + end end -- CURSOR FUNCTIONS