Builder4/ClutterFiles.bjs
[app.Builder.js] / Builder4 / ClutterFiles.vala
1 /* -- to compile
2 valac  --pkg gio-2.0  --pkg posix  --pkg gtk+-3.0 --pkg libnotify --pkg gtksourceview-3.0  --pkg  libwnck-3.0 \
3     /tmp/ClutterFiles.vala  -o /tmp/ClutterFiles
4 */
5
6
7 /* -- to test class
8 static int main (string[] args) {
9     Gtk.init (ref args);
10     new Xcls_ClutterFiles();
11     ClutterFiles.show_all();
12      Gtk.main ();
13     return 0;
14 }
15 */
16
17
18 public static Xcls_ClutterFiles  ClutterFiles;
19
20 public class Xcls_ClutterFiles : Object 
21 {
22     public Clutter.ScrollActor el;
23     private Xcls_ClutterFiles  _this;
24
25     public Xcls_filelayout filelayout;
26     public Xcls_filelayout_manager filelayout_manager;
27
28         // my vars
29
30         // ctor 
31     public Xcls_ClutterFiles()
32     {
33         _this = this;
34         ClutterFiles = this;
35         this.el = new Clutter.ScrollActor();
36
37         // my vars
38
39         // set gobject values
40         this.el.reactive = true;
41         var child_0 = new Xcls_filelayout( _this );
42         child_0.ref();
43         this.el.add_child (  child_0.el  );
44
45         // listeners 
46         this.el.scroll_event.connect( ( event)  => {
47         
48             //Sprint("scroll event");
49             var y = this.filelayout.el.y;
50             var dir = event.direction;
51             switch (dir) {
52                 case Clutter.ScrollDirection.UP:
53                     y += event.y /2;
54                     break;
55                 case Clutter.ScrollDirection.DOWN:
56                     y -= event.y /2 ;
57                     break;
58                 default:
59                     return false;
60             }
61             // range of scroll -- can go up -- eg.. -ve value.
62             
63             y = float.min(0, y);
64             
65             // to work out the max -ve number
66             // height of filelayout
67             // height of scrollactor..
68             
69             var last_child_bottom = this.filelayout.el.last_child.y +  this.filelayout.el.last_child.height;
70         //     if ( last_child_bottom - this.el.height  > last_child_bottom);
71         
72         
73             
74             
75             print("\nlast child - this height = %f  ==== new y %f\n ".printf( 
76                     last_child_bottom - this.el.height
77                     y));    
78            // y = float.min(0, y);    //??
79             print("scroll event of %f  - new y = %f ".printf(event.y, y));
80             this.filelayout.el.y = y;
81             return true;
82                 
83         } );
84     }
85
86     // userdefined functions 
87     public void set_size(float w, float h) {
88             _this.filelayout_manager.el.max_column_width = w - 150;
89            this.el.set_size(this.el.get_stage().width-150,
90                                 this.el.get_stage().height);
91                     this.el.set_position(100,50);
92         }
93     public void show(Project.Project pr) {
94             // list all the files, and create new Xcls_fileitem for each one.
95             
96             var fiter = pr.files.map_iterator();
97             while (fiter.next()) {
98                 var a = new Xcls_fileitem(this,fiter.get_value());
99                 a.ref();
100                 print("add " + fiter.get_value().name + "\n");
101                 this.filelayout.el.add_child(a.el);
102             }
103             this.el.show_all();
104         }
105
106     // skip |xns - no return type
107     public class Xcls_filelayout : Object 
108     {
109         public Clutter.Actor el;
110         private Xcls_ClutterFiles  _this;
111
112
113             // my vars
114
115             // ctor 
116         public Xcls_filelayout(Xcls_ClutterFiles _owner )
117         {
118             _this = _owner;
119             _this.filelayout = this;
120             this.el = new Clutter.Actor();
121
122             // my vars
123
124             // set gobject values
125             this.el.reactive = true;
126             var child_0 = new Xcls_filelayout_manager( _this );
127             child_0.ref();
128             this.el.layout_manager = child_0.el;
129
130             // init method 
131             this.el.add_constraint(
132                 new Clutter.BindConstraint(_this.el,Clutter.BindCoordinate.SIZE, 0.0f)
133             );
134         }
135
136         // userdefined functions 
137
138         // skip |xns - no return type
139     }
140     public class Xcls_filelayout_manager : Object 
141     {
142         public Clutter.FlowLayout el;
143         private Xcls_ClutterFiles  _this;
144
145
146             // my vars
147
148             // ctor 
149         public Xcls_filelayout_manager(Xcls_ClutterFiles _owner )
150         {
151             _this = _owner;
152             _this.filelayout_manager = this;
153             this.el = new Clutter.FlowLayout( Clutter.FlowOrientation.HORIZONTAL );
154
155             // my vars
156
157             // set gobject values
158             this.el.column_spacing = 20;
159             this.el.homogeneous = true;
160             this.el.row_spacing = 20;
161         }
162
163         // userdefined functions 
164
165         // skip |xns - no return type
166     }
167     public class Xcls_fileitem : Object 
168     {
169         public Clutter.Actor el;
170         private Xcls_ClutterFiles  _this;
171
172
173             // my vars
174         public Xcls_image image;
175         public Xcls_title title;
176
177             // ctor 
178         public Xcls_fileitem(Xcls_ClutterFiles _owner , JsRender.JsRender file)
179         {
180             _this = _owner;
181             this.el = new Clutter.Actor();
182
183             // my vars
184
185             // set gobject values
186             var child_0 = new Xcls_BoxLayout5( _this );
187             child_0.ref();
188             this.el.layout_manager = child_0.el;
189             var child_1 = new Xcls_image( _this ,file);
190             child_1.ref();
191             this.el.add_child (  child_1.el  );
192             this.image =  child_1;
193             var child_2 = new Xcls_title( _this ,file);
194             child_2.ref();
195             this.el.add_child (  child_2.el  );
196             this.title =  child_2;
197
198             // init method 
199             this.el.set_size(100,100);
200         }
201
202         // userdefined functions 
203
204         // skip |xns - no return type
205     }
206     public class Xcls_BoxLayout5 : Object 
207     {
208         public Clutter.BoxLayout el;
209         private Xcls_ClutterFiles  _this;
210
211
212             // my vars
213
214             // ctor 
215         public Xcls_BoxLayout5(Xcls_ClutterFiles _owner )
216         {
217             _this = _owner;
218             this.el = new Clutter.BoxLayout();
219
220             // my vars
221
222             // set gobject values
223             this.el.orientation = Clutter.Orientation.VERTICAL;
224             this.el.spacing = 4;
225         }
226
227         // userdefined functions 
228
229         // skip |xns - no return type
230     }
231     public class Xcls_image : Object 
232     {
233         public Clutter.Texture el;
234         private Xcls_ClutterFiles  _this;
235
236
237             // my vars
238
239             // ctor 
240         public Xcls_image(Xcls_ClutterFiles _owner , JsRender.JsRender file)
241         {
242             _this = _owner;
243             this.el = new Clutter.Texture.from_file(file.getIconFile());
244
245             // my vars
246
247             // set gobject values
248             this.el.x_align = Clutter.ActorAlign.START;
249             this.el.x_expand = true;
250             this.el.y_align = Clutter.ActorAlign.START;
251             this.el.y_expand = false;
252         }
253
254         // userdefined functions 
255
256         // skip |xns - no return type
257     }
258     public class Xcls_title : Object 
259     {
260         public Clutter.Text el;
261         private Xcls_ClutterFiles  _this;
262
263
264             // my vars
265
266             // ctor 
267         public Xcls_title(Xcls_ClutterFiles _owner , JsRender.JsRender file)
268         {
269             _this = _owner;
270             this.el = new Clutter.Text.full("Sans 10px", file.nickName(),new Clutter.Color.from_string("#fff"));
271
272             // my vars
273
274             // set gobject values
275             this.el.x_align = Clutter.ActorAlign.START;
276             this.el.x_expand = true;
277             this.el.y_align = Clutter.ActorAlign.START;
278             this.el.y_expand = false;
279         }
280
281         // userdefined functions 
282
283         // skip |xns - no return type
284     }
285 }