Skip to content

Enhancement Request: Clamp User Entered Values  #4792

Open

Description

Enhancement Request: Clamp User Entered Values

I would like to be able to clamp the values a user enters in the text input of a parameter field to specific values (for example the min, max values of the block).

Current Behavior:

If you look at the "leds -> more -> setBrightness" block in https://makecode.microbit.org/, you will see that if you click on the parameter and drag the slider, the block's min value is set to 0 and the max value is set to be 255. However, if you click on the parameter and type in 1000 and hit 'enter', the block accepts the value.

Requested Behavior:

When a user types in a value into a block that has a specified min/max, can you please clamp the value so it shows only numbers within range of the block?

Examples:

  1. Block min = 0, Block Max = 255
  • If the User enters 1000, expected: Block clamps to '255"
  • If the User enters -25, expected: Block clamps to '0"
  1. Block min = -100, Block Max = 0
  • If the User enters -200, expected: Block clamps to '-100"
  • If the User enters 5, expected: Block clamps to '0"

Additional Clamping Behavior Requests:

I'd also like to request parameters to allow Blocks to specify intervals to clamp to such as only whole numbers, or 5 unit increments. Clamping to a custom interval other than just whole numbers might need additional parameters/work and I can open another feature request for that if necessary.

Examples:

  1. If we have a block that should only accept whole numbers (-1,0,1,2,3 ect), the block should round and clamp the GUI to the nearest whole number
  • If the user enters 1.5, the block clamps to 2
  • If the user enters 1.4, the block clamps to 1
  • If the user enters - .8, the block clamps to -1
  1. If our block should only accept certain intervals of whole numbers (for example, we can only turn 45, 30, or 15 degrees because we have a 15 degree interval limit) then the block should clamp to the nearest 15 degree interval.
  • If the user enters 5, the block clamps to 0
  • If the user enters 10, the block clamps to 15
  • If the user enters 25, the block clamps to 30
  • If the user enters 50, the block clamps to 45
  • If the user enters 22.5, the block clamps to 30
  1. If the block has a slider for the parameter, the slider should also clamp to the intervals specified above

Nice to Have:

Allow the parameter's text input min-max and step clamping settings to be different from the slider min-max or clamp settings.

Examples:

  1. User input field allows finer control over degrees than the slider:
  • Slider has min = 0 max = 45, and snaps to every 15 degrees (ie the user can select 0, 15, 30, 45 easily but not 20)
  • Text input has min = 0, max = 45 and clamps to every whole number. When the user enters '20' into the text input, the input takes it and adjusts the slider to the appropriate spot. However if the user moves the slider, it will then snap to the nearest 'clamped' value (in this case 15).
  1. User input field allows for a wider range than the slider. This would be for cases such as 'driving distance' where most people would only drive a robot a short distance, but in some edge cases a user may want to drive further. For example:
  • Drive Distance Slider has min =1 cm, max = 100 cm (~3ft)
  • Drive Distance Input Field min = 1cm, max = 300 cm (~10ft) allows the user to input larger driving distances than the slider. The slider would update to show that it's at its 'max' value, but the drive distance would be 300. However, if the user adjusts the slider, it would re-clamp to the slider's max of 100cm.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions