Coder Social home page Coder Social logo

Trigger callback after load about controlp5 HOT 4 CLOSED

sojamo avatar sojamo commented on May 28, 2024
Trigger callback after load

from controlp5.

Comments (4)

sojamo avatar sojamo commented on May 28, 2024

Hi, the ControlP5propertiesCustom example works fine for me and updates variables and function calls accordingly and as expected when loading a setting. When adding a callback to a controller:

cp5.addSlider("slider")
  .setRange(0,200)
  .setValue(128)
  .setPosition(20,100)
  .setSize(20,100)
  .addCallback(new CallbackListener() {
    public void controlEvent(CallbackEvent theEvent) {
      if (theEvent.getAction()==ControlP5.ACTION_BROADCAST) {
        println("update received for", theEvent.getController().getName());
      }
    }
  }
  );

the callback event is triggered when loading a setting that contains a data entry for that particular Controller.

from controlp5.

MatteoFantasy avatar MatteoFantasy commented on May 28, 2024

Hello,
I managed to make it work with a toggle (the slider also works), but it doesn't work with text fields for example.
I wrote the following minimal sketch to demonstrate : when loading a previously saved value, the text in the field is changed but neither the usual callback (linked with the name) nor the callback I added are called.

import controlP5.*;

ControlP5 cp5;
Textfield portInput;

void setup() {

  size(640, 480, P2D);
  cp5 = new ControlP5(this);
  portInput = cp5.addTextfield("changeInputPort")
     .setPosition(10,40)
     .setSize(40,20)
     .setAutoClear(false)
     .setCaptionLabel("")
     .setInputFilter(ControlP5.INTEGER)
     .addCallback(new CallbackListener() {
        public void controlEvent(CallbackEvent theEvent) {
          if (theEvent.getAction()==ControlP5.ACTION_BROADCAST) {
            println("TEST");
          }
        }
     }
     );
}

public void changeInputPort(String s) {
  println("input : "+s);
}

void keyPressed() {
  if(key == 's'){
   saveSettings("settings"); 
  } else if (key == 'l'){
     loadSettings("settings"); 
  }
}

void saveSettings(String file){
  println("Saving to : "+file);
  cp5.saveProperties(file);
}

void loadSettings(String file){
  println("Loading from : "+file);
  cp5.loadProperties(file);
}

from controlp5.

sojamo avatar sojamo commented on May 28, 2024

Textfield indeed is problematic here. a manual keyboard return or calling Textfield.submit() is necessary to trigger a broadcast event. A workaround would be to call submit() on a textfield after properties have been loaded.

void loadSettings(String file){
  println("Loading from : "+file);
  cp5.loadProperties(file);
  // manually call submit() to trigger a broadcast for 
  // Textfield portInput when loading settings.
  portInput.submit(); 
}

from controlp5.

sojamo avatar sojamo commented on May 28, 2024

I will leave this to the work-around example in my previous post.

from controlp5.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.