I did a class whoss parent class is gtk.box in vala. linking to box constructor is not supported, so, how can I set the Orientation of the box in the constructor??
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
While calling
this.set_orientation (Gtk.Orientation.VERTICAL)might work, the more correct way to do this would be to set theorientationproperty at construct time, just like the Gtk.Box default constructor does. In Vala, you would do something like this:At the C level, this is a bit different than just calling
set_orientation… it will generate something a bit like this (simplified for clarity):Calling
set_orientation(or setting theorientationproperty), on the other hand, would generate something like this:The difference is that for the first version the orientation will be set correctly during instantiation (in other words, during the construct block of each of the ancestor classes), whereas for the second version the object will first be created with the wrong orientation, then the orientation will be changed. I’m not sure whether or not this difference is significant for Gtk.Box, but in some cases it is very important so it’s probably a good idea to get in the habit of doing it the right way.
If you’re not sure what I mean by “construct block”, take a look a the section in the Vala Tutorial on GObject-Style Construction.