Skip to content
coding.jackalope edited this page Feb 24, 2019 · 9 revisions
Table of Contents

Image

Images can be drawn within windows and react to user interaction. A path to an image can be specified through the options of the Image function. If this is done, Slab will manage the image resource and will use the path as a key to the resource.

Slab.BeginWindow('MyFirstWindow', {Title = "My First Window"})

Slab.Image('MyImage', {Path = "Slab/Internal/Resources/Textures/power.png"})

Slab.EndWindow()

A Love image object can also be used to pass into the Image function. These resources should be managed outside of Slab.

local Power = nil
function love.load(args)
	Power = love.graphics.newImage("Slab/Internal/Resources/Textures/power.png")
end

...

Slab.BeginWindow('MyFirstWindow', {Title = "My First Window"})

Slab.Image('MyImage', {Image = Power})

Slab.EndWindow()

Images can also react to user input. An image can react to a mouse click.

Slab.BeginWindow('MyFirstWindow', {Title = "My First Window"})

local PowerColor = PowerButton and {1.0, 0.0, 0.0, 1.0} or {1.0, 1.0, 1.0, 1.0}

if Slab.Image('MyImage', {Image = Power, Color = PowerColor, ReturnOnClick = true}) then
	PowerButton = not PowerButton
end

Slab.EndWindow()

An image can also react to hover.

Slab.BeginWindow('MyFirstWindow', {Title = "My First Window"})

local PowerColor = PowerButton and {1.0, 0.0, 0.0, 1.0} or {1.0, 1.0, 1.0, 1.0}

if Slab.Image('MyImage', {Image = Power, Color = PowerColor, ReturnOnHover = true}) then
	PowerButton = true
else
	PowerButton = false
end

Slab.EndWindow()

Options

There are a few options which can be configured to change the behavior of the Image control.

Option Type Description
Image Object A user supplied image. This must be a valid Love image or the call will assert.
Path String If the Image option is nil, then a path must be specified. Slab will load and manage the image resource.
Rotation: [Number] The rotation value to apply when this image is drawn.
Scale: [Number] The scale value to apply to both the X and Y axis.
ScaleX: [Number] The scale value to apply to the X axis.
ScaleY: [Number] The scale value to apply to the Y axis.
Color: [Table] The color to use when rendering this image.
ReturnOnHover: [Boolean] Returns true when the mouse is hovered over the image.
ReturnOnClick: [Boolean] Returns true when the mouse is released over the image.
Clone this wiki locally