Commit 17cb3483 authored by Bas Lijnse's avatar Bas Lijnse

Improved resize event handling to update scaled editors on window resizing

parent 8f9a454c
Pipeline #25918 passed with stage
in 5 minutes and 48 seconds
......@@ -99,6 +99,10 @@ itasks.Panel = {
case 'right': me.domEl.style['width'] = (startSize + (ev.clientX - startPos)) + 'px'; break;
case 'left': me.domEl.style['width'] = (startSize + (startPos - ev.clientX)) + 'px'; break;
}
//Trigger resize event on all siblings
me.parentCmp.children.forEach(function(child) {
child.onResize();
});
};
window.addEventListener('mousemove', resize, false);
......
......@@ -378,6 +378,8 @@ itasks.Viewport = {
//Create a temporary root element
me.insertChild(0,{type:'Loader', parentCmp: me});
me.parentViewport = me.getViewport();
//Get a connection
me.taskUrl = me.determineTaskEndpoint();
me.connection = itasks.ConnectionPool.getConnection(me.taskUrl);
......@@ -401,16 +403,15 @@ itasks.Viewport = {
uiChangeCallback,
exceptionCallback);
}
me.addWindowResizeListener();
},
getParentViewport: function() {
var me = this, parentVp = me.parentCmp;
while(parentVp) {
if(parentVp.cssCls == 'viewport') { //Bit of a hack...
return parentVp;
}
parentVp = parentVp.parentCmp;
addWindowResizeListener: function() {
var me = this;
if(me.parentViewport !== null) { //Only listen to window changes as the top level
return;
}
return null;
window.addEventListener('resize',me.onResize.bind(me));
},
determineTaskEndpoint: function() {
var me = this;
......@@ -421,12 +422,11 @@ itasks.Viewport = {
return 'ws://' + location.host + me.taskUrl + (me.taskUrl.endsWith('/') ? '' : '/') + 'gui-wsock';
}
}
var parentVp = me.getParentViewport();
if(parentVp === null) {
if(me.parentViewport === null) {
//If there is no parent, use the default url
return 'ws://' + location.host + location.pathname + (location.pathname.endsWith('/') ? '' : '/') + 'gui-wsock';
} else {
return parentVp.determineTaskEndpoint();
return me.parentViewport.determineTaskEndpoint();
}
},
doEditEvent: function (taskId, editorId, value) {
......
......@@ -5,12 +5,21 @@ import iTasks.Extensions.ScaledEditor
import StdFunctions
import Text.HTML
test :: Task HtmlTag
test = viewInformation () [ViewUsing id (scaledEditor 600 400 (htmlView <<@ styleAttr "padding: 0"))] html
<<@ ApplyLayout (layoutSubUIs (SelectByPath [1]) (setUIAttributes (sizeAttr FlexSize FlexSize)))
test = (testHtmlFrame -&&- testResizable) <<@ AddCSSClass "itasks-horizontal"
testHtmlFrame :: Task HtmlTag
testHtmlFrame = viewInformation () [ViewUsing id (scaledEditor 300 200 (htmlView <<@ styleAttr "padding: 0"))] html
<<@ ApplyLayout (sequenceLayouts [layoutSubUIs (SelectByPath [1]) (setUIAttributes (sizeAttr FlexSize FlexSize))
,setUIAttributes (sizeAttr FlexSize FlexSize)
]
)
where
html = DivTag [StyleAttr "width: 100%; height: 100%; background: blue; color: white; margin: 0"]
[SpanTag [StyleAttr "font-size: 20px"] [Text "This text is automatically scaled"]
]
testResizable :: Task String
testResizable = viewInformation () [] "RESIZE THIS PANEL"
<<@ ApplyLayout (sequenceLayouts[setUIType UIPanel,setUIAttributes (resizableAttr [LeftSide])])
Start world = doTasks test world
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment