# G4P custom sliders

**URL:** https://discourse.processing.org/t/g4p-custom-sliders/22223
**Category:** Libraries
**Created:** [June 28, 2020, 5:45pm UTC](https://discourse.processing.org/t/g4p-custom-sliders/22223 "2020-06-28T17:45:40Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![mike\_z](https://avatars.discourse-cdn.com/v4/letter/m/9d8465/32.png) [@mike\_z](https://discourse.processing.org/u/mike_z)
#### Post date: [June 28, 2020, 5:45pm UTC](https://discourse.processing.org/t/g4p-custom-sliders/22223/1 "2020-06-28T17:45:40Z")

</div>

I have just started to experiment with G Custom Sliders. I have found out how to position them, use different skins, change the limits, size etal. But for some reason I can not get a value from the slider. Here is my code.

```auto
import g4p_controls.*;

GCustomSlider sdr1;

void setup() {
  size(500, 140); 
  G4P.setSliderFont("Courier", G4P.BOLD, 14); // New for G4P V4.3
  cursor(CROSS);
  //=============================================================
  // Simple default slider,
  // constructor is `Parent applet', the x, y position and length
  sdr1 = new GCustomSlider(this, 20, 20, 400, 75, "red_yellow18px");
  // show opaque ticks value limits
  sdr1.setShowDecor(true, true, true, true);
  sdr1.setNbrTicks(11);
  sdr1.setLimits(20, 20, 1000);
}

void draw() {
  background(#FF0000);
}

void handleSliderEvents(GSlider slider) {
  println("Slider Value" + slider.getValueI()+ slider.getValueF());
}

```

It is basically a pared down version of the example. The event handler never seems to be run. Obviously I’m missing something. I tried to look at the g4p\_controls.GCustomSlider Class Reference for information, but do not understand what it is trying to tell me.  
What is the event that triggers the handler? The mouse click, stop what??? Thanks for the help Mike.

---

<div class="post-metadata">

### Author: ![quark](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/quark/32/26_2.png) [@quark](https://discourse.processing.org/u/quark)
#### Post date: [June 28, 2020, 9:30pm UTC](https://discourse.processing.org/t/g4p-custom-sliders/22223/2 "2020-06-28T21:30:15Z")

</div>

try  
`void handleSliderEvents(GSlider slider, GEvent event) {`

---

<div class="post-metadata">

### Author: ![mike\_z](https://avatars.discourse-cdn.com/v4/letter/m/9d8465/32.png) [@mike\_z](https://discourse.processing.org/u/mike_z)
#### Post date: [June 29, 2020, 6:23pm UTC](https://discourse.processing.org/t/g4p-custom-sliders/22223/3 "2020-06-29T18:23:43Z")

</div>

Peter, thanks for the tip. Can you help me better understand how your sliders work? What are the methods or events I should be looking for? If the mouse is over the image could be one, mouse click is another. If one drags the pointer over the slider without releasing the mouse, does the getvalue change as you drag? Or does the getvalue only change when the mouse is released? Is the getvalue integer or float dependent on the image skin choice? Where is this information? You have some really good items here, but for some reason I can not seem to make them work, at least as far as I can go. Thanks for the help, Mike

---

<div class="post-metadata">

### Author: ![paulgoux](https://avatars.discourse-cdn.com/v4/letter/p/b9bd4f/32.png) [@paulgoux](https://discourse.processing.org/u/paulgoux)
#### Post date: [June 30, 2020, 7:31am UTC](https://discourse.processing.org/t/g4p-custom-sliders/22223/4 "2020-06-30T07:31:49Z")

</div>

Have you looked at the g4p docs Google is your friend.

---

<div class="post-metadata">

### Author: ![paulgoux](https://avatars.discourse-cdn.com/v4/letter/p/b9bd4f/32.png) [@paulgoux](https://discourse.processing.org/u/paulgoux)
#### Post date: [June 30, 2020, 7:32am UTC](https://discourse.processing.org/t/g4p-custom-sliders/22223/5 "2020-06-30T07:32:23Z")

</div>

Alternatively try g4ps examples.

---

<div class="post-metadata">

### Author: ![quark](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/quark/32/26_2.png) [@quark](https://discourse.processing.org/u/quark)
#### Post date: [June 30, 2020, 12:07pm UTC](https://discourse.processing.org/t/g4p-custom-sliders/22223/6 "2020-06-30T12:07:58Z")

</div>

I suggest you look at the [G4P guides](http://www.lagers.org.uk/g4p/guides/g01-introduction.html) on my website and the examples that come with G4P. The very first page gives info about how to find stuff about controls by also looking at parent classes.

G4P has two types of event handler _ **by control type** _ and _ **by control** _. For sliders the _ **slider control type** _ event handler is

```auto
void handleSliderEvents(GSlider slider, GEvent event) {
}

```

This will handle **all slider events from all sliders** so it you have multiple sliders then you need to test the `slider` parameter to confirm which slider has fired the event and also test the event type before deciding on what action to take.

Sliders have 5 event types

```auto
GEvent.PRESSED
GEvent.RELEASED
GEvent.CLICKED
GEvent.VALUE_CHANGING
GEvent.VALUE_STEADY

```

For most applications the last two are the most important (personally I have never used the others)

There are some rules governing the sliders you should be aware of

- getValue() always returns the current slider value based on the thumb position
- when dragging the slider thumb, the mouse position represents the _target value_ of the slider
- when no easing is being implied the thumb position will always match the target value (i.e. mouse position)
- if easing is applied the thumb movement is smoothed so it will not always match the target value - but will always move towards it.

So when you drag the thumb (without easing) then it will fire GEvent.VALUE\_STEADY events until you release the mouse button.

When you drag the thumb (with easing) then it will fire GEvent.VALUE\_CHANGING until the thumb reaches the target velaue (mouse position) when it will fire a GEvent.VALUE\_STEADY event.

---

<div class="post-metadata">

### Author: ![mike\_z](https://avatars.discourse-cdn.com/v4/letter/m/9d8465/32.png) [@mike\_z](https://discourse.processing.org/u/mike_z)
#### Post date: [June 30, 2020, 1:55pm UTC](https://discourse.processing.org/t/g4p-custom-sliders/22223/7 "2020-06-30T13:55:42Z")

</div>

Thanks, I have read some of the G4P guides and need to read some more of the suggested Doc’s. I have gotten my code to work. My problem was that I had not established the event handler. I want to test out some of the other controls, I’m sure that armed with this new knowledge my sucess rate should be better. I appreciate the help, Mike.
