Segmented control with custom image sheet does not render dividers correctly

Is anyone else having this problem? I’m rendering a custom segmented control using an image sheet and it is failing to render the dividers at the same height as the rest of the control.

This is how it currently looks:

00000007.png

As you can see, the dividers are about half the height of the control. Changing the divider values in the sheet definition or the segmented control constructor fail to have any useful effect.

Here is the image sheet: segment.png

And here is the code I’m using:

 -- Listen for segmented control events local function onSegmentPress( event ) local target = event.target print( "Segment Label is:", target.segmentLabel ) print( "Segment Number is:", target.segmentNumber ) end -- Segment button labels local segments = { "Paid", "Free", "Top" } -- Image sheet options and declaration local options = { frames = { { x=0, y=0, width=40, height=58 }, { x=40, y=0, width=40, height=58 }, { x=80, y=0, width=40, height=58 }, { x=120, y=0, width=40, height=58 }, { x=160, y=0, width=40, height=58 }, { x=200, y=0, width=40, height=58 }, { x=240, y=0, width=2, height=58 } }, sheetContentWidth = 242, sheetContentHeight = 58 } local segmentSheet = graphics.newImageSheet( "segment.png", options ) -- Create a custom segmented control local segmentedControl = widget.newSegmentedControl { left = display.actualContentWidth\*.05, top = 60, sheet = segmentSheet, leftSegmentFrame = 1, middleSegmentFrame = 2, rightSegmentFrame = 3, leftSegmentSelectedFrame = 4, middleSegmentSelectedFrame = 5, rightSegmentSelectedFrame = 6, segmentFrameWidth = 40, segmentFrameHeight = 58, dividerFrame = 7, dividerFrameWidth = 2, dividerFrameHeight = 58, labelSize = 28, segmentWidth = display.actualContentWidth\*.9/#segments, segments = segments, defaultSegment = 1, labelColor = { default = { 0, .5, .98 }, over = { .97, .97, .97 }, }, onPress = onSegmentPress } parent:insert( segmentedControl )

Hi Matt,

This may be a bug, although I’m 99% sure that it was working before at some point. Let me explore further and get back to you…

Brent

More evidence that it is a bug: If you call removeSelf() on the returned segmentedControl and then call the exact same constructor, you get the segmented control that you want. I have, of course, wrapped the code in the post above in a function, so for example:

modebar = editlib.newSegmentBar( editlayer, 22, { "Edit", "Test" }, modeBarListener ) -- #1 modebar:removeSelf() -- #2 modebar = editlib.newSegmentBar( editlayer, 22, { "Edit", "Test" }, modeBarListener ) -- #3

Statement #1 produces this:

00000008.png

Statement #2 removes it, of course.

Statement #3 produces this:

00000009.png

FYI: The first time the function is called to create the segmented control it displays this warning in the console:

WARNING: Supplied frameIndex(36) exceeds image sheet's maximum frameIndex (7). Value will be clamped.

Yet, after that it is fine.

This might help you

https://forums.coronalabs.com/topic/56613-segment-control-propeties-methods/#entry293900

It solved my situation , also certain it would meet your needs by overdrawing the image…

Hi Matt,

This may be a bug, although I’m 99% sure that it was working before at some point. Let me explore further and get back to you…

Brent

More evidence that it is a bug: If you call removeSelf() on the returned segmentedControl and then call the exact same constructor, you get the segmented control that you want. I have, of course, wrapped the code in the post above in a function, so for example:

modebar = editlib.newSegmentBar( editlayer, 22, { "Edit", "Test" }, modeBarListener ) -- #1 modebar:removeSelf() -- #2 modebar = editlib.newSegmentBar( editlayer, 22, { "Edit", "Test" }, modeBarListener ) -- #3

Statement #1 produces this:

00000008.png

Statement #2 removes it, of course.

Statement #3 produces this:

00000009.png

FYI: The first time the function is called to create the segmented control it displays this warning in the console:

WARNING: Supplied frameIndex(36) exceeds image sheet's maximum frameIndex (7). Value will be clamped.

Yet, after that it is fine.

This might help you

https://forums.coronalabs.com/topic/56613-segment-control-propeties-methods/#entry293900

It solved my situation , also certain it would meet your needs by overdrawing the image…