2016-04-29 178 views
2

我一直在使用qooxdoo 3天,所以這只是開始,但顯然我已經有一些麻煩。Qooxdoo佈局問題

這是關於VBox HBox ...我真的不知道它是如何工作的。我看到了在線文檔和論壇,但無論我嘗試過什麼,我都無法獲得與我的代碼相同的結果(除了複製過去)。因此,你有一些提示嗎?

也可以幫我用我的代碼嗎?

我想有2個tabviews(很好),我想要2個groupboxs。事情是我可以顯示組框,但「自動縮放」剪切文本,我無法弄清楚爲什麼。

預先感謝您。

編輯:(解決方案) 答案不符合embed.Html的要求initaly,但與標籤(結果更容易)。我的目標是爲我的文本的形狀使用一些html代碼。因此,一些'翻譯'是瘋狂的。作爲basic.Label允許這種事情,它已被使用。

這裏我的代碼:

的application.js

qx.Class.define("Q.Application", 
{ 
    extend : qx.application.Standalone, 
    members : 
    { 
    main : function() 
    { 
     this.base(arguments); 
     if (qx.core.Environment.get("qx.debug")) 
     { 
     qx.log.appender.Native; 
     qx.log.appender.Console; 
     } 
     var main = new Q.Windows(); 
     main.open(); 
    } 
    } 
}); 

Windows.js:

qx.Class.define("Q.Windows", 
{ 
    extend : qx.ui.window.Window, 

    construct : function() 
    { 

     this.base(arguments, "windows"); 
     this.setWidth(600); 
     this.setHeight(700); 
     this.setResizable(true); 
     var layout = new qx.ui.layout.Grow(); 
    this.setLayout(layout); 

// ############################ CREATION SHAPE PAGE ######################## 


     var tabView = new qx.ui.tabview.TabView(); 
     this.add(tabView); 



// ############################ Page UN ######################## 
// ############################ Page UN ######################## 

     var page1 = new qx.ui.tabview.Page("History", ""); 
     page1.setLayout(new qx.ui.layout.Grow()); 
     tabView.add(page1); 
// ############################ Backgroung page ######################## 
     var group1 = new qx.ui.groupbox.GroupBox(this.tr("")); 
     group1.setLayout(new qx.ui.layout.Grow()); 

// ############################ Introduction ######################### 

     var htmlp1 = "<p align =\"justify\"> For more than 50 years hadron electromagnetic form factors are considered fundamental quantities for non point-like particles. They parametrize the internal structure of hadrons. </p><br> <p> <img src=\"images/proton_neutron.jpg\" width=\"140\" height=\"90\" border=\"0\" alt=\"CNRS\" style=\"margin: 0px 15px 15px 0px; float: left;\" /> <br> 
<strong>Nucleons</strong> 
<br> <p align=\"justify\">This database collects all data and their references in the scattering (space-like) and in the annihilation (time-like) region, as they were published in the original articles. Experiments and theoretical developments are ongoing. Space-like measurements are based on unpolarized (Rosenbluth separation) and polarized (Akhiezer-Rekalo method) electron elastic scattering off protons and, for neutron, on electron scattering off light nuclei. In the time-like region the reactions e⁺e⁻→ pp̄ (accompanied or not by initial state radiation) and pp̄ → e⁺e⁻ allow to extract form factors relying on a precise angular distribution.</p> "; 
     var embedp1 = new qx.ui.embed.Html(htmlp1); 
     group1.add(embedp1); 

// ############################ Nucleon ######################### 
     page1.add(group1); 



// ############################ Page DEUX ######################## 
// ############################ Page DEUX ######################## 

     var page2 = new qx.ui.tabview.Page("Computation", ""); 
     page2.setLayout(new qx.ui.layout.Grow()); 
     tabView.add(page2); 

// ############################ Backgroung page ######################## 


     var group2 = new qx.ui.groupbox.GroupBox(this.tr("")); 
     group2.setLayout(new qx.ui.layout.VBox(10)); 

// ############################ Objectif ######################### 

     var fs1 = new qx.ui.groupbox.GroupBox(this.tr("")); 
     fs1.setLayout(new qx.ui.layout.Grow()); 
     var htmlp2 ="This is a qooxdoo application skeleton which is used as a template. The 'create-application.py' script (usually under tool/bin/create-application.py)will use this and expand it into a self-contained qooxdoo application which can then be further extended. Please refer to the script and other documentationfor further information." 
     var embedp2 = new qx.ui.embed.Html(htmlp2); 

     fs1.add(embedp2); 
     group2.add(fs1); 


// ############################ Simul ######################### 


    var fs = new qx.ui.groupbox.GroupBox(this.tr("Choice")); 
    fs.setLayout(new qx.ui.layout.Grow()); 

//Setup of the checkboxes 

     var mainLayout = new qx.ui.layout.Grid(0,0); 
     mainLayout.setSpacing(10); 

     var container = new qx.ui.container.Composite(mainLayout); 
     container.setPadding(20); 

     var slp = new qx.ui.form.CheckBox("Space Like Protons"); 
     var tlp = new qx.ui.form.CheckBox("Time Like Protons"); 
     var sln = new qx.ui.form.CheckBox("Space Like Neutrons"); 
     var tln = new qx.ui.form.CheckBox("Time Like Neutrons"); 
     container.add(slp,{row:2,column:1}); 
     container.add(tlp,{row:2,column:2}); 
     container.add(sln,{row:1,column:1}); 
     container.add(tln,{row:1,column:2}); 

     var btOk = new qx.ui.form.Button("OK"); 
     var checkBoxes = [ slp, tlp, sln, tln ]; 
     container.add(btOk,{row:3,column:2}); 


    fs.add(container); 

    group2.add(fs); 

// Creation of the function linked to the button OK 

    btOk.addListener("execute", function(e) { 
    var cbs = checkBoxes; 
    var count = 0; 
    var str = ""; 

    for (var i=0; i<cbs.length; i++) 
    { 
     if (cbs[i].getValue()) 
     { 
     count++; 
     str += (cbs[i].getLabel() + ", "); 
     } 
    } 

    if (count > 0) 
    { 
     str = str.substring(0, str.length-2); 
     alert("You want" + str); 
    } 
    else 
    { 
     alert("No choice"); 
    } 
    }); 


    page2.add(group2); 

    } 

}); 
+0

