We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Is there a way of getting the individual id of scrollable list in controlP5 while hovering? In the sketch below you get the id by clicking. Possible to get it by hovering?
import controlP5.*;
import java.util.*;
//String info;
ControlP5 cp5;
void setup() {
size(400, 400);
cp5 = new ControlP5(this);
List l = Arrays.asList("a", "b", "c", "d", "e", "f", "g", "h");
cp5.addScrollableList("dropdown")
.setPosition(100, 100)
.setSize(200, 100)
.setBarHeight(20)
.setItemHeight(20)
.addItems(l)
.setType(ScrollableList.LIST) // currently supported DROPDOWN and LIST
.onMove(new CallbackListener() {
public void controlEvent(CallbackEvent theEvent) {
float value = theEvent.getController().getValue();
println("the value is " + value);
}
}
);
}
void draw() {
background(240);
// HOVER
boolean over = cp5.get(ScrollableList.class, "dropdown").isMouseOver();
// println("OVER " + over);
}
void dropdown(int n) {
println("id:" + n);
}
Answers
bump
not possible to get the value im rolling over somehow by Callbacklistener like this or am i on the wrong path:
@sojamo ?
Look in the... documentation maybe??
yes I have but cannot figure it out. I done it with buttons through a stringlist though but cannot manage rollover with a ScrollableList
i googled for this quite a bit, but couldn't find any solutions to this. is there someone who managed..?
I looked up the source code for this (libraries/controlP5/src/controlP5/ScrollableList.java), and saw that "itemHover", the variable storing the required info, is declared protected. Because of this, subclassing lets us access the value. A quick and dirty, working solution exposes said variable:
Hope this helps!