Skip to content

Commit

Permalink
Add support for parsing transition strings
Browse files Browse the repository at this point in the history
  • Loading branch information
scsole committed Jan 27, 2024
1 parent 912178c commit 27ec5bb
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@ local json = require("rapidjson")

local Module = {}

-- Valid transition strings
Module.Transitions = {
Left = 'left',
Right = 'right',
Top = 'top',
Bottom = 'bottom',
Fade = 'fade',
None = 'none'
}

--------------------------------Layer Groups and Controllers-----------------------------------------------

Module.Layer = {}
Expand Down Expand Up @@ -120,7 +130,7 @@ function Module.LayerController.New(page, list, transition)
self.Page = page or "Page 1"
self.List = list or {}
self.Debug = false
self.DefaultTransition = transition or "none"
self.DefaultTransition = transition or Module.Transitions.None
setmetatable(self, Module.LayerController)

return self
Expand All @@ -145,6 +155,19 @@ function Module.GetLayout(UCIName)
end
end

--- Check if a string represents a valid transition and return it. This will always return a valid transition type.
--- @param transition string A transition string to check
--- @return string # The provided transition type if `transition` was valid, else 'none'
function Module.ParseTransition(transition)
transition = transition:lower()
for _, t in pairs(Module.Transitions) do
if transition == t then
return transition
end
end
return Module.Transitions.None
end

---------------------------------------------------------------

-- Add the standard Uci library interface to this library
Expand Down

0 comments on commit 27ec5bb

Please sign in to comment.