Skip to content

Instantly share code, notes, and snippets.

@vindolin
Last active August 29, 2015 13:59
Show Gist options
  • Save vindolin/10755038 to your computer and use it in GitHub Desktop.
Save vindolin/10755038 to your computer and use it in GitHub Desktop.
clutter grid sizing problem
import sys
from gi.repository import Clutter
stage_size = (800, 600)
Clutter.init(sys.argv)
stage = Clutter.Stage()
stage.set_size(*stage_size)
stage.set_title('Problems...')
def stage_key(element, event):
if event.keyval == Clutter.Escape:
clutter_quit()
def clutter_quit(*args):
Clutter.main_quit()
stage.connect('destroy', clutter_quit)
stage.connect('key-press-event', stage_key)
def color(string):
return Clutter.color_from_string(string)[1]
vcontainer = Clutter.Actor()
vcontainer.set_size(*stage.get_size())
vcontainer.set_background_color(color('Dark Magenta'))
vcontainer_layout = Clutter.BoxLayout.new()
vcontainer_layout.set_orientation(Clutter.Orientation.VERTICAL)
vcontainer_layout.set_spacing(2)
vcontainer.set_layout_manager(vcontainer_layout)
header = Clutter.Actor()
header.set_background_color(color('Hot Pink'))
header.set_height(100)
header.set_x_expand(True)
vcontainer.add_child(header)
grid = Clutter.Actor()
grid.set_background_color(color('Orange Red'))
grid.set_y_expand(True)
grid_layout = Clutter.GridLayout.new()
grid_layout.set_column_spacing(2)
grid_layout.set_row_spacing(2)
grid.set_layout_manager(grid_layout)
vcontainer.add_child(grid)
footer = Clutter.Actor()
footer.set_background_color(color('Gold'))
footer.set_height(100)
footer.set_x_expand(True)
vcontainer.add_child(footer)
for i in range(4):
# fixed size actor 1
a = Clutter.Actor()
a.set_background_color(color('Green'))
a.set_size(50, 50)
# fixed size actor 2
b = Clutter.Actor()
b.set_background_color(color('Yellow'))
b.set_size(200, 100)
# compound a + b
ab = Clutter.Actor()
ab_layout = Clutter.BoxLayout.new()
ab_layout.set_spacing(2)
ab.set_layout_manager(ab_layout)
ab.add_child(a)
ab.add_child(b)
# why does this actor always get a heigh of = a.width + b.width!?
c = Clutter.Actor()
c.set_background_color(color('Blue'))
c.set_height(100)
c.set_x_expand(True)
grid_layout.attach(ab, 0, i, 1, 1)
grid_layout.attach(c, 1, i, 1, 1)
stage.set_user_resizable(True)
stage.add_child(vcontainer)
vcontainer.add_constraint(Clutter.BindConstraint.new(
stage, Clutter.BindCoordinate.SIZE, 0.0))
stage.show()
Clutter.main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment