Skip to content

Commit

Permalink
Merge pull request finale-lua#642 from rpatters1/RGP-checkbox-mixin-fix
Browse files Browse the repository at this point in the history
`FCMCtrlCheckBox` store check state
  • Loading branch information
rpatters1 authored Jan 19, 2024
2 parents 7b79df9 + dc332c3 commit f411bd6
Showing 1 changed file with 76 additions and 1 deletion.
77 changes: 76 additions & 1 deletion src/mixin/FCMCtrlCheckbox.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,47 @@ local mixin_helper = require("library.mixin_helper")

local class = {Methods = {}}
local methods = class.Methods
local private = setmetatable({}, {__mode = "k"})

local trigger_check_change
local each_last_check_change

--[[
% Init
**[Internal]**
@ self (FCMCtrlCheckbox)
]]
function class:Init()
if private[self] then
return
end

private[self] = {
Check = 0,
}
end

--[[
% GetCheck
**[Override]**
Override Changes:
- Hooks into control state preservation.
@ self (FCMCtrlCheckbox)
: (number)
]]
function methods:GetCheck()
if mixin.FCMControl.UseStoredState(self) then
return private[self].Check
end

return self:GetCheck__()
end

--[[
% SetCheck
Expand All @@ -29,7 +66,11 @@ Override Changes:
function methods:SetCheck(checked)
mixin_helper.assert_argument_type(2, checked, "number")

self:SetCheck__(checked)
if mixin.FCMControl.UseStoredState(self) then
private[self].Check = checked
else
self:SetCheck__(checked)
end

trigger_check_change(self)
end
Expand Down Expand Up @@ -78,4 +119,38 @@ methods.AddHandleCheckChange, methods.RemoveHandleCheckChange, trigger_check_cha
}
)

--[[
% StoreState
**[Fluid] [Internal] [Override]**
Override Changes:
- Stores `FCMCtrlCheckbox`-specific properties.
*Do not disable this method. Override as needed but call the parent first.*
@ self (FCMCtrlCheckbox)
]]
function methods:StoreState()
mixin.FCMControl.StoreState(self)
private[self].Check = self:GetCheck__()
end

--[[
% RestoreState
**[Fluid] [Internal] [Override]**
Override Changes:
- Restores `FCMCtrlCheckbox`-specific properties.
*Do not disable this method. Override as needed but call the parent first.*
@ self (FCMCtrlCheckbox)
]]
function methods:RestoreState()
mixin.FCMControl.RestoreState(self)
self:SetCheck__(private[self].Check)
end

return class

0 comments on commit f411bd6

Please sign in to comment.