question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

how to make stage responsive?

See original GitHub issue

https://konvajs.github.io/docs/sandbox/Responsive_Canvas.html

this is my code

computed: {
    stage() {
      return this.$refs.stage.getStage();
    },
  },
      const scale = 2;
      this.stage.width = this.stage.width * scale;
      this.stage.height = this.stage.height * scale;
      this.stage.scale({ x: scale, y: scale });
      this.configCircle.x = this.configCircle.x - 50;
      this.stage.draw();

the stage size is not changing,the canvas size seems can’t be changed by this way,but i can see the circle scale 2x bigger.

image

i see your componet, it has two div outside the canvas,it seems must set spectified width and hieght.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
lavrtoncommented, Jun 29, 2021

Konva is doing automatic adjustments for HDPI screens (like retina). It is required for sharp and good display. You can read more about it here: https://developer.mozilla.org/en-US/docs/Web/API/Window/devicePixelRatio

If you don’t need it, you can manually change that behavior:

Konva.pixelRatio = 1;
2reactions
lavrtoncommented, Jan 31, 2019

Sure. My you just need to set CSS values to fit the required size. Updated the demo: https://codesandbox.io/s/502p384jyp

<template>
  <div v-bind:style="{ height: '100vh', width: '100vw' }" ref="container">
    <v-stage ref="stage" :config="stageSize">
      <v-layer>
        <v-circle
          :config="{
            x: 50,
            y: 50,
            radius: 50,
            fill: 'green'
          }"
        />
        <v-circle
          :config="{
            x: stageSize.width - 50,
            y: 50,
            radius: 50,
            fill: 'green'
          }"
        />
        <v-circle
          :config="{
            x: stageSize.width - 50,
            y: stageSize.height - 50,
            radius: 50,
            fill: 'green'
          }"
        />
        <v-circle
          :config="{
            x: 50,
            y: stageSize.height - 50,
            radius: 50,
            fill: 'green'
          }"
        />
      </v-layer>
      <v-layer ref="dragLayer"></v-layer>
    </v-stage>
  </div>
</template>

<script>
const width = window.innerWidth;
const height = window.innerHeight;
let vm = {};
export default {
  data() {
    return {
      stageSize: {
        width: width,
        height: height
      }
    };
  },
  created: function() {
    window.addEventListener("resize", this.changeRect);
    this.changeRect();
  },
  methods: {
    changeRect: function() {
      const container = this.$refs.container;

      if (!container) {
        return;
      }

      const height = container.offsetHeight;
      const width = container.offsetWidth;

      console.log(height, height);
      this.stageSize.width = width;
      this.stageSize.height = height;
    }
  }
};
</script>
Read more comments on GitHub >

github_iconTop Results From Across the Web

How to make a responsive UI in JavaFX - Eden Coding
Any attempt to make JavaFX behave responsively must start by registering a listener to the widthProperty of the Stage object. Changes to the ......
Read more >
Responsive Canvas Stage Demo - Konva
So first of all, there are many way to make your canvas stage “responsive”. And you may need a different behavior for different...
Read more >
How to make responsive design in javafx - Stack Overflow
AnchorPane; import javafx.stage.Stage; public class Main extends Application { @Override public void start(Stage primaryStage) { try ...
Read more >
How to create a responsive layout in JavaFX - GuiGarage
Here I will show how a first solution to create such a responsive layout. ... public void start(Stage primaryStage) throws Exception { this....
Read more >
W+H Reshaping Responsive Stage - Adobe Support Community
It explains how to make canvas content responsive on desktop devices. I updated the example with a rec that scales proportionally according ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found