pgimeno wrote: ↑Sun Feb 14, 2021 12:07 pm
Do you have some other suggestion that keeps backwards compatibility?
In my opinion, it's a feature not worth keeping nor making backwards compatible, but... If you're gonna do it, you'd need to add a bool that uses the default functionality on false/nil, and not increment the colors for parented buttons on true. EDIT2: If you want *me* to write that code, I have no problem with that.
You could still add the depress coloring (seriously, buttons that don't change color when you mousedown? Pfft, that's crazy
), just use the bool for whether or not parented buttons will shift the color-states used.
You *could* forgo the bool and just make it a thing that happens on frame creation -- if it has a parent, then shift the color states -- and then the developer can "avoid" it by setting the parent after creating it, or perhaps by caching the default colors for an unparented button and then setting the colors afterwards, but that would remove the color-incrementing behavior occurring dynamically when the button is parented or unparented.
Regardless of how or whether you keep it backwards compatible, having three colors to use for default+hover+click is a good idea.
EDIT1: Since double-posting is frowned upon, here's a massive edit.
Gspot:image elements cannot be scaled. If you supply a width/height on element-creation, it's overwritten: pos.w = img:getWidth(), and pos.h = img:getHeight(). drawimg() function still uses pos.<dimension> and img:get<Dimension> for the offsets. For Gspot:image elements, they equal each other, so
the net offset is 0 (it adds and then subtracts itself). The only reason it does this: the `button` element can have its .img field supplied with a love.image object to add a centered image to the center of the button. That's it, it's the only object with this property.
So to add image scaling to Gspot, I changed imgdraw(), Gspot.image.load(), and Gpot.button.draw().
This is backwards compatible with old code. If you give a Gspot:image element a width and/or height, it will rescale to match. It also can take a pos.r parameter to rotate itself about its top-left anchor-point (this is exclusive to Gspot:image elements because I don't know what it would do otherwise). Here's the changes, with comments explaining the changes.
Code: Select all
Gspot.image = {
-- other code
load = function(this, Gspot, label, pos, parent, img)
local width, height = pos.w, pos.h -- cache width/height if supplied
local element = Gspot:element('image', label, pos, parent)
element:setimage(img) -- sets width and height to image width and height
if width then element.pos.w = width end -- overwrite object width
if height then element.pos.h = height end -- overwrite object height
return Gspot:add(element)
end,
-- other code
}
Gspot.util = {
-- other code
drawimg = function(this, pos, isNotScalable)
local r, g, b, a = love.graphics.getColor()
setColor(255, 255, 255, 255)
if isNotScalable == true then -- if this bool is true, it will center the image relative to its pos.w and pos.h
love.graphics.draw(this.img, (pos.x + (pos.w / 2)) - (this.img:getWidth() / 2), (pos.y + (pos.h / 2)) - (this.img:getHeight() / 2))
else -- if this bool is false, pos.w and pos.h are used to rescale the image to match the supplied dimensions
love.graphics.draw(this.img, pos.x, pos.y, pos.r, pos.w/this.img:getWidth(), pos.h/this.img:getHeight())
end
love.graphics.setColor(r, g, b, a)
end,
-- other code
}
Gspot.button = {
-- other code
draw = function(this, pos)
-- other code
if this.shape == 'circle' then
if this.img then this:drawimg(pos, true) end -- button images are not scaled to match the button's dimensions
if this.label then lgprint(this.label, (pos.x + pos.r) - (this.style.font:getWidth(this.label) / 2), (this.img and (pos.y + (pos.r * 2)) + ((this.style.unit - this.style.font:getHeight()) / 2)) or (pos.y + pos.r) - (this.style.font:getHeight() / 2)) end
else
if this.img then this:drawimg(pos, true) end -- button images are not scaled to match the button's dimensions
if this.label then lgprint(this.label, (pos.x + (pos.w / 2)) - (this.style.font:getWidth(this.label) / 2), (this.img and pos.y + ((this.style.unit - this.style.font:getHeight()) / 2)) or (pos.y + (pos.h / 2)) - (this.style.font:getHeight() / 2)) end
end
end,
-- other code
}
And if you want an image on a button that has these properties, add it as a separate Gspot:image element that is a child of the button.