While coding with images at double resolution, I found that Button Widgets using an image sheet cannot set width and height in the options.
http://docs.coronalabs.com/api/library/widget/newButton.html#frame-construction
What’s strange is that every other set of options for Button ( Shape, 2-Image, 9-Slice) and Checkboxes (which use imageSheets) all allow explicit options for width and height.
My Question is: Is this something that the Corona Team can include for Image Sheet Buttons, or am I just doing something wrong?
Buttons using Image sheets can only be scaled either by editing the image file itself or using :scale(), which changes the visual appearance but not the .width and .height properties of the button, which are inaccurate after scaling an object.
Having to finick with scaling and scalar multipliers instead of just setting width and height in the options leads to annoyances as seen in the code below.
For example[lua]
– Some handlers up here
– Get the Images, note they will be double resolution and need scaling
local sheetOptions = {
width = 144/2, – 2 Buttons side by side in an image sheet
height = 80,
numFrames = 2,
sheetContentWidth = 144,
sheetContentHeight = 80,
}
local imageSheet = graphics.newImageSheet( “images/button.png”, sheetOptions )
local scalar = 0.5
firstButton = widget.newButton {
top = 0,
left = 0,
sheet = imageSheet,
defaultFrame = 1,
overFrame = 2,
onEvent = firstButtonPress,
}
– First annoyance: Would be better to use width and height
firstButton:scale(scalar, scalar) – Buttons with ImageSheet cannot be described in width/height, so scaling is needed
– Create a second button based on the position of the first button
secondButton = widget.newButton {
top = 0,
– Second Annoyance: width needs to be scaled as well
left = firstButton.x + (firstButton.width/2) * scalar, – Apply scalar to width which is already divided in half for positioning
sheet = imageSheet,
defaultFrame = 1,
overFrame = 2,
onEvent = secondButtonPress,
}
– First annoyance again
secondButton:scale(scalar,scalar) – Buttons with ImageSheet cannot be described in width/height, so scaling is needed
[/lua]
Note the two annoyances which would be solved by including width and height for Buttons with Frame Construction.
Can the Corona Team please add width and height to Button Frame Construction options, consistent with the way checkboxes can accept width and height?