Created
March 13, 2017 19:13
-
-
Save rmacqueen/ca339a953e3899e0ea38a26e88aa13b3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const Gtk = imports.gi.Gtk; | |
const Emeus = imports.gi.Emeus; | |
Gtk.init(null) | |
let layout1 = new Emeus.ConstraintLayout(); | |
let layout2 = new Emeus.ConstraintLayout(); | |
layout1.add(layout2) | |
let label2 = new Gtk.Label({ | |
label: "Label 2" | |
}) | |
let label3 = new Gtk.Label({ | |
label: "Label 3" | |
}) | |
layout2.add(label2); | |
layout2.add(label3); | |
function _add_constraint (props, layout) { | |
props.constant = props.constant || 0; | |
props.multiplier = props.multiplier || 1; | |
props.relation = props.relation || Emeus.ConstraintRelation.EQ; | |
props.source_object = props.source_object || null; | |
props.strength = props.strength || Emeus.ConstraintStrength.REQUIRED; | |
let c = new Emeus.Constraint(props); | |
layout.add_constraint(c); | |
} | |
let constraints1 = [ | |
{ | |
target_object: layout2, | |
target_attribute: Emeus.ConstraintAttribute.RIGHT, | |
source_attribute: Emeus.ConstraintAttribute.RIGHT, | |
}, | |
{ | |
target_object: layout2, | |
target_attribute: Emeus.ConstraintAttribute.BOTTOM, | |
source_attribute: Emeus.ConstraintAttribute.BOTTOM, | |
}, | |
{ | |
target_object: layout2, | |
target_attribute: Emeus.ConstraintAttribute.HEIGHT, | |
source_attribute: Emeus.ConstraintAttribute.HEIGHT, | |
multiplier: 0.5, | |
}, | |
{ | |
target_object: layout2, | |
target_attribute: Emeus.ConstraintAttribute.WIDTH, | |
source_attribute: Emeus.ConstraintAttribute.WIDTH, | |
}, | |
] | |
let constraints2 = [ | |
{ | |
target_object: label2, | |
target_attribute: Emeus.ConstraintAttribute.LEFT, | |
source_attribute: Emeus.ConstraintAttribute.LEFT, | |
source_object: layout2, // Changing layout2 to null here alters the final layout, even though documentation says that setting source_object to null should be equivalent to setting it to parent layout | |
}, | |
{ | |
target_object: label2, | |
target_attribute: Emeus.ConstraintAttribute.TOP, | |
source_attribute: Emeus.ConstraintAttribute.TOP, | |
source_object: layout2, // Changing layout2 to null here alters the final layout, even though documentation says that setting source_object to null should be equivalent to setting it to parent layout | |
}, | |
{ | |
target_object: label2, | |
target_attribute: Emeus.ConstraintAttribute.HEIGHT, | |
source_attribute: Emeus.ConstraintAttribute.HEIGHT, | |
source_object: layout2, // Changing layout2 to null here alters the final layout, even though documentation says that setting source_object to null should be equivalent to setting it to parent layout | |
multiplier: 0.5, | |
}, | |
{ | |
target_object: label2, | |
target_attribute: Emeus.ConstraintAttribute.WIDTH, | |
source_attribute: Emeus.ConstraintAttribute.WIDTH, | |
source_object: layout2, // Changing layout2 to null here alters the final layout, even though documentation says that setting source_object to null should be equivalent to setting it to parent layout | |
}, | |
{ | |
target_object: label3, | |
target_attribute: Emeus.ConstraintAttribute.LEFT, | |
source_attribute: Emeus.ConstraintAttribute.LEFT, | |
}, | |
{ | |
target_object: label3, | |
target_attribute: Emeus.ConstraintAttribute.BOTTOM, | |
source_attribute: Emeus.ConstraintAttribute.BOTTOM, | |
}, | |
{ | |
target_object: label3, | |
target_attribute: Emeus.ConstraintAttribute.HEIGHT, | |
source_attribute: Emeus.ConstraintAttribute.HEIGHT, | |
multiplier: 0.5, | |
}, | |
{ | |
target_object: label3, | |
target_attribute: Emeus.ConstraintAttribute.WIDTH, | |
source_attribute: Emeus.ConstraintAttribute.WIDTH, | |
}, | |
] | |
constraints1.forEach((props) => _add_constraint(props, layout1)) | |
constraints2.forEach((props) => _add_constraint(props, layout2)) | |
let mwindow = new Gtk.Window({ | |
default_width: 800, | |
default_height: 600 | |
}); | |
mwindow.add(layout1); | |
mwindow.show_all(); | |
mwindow.connect('destroy', function() { Gtk.main_quit() }); | |
Gtk.main(); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment