8f7e6f8117
When a NbtkBoxLayout is allocated a size less than its natural size, think "shrink" needs to be divided among the children that have a smaller minimum size than natural size. This is done by preferentially shrinking the children that are most expanded from their minimum size and then increasing that set of children until we've found enough total shrink. A new method is used of allocating children at integral sizes - instead of rounding the per-child extra amount to an integer (which causes cumulative round-off errors), compute the position as we go along in floats and round individually for each child widget. Extend the box-layout test to include of a test of a box being set to various widths, starting quite narrow. http://bugzilla.moblin.org/show_bug.cgi?id=6311
88 lines
3.3 KiB
JavaScript
88 lines
3.3 KiB
JavaScript
/* -*- mode: js2; js2-basic-offset: 4; indent-tabs-mode: nil -*- */
|
|
|
|
const Clutter = imports.gi.Clutter;
|
|
const Nbtk = imports.gi.Nbtk;
|
|
|
|
const UI = imports.testcommon.ui;
|
|
|
|
UI.init();
|
|
let stage = Clutter.Stage.get_default();
|
|
|
|
let vbox = new Nbtk.BoxLayout({ vertical: true,
|
|
width: stage.width,
|
|
height: stage.height,
|
|
spacing: 10,
|
|
style: 'padding: 10px' });
|
|
stage.add_actor(vbox);
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
let colored_boxes = new Nbtk.BoxLayout({ vertical: true,
|
|
width: 200,
|
|
height: 200,
|
|
style: 'border: 2px solid black;' });
|
|
vbox.add(colored_boxes, { x_fill: false,
|
|
x_align: Nbtk.Align.MIDDLE });
|
|
|
|
let b2 = new Nbtk.BoxLayout({ style: 'border: 2px solid #666666' });
|
|
colored_boxes.add(b2, { expand: true });
|
|
|
|
b2.add(new Nbtk.Label({ text: "Expand",
|
|
style: 'border: 1px solid #aaaaaa; '
|
|
+ 'background: #ffeecc' }),
|
|
{ expand: true });
|
|
b2.add(new Nbtk.Label({ text: "Expand\nNo Fill",
|
|
style: 'border: 1px solid #aaaaaa; '
|
|
+ 'background: #ccffaa' }),
|
|
{ expand: true,
|
|
x_fill: false,
|
|
x_align: Nbtk.Align.MIDDLE,
|
|
y_fill: false,
|
|
y_align: Nbtk.Align.MIDDLE });
|
|
|
|
colored_boxes.add(new Nbtk.Label({ text: "Default",
|
|
style: 'border: 1px solid #aaaaaa; '
|
|
+ 'background: #cceeff' }));
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
function createCollapsableBox(width) {
|
|
let b = new Nbtk.BoxLayout({ width: width,
|
|
style: 'border: 1px solid black;'
|
|
+ 'font: 13px Sans;' });
|
|
b.add(new Nbtk.Label({ text: "Very Very Very Long",
|
|
style: 'background: #ffaacc;'
|
|
+ 'padding: 5px; '
|
|
+ 'border: 1px solid #666666;' }),
|
|
{ expand: true });
|
|
b.add(new Nbtk.Label({ text: "Very Very Long",
|
|
style: 'background: #ffeecc; '
|
|
+ 'padding: 5px; '
|
|
+ 'border: 1px solid #666666;' }),
|
|
{ expand: true });
|
|
b.add(new Nbtk.Label({ text: "Very Long",
|
|
style: 'background: #ccffaa; '
|
|
+ 'padding: 5px; '
|
|
+ 'border: 1px solid #666666;' }),
|
|
{ expand: true });
|
|
b.add(new Nbtk.Label({ text: "Short",
|
|
style: 'background: #cceeff; '
|
|
+ 'padding: 5px; '
|
|
+ 'border: 1px solid #666666;' }),
|
|
{ expand: true });
|
|
|
|
return b;
|
|
}
|
|
|
|
for (let width = 200; width <= 500; width += 60 ) {
|
|
vbox.add(createCollapsableBox (width),
|
|
{ x_fill: false,
|
|
x_align: Nbtk.Align.MIDDLE });
|
|
}
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
stage.show();
|
|
Clutter.main();
|