problem with cp5 range object and frame.setResizable()

edited April 2018 in Library Questions

Hi My problem is change dinamically a range object from controlP5 library when the frame is resized by the user. It's ok, the setSize() works fine, but the handler does not update, so, I must change the values of the handle with the function: range.setRangeValues(range.getArrayValue(0),range.getArrayValue(1)) to put the handle in the correct position after the frame is resized. This works saving the values of the previous frame(before resize) and put them into the range object after the frame is resized. Apparently this would be work, but the function range.getArrayValue(n) return a value near the value of the previous frame when I call setSize() and the frame is resized.

Any idea to how solve this problem?, thanks!

The next code is an example, change the width of the screen to see how change slightly the values of the handle.

import controlP5.*; ControlP5 cp5; int myColorBackground = color(0, 0, 0); int colorMin = 100; int colorMax = 100; Range range; void setup() { frame.setResizable(true); size(700, 400); cp5 = new ControlP5(this); range = cp5.addRange("rangeController") // disable broadcasting since setRange and setRangeValues will trigger an event .setBroadcast(false) .setPosition(0, 0) .setSize(400, 40) .setHandleSize(20) .setRange(0, 255) .setRangeValues(50, 100) // after the initialization we turn broadcast back on again .setBroadcast(true) .setColorForeground(color(255, 40)) .setColorBackground(color(255, 40)) ; noStroke(); } void draw() { range.setSize(width, 30); range.setRangeValues(range.getArrayValue(0), range.getArrayValue(1)); background(colorMax); fill(colorMin); rect(0, 0, width, height/2); text(range.getArrayValue(0), 300, 300); }

Sign In or Register to comment.