Skip to content

Commit

Permalink
Clear method to remove components
Browse files Browse the repository at this point in the history
  • Loading branch information
tredfern committed Aug 20, 2020
1 parent bd0b111 commit db54033
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
6 changes: 6 additions & 0 deletions docs/moonpie.ui.components.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@ moonpie.ui.components

The main engine for creating UI elements. Components represent widgets of logic and display.

Component Methods
^^^^^^^^^^^^^^^^^

remove
Flags the component to be removed from the render tree.

Component Properties
^^^^^^^^^^^^^^^^^^^^

Expand Down
1 change: 1 addition & 0 deletions moonpie/ui/components/component.lua
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ function ComponentFactory.add_component_methods(c)
c.flag_updates = function(self, f) self.updates_available = f end
c.has_updates = function(self) return self.updates_available end
c.flag_removal = function(self) self:update({ ready_to_remove = true }) end
c.remove = function(self) self:flag_removal() end
c.logger = require "moonpie.logger"
c.needs_removal = function(self) return self.ready_to_remove end
c.set_focus = function(self) require("moonpie.ui.user_focus"):set_focus(self) end
Expand Down
7 changes: 7 additions & 0 deletions moonpie/ui/components/component_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,13 @@ describe("Component", function()
assert.is_true(c:has_updates())
end)

it("can use remove component", function()
local c = Component.button()
c:remove()
assert.is_true(c:needs_removal())
assert.is_true(c:has_updates())
end)

it("returns decipherable error if component render function is not set up properly", function()
Component("bad_component", function() end)
assert.has_errors(Component.bad_component, "Component did not render table")
Expand Down

0 comments on commit db54033

Please sign in to comment.