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

Create API for limiting sliders to ranges within their set bounds #85

Open
stackotter opened this issue Apr 9, 2024 · 0 comments
Open
Labels
API enhancement New feature or request good first issue Good for newcomers

Comments

@stackotter
Copy link
Owner

RandomNumberGeneratorExample has a minimum slider and a maximum slider which are both from 0 to 100. In addition to their hard bounds (which don't change), there's an extra constraint that the minimum slider can't have a value greater than the maximum slider, and another that thte maximum slider can't have a value lower than the minimum slider.

Here's how this is achieved (for the minimum slider) with the current API,

Slider(
    state.$minNum.onChange { newValue in
        if newValue > state.maxNum {
            state.minNum = state.maxNum
        }
    },
    minimum: 0,
    maximum: 100
)

And here's how I could imagine it working with a declarative-style API,

Slider(state.$minNum, minimum: 0, maximum: 100)
    .limited(to: state.minNum...)

I'd love to hear alternative solutions if anyone has ideas!

This API would have overloads for ClosedRange, PartialRangeFrom, and PartialRangeThrough.

@stackotter stackotter added enhancement New feature or request good first issue Good for newcomers API labels Apr 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

1 participant