Clutter のドキュメントの中で Constraint がよく解らない。
Google 翻訳によると「制約」、っていったい何の制約なのだろう?
検索検索。
Clutter の Constraint (制約条件) – ふとしの日記
Gjs で動かないって new キーワードの場合引数はプロパティを JSON 指定ですし。
JSON 引数に書き換えたら普通に動いた、多分今は自身で解っていると思うけど。
五年前のこの当事はみんな手探り状態だったししかたがないね。
えっとつまり。
Constraint ってアクションを他の Actor と連動させるって解釈でいいのかな?
この名前が不適切なのか、実は英語ではコレで合っているということなのかシラネ!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 | #!/usr/bin/gjs const Gtk = imports .gi.Gtk; const GtkClutter = imports .gi.GtkClutter; const Clutter = imports .gi.Clutter; const Lang = imports .lang; const ConstraintWin = new Lang.Class({ Name: 'ConstraintWin' , Extends: Gtk.ApplicationWindow, _init: function (app) { this .parent({ application: app }); this .red = new Clutter.Actor({ background_color: Clutter.Color. new (255, 0, 0, 255), x: 25, y: 25, width: 50, height: 50, reactive: true }); this .blue = new Clutter.Actor({ background_color: Clutter.Color. new (0, 0, 255, 255), width: 50, height: 50, }); // DnD this .red.add_action( new Clutter.DragAction()); // Constraint let bind = new Clutter.BindConstraint({ coordinate: Clutter.BindCoordinate.POSITION, offset: 50, source: this .red }); this .blue.add_constraint(bind); // Embed let embed = new GtkClutter.Embed(); let stage = embed.get_stage(); stage.add_child( this .red); stage.add_child( this .blue); this .add(embed); this .show_all(); } }); // init GtkClutter.init( null ); let app = new Gtk.Application(); app.connect( "activate" , function () { new ConstraintWin(app); }); app.run( null ); |
で赤いブロックをドラッグする。
うん、見事にオフセットされたまま連動してドラッグされるんだね。
ClutterAlignConstraint は Totem のボタン類みたいな用途で使えそう。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 | #!/usr/bin/gjs const Gtk = imports .gi.Gtk; const GtkClutter = imports .gi.GtkClutter; const Clutter = imports .gi.Clutter; const Lang = imports .lang; const TotemLikeWin = new Lang.Class({ Name: 'TotemLikeWin' , Extends: Gtk.ApplicationWindow, _init: function (app) { this .parent({ application: app }); // Embed let embed = new GtkClutter.Embed(); let stage = embed.get_stage(); // this .red = new Clutter.Actor({ background_color: Clutter.Color. new (255, 0, 0, 255), width: 200, height: 50, reactive: true }); stage.add_child( this .red); // Constraint let x = new Clutter.AlignConstraint({ align_axis: Clutter.AlignAxis.X_AXIS, factor: 0.5, source: stage }); let y = new Clutter.AlignConstraint({ align_axis: Clutter.AlignAxis.Y_AXIS, factor: 0.8, source: stage }); this .red.add_constraint(x); this .red.add_constraint(y); // this .add(embed); this .show_all(); } }); // init GtkClutter.init( null ); let app = new Gtk.Application(); app.connect( "activate" , function () { new TotemLikeWin(app); }); app.run( null ); |
いくらリサイズしても常に同じ位置に貼り付ける動作がこんなにアッサリ!
多分こういうのが本来の使い方だと思う。