Button and text vertical centering

Hello, I have a question about p5.js and p5.dom.js .

I want to add a button in my p5.js sketch using p5.dom.js, and want that I place a button on vertical center with text. So I write a code as follows.

textAlign(CENTER, CENTER);
text(“HELLO!", width/2, height/2);

var button = createButton(“<-");
button.position(width/4, height/2);

But the button and text have different base line, so I don’t get expected result. What should I do for vertical centering button and text?

Answers

  • Thank you for your advice!

    I write a code as follow, but I don’t get result yet.
    Button and text have different base line in this code, so I put them vertical center.
    Please your help!

    textAlign(CENTER, CENTER);
    text(“HELLO!", width/2, height/2);
    
    var button = createButton(“<-");
    button.position(width/4, height-button.height >> 1);
    
  • I solve this problem as follow, thank you!

    textAlign(CENTER, CENTER);
    text(“HELLO!", width/2, height/2);
    
    var button = createButton(“<-");
    button.style("height","50px");
    button.position(width/4, height-button.height >> 1);
    
Sign In or Register to comment.