flamendless / Slab

An immediate mode GUI for the Love2D framework.
MIT License
289 stars 25 forks source link

ColorPicker - optional alpha value passing and return value use int instead of string #69

Closed flamendless closed 3 years ago

flamendless commented 3 years ago

This is useful for those who don't want to pass any 4th value (alpha) to the Color parameter.

I've encountered something weird: in testing outside of my project (using Slab's own main.lua):

local color = {1, 1, 1} --no alpha

--in update
Slab.ColorPicker({Color = color}) -- no error

But in my project, the same thing is done:

local color = e.color.color -- a table of {1, 1, 1}
Slab.ColorPicker({Color = color}) -- gives error (ColorPicker.lua line 384) about a `nil` value, I assume the `CurrentColor[4]`

This PR fixes those.

flamendless commented 3 years ago

The 2nd commit of this PR changes:

local t = Slab.ColorPicker(...)
if t.Button == "OK" then ... end

to

local t = Slab.ColorPicker(...)
if t.Button == 1 then --okay
elseif t.Button == -1 then --cancel
end

As ColorPicker's buttons (according to the wiki API) are not customizable. So returning a boolean integer would suffice to check if the OK is pressed or not.