G4P Droplist scroll bar

Hi Peter, simple question - if I’m using the mousewheel event to change the droplist items, I notice the vertical scrollbar stays put. The scrollbar only moves if I click the down or up arrows.

Also, I cannot drag the scroll box (or “indicator” since it’s not a box).

Is there any way to implement the mouse wheel moving not only the selection, which I’ve got working, but also the scroll bar? And also to be able to drag the scrollbar?

I’ve got a list of 64 items, so using the mouse wheel is really helpful, but it’s confusing since the scroll box does not move unless you click the arrows, and you cannot drag the scroll box.

Thanks for any insights. I think I already know the answer :slight_smile:

The sketch below has a single droplist control with 64 items.

I can scroll the list by

  1. using the scroll button (if the mouse is over the scrollbar)
  2. clicking on the top and bottom scrollbar buttons
  3. dragging the scrollbar thumb (provided the mouse stays over the thumb)

When scrolling using (1) & (2) the thumb moves as expected, at least it did for me :grin:

import g4p_controls.*;

GDropList dropList1;

public void setup() {
  size(480, 320);
  G4P.setDisplayFont("Arial", G4P.PLAIN, 14);
  surface.setTitle("Sketch Window");
  String[] items = new String[64];
  for (int i = 0; i < items.length; i++) {
    items[i] = "Option " + (i+1);
  }
  dropList1 = new GDropList(this, 80, 40, 120, 180, 8, 10);
  dropList1.setItems(items, 0);
}

public void draw() {
  background(230);
}

Not sure what you have got working but if you are trying to change the droplist functionality that might explain why things are not working as expected.

2 Likes

Thank you Peter.

Yes it is “working” as in I can select items and use the mouse wheel to scroll up and down in my sketch. But it does not move the scrollbar thumb with the mouse wheel.

Try this:

int itemSelected = 0;
public void setup() {
  size(480, 320);
  G4P.setDisplayFont("Arial", G4P.PLAIN, 14);
  surface.setTitle("Sketch Window");
  String[] items = new String[64];
  for (int i = 0; i < items.length; i++) {
    items[i] = "Option " + (i+1);
  }
  dropList1 = new GDropList(this, 80, 40, 120, 180, 8, 10);
  dropList1.setItems(items, 0);
}

public void draw() {
  background(230);
}

void mouseWheel(MouseEvent event) {
  float e = event.getCount();  
  if (dropList1.hasFocus()){
    itemSelected += e;
    if (itemSelected > 63) itemSelected = 63;
    if (itemSelected < 0) itemSelected = 0;
    dropList1.setSelected(itemSelected);
  }
}

If you use the mouse wheel (or in my case I’m on a Mac so two-finger scroll up/down on the trackpad), the list scrolls up or down nicely. However, the scrollbar thumb stays stationary.

Is there any way to get the scrollbar thumb to move when the mouse wheel is used?

Also, is there any way to get the scrollbar thumb to move when the mouse is not directly on top of it? If I try dragging up or down, sometimes the mouse isn’t directly over it and the motion stops. Somehow, if the mouse is still in the PRESSED position it would be nice if the scrollbar thumb would still move when the mouse is moved.

Wishes like fishes.

Thanks,

Mike

Also, another small niggle - the scrollbar thumb is not large enough to use when the font is made bigger. I have the font at 24 and showing 3 rows, but the scrollbar thumb is just a line. I have to go up to showing 5-6 rows on the droplist before the scrollbar thumb is big enough to drag…

Showing 3 rows with 24 point font. Scrollbar thumb cannot be dragged with mouse:
Screenshot 2024-05-29 at 6.50.00 AM

Scrollbar thumb is too small to use like this. If I show 6 rows, then the droplist is at the bottom of the app window and droplist menu goes off the screen and is inaccessible for end values.

Sorry to keep asking you this kind of stuff. Thanks for your patience.

Mike

Your mouseWheel function is trying to add new functionality i.e. changing the selected item using the mouse wheel and it is in conflict with the way G4P implements droplists. This functionality is not part of the expected behaviour for a droplist control so I won’t be taking action on that.

Yes I noticed that and it affects usability so definitely something for me to look at. Perhaps you would add a ticket to Sourceforge although I am not sure when I will get to do something about it. :grin:

1 Like

I appreciate it.

But with long lists, it’s so much easier to use the mousewheel. Might you consider this for a future update? :innocent:

Thanks for your amazing support!! I will put a source forge ticket for the scroll bar thumb, and maybe another feature request you can ignore :grimacing:

Thanks again kind sir! :smiling_face_with_three_hearts:

Hi again Peter, sorry to add to the list, but I’ve noticed that list items are skipped when using the up/down arrows, if the thumb control is too small to use.

See this video:

Thanks,

Mike

EDIT: changed to better example, using more droplist items causes more skips.

Here’s a replicable example. Numbers are skipped when clicking the up/down arrows.

It seems the more items in the droplist, the more things skip…

