spacenation / swiftui-sliders

:rocket: SwiftUI Sliders with custom styles
MIT License
805 stars 85 forks source link

Minimum selectable range #8

Closed ay42 closed 3 years ago

ay42 commented 4 years ago

As mentioned in #6 RangeSliders should have a minimum selectable range option.

fracturedsoftware commented 4 years ago

I am using your sliders package for some sliders in my app, but I am having trouble figuring out how to make a small configuration change to the slider. The slider I am using is just the basic horizontal slider. The default slider has a range of 0.0...1.0 but I really need to alter the range slightly to avoid a divide by 0 error. My understanding is that this is easily done but I can quite figure out how.

I have:

HSlider(value: self.$model.currentScale,  configuration: .init( thumbSize: CGSize(width: 8, height: 8))

And my understanding is that I can add a ClosedRange as part of the init(). I tried to make a ClosedRange:

var range: ClosedRange = 0.0...1.0

But can't figure out how to add it. The errors I get are completely unhelpful showing errors after and before that have nothing to do with the problem. Thanks!

ay42 commented 4 years ago

@fracturedsoftware

HSlider(
    value: self.$model.currentScale,
    in: .leastNonzeroMagnitude...1.0,  
    configuration: .init( thumbSize: CGSize(width: 8, height: 8)
)

This should work. Your currentScale type should be the same as in range's types. Let me know if it works for you.

fracturedsoftware commented 4 years ago

Hi Alex,

Thank you for your quick reply. I can see now how it works, but I am still getting problems. I am sure it is really minor but Swift seems to be really strict with everything ( which is good ). Assuming my self.$model.currentScale is a CGFloat, how would I write the range? Alternatively I tried a local @State variable for the currentScale and Double or Float types caused the same errors. Of course at the moment the errors in SwiftUI are really unhelpful..

I usually find if I manage to get a working example I can ‘work backwards’ and solve the problem.

Thanks again for your quick help and kind regards,

Peter

On 22 Mar 2020, at 10:10 am, Alex Young notifications@github.com wrote:

@fracturedsoftware https://github.com/fracturedsoftware HSlider( value: self.$model.currentScale, in: .leastNonzeroMagnitude...1.0,
configuration: .init( thumbSize: CGSize(width: 8, height: 8) ) This should work. Your currentScale type should be the same as in range's types. Let me know if it works for you.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/spacenation/swiftui-sliders/issues/8#issuecomment-602117356, or unsubscribe https://github.com/notifications/unsubscribe-auth/AIM5O6U4GUMLBHNSTP5TD5DRIVCMXANCNFSM4LGFXUSA.

Sent via Migadu.com, world's easiest email hosting

fracturedsoftware commented 4 years ago

Hi Again,

Problem solved I think. SwiftUI errors threw me off. Everything is fine.

Thanks again,

Peter

On 22 Mar 2020, at 10:36 am, Peter peter@fracturedsoftware.com wrote:

Hi Alex,

Thank you for your quick reply. I can see now how it works, but I am still getting problems. I am sure it is really minor but Swift seems to be really strict with everything ( which is good ). Assuming my self.$model.currentScale is a CGFloat, how would I write the range? Alternatively I tried a local @State variable for the currentScale and Double or Float types caused the same errors. Of course at the moment the errors in SwiftUI are really unhelpful..

I usually find if I manage to get a working example I can ‘work backwards’ and solve the problem.

Thanks again for your quick help and kind regards,

Peter

On 22 Mar 2020, at 10:10 am, Alex Young <notifications@github.com mailto:notifications@github.com> wrote:

@fracturedsoftware https://github.com/fracturedsoftware HSlider( value: self.$model.currentScale, in: .leastNonzeroMagnitude...1.0,
configuration: .init( thumbSize: CGSize(width: 8, height: 8) ) This should work. Your currentScale type should be the same as in range's types. Let me know if it works for you.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/spacenation/swiftui-sliders/issues/8#issuecomment-602117356, or unsubscribe https://github.com/notifications/unsubscribe-auth/AIM5O6U4GUMLBHNSTP5TD5DRIVCMXANCNFSM4LGFXUSA.

Sent via Migadu.com, world's easiest email hosting