Skip to content

Commit

Permalink
Translates custom content properly
Browse files Browse the repository at this point in the history
  • Loading branch information
tredfern committed Jan 28, 2020
1 parent 86cc065 commit 902ddba
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
11 changes: 9 additions & 2 deletions moonpie/ui/drawing.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
local drawing = {}
local colors = require "moonpie.graphics.colors"
local image = require "moonpie.graphics.image"
local safecall = require "moonpie.utility.safe_call"

function drawing.standard(node)
if node.hidden then return end
Expand All @@ -15,7 +14,7 @@ function drawing.standard(node)
drawing.draw_background(node)
drawing.draw_border(node)
drawing.image(node)
safecall(node.draw_component, node)
drawing.custom_content(node)

love.graphics.translate(node.box:content_position())

Expand Down Expand Up @@ -74,4 +73,12 @@ function drawing.image(node)
love.graphics.pop()
end

function drawing.custom_content(node)
if not node.draw_component then return end
love.graphics.push()
love.graphics.translate(node.box:content_position())
node:draw_component()
love.graphics.pop()
end

return drawing
14 changes: 14 additions & 0 deletions moonpie/ui/drawing_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -227,4 +227,18 @@ describe("Renderers", function()
node:paint()
assert.spy(c.draw_component).was.called_with(node)
end)

it("translates the custom content properly", function()
local c = {
draw_component = spy.new(function() end),
width = 100,
height = 100,
padding = 10,
margin = 10
}
local node = Node(c)
node:layout()
drawing.custom_content(node)
assert.spy(love.graphics.translate).was.called_with(20, 20)
end)
end)

0 comments on commit 902ddba

Please sign in to comment.