// Need G4P library
import g4p_controls.*;
// You can remove the PeasyCam import if you are not using
// the GViewPeasyCam control or the PeasyCam library.
import peasy.*;
import java.awt.Font; 


public void setup(){
  size(480, 320, JAVA2D);
  createGUI();
  customGUI();
  // Place your setup code here
  
  dropList1.setFont(new Font("Noto Sans Bold", G4P.PLAIN, 24));
  String[] dropListItems = new String[64];
  for (int i = 0; i < 64; i++) {
    dropListItems[i] = "Custom " + str(i);
  }
  dropList1.setItems(dropListItems, 7);
}

public void draw(){
  background(230);
  
}

// Use this method to add additional statements
// to customise the GUI controls
public void customGUI(){

}

/* =========================================================
 * ====                   WARNING                        ===
 * =========================================================
 * The code in this tab has been generated from the GUI form
 * designer and care should be taken when editing this file.
 * Only add/edit code inside the event handlers i.e. only
 * use lines between the matching comment tags. e.g.

 void myBtnEvents(GButton button) { //_CODE_:button1:12356:
     // It is safe to enter your event code here  
 } //_CODE_:button1:12356:
 
 * Do not rename this tab!
 * =========================================================
 */

public void dropList1_click1(GDropList source, GEvent event) { //_CODE_:dropList1:874648:
  println("dropList1 - GDropList >> GEvent." + event + " @ " + millis());
} //_CODE_:dropList1:874648:



// Create all the GUI controls. 
// autogenerated do not edit
public void createGUI(){
  G4P.messagesEnabled(false);
  G4P.setGlobalColorScheme(GCScheme.BLUE_SCHEME);
  G4P.setMouseOverEnabled(false);
  surface.setTitle("Sketch Window");
  dropList1 = new GDropList(this, 100, 100, 164, 132, 4, 10);
  dropList1.setItems(loadStrings("list_874648"), 0);
  dropList1.addEventHandler(this, "dropList1_click1");
}

// Variable declarations 
// autogenerated do not edit
GDropList dropList1;

Thanks for the working example it does make it easier for me to do some testing etc.

You have raised two issues on Sourceforge that are both related to droplist controls, in particular their scrollbars

  1. With large lists the scrollbar thumb becomes very small and difficult to drag (ticket 53)
  2. When clicking on the scrollbar buttons the list view movement skips over some of the list items, as show in your last post (ticket 56)

In the 15 years since G4P was first released these have never been reported as an issue before. :crazy_face:

So lets get started -

  • The thumb size is calculated from the ratio of the number of visible items to the total number of items in the list. So if the list contains 20 items and we can see 5 when the list is open then the thumb size is 20/5 or 0.25 * the scrollbar track length. If only 4 from 64 items are visible then it would be 0.0625 * the scrollbar track length :cry:
  • When one of the scrollbar buttons is clicked the list view moves up or down. The amount of movement (number of items skipped) is determined by the number of items in the list. If there are n items in the list then the view is shifted by floor(0.1*n) items. So in your list of 64 items the view is shifted by 6 items but since the list view is only 4 high a couple are skipped. :cry:

Do you see the pattern - both problems are caused by a combination of two factors

  • large number of items in the list
  • small number of items visible in the drop list

Obviously in the last 15 years no one has created a droplist where the number of visible items has been >10% of the total number of items. It was not a situation I anticipated when I created G4P. :innocent:

I should be able to correct both issues in the next release. :grinning: :+1:

3 Likes

As I’ve become a fledgling developer myself, I have come to realize there is no such thing as a “bug” - only the difference between what you want and what happens.

Of course this hasn’t come up; I’m doing things no one else has done :slight_smile:

I appreciate your willingness to modify the library to fix these “bugs”. But the library is fantastic so as I say, the word “bug” is subjective.

Thank you so much Peter :pray::heart_eyes::two_hearts:

Don’t say that to the sub-postmasters LOL :crazy_face:

Most errors fit one of 3 categories
1 Syntax errors
the source code dose not compile.

2. Runtime errors
the source code compiles but but the program suffers from undetected / unrecoverable errors that stop execution

3. Logic errors
the source code compiles, the program executes but the output is not as expected based on the inputs.

In terms of fixing them they go from
EASIEST 1 - 2 - 3 HARDEST

3 Likes

100%.

I’m finding sometimes the hardest aspect of developing this app is figuring out HOW it should work. The programming isn’t as hard as functionality.

Sometimes I’m stuck for days in the “pondering” phase.

But yeah, overt errors are way easier to spot and fix than the subtle functionality ones.

Oh, and then of course the famous intermittent bug. I’ve got a few of those and unless I catch that little gremlin in the act, it’s hard to fix!

Both of these issues are now resolved and will be available in the next release.

1 Like

Fantastic!! Thank you so much!!! That is such great news!

Any idea when it will be released? Or if I can get my hands on an early copy :slight_smile:

Thank you!

Mike