<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                # PHP GTK 中的布局管理 > 原文: [http://zetcode.com/gui/phpgtktutorial/layoutmanagement/](http://zetcode.com/gui/phpgtktutorial/layoutmanagement/) 在本章中,我們將展示如何在窗口或對話框中布置窗口小部件。 在設計應用的 GUI 時,我們決定要使用哪些小部件以及如何在應用中組織這些小部件。 為了組織窗口小部件,我們使用專門的不可見窗口小部件,稱為布局容器。 在本章中,我們將提到`GtkAlignment`,`GtkFixed`,`GtkVBox`和`GtkTable`。 ## `GtkFixed` `GtkFixed`容器將子窗口小部件放置在固定位置并具有固定大小。 此容器不執行自動布局管理。 在大多數應用中,我們不使用此容器。 我們在某些專業領域使用它。 例如游戲,使用圖表的專用應用,可以移動的可調整大小的組件(如電子表格應用中的圖表),小型教育示例。 ```php <?php /* ZetCode PHP GTK tutorial In this program, we lay out widgets using absolute positioning. author: Jan Bodnar website: www.zetcode.com last modified: September 2011 */ class Example extends GtkWindow { public function __construct() { parent::__construct(); $this->init_ui(); } public function init_ui() { $this->set_title('Fixed'); $this->connect_simple('destroy', array('gtk', 'main_quit')); $this->modify_bg(Gtk::STATE_NORMAL, new GdkColor(6400, 6400, 6440)); $bardejov = GtkImage::new_from_file("bardejov.jpg"); $rotunda = GtkImage::new_from_file("rotunda.jpg"); $mincol = GtkImage::new_from_file("mincol.jpg"); $fixed = new GtkFixed(); $fixed->put($bardejov, 20, 20); $fixed->put($rotunda, 40, 160); $fixed->put($mincol, 170, 50); $this->add($fixed); $this->set_default_size(300, 280); $this->set_position(GTK::WIN_POS_CENTER); $this->show_all(); } } new Example(); Gtk::main(); ?> ``` 在我們的示例中,我們在窗口上顯示了三個小圖像。 我們明確指定放置這些圖像的 x,y 坐標。 ```php $this->modify_bg(Gtk::STATE_NORMAL, new GdkColor(6400, 6400, 6440)); ``` 為了獲得更好的視覺體驗,我們將背景色更改為深灰色。 ```php $bardejov = GtkImage::new_from_file("bardejov.jpg"); ``` `GtkImage`是用于顯示圖像的小部件。 圖片是從磁盤上的文件加載的。 ```php $fixed = new GtkFixed(); ``` 我們創建`GtkFixed`容器。 ```php $fixed->put($bardejov, 20, 20); ``` 我們將第一個圖像放置在`x = 20`,`y = 20`坐標處。 ```php w.add(fixed); ``` 最后,我們將`GtkFixed`容器添加到窗口中。 ![Fixed](https://img.kancloud.cn/f5/1c/f51c43f080c4f8dcb4c5c245f65db533_308x308.jpg) 圖:固定 ## 按鈕 在此代碼示例中,我們將使用垂直框,水平框和對齊小部件。 水平框將小部件排列為一行。 同樣,垂直框將其小部件放在一列中。 `Alignment`容器控制其子窗口小部件的對齊方式和大小。 ```php <?php /* ZetCode PHP GTK tutorial In this program, we position two buttons in the bottom right corner of the window. We use horizontal and vertical boxes. author: Jan Bodnar website: www.zetcode.com last modified: August 2011 */ class Example extends GtkWindow { public function __construct() { parent::__construct(); $this->init_ui(); } public function init_ui() { $this->set_title('Buttons'); $this->connect_simple('destroy', array('gtk', 'main_quit')); $this->set_border_width(3); $vbox = new GtkVBox(false, 5); $hbox = new GtkHBox(true, 3); $frame = new GtkFrame(); $vbox->pack_start($frame, true, true, 0); $okButton = new GtkButton("OK"); $okButton->set_size_request(70, 30); $closeButton = new GtkButton("Close"); $hbox->add($okButton); $hbox->add($closeButton); $halign = new GtkAlignment(1, 0, 0, 0); $halign->add($hbox); $vbox->pack_start($halign, false, false, 3); $this->add($vbox); $this->set_default_size(260, 150); $this->set_position(GTK::WIN_POS_CENTER); $this->show_all(); } } new Example(); Gtk::main(); ?> ``` 在代碼示例中,我們在窗口的右下角放置了兩個按鈕。 為此,我們使用一個水平框,一個垂直框和一個對齊容器。 ```php $vbox = new GtkVBox(false, 5); ``` 將創建一個垂直框容器。 我們將同構成員設置為`false`。 這意味著放在垂直框中的窗口小部件將具有相同的大小。 小部件之間的垂直間距設置為 5 像素。 ```php $frame = new GtkFrame(); ``` 在這里,我們創建一個`GtkFrame`小部件。 該小部件的目的是占用兩個按鈕上方的空間。 ```php $vbox->pack_start($frame, true, true, 0); ``` 在這里,我們將框架小部件放入垂直框中。 該方法的第一個參數是小部件,它被放置在框中。 以下三個參數是`expand`,`fill`和`padding`。 `expand`參數設置為`true`,這意味著將在小部件周圍分配可用空間。 當`fill`參數設置為`true`時,小部件實際上會占用其周圍的所有可用空間。 子窗口小部件周圍沒有填充。 ```php $hbox = new GtkHBox(true, 3); ``` 此代碼行創建一個水平框。 框內的所有小部件都將具有相同的大小。 小部件之間的水平間隔為 3px。 ```php $okButton = new GtkButton("OK"); $okButton->set_size_request(70, 30); $closeButton = new GtkButton("Close"); $hbox->add($okButton); $hbox->add($closeButton); ``` 我們創建兩個按鈕,并將它們放在水平框中。 ```php $halign = new GtkAlignment(1, 0, 0, 0); $halign->add($hbox); $vbox->pack_start($halign, false, false, 3); ``` 這將創建一個對齊容器,它將其子窗口小部件放在右側。 設置為 1.0 的`xalign`成員會將所有可用空間放在水平框的左側。 這將向右推兩個按鈕。 我們將水平框添加到對齊容器中,然后將對齊容器包裝到垂直框中。 我們必須記住,對齊容器僅包含一個子窗口小部件。 這就是為什么我們必須使用水平框。 ![Buttons](https://img.kancloud.cn/a6/ae/a6ae3df4bebfb00519a8c4ef07f2cec3_268x178.jpg) 圖:按鈕 ## 計算器骨架 `GtkTable`小部件按行和列排列小部件。 ```php <?php /* ZetCode PHP GTK tutorial In this program we create a skeleton of a calculator. We use the GtkTable widget. author: Jan Bodnar website: www.zetcode.com last modified: August 2011 */ class Example extends GtkWindow { public function __construct() { parent::__construct(); $this->init_ui(); } public function init_ui() { $this->set_title('Calculator'); $this->connect_simple('destroy', array('gtk', 'main_quit')); $vbox = new GtkVBox(false, 2); $mb = new GtkMenubar(); $filemenu = new GtkMenu(); $filemi = new GtkMenuItem("File"); $filemi->set_submenu($filemenu); $mb->append($filemi); $vbox->pack_start($mb, false, false, 0); $table = new GtkTable(5, 4, true); $table->attach_defaults(new GtkButton("Cls"), 0, 1, 0, 1); $table->attach_defaults(new GtkButton("Bck"), 1, 2, 0, 1); $table->attach_defaults(new GtkLabel(), 2, 3, 0, 1); $table->attach_defaults(new GtkButton("Close"), 3, 4, 0, 1); $table->attach_defaults(new GtkButton("7"), 0, 1, 1, 2); $table->attach_defaults(new GtkButton("8"), 1, 2, 1, 2); $table->attach_defaults(new GtkButton("9"), 2, 3, 1, 2); $table->attach_defaults(new GtkButton("/"), 3, 4, 1, 2); $table->attach_defaults(new GtkButton("4"), 0, 1, 2, 3); $table->attach_defaults(new GtkButton("5"), 1, 2, 2, 3); $table->attach_defaults(new GtkButton("6"), 2, 3, 2, 3); $table->attach_defaults(new GtkButton("*"), 3, 4, 2, 3); $table->attach_defaults(new GtkButton("1"), 0, 1, 3, 4); $table->attach_defaults(new GtkButton("2"), 1, 2, 3, 4); $table->attach_defaults(new GtkButton("3"), 2, 3, 3, 4); $table->attach_defaults(new GtkButton("-"), 3, 4, 3, 4); $table->attach_defaults(new GtkButton("0"), 0, 1, 4, 5); $table->attach_defaults(new GtkButton("."), 1, 2, 4, 5); $table->attach_defaults(new GtkButton("="), 2, 3, 4, 5); $table->attach_defaults(new GtkButton("+"), 3, 4, 4, 5); $vbox->pack_start(new GtkEntry(), false, false, 0); $vbox->pack_end($table, true, true, 0); $this->add($vbox); $this->set_default_size(300, 250); $this->set_position(GTK::WIN_POS_CENTER); $this->show_all(); } } new Example(); Gtk::main(); ?> ``` 我們使用`GtkTable`小部件創建一個計算器框架。 ```php $table = new GtkTable(5, 4, true); ``` 我們創建一個具有 5 行 4 列的表小部件。 第三個參數是同質參數。 如果設置為`true`,則表中的所有小部件都具有相同的大小。 所有窗口小部件的大小等于表容器中最大的窗口小部件。 ```php $table->attach_defaults(new GtkButton("Cls"), 0, 1, 0, 1); ``` 我們在表格容器上附加一個按鈕。 到表格的左上方單元格。 前兩個參數是單元格的左側和右側,后兩個參數是單元格的頂部和左側。 ```php $vbox->pack_end($table, true, true, 0); ``` 我們將表格小部件打包到垂直框中。 ![Calculator skeleton](https://img.kancloud.cn/bc/34/bc34ee48dec1ce719201ec427f4384f5_308x278.jpg) 圖:計算機骨架 ## 窗口 接下來,我們將創建一個更高級的示例。 我們顯示一個窗口,可以在 JDeveloper IDE 中找到它。 ```php <?php /* ZetCode PHP GTK tutorial This is a more complicated layout example. We use GtkAlignment and GtkTable widgets. author: Jan Bodnar website: www.zetcode.com last modified: August 2011 */ class Example extends GtkWindow { public function __construct() { parent::__construct(); $this->init_ui(); } public function init_ui() { $this->set_title('Windows'); $this->connect_simple('destroy', array('gtk', 'main_quit')); $this->set_border_width(15); $table = new GtkTable(8, 4, false); $table->set_col_spacings(3); $title = new GtkLabel("Windows"); $halign = new GtkAlignment(0, 0, 0, 0); $halign->add($title); $table->attach($halign, 0, 1, 0, 1, GTK::FILL, GTK::FILL, 0, 0); $frame = new GtkFrame(); $table->attach($frame, 0, 2, 1, 3, GTK::FILL | Gtk::EXPAND, GTK::FILL | GTK::EXPAND, 1, 1); $activate = new GtkButton("Activate"); $activate->set_size_request(50, 30); $table->attach($activate, 3, 4, 1, 2, GTK::FILL, GTK::SHRINK, 1, 1); $valign = new GtkAlignment(0, 0, 0, 0); $close = new GtkButton("Close"); $close->set_size_request(70, 30); $valign->add($close); $table->set_row_spacing(1, 3); $table->attach($valign, 3, 4, 2, 3, Gtk::FILL, Gtk::FILL | Gtk::EXPAND, 1, 1); $halign2 = new GtkAlignment(0, 1, 0, 0); $help = new GtkButton("Help"); $help->set_size_request(70, 30); $halign2->add($help); $table->set_row_spacing(3, 6); $table->attach($halign2, 0, 1, 4, 5, Gtk::FILL, Gtk::FILL, 0, 0); $ok = new GtkButton("OK"); $ok->set_size_request(70, 30); $table->attach($ok, 3, 4, 4, 5, Gtk::FILL, Gtk::FILL, 0, 0); $this->add($table); $this->set_default_size(300, 250); $this->set_position(GTK::WIN_POS_CENTER); $this->show_all(); } } new Example(); Gtk::main(); ?> ``` 該代碼示例顯示了如何在 PHP GTK 中創建類似的窗口。 ```php $table = new GtkTable(8, 4, false); $table->set_col_spacings(3); ``` 該示例基于`GtkTable`容器。 列之間將有 3px 的間隔。 ```php $title = new GtkLabel("Windows"); $halign = new GtkAlignment(0, 0, 0, 0); $halign->add($title); $table->attach($halign, 0, 1, 0, 1, GTK::FILL, GTK::FILL, 0, 0); ``` 這段代碼創建了一個向左對齊的標簽。 標簽放置在`Table`容器的第一列的第一行中。 ```php $frame = new GtkFrame(); $table->attach($frame, 0, 2, 1, 3, GTK::FILL | Gtk::EXPAND, GTK::FILL | GTK::EXPAND, 1, 1); ``` 框架小部件跨越兩行兩列。 它將消耗其周圍的所有可用空間。 因此,占用了窗口的大部分區域。 ```php $valign = new GtkAlignment(0, 0, 0, 0); $close = new GtkButton("Close"); $close->set_size_request(70, 30); $valign->add($close); $table->set_row_spacing(1, 3); $table->attach($valign, 3, 4, 2, 3, Gtk::FILL, Gtk::FILL | Gtk::EXPAND, 1, 1); ``` 我們將關閉按鈕放在框架小部件旁邊,進入第四列。 (我們從零開始計數)將按鈕添加到對齊小部件中,以便可以將其對齊到頂部。 ```php $halign2 = new GtkAlignment(0, 1, 0, 0); $help = new GtkButton("Help"); $help->set_size_request(70, 30); $halign2->add($help); $table->set_row_spacing(3, 6); $table->attach($halign2, 0, 1, 4, 5, Gtk::FILL, Gtk::FILL, 0, 0); ``` 將幫助按鈕放置在對齊小部件中,以便可以在其表格單元格中使其對齊。 它位于第一列第五行。 ```php $ok = new GtkButton("OK"); $ok->set_size_request(70, 30); $table->attach($ok, 3, 4, 4, 5, Gtk::FILL, Gtk::FILL, 0, 0); ``` 最后,單擊確定按鈕。 它位于第四列和第五行。 ![Windows](https://img.kancloud.cn/fc/5e/fc5ebc5a46de8c4545a50d4401e315bd_308x278.jpg) 圖:窗口 在 PHP GTK 教程的這一部分中,我們提到了小部件的布局管理。
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看