Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Please elaborate on how to deal with browser resizing #27

Closed
moritzsalla opened this issue Feb 20, 2020 · 3 comments
Closed

Please elaborate on how to deal with browser resizing #27

moritzsalla opened this issue Feb 20, 2020 · 3 comments
Labels
event-casing Related to the Vue event name casing gotcha

Comments

@moritzsalla
Copy link

I am aware the documentation includes a small section on missing events but I am unable to implement this with the information given.

@Kinrany
Copy link
Owner

Kinrany commented Feb 21, 2020

Here's an example:

<div id="app">
  <!-- `windowresized` is lowercase! -->
  <vue-p5 v-on="{setup, draw, windowresized}"></vue-p5>
</div>
new Vue({
  el: '#app',
  data() {
    return { text: 'Hello p5!' };
  },
  methods: {
    setup(sketch) {
      sketch.resizeCanvas(200, 100);
    },
    draw(sketch) {
      sketch.background('green');
      sketch.text(this.text, 20, 20);
    },
    windowresized(sketch) {                          // also lowercase!
      const width = sketch.windowWidth;
      const height = sketch.windowHeight;
      this.text = `size: (${width}, ${height})`;
    }
  }
});

Codepen: https://codepen.io/Kinrany/pen/zYGoxNK


Note the gotcha: it must be lowercase windowresized instead of windowResized.

I even made the same mistake in the documentation, haha. Thanks for making me aware of this.

Also note that windowResized is already defined (the full list of supported events is available here), so there's no need to use additionalEvents in this case. (Btw, does the name of the prop make sense?)

@moritzsalla
Copy link
Author

Great, thanks!

@Kinrany
Copy link
Owner

Kinrany commented Feb 21, 2020

You're welcome 🙂

@Kinrany Kinrany added the event-casing Related to the Vue event name casing gotcha label May 22, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
event-casing Related to the Vue event name casing gotcha
Projects
None yet
Development

No branches or pull requests

2 participants