Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Quick Fix for Lower Value not set when Min Range is specified first... #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Air-Craft
Copy link

In the setters, lowerValue depends on upperValue when minRange is set. If upperValue is still 0 then this causes lowerValue to not be set.

This commit is a quick fix (hack) that just calls setLowerValue a second time in the setLowerValue:upperValue method. It still doesn't solve the problem of the client using the properties to initialise the lower and upper values.

A better fix might be to have lower/upperValue initialise to -/+FLT_MAX or have lower value only adjust for minRange if (upperValue != some-pre-decided-init)...it's probably worth a bit more thought...

Thx for the component. I've given it 5 stars on CocoaControls :)

…ue when minRange is set and upperValue hasn't been
@muZZkat
Copy link
Owner

muZZkat commented Sep 29, 2013

Sorry its been so long. The upper value is never 0, its initialised to 1.0, equal to the controls initial max value. Setting the upper value to FLT_MAX doesn't really make sense. Im not 100% sure how to replicate you issue, if you can give me more detail I can have a look.

Thanks

@1ex
Copy link

1ex commented Dec 2, 2013

Hi! I've got the same issue. Here is the way how to replicate it, change minimumValue and lowerValue in configureLabelSlider method from NMDemoTVC.m:

- (void) configureLabelSlider
{
    self.labelSlider.minimumValue = 20; // !!!!! Changed from 0 to 20
    self.labelSlider.maximumValue = 100;

    self.labelSlider.lowerValue = 50; // !!!!! Changed from 0 to 50
    self.labelSlider.upperValue = 100;

    self.labelSlider.minimumRange = 10;
}

after that you see a bug in label slider:

  1. The lowerValue is set with 1, but it must be 50
  2. left handle has half vision (if you set minimumValue at 30, left handle will be out of vision)

The solution with setting FLT_MAX in default upperValue fixes the bug:

- (void) configureView
{
// ...
// _upperValue = 1.0;
_upperValue = FLT_MAX;
// ...
}

@ericrisler
Copy link

If you set the upperValue before setting the lowerValue then you don't have an issue. Probably by design, not really a bug...but...perhaps the slider default behaviour should be to move the upperValue along with the desired lowerValue if the upper < lower you are trying to set. A matter of opinion I think. However, if the slider allows crossover, then the lower should move past the upper and pin to the maximum if it exceeds.

@vincentjames501
Copy link

I haven't looked into this at all, but if you do this:

    slider.upperValue = [SettingsStore instance].maxAcceptableRange;
    slider.lowerValue = [SettingsStore instance].minAcceptableRange;

Everything is fine. If you do it in reverse:

    slider.lowerValue = [SettingsStore instance].minAcceptableRange;
    slider.upperValue = [SettingsStore instance].maxAcceptableRange;

Lower value gets drawn as 1 on the slider. Here's my code demonstrating the problem (just swap the two lines to see the issue):

NMRangeSlider *slider = [[NMRangeSlider alloc] initWithFrame:CGRectMake(60, 110, 200, 30)];
    slider.minimumRange = 30;
    slider.minimumValue = 0;
    slider.maximumValue = 240;
    slider.stepValue = 1;
    slider.continuous = YES;
    [slider bk_addEventHandler:^(id sender) {
        self.minLabel.text = [NSString stringWithFormat:@"%i", (int) slider.lowerValue];
        self.maxLabel.text = [NSString stringWithFormat:@"%i", (int) slider.upperValue];
    }         forControlEvents:UIControlEventValueChanged];
    slider.upperValue = [SettingsStore instance].maxAcceptableRange;
    slider.lowerValue = [SettingsStore instance].minAcceptableRange;
    [self.view addSubview:slider];

@kunni80
Copy link

kunni80 commented Mar 27, 2014

@1ex Is right here - setting _upperValue = FLT_MAX; solves the issue

@lavaxun
Copy link

lavaxun commented Aug 11, 2014

setting the lowerValue before upperValue cause problem.
as you can see from the attached, I'm using the demo file and i change both minimumValue & lowerValue to 10.
the problem comes from the file NMRangeSlider.m in line #138

-(void) setLowerValue:(float)lowerValue
{
    // ...
    value = MIN(value, _upperValue - _minimumRange); // line #138
    // ... 
}

using @1ex solution does help to solve the issue here.

screen shot 2014-08-11 at 10 17 30 am

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants