Skip to content

Commit

Permalink
Fix zoom-to-mouse problem
Browse files Browse the repository at this point in the history
turns out that the view container, '#canvas' in our case, must be
in absolute display in order for zooming to properly calculate
and scroll to mouse position.

draw2d in their examples they use some jquery layout plugin that
achieved such effect.
  • Loading branch information
AlaaSarhan committed Nov 20, 2019
1 parent d34cfda commit 571f965
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 5 deletions.
8 changes: 7 additions & 1 deletion dist/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,20 @@
background-color: #eee;
margin: 0;
padding: 0;
overflow: hidden;
}

.quickMock__toolbar {
border-bottom: 1px solid grey;
padding: 16px;
height: 40px;
}

.quickMock__canvas {
width: 1000px;
height: 1000px;
position: absolute;
overflow: scroll;
}
</style>
</head>
Expand All @@ -31,12 +35,14 @@
<script type="text/javascript">
window.onload = function () {
const { canvas, elements, draw2d } = LibQMock.createApp('canvas', 1000, 1000)

const win = elements.createWindow({ title: "I'm window", width: 400, height: 400 })
const win2 = elements.createWindow({ title: "I'm inside window", width: 200, height: 200 })
canvas.add(win2, 200, 200)
canvas.add(win, 100, 100)
canvas.add(new draw2d.shape.basic.Label({ text: "I'm inside inner window", bgColor: 'grey'}), 230, 230)


window.addEventListener('keyup', (e) => {
switch(e.key) {
case 'y':
Expand All @@ -49,5 +55,5 @@
})
}
</script>
<script type="text/javascript" src="libqmock-c6bc2f1219d1ee2f214a.js"></script></body>
<script type="text/javascript" src="libqmock-cf91cc219150643297c1.js"></script></body>
</html>
1 change: 0 additions & 1 deletion dist/libqmock-c6bc2f1219d1ee2f214a.js.map

This file was deleted.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions dist/libqmock-cf91cc219150643297c1.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion lib/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import elements from '../lib/elements'

export default function createApp( canvasContainerId, width, height ) {
const canvas = new draw2d.Canvas( canvasContainerId, width, height )

canvas.setScrollArea('#'+canvasContainerId)
return {
canvas,
elements,
Expand Down
6 changes: 6 additions & 0 deletions lib/demo.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,20 @@
background-color: #eee;
margin: 0;
padding: 0;
overflow: hidden;
}
.quickMock__toolbar {
border-bottom: 1px solid grey;
padding: 16px;
height: 40px;
}
.quickMock__canvas {
width: 1000px;
height: 1000px;
position: absolute;
overflow: scroll;
}
</style>
</head>
Expand All @@ -31,12 +35,14 @@
<script type="text/javascript">
window.onload = function () {
const { canvas, elements, draw2d } = LibQMock.createApp('canvas', 1000, 1000)
const win = elements.createWindow({ title: "I'm window", width: 400, height: 400 })
const win2 = elements.createWindow({ title: "I'm inside window", width: 200, height: 200 })
canvas.add(win2, 200, 200)
canvas.add(win, 100, 100)
canvas.add(new draw2d.shape.basic.Label({ text: "I'm inside inner window", bgColor: 'grey'}), 230, 230)
window.addEventListener('keyup', (e) => {
switch(e.key) {
case 'y':
Expand Down

0 comments on commit 571f965

Please sign in to comment.