Modify text alignment of a ScrollableList in ControlP5 library

I am trying to create a menu type list in my program, which when clicked reveals a drop down list of different screens to show next. This is how it looks at the moment:

image

I have changed the font but can’t get to center the text in both the “MENU” bar and the other items in the list. Is there a way to do this that I am missing? I’ve been scrolling through the javadocs of the library but can’t seem to find it.

Thank you!

PS: Happy quarantine everyone. Stay safe.

1 Like

@NaniAromix – Were you able to resolve this issue?

No, I still haven’t figured it out…

Can you provide a minimal example of your code that exhibits the problem?

Sure. This is the part of the code dedicated to the menu:

PFont pfont = createFont("Helvetica", 20, true);
ControlFont f = new ControlFont(pfont, 20);

cp5 = new ControlP5(this);
List windowList = Arrays.asList ("ALARMAS", "MOTORES", "LUCES Y AC", "PC PLOTTER", "MEDIA", "CAMARAS",);

...

 cp5.addScrollableList("MENU")
    .setPosition(1280-200, 0)
    .setSize(200, 400)
    .setBarHeight(50)
    .setItemHeight(30)
    .addItems(windowList)
    .setType(ScrollableList.DROPDOWN) // currently supported DROPDOWN and LIST
    .setFont(f)
    ;

My issue is that I can’t find a method that changes the alignment inside of the boxes of the scrollable list.

As a sidenote, is there any way to hace the dropdown list disappear when clicking outside of the actual list? As a way to hide it without having to click an actual item in the list. Also, is there a way to distinguish from the items and the top bar? My idea is to have the text in them in different sizes, so the top bar has a bigger size font than the items in the list.

Thank you!

Hi Nani – any chance you could make that a minimal sketch? This broken snippet requires substantial work for someone to help you test / investigate – they need to add the java.util imports, move createFont to setup, guess the size of your screen (!!) etc. An MCVE would really help people help you.

I don’t know of a magic setting that isn’t in the CP5 docs – but if it isn’t there, there might be workarounds.

Of course. Thanks for the heads up, I’ll keep that in mind from now on. Here it is:

import controlP5.*;
import java.util.*;

ControlP5 cp5;

void setup() {
   size(1280, 1024);
   
  PFont pfont = createFont("Arial Bold", 20, true);
  ControlFont f = new ControlFont(pfont, 20);

  cp5 = new ControlP5(this);
  List windowList = Arrays.asList("WINDOW1", "WINDOW2", "WINDOW3");

  cp5.addScrollableList("MENU")
    .setPosition(1280-200, 0)
    .setSize(200, 400)
    .setBarHeight(50)
    .setItemHeight(30)
    .addItems(windowList)
    .setType(ScrollableList.DROPDOWN) // currently supported DROPDOWN and LIST
    .setFont(f)
    ;
}

void draw() {
  background(150);
}
1 Like