Question about GCheckbox in G4P library

I have a question about GCheckbox objects. Depending on the control mode, the 4th & 5th parameters in the creation methods are supposed to specify either the X/Y positions (of the bottom right corner, I think) or the width/height. If I understand correctly, using control mode ‘CORNER’, they should be the width and height. But no matter which control mode I use, the checkboxes are always 20 X 20. What am I doing wrong?

I’m not sure which version of the library I have installed, the constants in ‘’ seem to be contradictory:

# A version number that increments once with each release. This is used to 
# compare different versions of the same library, and check if an update is 
# available. You should think of it as a counter, counting the total number of 
# releases you've had.
version = 44  # This must be parsable as an int

# The version as the user will see it. If blank, the version attribute will be 
# used here. This should be a single word, with no spaces.
prettyVersion = 4.3.5  # This is treated as a String

Here’s a short example:

import g4p_controls.*;

GCheckbox checkbox1 = null;
GCheckbox checkbox2 = null;
GCheckbox checkbox3 = null;

void setup () {
//  G4P.setCtrlMode(GControlMode.CENTER);
//  G4P.setCtrlMode(GControlMode.CORNERS);
  G4P.setDisplayFont("Arial", G4P.BOLD, 12);
  G4P.setInputFont("Arial", G4P.BOLD, 12);
  checkbox1 = new GCheckbox(this, 50, 50, 20, 20);
  checkbox2 = new GCheckbox(this, 50, 100, 40, 40);
  checkbox3 = new GCheckbox(this, 50, 150, 60, 60);

public void draw() {
1 Like

The GCheckbox control has two parts the image showing whether it is checked or not and some text. When creating the checkbox you specify the size of the whole control not the size of the image. So in your example the image always occupies the same space (13x13 pixels) no matter what size you specify in the ctor.

Here is the actual icon file which is 26x13 pixels and contains both selected and deselected images.
You can change the icon using the setIcon(...) method in the GTextIconBase class.

It is also possible to define the position of the icon within the control and the text alignment. I strongly recommend that you look at the G4P_TextIconControls example sketch that comes with the library.

1 Like

Thanks, I’ll take a look at the example.