ここでは frameLayoutによる絶対位置による自由なレイアウトとtabLayoutを使ったタブによるGUIの切替えをやってみよう。
formLayoutはウインドウの上下左右からの絶対位置や、他の部品からの相対位置によって配置することができる。
tabLayoutを実行すると、それ以降の部品・レイアウトはタブの一つ(タブグループ)になってゆく。
以下のMELスクリプトをlayout4.melという名前で作る。
$winName = `window -title "layout4" -widthHeight 200 200`;
string $form = `formLayout`;
$closeButton = `button -label "Close" -command "deleteUI $winName"`;
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 "Tab1" -tabLabel $tab2 "Tab2" $tabs;
showWindow;
このMELスクリプトを読み込んで実行すると以下のウインドウが表示される。
(各ボタンにはコマンドを割り当てていないので押しても何も実行されない。)
$winName = `window -title "layout4" -widthHeight 200 200`;
ウインドウをlayout4というタイトルで、縦横200ピクセルの大きさで作る。
string $form = `formLayout`;
formLayoutを作る。
$closeButton = `button -label "Close" -command "deleteUI $winName"`;
ウインドウをクローズするためのボタンを作る。
formLayout -edit
formLayout($form)をエディットモードによって編集する。
-attachForm $closeButton "top" 130
ボタン($closeButton)の上辺はウインドウ上辺から130ピクセルの位置。
-attachForm $closeButton "left" 0
ボタン($closeButton)の左辺はウインドウ左辺から0ピクセルの位置。
-attachForm $closeButton "bottom" 0
ボタン($closeButton)の下辺はウインドウ下辺から0ピクセルの位置。
-attachForm $closeButton "right" 0
ボタン($closeButton)の右辺はウインドウ右辺から0ピクセルの位置。
$form;
formLayoutの名前の入った変数。
formLayout -edit コマンドがここで終り。
string $tabs = `tabLayout -innerMarginWidth 10 -innerMarginHeight 10`;
tabLayoutを作る。
formLayout -edit
formLayout($form)をエディットモードによって編集する。
-attachForm $tabs "top" 0
タブ($tab)の上辺はウインドウ上辺から0ピクセルの位置。
-attachForm $tabs "left" 0
タブ($tab)の左辺はウインドウ左辺から0ピクセルの位置。
-attachControl $tabs "bottom" 10 $closeButton
タブ($tab)の下辺はボタン($closeButton)の上辺から10ピクセルの位置。
-attachForm $tabs "right" 0
タブ($tab)の右辺はウインドウ右辺から0ピクセルの位置。
$form;
formLayout -edit コマンドがここで終り。
string $tab1 = `columnLayout`;
columnLayoutを作る。
button -label "A";
Aボタンを作る。
button -label "B";
Bボタンを作る。
setParent ..;
ここまでが一つ目のcolumnLayoutの範囲。
string $tab2 = `columnLayout`;
columnLayoutを作る。
button -label "C";
Cボタンを作る。
button -label "D";
Dボタンを作る。
setParent ..;
ここまでが二つ目のcolumnLayoutの範囲。
tabLayout -edit -tabLabel $tab1 "Tab1" -tabLabel $tab2 "Tab2" $tabs;
tabLayoutを編集モードにして一つ目のタブ($tab1)にTab1というラベルを、
二つ目のタブ($tab2)にTab2というラベルをつける。
showWindow;
windowを表示する。