-
Notifications
You must be signed in to change notification settings - Fork 471
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: custom modal component API (#2205)
- Loading branch information
Showing
5 changed files
with
51 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
Modal = { | ||
_id = "modal", | ||
|
||
_inc = 1000, | ||
_children = {}, | ||
} | ||
|
||
function Modal:new(area) return setmetatable({ _area = area }, { __index = self }) end | ||
|
||
function Modal:reflow() | ||
local components = {} | ||
for _, child in ipairs(self._children) do | ||
components = ya.list_merge(components, child[1]:new(self._area):reflow()) | ||
end | ||
return components | ||
end | ||
|
||
function Modal:redraw() | ||
local elements = {} | ||
for _, child in ipairs(self._children) do | ||
elements = ya.list_merge(elements, ya.redraw_with(child[1]:new(self._area))) | ||
end | ||
return elements | ||
end | ||
|
||
-- Children | ||
function Modal:children_add(tbl, order) | ||
self._inc = self._inc + 1 | ||
self._children[#self._children + 1] = { tbl, id = self._inc, order = order } | ||
|
||
table.sort(self._children, function(a, b) return a.order < b.order end) | ||
return self._inc | ||
end | ||
|
||
function Modal:children_remove(id) | ||
for i, child in ipairs(self._children) do | ||
if child.id == id then | ||
table.remove(self._children, i) | ||
break | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters