所以问题是:如何将pack_start / pack_end与ui xml文件一起使用?是否有生成的xml ui文件的示例或如何在Glade中生成?它会作为HeaderBar / ActionBar的属性/属性/子项输入吗?这会是什么样的 – 一般结构是什么?如果它不是GtkChild,那么如何在Vala / Genie源文件中访问它?
例如,提供以下简单的xml文件MainApplication.ui,如何将一个pack_start和pack_end GtkColorButton添加到GtkHeaderBar?
<?xml version="1.0" encoding="UTF-8"?> <!-- Generated with glade 3.20.2 --> <interface> <requires lib="gtk+" version="3.20"/> <template class="MainWindow" parent="GtkApplicationWindow"> <property name="can_focus">False</property> <property name="default_width">1024</property> <property name="default_height">768</property> <child type="titlebar"> <object class="GtkHeaderBar" id="header_bar"> <property name="visible">True</property> <property name="can_focus">False</property> <property name="title">Test Application</property> <property name="subtitle">gnome.org</property> <property name="show_close_button">True</property> </object> </child> <child> <object class="GtkBox" id="content_Box"> <property name="visible">True</property> <property name="can_focus">False</property> <property name="orientation">vertical</property> <child> <placeholder/> </child> <child> <object class="GtkActionBar" id="action_bar"> <property name="visible">True</property> <property name="can_focus">False</property> </object> <packing> <property name="expand">False</property> <property name="fill">True</property> <property name="position">1</property> </packing> </child> </object> </child> </template> </interface>
这在源文件MainApplication.gs中使用如下:
[GtkTemplate (ui = "/org/gnome/application/ui/MainApplication.ui")] class MainWindow : Gtk.ApplicationWindow [GtkChild] header_bar:Gtk.HeaderBar [GtkChild] action_bar:Gtk.ActionBar construct ( application:Gtk.Application ) GLib.Object( application: application ) class MainApplication:Gtk.Application construct( id:string,flags:GLib.ApplicationFlags ) /* set locale: ALL,"" */ Intl.setlocale() /* set properties */ set_application_id( id ) set_flags( flags )
解决方法
how does one use pack_start/pack_end with the ui xml file?
你没有.这些方法用于以编程方式将子窗口小部件添加到容器窗口小部件.使用glade执行此操作可避免使用代码执行此操作.
Are there any examples of a generated xml ui file or how to generate
within Glade?
我不确定我在这里理解这个问题. Glade生成xml ui定义文件.将它们与GtkBuilder一起使用将实例化您可以使用Gtk.Builder get_object方法检索的小部件.您正在使用另一个选项,称为Gtk复合模板.这允许您在glade中创建复合窗口小部件并将窗口小部件映射到您的代码类/类属性/字段,这将加速编码过程.你可以read more here
Would this be entered as a property/attribute/child of the
HeaderBar/ActionBar?
它足够灵活,可以将一个带有标题栏的Window类作为属性/字段,标题栏中的小部件也可以是窗口的属性或单独的关注点,并将标题栏作为复合小部件,然后将标题栏添加到窗口.对于最后一个选项,您需要以编程方式将标题栏设置为窗口,除非您已准备好处理glade小部件目录,从而允许您在glade中的左侧小部件选项板上使用自己的标题栏组合小部件.
What would this look like – what would be the general structure? If it
is not a GtkChild,then how does one access it within the Vala/Genie
source file?
如果它不是一个孩子,我们会认为它不在林间空地定义中或不住在任何地方,所以它必须以编程方式实例化并添加到具有Gtk.Container添加方法或特定容器添加方法(如pack_start / end等)的容器中.
Supplying the following trivial xml file MainApplication.ui,for
example,how would one pack_start and pack_end a GtkColorButton to the
GtkHeaderBar?
您可以添加带有glade的GtkColorButton,命名它,将其设置为GtkChild并检索它.它将是您的复合窗口小部件的字段(假设您的代码和模板的使用).
如果没有,那么你将创建一个新的Gtk.ColorButton实例,并以编程方式将其添加到Gtk.HeaderBar.由于Gtk.HeaderBar是一个容器(继承自Gtk.Container抽象类),因此您可以使用一些方法向其中添加子项:
> Gtk.HeaderBar pack_start和pack_end
> Gtk.Container methods(add,add_with_properties ……)
例如,在Vala中,使用1和2添加Gtk.ColorButton
:
> header_bar.pack_start(new Gtk.ColorButton());> header_bar.add(new Gtk.ColorButton());