A Fuse Powered Company

Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

Is this a bug (widget.scrollView + widget.newSegmentedControl) ? It's not working!
Started by joe528 Dec 19 2013 07:23 PM

25 replies to this topic
[TOPIC CONTROLS]
Page 1 of 2 1 2
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

joe528

[GLOBAL: userInfoPane.html]
joe528
  • Pro
  • PipPipPipPipPipPip
  • 698 posts
  • Jedi

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.



[TOPIC: post.html]
#2

ksan

[GLOBAL: userInfoPane.html]
ksan
  • Pro
  • PipPipPipPipPipPip
  • 2,780 posts
  • Jedi

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. 



[TOPIC: post.html]
#3

joe528

[GLOBAL: userInfoPane.html]
joe528
  • Pro
  • PipPipPipPipPipPip
  • 698 posts
  • Jedi

Thanks for the testing & confirmation, ksan.

 

I will file a bug report then.



[TOPIC: post.html]
#4

joe528

[GLOBAL: userInfoPane.html]
joe528
  • Pro
  • PipPipPipPipPipPip
  • 698 posts
  • Jedi

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.



[TOPIC: post.html]
#5

ksan

[GLOBAL: userInfoPane.html]
ksan
  • Pro
  • PipPipPipPipPipPip
  • 2,780 posts
  • Jedi

Great catch. Will enter it in my list as well if you don't mind.



[TOPIC: post.html]
#6

atanas

[GLOBAL: userInfoPane.html]
atanas
  • Pro
  • PipPipPipPipPipPip
  • 225 posts
  • Jedi

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



[TOPIC: post.html]
#7

joe528

[GLOBAL: userInfoPane.html]
joe528
  • Pro
  • PipPipPipPipPipPip
  • 698 posts
  • Jedi

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



[TOPIC: post.html]
#8

atanas

[GLOBAL: userInfoPane.html]
atanas
  • Pro
  • PipPipPipPipPipPip
  • 225 posts
  • Jedi

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



[TOPIC: post.html]
#9

joe528

[GLOBAL: userInfoPane.html]
joe528
  • Pro
  • PipPipPipPipPipPip
  • 698 posts
  • Jedi

@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?



[TOPIC: post.html]
#10

atanas

[GLOBAL: userInfoPane.html]
atanas
  • Pro
  • PipPipPipPipPipPip
  • 225 posts
  • Jedi

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


[TOPIC: post.html]
#11

joe528

[GLOBAL: userInfoPane.html]
joe528
  • Pro
  • PipPipPipPipPipPip
  • 698 posts
  • Jedi

I didn't know I could change the source code for widgets.

 

I will see if I could find how to do it.

 

Thanks!



[TOPIC: post.html]
#12

ksan

[GLOBAL: userInfoPane.html]
ksan
  • Pro
  • PipPipPipPipPipPip
  • 2,780 posts
  • Jedi

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.



[TOPIC: post.html]
#13

joe528

[GLOBAL: userInfoPane.html]
joe528
  • Pro
  • PipPipPipPipPipPip
  • 698 posts
  • Jedi

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.



[TOPIC: post.html]
#14

atanas

[GLOBAL: userInfoPane.html]
atanas
  • Pro
  • PipPipPipPipPipPip
  • 225 posts
  • Jedi

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

[TOPIC: post.html]
#15

joe528

[GLOBAL: userInfoPane.html]
joe528
  • Pro
  • PipPipPipPipPipPip
  • 698 posts
  • Jedi

@atanas

 

Thanks a lot for the update.

 

Are you branching out a new version of the widget?



[TOPIC: post.html]
#16

atanas

[GLOBAL: userInfoPane.html]
atanas
  • Pro
  • PipPipPipPipPipPip
  • 225 posts
  • Jedi

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



[TOPIC: post.html]
#17

atanas

[GLOBAL: userInfoPane.html]
atanas
  • Pro
  • PipPipPipPipPipPip
  • 225 posts
  • Jedi

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 -

 

1. Download the file you need (for example widget_segmentedControl) for my branch and copy it into a widgets folder of your project

2. Download my widgetext.lua and also place it in the widgets folder.

3. 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;
4. 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


[TOPIC: post.html]
#18

ksan

[GLOBAL: userInfoPane.html]
ksan
  • Pro
  • PipPipPipPipPipPip
  • 2,780 posts
  • Jedi

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. 



[TOPIC: post.html]
#19

joe528

[GLOBAL: userInfoPane.html]
joe528
  • Pro
  • PipPipPipPipPipPip
  • 698 posts
  • Jedi

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 -

 

1. Download the file you need (for example widget_segmentedControl) for my branch and copy it into a widgets folder of your project

2. Download my widgetext.lua and also place it in the widgets folder.

3. 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;
4. 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?



[TOPIC: post.html]
#20

joe528

[GLOBAL: userInfoPane.html]
joe528
  • Pro
  • PipPipPipPipPipPip
  • 698 posts
  • Jedi

The latest daily build 2014.2059 still not fixing this bug.

 

Looks like not many users try to put segmented controls inside a scrollView!



[TOPIC: post.html]
#21

atanas

[GLOBAL: userInfoPane.html]
atanas
  • Pro
  • PipPipPipPipPipPip
  • 225 posts
  • Jedi

Thanks for confirming Joe. Its a little frustrating as CL have gotten the fix for quite some time already and I have double work to re-apply the fix when they release a new version of the widgets in github



[TOPIC: post.html]
#22

ksan

[GLOBAL: userInfoPane.html]
ksan
  • Pro
  • PipPipPipPipPipPip
  • 2,780 posts
  • Jedi

I just don't understand why they are not capitalizing on your good work. All it takes is to accept the pull request and test the fix.



[TOPIC: post.html]
#23

atanas

[GLOBAL: userInfoPane.html]
atanas
  • Pro
  • PipPipPipPipPipPip
  • 225 posts
  • Jedi

It seems they can't accept a pull request as I have more files in there than in the widgets library. 

 

However, they could and should fix the bugs any which way they can - finding their own fix, or manually apply my updates instead of frustrating everybody. 



[TOPIC: post.html]
#24

ksan

[GLOBAL: userInfoPane.html]
ksan
  • Pro
  • PipPipPipPipPipPip
  • 2,780 posts
  • Jedi

Exactly! How hard it is to do a one time copy/paste. Think about all the additional good will they would generate if everyone suddenly had all your fixes & improvements. Oh well, meanwhile we can't even figure out what was included in todays update. Serenity now...



[TOPIC: post.html]
#25

joe528

[GLOBAL: userInfoPane.html]
joe528
  • Pro
  • PipPipPipPipPipPip
  • 698 posts
  • Jedi

Build 2282 fixes a lot of widget bugs, but this one is not fixed




[topic_controls]
Page 1 of 2 1 2
 
[/topic_controls]