ControlP5 has any copy and paste function in Textarea or input field?

How do I add copy & paste functionality to a Textarea or input field?

Sample Code from ControlP5

cp5.addTextfield("word1")
 .setPosition(290,245)
 .setSize(240,25)
 .setFont(createFont("arial",16))
 .setColorValue(#000000)
 .setColorActive(#FC0000)  
 .setColorForeground(#000000)
 .setColorBackground(#FFFFFF)
 .setAutoClear(false)
 .getCaptionLabel().setVisible(false); 

Thank you

1 Like

possibly not, but
G4P lib example EditTextControls
works.

1 Like

Thank you and can I store value from text inside G4P text field?

-a- i take that example again
-b- and cut it down to that one text area

/**
 This sketch is to demonstrate some features of GTextArea controls. 
 
 for Processing V2 and V3
 (c) 2015 Peter Lager
 
 */

import g4p_controls.*;

GTextArea txa1;

public void setup() {
  size(500, 300);
  G4P.setGlobalColorScheme(GCScheme.PURPLE_SCHEME);
  txa1 = new GTextArea(this, 10, 10, 480, 280);
  txa1.tag = "txa1";
  txa1.setPromptText("Text area 1");

}

public void draw() {
  background(200, 128, 200);
}

public void displayEvent(String name, GEvent event) {
  String extra = " event fired at " + millis() / 1000.0 + "s";
  print(name + "   ");
  switch(event) {
  case CHANGED:
    println("CHANGED " + extra);
    break;
  case SELECTION_CHANGED:
    println("SELECTION_CHANGED " + extra);
    break;
  case LOST_FOCUS:
    println("LOST_FOCUS " + extra);
    break;
  case GETS_FOCUS:
    println("GETS_FOCUS " + extra);
    break;
  case ENTERED:
    println("ENTERED " + extra);  
    break;
  default:
    println("UNKNOWN " + extra);
  }
}

public void handleTextEvents(GEditableTextControl textControl, GEvent event) { 
  displayEvent(textControl.tag, event);
}

-c- test the cut and paste

-d- @quark
why i can not have a empty line by [enter]

-e- so, now i want understand your question?
what you want to do?
save the content of the edited text area to a file?
( basic feature of a text editor )

or add some more text from any string into the text area
++ at the end?
++ at cursor position? ( that one might be tricky )

2 Likes

Ok thank you so much

I am not sure where [enter] is. I suspect you are trying to get 2 blank lines together. GTextArea does not support that, one single blank lines allowed.

1 Like

hm, ( again play your example: G4P EditTextControls Textarea 1 )

i can type text and [enter] go next line.

[enter] again does not create ONE empty line.

[space][enter] creates a line what looks like a empty line.
if i have many lines and go up with cursor and delete the content of a line
a empty line can be created ( so it is allowed by your textarea field ).
if i try to create a second empty line this way ( deleting the content of a existing line after a empty line ) the line is removed, like you suggested.
when i am at the end of a not empty line and press [enter] a following empty line is created.

sorry @quark, i think a [enter] at the beginning of a line should be allowed ( to create ONE empty line ).

environment:
Raspbery Pi, OS RASPBIAN && win 7 / 64b
Processing 3.5.2
G4P 4.2.0

There are some limitations with GTextArea.

  1. It cannot be completely empty. If you try and delete all the test it will put in a single space
  2. You cannot have two adjacent lines with no text i.e. zero length. You can use lines with one or more spaces to represent blanks lines.
  3. It is not designed to hold massive amounts of text.

The reason for these limitations is due to the fact I used a number of Java classes so that some or all of the text can be styled i.e. bold, italic, font, font size, foreground colour etc. To do this I used a number of Java classes that were never designed to be used directly.

2 Likes