On Tue, 2010-07-27 at 08:52 +0100, Emmanuele Bassi wrote:
> if you want to change the font in response to width changes I suggest
> you use an idle handler, with clutter_threads_add_idle().
you can also use notify::width on the parent; this JavaScript snippet
sets the text (and font) of a Text actor using the width of the stage:
#!/usr/bin/env gjs
const Lang = imports.lang;
const Clutter = imports.gi.Clutter;
Clutter.init(0, null);
var stage = new Clutter.Stage();
stage.title = 'Test bind';
stage.user_resizable = true;
stage.connect('destroy', Clutter.main_quit);
stage.show();
var text = new Clutter.Text({ text: 'This is some text' });
stage.add_actor(text);
stage.connect('notify::width', function() {
let width = stage.width * 0.1;
text.font_name = 'Sans Bold ' + width + 'px';
text.text = 'Sans Bold\n' + width + 'px';
});
Clutter.main();
+++
the example code works correctly because the change of the Text actor is
done outside of the allocation cycle of the Text actor (but within the
allocation cycle of its parent, the Stage).
in theory, and with g_object_bind_property(), it would be possible to
bind the :width property of a parent to the :font-name property of a
Text actor (using a transformation function, obviously) and avoid using
notify::width and a callback.
ciao,
Emmanuele.
--
Emmanuele Bassi, Open Source Software Engineer
Intel Open Source Technology Center
_______________________________________________
clutter-app-devel-list mailing list
[email protected]
http://lists.clutter-project.org/listinfo/clutter-app-devel-list