@johnspackman已經回答了您的問題,但讓我向您介紹一些可幫助您更好地瞭解qooxdoo佈局的文章:* [intro](http://blog.muhuk.com/2009/01/30/using -layouts-in-qooxdoo-part-1.html)* [vbox](http://blog.muhuk.com/2009/02/04/using-layouts-in-qooxdoo-part-2-vbox-layout。 html)* [hbox](http://blog.muhuk.com/2009/02/15/using-layouts-in-qooxdoo-part-3-hbox-layout.html)* [grid](http:// blog.muhuk.com/2009/02/21/using-layouts-in-qooxdoo-part-4-grid-layout.html) – voger

回答

1

首先,請在答案下面回答您的意見,這樣答案的作者將得到通知您的評論和將能夠提供更多的幫助。

關於你的問題更多的自動和空間,你不想在你的文本下面。我不知道如果我理解正確的,但我猜你想是這樣的截圖

enter image description here

在這種情況下,你需要在你的佈局框的文本,qx.ui.core補充。墊片和帶按鈕的盒子。按此順序。

下面是修改代碼,以產生screenshoot

qx.Class.define("q.Windows", 
    { 
     extend: qx.ui.window.Window, 

     construct: function(){ 

      this.base(arguments, "windows"); 
      this.setWidth(600); 
      this.setHeight(700); 
      this.setResizable(true); 
      var layout = new qx.ui.layout.Grow(); 
      this.setLayout(layout); 

// ############################ CREATION SHAPE PAGE ######################## 


      var tabView = new qx.ui.tabview.TabView(); 
      this.add(tabView); 


// ############################ Page UN ######################## 
// ############################ Page UN ######################## 

      var page1 = new qx.ui.tabview.Page("History", ""); 
      page1.setLayout(new qx.ui.layout.Grow()); 
      tabView.add(page1); 
// ############################ Backgroung page ######################## 
      var group1 = new qx.ui.groupbox.GroupBox(this.tr("")); 
      group1.setLayout(new qx.ui.layout.Grow()); 

// ############################ Introduction ######################### 

      var htmlp1 = '<p align ="justify"> For more than 50 years hadron electromagnetic form factors are considered fundamental quantities for non point-like particles. They parametrize the internal structure of hadrons. </p><br> <p> <img src="images/proton_neutron.jpg" width="140" height="90" border="0" alt="CNRS" style="margin: 0px 15px 15px 0px; float: left;" /> <br>' + 
       '<strong> Nucleons </strong>' + 
       '<br><p align ="justify">This database collects all data and their references in the scattering (space-like) and in the annihilation (time-like) region, as they were published in the original articles. Experiments and theoretical developments are ongoing. Space-like measurements are based on unpolarized (Rosenbluth separation) and polarized (Akhiezer-Rekalo method) electron elastic scattering off protons and, for neutron, on electron scattering off light nuclei. In the time-like region the reactions e⁺e⁻→ pp̄ (accompanied or not by initial state radiation) and pp̄ → e⁺e⁻ allow to extract form factors relying on a precise angular distribution.</p>'; 
      var embedp1 = new qx.ui.embed.Html(htmlp1); 
      group1.add(embedp1); 

// ############################ Nucleon ######################### 
      page1.add(group1); 


// ############################ Page DEUX ######################## 
// ############################ Page DEUX ######################## 

      var page2 = new qx.ui.tabview.Page("Computation", ""); 
      page2.setLayout(new qx.ui.layout.Grow()); 
      tabView.add(page2); 

// ############################ Backgroung page ######################## 


      var group2 = new qx.ui.groupbox.GroupBox(this.tr("")); 
      group2.setLayout(new qx.ui.layout.VBox(10)); 

// ############################ Objectif ######################### 

      var fs1 = new qx.ui.groupbox.GroupBox(this.tr("")); 
      fs1.setLayout(new qx.ui.layout.Grow()); 
      var label = new qx.ui.basic.Label(); 
      label.setValue("This is a qooxdoo application skeleton which is used as a template. The 'create-application.py' script (usually under tool/bin/create-application.py)will use this and expand it into a self-contained qooxdoo application which can then be further extended. Please refer to the script and other documentationfor further information."); 
      label.setRich(true); 
      // var embedp2 = new qx.ui.embed.Html(htmlp2); 

      fs1.add(label); 
      group2.add(fs1); 
      var spacer = new qx.ui.core.Spacer(); 
      group2.add(spacer, {flex: 1}); 


// ############################ Simul ######################### 


      var fs = new qx.ui.groupbox.GroupBox(this.tr("Choice")); 
      fs.setLayout(new qx.ui.layout.Grow()); 

//Setup of the checkboxes 

      var mainLayout = new qx.ui.layout.Grid(0, 0); 
      mainLayout.setSpacing(10); 

      var container = new qx.ui.container.Composite(mainLayout); 
      container.setPadding(20); 

      var slp = new qx.ui.form.CheckBox("Space Like Protons"); 
      var tlp = new qx.ui.form.CheckBox("Time Like Protons"); 
      var sln = new qx.ui.form.CheckBox("Space Like Neutrons"); 
      var tln = new qx.ui.form.CheckBox("Time Like Neutrons"); 
      container.add(slp, {row: 2, column: 1}); 
      container.add(tlp, {row: 2, column: 2}); 
      container.add(sln, {row: 1, column: 1}); 
      container.add(tln, {row: 1, column: 2}); 

      var btOk = new qx.ui.form.Button("OK"); 
      var checkBoxes = [slp, tlp, sln, tln]; 
      container.add(btOk, {row: 3, column: 2}); 


      fs.add(container); 

      group2.add(fs); 

// Creation of the function linked to the button OK 

      btOk.addListener("execute", function (e){ 
       var cbs = checkBoxes; 
       var count = 0; 
       var str = ""; 

       for (var i = 0; i < cbs.length; i++) { 
        if (cbs[i].getValue()) { 
         count++; 
         str += (cbs[i].getLabel() + ", "); 
        } 
       } 

       if (count > 0) { 
        str = str.substring(0, str.length - 2); 
        alert("You want" + str); 
       } 
       else { 
        alert("No choice"); 
       } 
      }); 


      page2.add(group2); 

     } 

    }); 

我冒昧你embedp2變量轉換爲qx.ui.basic.Label,因爲這給了更容易的結果。如果你將它設置爲豐富的(就像我在這段代碼中所做的那樣),那麼文本就會被包裝起來,如果你願意,你也可以應用HTML標記。

+0

嗨, 你的答案很好,填補了我在找的東西。只要我可以使用html代碼,標籤對我來說都很好。因此一切都是完美的。 謝謝大家的幫助。 –

3

HBox中和垂直框只是鋪陳部件由左到右/從上到下您添加的順序;在你的示例代碼中工作得很好。

您可以添加布局選項,您添加到了由佈局該容器解釋的容器每個插件,因此,例如,你有這樣的代碼:

group2.add(fs1); group2.add(fs);

你只是依次添加fs1和fs小部件;每個小部件將佔用盡可能多的空間,因爲它至少需要(這顯然不同於佔用儘可能多的空間)

.add的第二個參數允許您指定一些設置以更改這是如何完成的,例如:

group2.add(fs1, { flex: 1 }); group2.add(fs);

這告訴該組中2的垂直框佈局FS1是採取儘可能多的房間成爲可能。

documentation列出了可用的選項

PS - 「柔性」並不僅僅意味着「走了所有的空間:如果一個小窗口有2柔性和其他有1柔性,第一小部件將有2/3的空間,第二個小部件將有1/3

+0

嗨,謝謝你的這個鏈接,也是爲了這個答案。 但是,有沒有辦法通過「自動」來做到這一點?我的意思是,在這裏,所有的頁面都被填滿了,但是我的文本下面有一些空格。我可以騎他們嗎? 我看過幾個鏈接,但我還沒有找到「我的答案」。也許這很簡單,但我不知道。我想爲我的文本「完美的盒子」。 –

+0

我不明白你的意思 - 請你可以把一個快速的操場示例[在這裏](http://demo.qooxdoo.org/current/playground/#Hello%20World-ria) – johnspackman

+0

好吧抱歉,延遲。我的觀點是:我想看到很好的東西。因此,我可以用flex獲得一個很大的黑色空間,這並不是我想要的。不過,這個選項稍後對我的項目非常敏感。正如網頁上的某處所說,我確實有答案。使用標籤非常合適。事情是與embed.html形狀的大小被阻止(exept與flex)這是我的主要問題。 –