Button.hx 646 B

123456789101112131415161718192021222324252627282930313233343536
  1. package h2d.comp;
  2. class Button extends Interactive {
  3. var tf : h2d.Text;
  4. public var text(default, set) : String;
  5. public function new(text, ?parent) {
  6. super("button",parent);
  7. tf = new h2d.Text(null, this);
  8. this.text = text;
  9. }
  10. function get_text() {
  11. return tf.text;
  12. }
  13. function set_text(t) {
  14. needRebuild = true;
  15. return text = t;
  16. }
  17. override function resize( ctx : Context ) {
  18. if( ctx.measure ) {
  19. tf.font = getFont();
  20. tf.textColor = style.color;
  21. tf.text = text;
  22. tf.filter = true;
  23. contentWidth = tf.textWidth;
  24. contentHeight = tf.textHeight;
  25. }
  26. super.resize(ctx);
  27. }
  28. }