Can you create a GridLayout widget dynamically? [message #1016205] |
Tue, 05 March 2013 13:36 |
Richard Moulton Messages: 92 Registered: August 2011 Location: Devon, UK |
Member |
|
|
Using EDT 0.8.2
I was building a set of widgets 'on the fly' and was looking to use a GridLayout widget to achieve the result I was after, rather than a series of boxes.
Should the following work?
package client;
import org.eclipse.edt.rui.widgets.Div;
import org.eclipse.edt.rui.widgets.GridLayout;
import org.eclipse.edt.rui.widgets.GridLayoutData;
import org.eclipse.edt.rui.widgets.HTML;
import eglx.ui.rui.RUIHandler;
handler TestGridLayout type RUIhandler{initialUI =[ui], onConstructionFunction = start}
ui Div{children =[]};
function start()
grid GridLayout = new GridLayout{ rows=2, columns=3, children=[] };
grid.appendChild( new HTML{text="R1C1", layoutData = new GridLayoutData{row=1, column=1} } );
ui.appendChild(grid);
end
end
If I do the following then this does work ...
package client;
import org.eclipse.edt.rui.widgets.Div;
import org.eclipse.edt.rui.widgets.GridLayout;
import org.eclipse.edt.rui.widgets.GridLayoutData;
import org.eclipse.edt.rui.widgets.HTML;
import eglx.ui.rui.RUIHandler;
handler TestGridLayout type RUIhandler{initialUI =[ui], onConstructionFunction = start}
ui Div{children =[]};
function start()
grid GridLayout = new GridLayout{ rows=2, columns=3,
children=[ new HTML{text="R1C1", layoutData = new GridLayoutData{row=1, column=1} } ] };
ui.appendChild(grid);
end
end
If I do the following then I still get R1C1 but not R1C21 ...
package client;
import org.eclipse.edt.rui.widgets.Div;
import org.eclipse.edt.rui.widgets.GridLayout;
import org.eclipse.edt.rui.widgets.GridLayoutData;
import org.eclipse.edt.rui.widgets.HTML;
import eglx.ui.rui.RUIHandler;
handler TestGridLayout type RUIhandler{initialUI =[ui], onConstructionFunction = start}
ui Div{children =[]};
function start()
grid GridLayout = new GridLayout{ rows=2, columns=3,
children=[ new HTML{text="R1C1", layoutData = new GridLayoutData{row=1, column=1} } ] };
grid.appendChild( new HTML{text="R1C2", layoutData = new GridLayoutData{row=1, column=2} } );
ui.appendChild(grid);
end
end
Richard
|
|
|
|
Re: Can you create a GridLayout widget dynamically? [message #1017948 is a reply to message #1017472] |
Tue, 12 March 2013 20:43 |
Richard Moulton Messages: 92 Registered: August 2011 Location: Devon, UK |
Member |
|
|
Paul,
Both solutions worked.
I expanded my example slightly to prove the point, the create button creates a new GridLayout and the refresh button performs the grid.layout() function.
package client;
import org.eclipse.edt.rui.widgets.Box;
import org.eclipse.edt.rui.widgets.Button;
import org.eclipse.edt.rui.widgets.Div;
import org.eclipse.edt.rui.widgets.GridLayout;
import org.eclipse.edt.rui.widgets.GridLayoutData;
import org.eclipse.edt.rui.widgets.HTML;
import eglx.ui.rui.Event;
import eglx.ui.rui.RUIHandler;
import eglx.ui.rui.Widget;
handler TestGridLayout type RUIhandler{initialUI =[ui], onConstructionFunction = start}
ui Div{children =[ box, create, refresh ]};
box Box{};
create Button{ text="Create Grid", onClick ::= create_onClick };
refresh Button{ text="Refresh Grid", onClick ::= refresh_onClick };
function start()
end
function createGrid()
grid GridLayout = new GridLayout{ rows=2, columns=3, children=[] };
grid.appendChild( new HTML{text="R1C1", layoutData = new GridLayoutData{row=1, column=1} } );
box.appendChild( grid );
end
function create_onClick(event Event in)
createGrid();
end
function refresh_onClick(event Event in)
w widget[] = box.children;
for ( i int from 1 to w.getSize())
if ( w[i] isa GridLayout )
g GridLayout = w[i] as GridLayout;
//g.children = g.children;
g.layout();
end
end
end
end
Many Thanks
Richard
|
|
|
Powered by
FUDForum. Page generated in 0.02946 seconds