Animal
28 May 2007, 4:14 AM
Ext.Resizable resizes any element. It is applied to BasicDialog (and also to the new Ext2.0 Window class)
Resizability, and draggability are related in that draggable constraints should be applied to resizability so that a resizable element should not be allowed to be resized so that a boundary goes outside its drag constraint area.
BasicDialog has the "container" config option (though not fully implemented), and Ext2.0 Window seems to have this too, in that dragging is constrained to top:0 left:0. (But resizability isn't, and in the (alpha code, so I know it's not going to be perfect) demo you can resize a Window so that its title bar becomes in accessible), so...
Resizability should be configurable to be resizable only within a certain container element.
I have added the following code at the beginning of Resizable.onMouseMove. My addition in bold:
Ext.override(Ext.Resizable, {
onMouseMove : function(e){
if(this.enabled){
try{// try catch so if something goes wrong the user doesn't get hung
// Ignore drag gestures that are outside the constrainTo Element.
var eventXY = e.getXY();
if (this.constrainTo) {
var viewport = Ext.get(this.constrainTo).getBox(true);
if ((eventXY[0] < viewport.x) || (eventXY[0] > viewport.right) ||
(eventXY[1] < viewport.y) || (eventXY[1] > viewport.bottom)) {
return;
}
}
//...snip...
});
That's not perfect because resize handles are a few pixels wide, and a mouse move within the container may still move the boundary outside the container, but it's a start...
Also, I've added this to BasicDialog which makes it obey dragging constraints, and, with the above change, resizing constraints. My changes in bold:
Ext.override(Ext.BasicDialog, {
startMove : function(){
if(this.proxyDrag){
this.proxy.show();
}
if(this.constraintoviewport !== false){
this.dd.constrainTo(this.container || document.body, {right: this.shadowOffset, bottom: this.shadowOffset});
}
},
// private
beforeResize : function(){
this.resizer.constrainTo = this.container;
this.resizer.minHeight = Math.max(this.minHeight, this.getHeaderFooterHeight(true)+40);
}
});
Looking to the future, and Ext 2.0, perhaps Ext.Resizable should also handle dragging its Element as well as resizing it?
It has resize "handles", so perhaps it could also handle being given a drag "handle", and take care of the moving of an element.
So these two related operations would be handled in one class and could share the same constraints easily.
Dialogs and Windows, would just hand their title bars to their resize handlers to be draggable rather than handle moving themselves?
Resizability, and draggability are related in that draggable constraints should be applied to resizability so that a resizable element should not be allowed to be resized so that a boundary goes outside its drag constraint area.
BasicDialog has the "container" config option (though not fully implemented), and Ext2.0 Window seems to have this too, in that dragging is constrained to top:0 left:0. (But resizability isn't, and in the (alpha code, so I know it's not going to be perfect) demo you can resize a Window so that its title bar becomes in accessible), so...
Resizability should be configurable to be resizable only within a certain container element.
I have added the following code at the beginning of Resizable.onMouseMove. My addition in bold:
Ext.override(Ext.Resizable, {
onMouseMove : function(e){
if(this.enabled){
try{// try catch so if something goes wrong the user doesn't get hung
// Ignore drag gestures that are outside the constrainTo Element.
var eventXY = e.getXY();
if (this.constrainTo) {
var viewport = Ext.get(this.constrainTo).getBox(true);
if ((eventXY[0] < viewport.x) || (eventXY[0] > viewport.right) ||
(eventXY[1] < viewport.y) || (eventXY[1] > viewport.bottom)) {
return;
}
}
//...snip...
});
That's not perfect because resize handles are a few pixels wide, and a mouse move within the container may still move the boundary outside the container, but it's a start...
Also, I've added this to BasicDialog which makes it obey dragging constraints, and, with the above change, resizing constraints. My changes in bold:
Ext.override(Ext.BasicDialog, {
startMove : function(){
if(this.proxyDrag){
this.proxy.show();
}
if(this.constraintoviewport !== false){
this.dd.constrainTo(this.container || document.body, {right: this.shadowOffset, bottom: this.shadowOffset});
}
},
// private
beforeResize : function(){
this.resizer.constrainTo = this.container;
this.resizer.minHeight = Math.max(this.minHeight, this.getHeaderFooterHeight(true)+40);
}
});
Looking to the future, and Ext 2.0, perhaps Ext.Resizable should also handle dragging its Element as well as resizing it?
It has resize "handles", so perhaps it could also handle being given a drag "handle", and take care of the moving of an element.
So these two related operations would be handled in one class and could share the same constraints easily.
Dialogs and Windows, would just hand their title bars to their resize handlers to be draggable rather than handle moving themselves?