joe528
December 20, 2013, 3:23am
1
Consider following code. It’s very simple: create a scrollview & put a segmented control on it:
local widget=require("widget") local function onSegmentSwitch(event) local target = event.target print( "Segment Label is:", target.segmentLabel ) print( "Segment Number is:", target.segmentNumber ) end mScrollView = widget.newScrollView { top = 0, left = 0, width = display.contentWidth, height = display.contentHeight , hideBackground = true, --listener = scrollListener, --hideScrollBar = true, } local segmentedControl = widget.newSegmentedControl { top = 100, left = 100, segments = { "1", "2", "3", "4", "5"}, segmentWidth = 40, defaultSegment = 3, onPress = onSegmentSwitch, } mScrollView:insert(segmentedControl)
And from my testing, it’s not working! When I click on the segmented control buttons, nothing happens.
If I comment out the last line,
-- mScrollView:insert(segmentedControl)
It works then. (Of course)
Am I doing anything wrong here?
P.S. I am using daily build 2108.
ksan
December 20, 2013, 3:32am
2
Tried this on my test app and can confirm same behavior. Seems like scrollView is not allowing newSegmentedControl take focus. It looks like a bug.
joe528
December 20, 2013, 3:36am
3
Thanks for the testing & confirmation, ksan.
I will file a bug report then.
joe528
December 20, 2013, 3:42am
4
Bug report case 29097.
This case (scrollView + segmented control) is quite common & fundamental. For example, a setting page. Hope Corona can fix it as soon as possible.
ksan
December 20, 2013, 3:45am
5
Great catch. Will enter it in my list as well if you don’t mind.
atanas
December 20, 2013, 4:33am
6
Yup, got bitten by that one too (outside of a scrollView). Fixed it for my use case scenario but didn’t check it in github as it needs a much wider testing.
Joe, if you are into patching widgets and in a hurry, I will send you the quick fix to get you going
Thanks
Atanas
joe528
December 20, 2013, 5:30am
7
Hi, Atanas,
I am not really needing it in a hurry, but do wish a fix within 2 weeks from Corona.
And I am also interested in how you could fix this. I would like to learn your quick fix if you don’t mind sharing it.
Thanks.
Joe
atanas
December 20, 2013, 5:40am
8
Hi Joe,
I am just eliminating all parents with a negative offset
if you look at view:touch(event), those are the lines I changed (added a math.max) :
local currentSegmentLeftEdge = segmentedControlXPosition + ( segmentWidth * currentSegment ) - segmentWidth + math.max(0,parentOffsetX)
local currentSegmentRightEdge = segmentedControlXPosition + ( segmentWidth * currentSegment ) + math.max(0,parentOffsetX);
Works for your scrollView case and for my case with a custom pageSlider widget. Wont work with displayGroups with negative offsets.
Atanas
joe528
December 20, 2013, 5:48am
9
@atanas
Sorry I don’t really understand how to use your code
You calculated two variables and then how to use them?
And how about other parameters?
atanas
December 20, 2013, 5:52am
10
I guess I missed some steps
in widget_segmentedControl.lua, around line 291 in function view:touch( event )
replace the lines
local currentSegmentLeftEdge = segmentedControlXPosition + ( segmentWidth * currentSegment ) - segmentWidth + parentOffsetX
local currentSegmentRightEdge = segmentedControlXPosition + ( segmentWidth * currentSegment ) + parentOffsetX
with
–add the math.max to take into account only positive parent offsets
local currentSegmentLeftEdge = segmentedControlXPosition + ( segmentWidth * currentSegment ) - segmentWidth + math.max(0,parentOffsetX)
local currentSegmentRightEdge = segmentedControlXPosition + ( segmentWidth * currentSegment ) + math.max(0,parentOffsetX);
Cheers,
Atanas
joe528
December 20, 2013, 6:02am
11
I didn’t know I could change the source code for widgets.
I will see if I could find how to do it.
Thanks!
ksan
December 20, 2013, 6:12am
12
Start here : http://forums.coronalabs.com/topic/34183-widgets-20-open-source/
You need to download the code from GitHub, copy it to your project directory and override the built-in version that comes with your installed Corona SDK.
joe528
December 23, 2013, 10:51am
13
Is this the one I should be looking for?
https://github.com/coronalabs/framework-widget/commits/master
but the last update was Nov, 13, 2013… It seems not the latest build?
I really hope Corona can fix this bug instead.
My setting page totally needs this fundamental fix.
atanas
December 23, 2013, 11:15am
14
Hi joe, i am pretty sure Alex is fixing this issue in the next update. If not, I uploaded a more robust fix at https://github.com/atanasster/framework-widget/blob/master/widgetLibrary/widget_segmentedControl.lua This fix now uses contentToLocal to calculate the coordinates
joe528
December 23, 2013, 12:09pm
15
@atanas
Thanks a lot for the update.
Are you branching out a new version of the widget?
atanas
December 23, 2013, 12:35pm
16
Hi Joe,
Well - its a branch, but I hope it gets eventually merged when Corona pushes a new version of the source code as I don’t really have the time to maintain a full branch of the widgets.
Additionally I am adding some new “widgets” and extending some of the current ones - right now I have uploaded a newEditField widget and a mod to tableView to allow for a sliding row where we can put delete buttons or other widgets. Have a couple more that I needed for my apps that I will upload eventually.
Thanks,
Atanas
atanas
December 23, 2013, 1:05pm
17
Also, I am not really overwriting the whole widgets library to install a patch as in the post you were redirected to.
What you can do is -
Download the file you need (for example widget_segmentedControl) for my branch and copy it into a widgets folder of your project
Download my widgetext.lua and also place it in the widgets folder.
Edit widgetext.lua to contain only the hooks for the files you need to replace from the CL widgets lib
in your case, its the segmentedControl portion :
local function newSegmentedControl( options )
local theme = _getTheme( “segmentedControl”, options )
local _segmentedControl = require( “widgets.widget_segmentedControl” )
return _segmentedControl.new( options, theme )
end
widget.newSegmentedControl = newSegmentedControl;
in your main.lua file add a require -
require(“widgets.widgetext”)
This will make you use only a custom version of segmentedControl and all the other files from the default CL widgets lib
Atanas
ksan
December 23, 2013, 7:19pm
18
Atanas’s version rocks! If you’re in a rush go get it and you’ll be all set! I confirmed that it works in your use case.
On a side note, I really like Atanas’s way of substituting modified widgets selectively through widgetext.lua. Previously, we had to do all or none using the GitHub version of the widget code. This approach is very flexible.
Last but not least, I see the cat is out of the bag on “Slide the row to get IOS style Delete button…” Just have to say that thing is amazing. Works just like IOS7.
Great work Atanas. Thank you so much for all your contribution.
joe528
December 27, 2013, 12:20pm
19
atanas:
Also, I am not really overwriting the whole widgets library to install a patch as in the post you were redirected to.
What you can do is -
Download the file you need (for example widget_segmentedControl) for my branch and copy it into a widgets folder of your project
Download my widgetext.lua and also place it in the widgets folder.
Edit widgetext.lua to contain only the hooks for the files you need to replace from the CL widgets lib
in your case, its the segmentedControl portion :
local function newSegmentedControl( options )
local theme = _getTheme( “segmentedControl”, options )
local _segmentedControl = require( “widgets.widget_segmentedControl” )
return _segmentedControl.new( options, theme )
end
widget.newSegmentedControl = newSegmentedControl;
in your main.lua file add a require -
require(“widgets.widgetext”)
This will make you use only a custom version of segmentedControl and all the other files from the default CL widgets lib
Atanas
Thanks a lot. I am using this method to fix the segmented control problem for now.
By the way, I have been seeing “changing order” feature by dragging an item up or down in some apps. Do we have this kind of feature somewhere in the widget as well?
ksan
December 20, 2013, 3:32am
20
Tried this on my test app and can confirm same behavior. Seems like scrollView is not allowing newSegmentedControl take focus. It looks like a bug.