ControlP5 Tabs Container for Non-ControlP5 objects

edited October 2017 in Library Questions

I tried using the solution given to a similar question years ago. However, when i tried using it a "The type new ControllerView(sketch) must implement the inherent abstract method at Line 20. I tried searching the net but unable to find one that is related to processing... What I want to achieve is add an image and headers inside my Controlp5 tabs.

Here is the code from sojamo : https://forum.processing.org/two/discussion/1380/controlp5-tabs

import controlP5.*;

// using processing 2.0, ControlP5 2.0.4

ControlP5 cp5;

PFont f1;

void setup() {
  size(400, 400);
  f1 = createFont("Helvetica" , 20);
  cp5 = new ControlP5(this);
  cp5.addTab("extra");
  Container c = new Container(cp5, "hello");
  c.setPosition(100, 100).moveTo("extra");

  // give controller hello a custom view - just draw 
  // a white rectangle and a bit of text for a start. 

  c.setView( new ControllerView<Container>() {
    public void display(PApplet p, Container o) {
      p.fill(255);
      p.rect(0, 0, random(100) + 100, 40);
      p.textFont(f1);
      p.text("Hello World" , 0 , 60);
    }
  }
  );
}


void draw() {
  background( 40 );
}

// an empty container controller
class Container extends Controller<Container> {
  Container(ControlP5 c, String theName) {
    super( c, theName, 0, 0, 0, 0 );
    c.register( null, theName, this );
  }
}

Cheers!

Answers

  • edited October 2017 Answer ✓

    That solution is from 2013! And it seems like ControllerView::display()'s signature has changed. b-(

    Apparently, its 1st parameter, instead of PApplet, it is now PGraphics. @-)

    Here's my attempt to upgrade it: :\">

    c.setView(new ControllerView<Container>() {
      static final String MSG = "Hello World";
      final PFont font = createFont("Helvetica", 20, true);
    
      @ Override public void display(final PGraphics pg, final Container c) {
        pg.pushStyle();
    
        pg.strokeWeight(2.5);
        pg.stroke(#0000FF);
        pg.fill(-1);
        pg.rect(0, 0, random(pg.width>>2, pg.width>>1), 40);
    
        pg.fill(#FFFF00);
        pg.textFont(font);
        pg.text(MSG, 0, 60);
    
        pg.popStyle();
      }
    }
    );
    
  • Thank you so much!!!

Sign In or Register to comment.