From 6fd3c0fbb4a9b0f59903599564947f313379bcfb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20M=C3=BCllner?= Date: Tue, 9 Jul 2013 23:04:45 +0200 Subject: [PATCH] environment: Add some convenience LayoutManager monkey-patching Similar to our ClutterContainer monkey-patching, we can add some convenience to existing ClutterLayoutManagers: - hookup_style() to bind layoutManager properties to CSS properties - child_set() to set child properties https://bugzilla.gnome.org/show_bug.cgi?id=703905 --- js/ui/environment.js | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/js/ui/environment.js b/js/ui/environment.js index aa7a4bd07..3d6ba694b 100644 --- a/js/ui/environment.js +++ b/js/ui/environment.js @@ -10,6 +10,7 @@ const Clutter = imports.gi.Clutter;; const Gettext = imports.gettext; const GLib = imports.gi.GLib; const Gtk = imports.gi.Gtk; +const Lang = imports.lang; const Shell = imports.gi.Shell; const St = imports.gi.St; @@ -39,6 +40,22 @@ function _patchContainerClass(containerClass) { }; } +function _patchLayoutClass(layoutClass, styleProps) { + if (styleProps) + layoutClass.prototype.hookup_style = function(container) { + container.connect('style-changed', Lang.bind(this, function() { + let node = container.get_theme_node(); + for (let prop in styleProps) + this[prop] = node.get_length(styleProps[prop]); + })); + }; + layoutClass.prototype.child_set = function(actor, props) { + let meta = this.get_child_meta(actor.get_parent(), actor); + for (let prop in props) + meta[prop] = props[prop]; + }; +} + function _makeLoggingFunc(func) { return function() { return func([].join.call(arguments, ', ')); @@ -60,6 +77,12 @@ function init() { _patchContainerClass(St.BoxLayout); _patchContainerClass(St.Table); + _patchLayoutClass(Clutter.TableLayout, { row_spacing: 'spacing-rows', + column_spacing: 'spacing-columns' }); + _patchLayoutClass(Clutter.GridLayout, { row_spacing: 'spacing-rows', + column_spacing: 'spacing-columns' }); + _patchLayoutClass(Clutter.BoxLayout, { spacing: 'spacing' }); + Clutter.Actor.prototype.toString = function() { return St.describe_actor(this); };