controlP5 Tabs

edited October 2017 in Library Questions

Hello-

Just wondering - can you add non-controlP5 items (like boxes and text) to some tabs? For example, if I wanted a different header on top of each tab page, how would I implement that? Thanks in advance.

Answers

  • edited November 2013 Answer ✓

    Hi, hope the following example helps, the part you want to customize is c.setView()

    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 );
      }
    }
    
Sign In or Register to comment.