Field Slider - min = "string"

38 views
Skip to first unread message

Jonty Small

unread,
Jun 6, 2022, 11:52:35 AM6/6/22
to Blockly
Hi All,

We've come into a bit of a challenge.
We want to represent time in a block.
X seconds ago, minutes etc.
But we want to avoid 0 seconds ago as its not natural. We also have an upper limit for how far our data can go back.
As such the Field Slider felt like a perfect solution.

What we'd like to do is have a Field Slider set up as such:
.appendField(new FieldSlider(0,30,60,1), "FIELDNAME")

Where it can go from 0-60 in increments of 1 and initialised at 30.

But We'd like to have it show "live" when the slider is dragged to 0.

But as it extends field_number I'm a bit at a loss at how to modify it in order to get this kind of functionality without breaking a lot of things!

I was thinking one option would be to have it extend field_dropdown. And then build the options as a massive array that's ordered. But I'm not sure where to begin with that.

Any guidance would be greatly appreciated!

Also, as a share to say thank you for reading this far, in trying alternative solutions i realised you can redefine:
this.setInputsInline(!0);
inside a mutator, so that if your block gets too long/short it changes from inline to external.


Best,
Jonty

Neil Fraser

unread,
Jun 7, 2022, 12:15:49 PM6/7/22
to blo...@googlegroups.com
Am Mo., 6. Juni 2022 um 17:52 Uhr schrieb Jonty Small <smal...@gmail.com>:
What we'd like to do is have a Field Slider set up as such:
.appendField(new FieldSlider(0,30,60,1), "FIELDNAME")

Where it can go from 0-60 in increments of 1 and initialised at 30.

But We'd like to have it show "live" when the slider is dragged to 0.

I think you might be able to just add a getDisplayText function to your subclass of FieldSlider like this:

getDisplayText() {
  let text = super.getDisplayText();
  if (text == '0') {
    text = 'live'
  }
  return text;
}

--
Reply all
Reply to author
Forward
0 new messages