G4P 4.3.3 preview new controls - comments welcome

The next version of G4P will include 2 new controls based on ideas from this discussion. The controls are the

GContolPalette (API) (source code) (video)
GSpinner (API) (source code)

the GTextField control has also been modified to validate numeric input.
GTextField (API)

I have created a demo sketch that demonstrates these controls and I would appreciate any constructive comments before I release the new version of G4P. The sketch is totally self contained so will not affect your current installation of G4P. (download sketch)

3 Likes

Good work :+1:

Have tested the example sketch and have only one question… Is it possible to have decimal option for the spinner as well ?

Very nice – and very nice method of distributing a test sketch.

It all looks good, with two minor points:

  1. I can enter -55.670000000001 into the decimal field and it validates. Makes some sense because of float precision, but still just a bit odd.

  2. When I give the sp1 spinner a hard scroll down, it scrolls to -50 and then stops there. When I give it a hard scroll UP it scrolls to 50, pauses for a moment, then scrolls itself back down to 24 or 26. I’m not sure why.

@jeremydouglass Thanks for your comments with regard to the two issues you raised.

  1. The decimal field is in fact a text field which validates the input against either an integer or a float range provided by the user. The control uses the Float.parseFloat(String) method to create a float value from the input. So although the float data type only has 6-7 significant digits the method will convert any valid decimal value no matter how many significant digits it might have, slight loss of accuracy but what the heck.

  2. I was unable to repeat this either in Processing or Eclipse and it is hard to see how it comes about because the spinner checks the mouse event generated by Processing.

Having said that I have looked at the source code and it highlights something interesting. Here is the code

case MouseEvent.WHEEL:
	if(currSpot == 1){
		if(focusIsWith == this)
			loseFocus(parent);
		if(event.getCount() * G4P.wheelForSpinner > 0)
			inc();
		else
			dec();
	}

since G4P.wheelForSpinner can only have values -1 or 1 can you spot the logic error.

I assumed that getCount() will always return a non-zero value for a wheel event.

So either your mouseWheel suddenly changed direction under its own volition (unlikely unless you believe in the paranormal :wink:) or Processing is generating wheel events where getCount() returns zero (why???). Just goes to show how assumptions can be very wrong.

The fix is easy enough and will be implemented before release.

1 Like

@mala I am pleased you like what I have done so far. I have have been thinking about your request for a decimal spinner and for the moment I have decided against it.

Any G4P control that displays text uses the StyledString class (part of the library) this was introduced a long time ago so that

  1. any true-type font on the computer system can be used
  2. font styles can be applied to all or any sub-part of the text e.g. bold, italic, strike-through, underline , colour, size etc
  3. enables left, right, and center alignment
  4. enables full justification of text in the text area control

To do this I make use of some very low level Java classes which put some restrictions on what I can do. The main restriction is that inside the key event handler the text can only be safely modified using the StyledString member functions . This means I can’t programmatically change the text based on some arbitrary validation rules.

As I said in our other discussion when entering decimal numbers there will be times when the text will not be a valid float so will fail the validity test e…g. when entering -12.78E-6 the following 3 stages are invalid.

-
-12.78E
-12.78E-

Length explanation but it shows unlike an integer I can’t force the display to always show a valid decimal.

1 Like

Thanks for the explanation Peter, understood :+1:

G4P 4.3.3 has now been released and will appear in the Contributions Manager in the next couple of days.

2 Likes

First of all, thanks for this very useful library and its new classes.
I have a GPanel with CustomSliders, Checkboxes, Buttons and GControlPalette in it.
I am using GControlPalette to display some texts (GLabel ()) when the mouse is in some specific areas of the Panel (sort of Contextual Help about each Slider).
It’s probably me … but I haven’t found a way to ‘fix’ the Icon’s position to prevent the user from accidentally moving it (something like GPanel.setDraggable (false))

There is no option to do that.