XSIユーザーから観たMELスクリプトについて 其の十
ではWindow系の最後
Formとタブですね。
ではさっそくコード
string $windowName = `window -title "レイアウト 5"`; string $form = `formLayout`; string $closeButton = `button -label "閉じる" -command ("deleteUI " + $windowName)`; formLayout -edit -attachForm $closeButton "top" 130 -attachForm $closeButton "left" 0 -attachForm $closeButton "bottom" 0 -attachForm $closeButton "right" 0 $form; string $tabs = `tabLayout -innerMarginWidth 10 -innerMarginHeight 10`; formLayout -edit -attachForm $tabs "top" 0 -attachForm $tabs "left" 0 -attachControl $tabs "bottom" 10 $closeButton -attachForm $tabs "right" 0 $form; string $tab1 = `columnLayout`; button -label "A"; button -label "B"; setParent ..; string $tab2 = `columnLayout`; button -label "C"; button -label "D"; setParent ..; tabLayout -edit -tabLabel $tab1 "タブ1" -tabLabel $tab2 "タブ2" $tabs; showWindow;
レイアウトの際に常法しそうなコードですね。
では内容見て行きましょう。
まずはこれ。
string $closeButton = `button -label "閉じる" -command ("deleteUI " + $windowName)`; formLayout -edit -attachForm $closeButton "top" 130 -attachForm $closeButton "left" 0 -attachForm $closeButton "bottom" 0 -attachForm $closeButton "right" 0 $form;
この一文。閉じるボタンを実行文込みで作成し、
Formで上辺から130ピクセル
左右、下から0ピクセルの位置にボタンを作るってやつです。
この「0」ピクセルが重要ですね。
これで、ウィンドウの上から130ピクセル空き
左右、下から0ピクセルの余白もないボタンを配置できます。
んで次の文
string $tabs = `tabLayout -innerMarginWidth 10 -innerMarginHeight 10`; formLayout -edit -attachForm $tabs "top" 0 -attachForm $tabs "left" 0 -attachControl $tabs "bottom" 10 $closeButton -attachForm $tabs "right" 0 $form;
これの中身は一緒です。
違う部分は配置してる場所です。
-attachControl $tabs "bottom" 10 $closeButton
この部分で閉じるから上に10ピクセル上に配置します。
んで
string $tab1 = `columnLayout`; button -label "A"; button -label "B"; setParent ..;
そのFormの中にボタンを作成し、「setParent ..;」
でtabを終了しています。
CDも一緒ですね。
最後に
tabLayout -edit -tabLabel $tab1 "タブ1" -tabLabel $tab2 "タブ2" $tabs;
でタブを作成し、そのタブにformの二個目を格納してます。
要約すると、
「閉じる」ボタンをFormで下辺に配置し、
「ABCD」があるFormをタブで区切り配置してる感じです。
なんで、タブ1タブ2で切り替わるのは、ABCDだけで閉じるは変わらないということになります。
FormとFormをくっつけてるだけなんですね~。
こんな感じでFormはレイアウトしていきます。
ではもう一個。
その応用編。
結構迷いました。
string $windowName = `window -title "レイアウト 5"`; string $form = `formLayout`; string $closeButton = `button -label "閉じる" -command ("deleteUI " + $windowName)`; formLayout -edit -attachForm $closeButton "top" 130 -attachForm $closeButton "left" 0 -attachForm $closeButton "bottom" 0 -attachForm $closeButton "right" 0 $form; string $tabs = `tabLayout -innerMarginWidth 10 -innerMarginHeight 10`; formLayout -edit -attachForm $tabs "top" 0 -attachForm $tabs "left" 0 -attachControl $tabs "bottom" 10 $closeButton -attachForm $tabs "right" 0 $form; string $tab1 = `columnLayout`; text -label "プリミティブ作成1"; rowLayout -numberOfColumns 2 -columnWidth2 40 40; button -label "球体" -command "sphere"; button -label "立方体" -command "nurbsCube"; setParent ..; setParent ..; string $tab2 = `columnLayout`; text -label "プリミティブ作成2"; rowLayout -numberOfColumns 2 -columnWidth2 40 40; button -label "コーン" -command "cone"; button -label "トーラス" -command "torus"; setParent ..; setParent ..; tabLayout -edit -tabLabel $tab1 "タブ1" -tabLabel $tab2 "タブ2" $tabs; showWindow;
Formの中にテキストや、Rowレイアウトを仕込むものです。
順番が大事なんですね。。。
こんな感じ。
string $tab1 = `columnLayout`; text -label "プリミティブ作成1"; rowLayout -numberOfColumns 2 -columnWidth2 40 40; button -label "球体" -command "sphere"; button -label "立方体" -command "nurbsCube"; setParent ..; setParent ..;
まずは「string $tab1 = `columnLayout`;」で行の配置を作り
「text -label "プリミティブ作成1";」一行目にテキストを入れ
「rowLayout -numberOfColumns 2 -columnWidth2 40 40;」以下列制御にして
「setParent ..;」まずは列の終了宣言し
「setParent ..;」で行の終了宣言もしないといけないんですね。。
面倒だわこれw
で、SI版
var oP = XSIFactory.CreateObject( "CustomProperty" ); /////////////////////////////////////////////////////////////////////////////////// var oL, oItem;//空の宣言 oL = oP.PPGLayout;//PPGを追加 oL.AddTab("タブ1"); oL.AddGroup( "", true, 100 ); oItem = oL.AddButton( "A", "A" ); oItem.SetAttribute( siUICX, 20 ); oItem.SetAttribute( siUICY, 20 ); oL.EndGroup(); oL.AddSpacer(300,10); oL.AddGroup("",true,100); oCl = oL.AddButton("Close","閉じる"); oCl.WidthPercentage = 100; oCl.SetAttribute( siUICX, 300 ); oCl.SetAttribute( siUICY, 300 ); oL.EndGroup(); oL.AddTab("タブ2"); oL.AddGroup( "", true, 100 ); oL.AddRow(); oItem = oL.AddButton( "B", "B" ); oItem.SetAttribute( siUICX, 20 ); oItem.SetAttribute( siUICY, 20 ); oItem = oL.AddButton( "C", "C" ); oItem.SetAttribute( siUICX, 20 ); oItem.SetAttribute( siUICY, 20 ); oL.EndRow(); oL.EndGroup(); oL.AddSpacer(300,10); oL.AddGroup("",true,100); oCl = oL.AddButton("Close","閉じる"); oCl.WidthPercentage = 100; oCl.SetAttribute( siUICX, 300 ); oCl.SetAttribute( siUICY, 300 ); oL.EndGroup();/////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////// //実行分 oL.Logic = Close_OnClicked.toString(); oL.Language = "JScript" ; function Close_OnClicked() { DeleteObj( PPG.Inspected.Item(0) ) ; PPG.Close() ; } InspectObj( oP, null, null, siLock );
SI版では閉じるが独立してません。
やり方わかんなかった。
あと閉じるはウィンドウサイズに固定されてません。
やり方忘れましたorz
とまぁこんな感じでレイアウトの基本は終わり。
全体的にMEL便利かも。。
特にこのFormはわかりやすくて、レイアウト自体も
SIにはできないことが結構できそうでした。
よし、次はイベントやりましょう。
では…