imagebox: Use a different entry for saving the image
In 3.4, an imagebox' image is set via "box.image = foo". Since widgets are just ordinary tables in 3.5, this will actually mess with the imagebox' image without setting it correctly. Fix this by renaming the entry to "_image". A similar patch was applied to the textbox widget ages ago. Signed-off-by: Uli Schlachter <psychon@znc.in>
This commit is contained in:
parent
fbecd40c62
commit
b7eb233aee
|
@ -17,21 +17,21 @@ local imagebox = { mt = {} }
|
|||
|
||||
--- Draw an imagebox with the given cairo context in the given geometry.
|
||||
function imagebox:draw(wibox, cr, width, height)
|
||||
if not self.image then return end
|
||||
if not self._image then return end
|
||||
|
||||
cr:save()
|
||||
|
||||
if not self.resize_forbidden then
|
||||
-- Let's scale the image so that it fits into (width, height)
|
||||
local w = self.image:get_width()
|
||||
local h = self.image:get_height()
|
||||
local w = self._image:get_width()
|
||||
local h = self._image:get_height()
|
||||
local aspect = width / w
|
||||
local aspect_h = height / h
|
||||
if aspect > aspect_h then aspect = aspect_h end
|
||||
|
||||
cr:scale(aspect, aspect)
|
||||
end
|
||||
cr:set_source_surface(self.image, 0, 0)
|
||||
cr:set_source_surface(self._image, 0, 0)
|
||||
cr:paint()
|
||||
|
||||
cr:restore()
|
||||
|
@ -39,12 +39,12 @@ end
|
|||
|
||||
--- Fit the imagebox into the given geometry
|
||||
function imagebox:fit(width, height)
|
||||
if not self.image then
|
||||
if not self._image then
|
||||
return 0, 0
|
||||
end
|
||||
|
||||
local w = self.image:get_width()
|
||||
local h = self.image:get_height()
|
||||
local w = self._image:get_width()
|
||||
local h = self._image:get_height()
|
||||
|
||||
if w > width then
|
||||
h = h * width / w
|
||||
|
@ -93,7 +93,7 @@ function imagebox:set_image(image)
|
|||
end
|
||||
end
|
||||
|
||||
self.image = image
|
||||
self._image = image
|
||||
|
||||
self:emit_signal("widget::updated")
|
||||
return true
|
||||
|
|
Loading…
Reference in New Issue