Skip to content

Commit c7cf80b

Browse files
committed
Update 02 Version 1.2
Screen Bound
1 parent ab48b56 commit c7cf80b

3 files changed

Lines changed: 48 additions & 27 deletions

File tree

README.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
# MovableView
1+
# MovableView v1.2
22
Movable view for Sciter windows, allows you to move the window using any element in it.
33
Advantages:
44
1. Cheating windows performance setting, you will see the full window and not just a rectangle while moving it in performance mode.
5-
2. Smoothed movement.
5+
2. Optional prevent crossing screen bounds.
66

77
Using inside a compiled application should use less than 1% CPU (while moving the view).
88

@@ -24,6 +24,7 @@ include "movableView.tis";
2424

2525
Then initiate it by calling
2626
```js
27-
movableView("selector");
27+
movableView("selector" [, screenBound:bool(false)]);
2828
```
29-
with the selector being any CSS selector i.e. `div` `.div` `#div`
29+
with the selector being any CSS selector i.e. `div` `.div` `#div`
30+
the second parameter will prevent window from going past the screen boundaries.

demo.htm

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<html window-frame="transparent">
22
<head>
3-
<title>Moveable View</title>
3+
<title>MovableView</title>
44
<style>
5-
.header {
5+
.header, .footer {
66
padding: 10dip;
77
background: #ddd;
88
}
@@ -14,11 +14,12 @@
1414
<script src="movableView.tis" type="text/tiscript"></script>
1515
<script type="text/tiscript">
1616
movableView(".header");
17+
movableView(".footer", true);
1718
</script>
1819
</head>
1920
<body>
2021
<div class="header">Header</div>
21-
<div class="content">Content - Grab the header or footer to move</div>
22-
<div class="header">Footer</div>
22+
<div class="content">Content - Grab the header or footer to move (footer will not allow you to cross screen bounds)</div>
23+
<div class="footer">Footer</div>
2324
</body>
2425
</html>

movableView.tis

Lines changed: 38 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,63 @@
1-
// Movable View v1.1
1+
// Movable View v1.2
22
// https://github.com/MustafaHi/Sciter-MovableView
33

4-
// Call movableView('.selector');
5-
function movableView(s)
4+
// Call movableView('selector' [, screenBound:bool(false)]);
5+
function movableView(s, screenBound = false)
66
{
7-
var xoff,yoff;
7+
var xoff,yoff, minXY, maxX, maxY;
88
var dragging = false;
9+
910
function doDrag() { while( dragging ) view.doEvent(); }
11+
12+
function screenBounds()
13+
{
14+
if (screenBound)
15+
{
16+
(maxX, maxY) = view.screenBox(#workarea, #dimension);
17+
var (w, h) = view.box(#dimension, #border);
18+
maxX -= w;
19+
maxY -= h;
20+
minXY = 0;
21+
}
22+
else
23+
{
24+
(maxX, maxY) = Integer.MAX;
25+
minXY = Integer.MIN;
26+
}
27+
}
1028

1129
function onMouseDown(e)
1230
{
13-
if(!e.target.$is({s}) ){ return false; }
31+
if(!e.target.$is({s}) ) { return false; }
32+
33+
screenBounds();
1434
e.target.capture(true);
1535
xoff = e.xView; yoff = e.yView;
1636
dragging = true;
1737
doDrag();
1838
}
19-
39+
2040
function onMouseMove(e)
2141
{
22-
if( dragging )
42+
if(dragging)
2343
{
24-
view.move( e.xScreen - xoff, e.yScreen - yoff, false);
25-
return true;
44+
view.move( (e.xScreen - xoff).limit(minXY, maxX), (e.yScreen - yoff).limit(minXY, maxY), false );
2645
}
2746
return true;
2847
}
2948

30-
function stopDrag(e)
49+
function onMouseUp(e)
3150
{
32-
if(dragging) { dragging = false; e.target.capture(false); return true; }
33-
return false;
51+
if(dragging) { dragging = false; e.target.capture(false); }
52+
return true;
3453
}
3554

36-
function onKeyDown(e) { if(e.keyCode == Event.VK_ESCAPE ) return stopDrag(e); }
37-
for(var i=0; i<$$({s}).length; ++i) {
38-
$$({s})[i].subscribe(onMouseDown, Event.MOUSE, Event.MOUSE_DOWN );
39-
$$({s})[i].subscribe(stopDrag, Event.MOUSE, Event.MOUSE_UP );
40-
$$({s})[i].subscribe(onMouseMove, Event.MOUSE, Event.MOUSE_MOVE );
41-
$$({s})[i].subscribe(onKeyDown, Event.KEY, Event.KEY_DOWN );
55+
const elements = $$({s});
56+
for(var i=0; i<elements.length; ++i) {
57+
elements[i].subscribe(onMouseDown, Event.MOUSE, Event.MOUSE_DOWN );
58+
elements[i].subscribe(onMouseUp, Event.MOUSE, Event.MOUSE_UP );
59+
elements[i].subscribe(onMouseMove, Event.MOUSE, Event.MOUSE_MOVE );
4260
}
43-
return false;
61+
return true;
4462
}
63+

0 commit comments

Comments
 (0)