35.3 UI要素
ui* シリーズの関数はqtグラフィックス ツールキットで最も効果的に機能しますが、一部の機能はfltkツールキットで利用できます。ツールキットはサポートされていませんgnuplot。
: h = uifigure ()
: h = uifigure ("property", value, …)
アプリケーション用の新しい図ウィンドウを作成します。
図オブジェクトには複数のプロパティと値のペアを指定できますが、ペアで指定する必要があります。
戻り値hは、作成された図オブジェクトへのグラフィックス ハンドルです。
プログラミング ノート: プロパティの完全なリストは、 Figure Propertiesに記載されています。 この関数は、figure作成された Figure がプロット用ではなくアプリケーション開発用に最適化される点で と異なります。 つまり、メニュー バーやツールバーなどの機能はオフになります。
参照: uipanel、uibuttongroup。
: hui = uipanel ()
: hui = uipanel (property, value, …)
: hui = uipanel (parent)
: hui = uipanel (parent, property, value, …)
Uipanel オブジェクトを作成します。
uipanel は、他の uicontrol オブジェクトをグループ化するコンテナーとして使用されます。
親が省略された場合、現在の図の uipanel が作成されます。使用可能な図がない場合は、まず新しい図が作成されます。
親が指定されている場合は、親に関連する uipanelが作成されます。
提供されたプロパティ値のペアは、作成された uipanel オブジェクトのデフォルト値を上書きします。
プロパティの完全なリストは、Uipanel Propertiesに記載されています。
オプションの戻り値huiは、作成された uipanel オブジェクトへのグラフィックス ハンドルです。
例:
## create figure and panel on it
f = figure;
p = uipanel ("title", "Panel Title", "position", [.25 .25 .5 .5]);
## add two buttons to the panel
b1 = uicontrol ("parent", p, "string", "A Button", ...
"position", [18 10 150 36]);
b2 = uicontrol ("parent", p, "string", "Another Button", ...
"position",[18 60 150 36]);
参照: figure、uicontrol。
: hui = uibuttongroup ()
: hui = uibuttongroup (property, value, …)
: hui = uibuttongroup (parent)
: hui = uibuttongroup (parent, property, value, …)
: uibuttongroup (h)
uibuttongroup オブジェクトを作成し、そのハンドルを返します。
uibuttongroup は、uicontrol オブジェクトをグループ化するために使用されます。
親が省略されている場合、現在の図の uibuttongroup が作成されます。使用可能な図がない場合は、まず新しい図が作成されます。
親が指定されている場合は、親に関連する uibuttongroupが作成されます。
提供されたプロパティ値のペアは、作成された uibuttongroup オブジェクトのデフォルト値を上書きします。
プロパティの完全なリストは、Uibuttongroup Propertiesに記載されています。
例:
## Create figure and panel on it f = figure; ## Create a button group gp = uibuttongroup (f, "Position", [ 0 0.5 1 1]) ## Create a buttons in the group b1 = uicontrol (gp, "style", "radiobutton", ...
"string", "Choice 1", ...
"Position", [ 10 150 100 50 ]);
b2 = uicontrol (gp, "style", "radiobutton", ...
"string", "Choice 2", ...
"Position", [ 10 50 100 30 ]);
## Create a button not in the group
b3 = uicontrol (f, "style", "radiobutton", ...
"string", "Not in the group", ...
"Position", [ 10 50 100 50 ]);
既存の uibuttongroup オブジェクトへのハンドルである単一の引数hを指定して呼び出されると、指定された uibuttongroup にフォーカスを切り替えます。この機能は現在実装されていません。
See also: figure, uipanel.
: hui = uicontrol ()
: hui = uicontrol (property, value, …)
: hui = uicontrol (parent)
: hui = uicontrol (parent, property, value, …)
: uicontrol (h)
uicontrol オブジェクトを作成し、そのハンドルを返します。
uicontrol オブジェクトは、プッシュ ボタン、チェック ボックス、編集コントロール、リスト コントロールなどのシンプルなインタラクティブ コントロールを作成するために使用されます。
親が省略されている場合は、現在の図の uicontrol が作成されます。使用可能な図がない場合は、まず新しい図が作成されます。
親が指定されている場合は、親に関連する uicontrolが作成されます。
提供されたプロパティ値のペアは、作成された uicontrol オブジェクトのデフォルト値を上書きします。
プロパティの完全なリストは、Uicontrol Propertiesに記載されています。
作成される uicontrol のタイプは、スタイルプロパティによって指定されます。スタイル プロパティが指定されていない場合は、プッシュ ボタンが作成されます。
uicontrol の有効なスタイルは次のとおりです。
"checkbox"
ユーザーがオン/オフを選択できるチェックボックス コントロールを作成します。
"edit"
ユーザーが 1 行または複数行のテキストを入力できる編集コントロールを作成します。
"listbox"
項目のリストを表示し、ユーザーが 1 つまたは複数の項目を選択できるようにするリスト ボックス コントロールを作成します。
"popupmenu"
ユーザーがコントロールをクリックしたときに選択できるオプションのリストを表示するポップアップメニュー コントロールを作成します。
"pushbutton"
ユーザーが押してアクションを実行できるプッシュ ボタン コントロールを作成します。
"radiobutton"
ラジオ ボタン コントロールのグループ内で相互に排他的な入力に使用するラジオ ボタン コントロールを作成します。
"slider"
コントロール上のノブをスライドして、ユーザーが値の範囲から選択できるようにするスライダー コントロールを作成します。
"text"
1 行または複数行のテキストを表示するための静的テキスト コントロールを作成します。
"togglebutton"
プッシュ ボタンのように見えますが、ユーザーが 2 つの状態を選択できるトグル ボタン コントロールを作成します。
注:"edit"および"listbox"スタイルの場合、単一または複数の行/選択の動作は"Min"および "Max"プロパティによって決定され、 の値が のように設定されている場合は複数の行/選択が許可されますMax - Min > 1。
例:
## Create figure and panel on it
f = figure;
## Create a button (default style)
b1 = uicontrol (f, "string", "A Button", ...
"position", [10 10 150 40]);
## Create an edit control
e1 = uicontrol (f, "style", "edit", "string", "editable text", ...
"position", [10 60 300 40]);
## Create a checkbox
c1 = uicontrol (f, "style", "checkbox", "string", "a checkbox", ...
"position", [10 120 150 40]);
既存の uicontrol オブジェクトへのハンドルである単一の引数hを指定して呼び出されると、キーボード フォーカスが指定された uicontrol に切り替わります。その結果、uicontrol オブジェクトは、"keypressfcn"コールバックを使用して処理できるキーボード イベントを受け取ります。
See also: figure, uipanel.
: hui = uitable (property, value, …)
: hui = uitable (parent, property, value, …)
uitable オブジェクトを作成し、そのハンドルを返します。
uitable オブジェクトは、図ウィンドウにデータのテーブルを表示するために使用されます。
親が省略されている場合は、現在の図の uitable が作成されます。使用可能な図がない場合は、まず新しい図が作成されます。
親が指定されている場合は、親に関連する uitable が作成されます。
提供されたプロパティ値のペアは、作成された uitable オブジェクトのデフォルト値を上書きします。
プロパティの完全なリストは、Uitable Propertiesに記載されています。
例:
## Create figure and place a table on it
f = figure ();
m = magic (8);
t = uitable (f, "Data", m, "ColumnWidth", { 40 });
## Create a table with labeled rows and columns
f = figure ();
d = reshape (1:9, [3, 3]);
row_names = { "Row1", "Row2", "Row3" };
col_names = { "Col1", "Col2", "Col3" };
t = uitable (f, "Data", d, ...
"RowName", row_names, "ColumnName", col_names);
p = get (t, "Position");
e = get (t, "Extent");
p(3:4) = e(3:4);
set (t, "Position", p);
## Long demo with callbacks
function uitable_demo ()
f = figure ("Name", "uitable Demo", "Menu", "none", ...
"Position", [10 10 1000 680]);
## A basic example
d = { "char" , "A string";
"double" , 12.3456789;
"complex", 1+2i;
"bool" , true;
"single" , single(12.3456789);
"int8" , int8(-128);
"uint8" , uint8(128);
"int16" , int16(-32768);
"uint16" , uint16(32768);
"int32" , int32(-2147483648);
"uint32" , uint32(2147483648);
"int64" , int64(-2147483649);
"uint64" , uint64(2147843649)};
popup_options = {"A", "B", "C", "D", "E"};
columnformat_options = { "[]", "char", "pop-up", "numeric", ...
"short", "short e", "short eng", ...
"short g", "long", "long e", ...
"long eng", "long g", "bank", "+", ...
"rat", "logical"};
columnformat_values = columnformat_options;
columnformat_values{1} = "";
columnformat_values{3} = popup_options;
default_data = repmat (d(:,2), 1, columns (columnformat_options));
b_add = uicontrol (f, "Position", [285 630 600 50], ...
"UserData", [rows(d), 1], ...
"Style", "pushbutton", ...
"String", "Set data at selected point to selected datatype");
l_type_table = uicontrol (f, "Position", [ 0 603 120 25 ], ...
"String", "Datatype Table:", ...
"Style", "text");
t_type_table = uitable (f, "Position", [ 0 530 1000 70 ], ...
"Data", transpose (d(:, 2)), ...
"ColumnName", transpose (d(:, 1)), ...
"RowName", "Value", ...
"CellSelectionCallback", ...
@(x, y) set (b_add, "UserData", y.Indices ));
l_point_table = uicontrol (f, "Position", [ 0 640 60 25 ], ...
"String", "Point:", ...
"Style", "text");
t_point_table = uitable (f, "Position", [ 80 630 160 42 ], ...
"RowName", [], ...
"ColumnName", {"x", "y"}, ...
"Data", [ 1, 1 ], ...
"ColumnEditable", true);
l_editable_table = uicontrol (f, "Position", [ 0 502 200 25 ], ...
"Style", "text", ...
"String", "Set Data Columns Editable:");
t_editable_table = ...
uitable (f, "Position", [ 0 434 1000 65 ], ...
"Data", repmat (false, 1, columns (default_data)), ...
"ColumnEditable", true);
l_format_table = uicontrol (f, "Position", [ 0 406 200 25 ], ...
"Style", "text", ...
"String", "Set Data Column Format:");
t_format_table = ...
uitable (f, "Position", [ 0 338 1000 65 ], ...
"Data", columnformat_options, ...
"ColumnEditable", true, ...
"ColumnFormat", arrayfun (@(x) {columnformat_options}, ...
1:columns (columnformat_options)));
l_data_table = uicontrol (f, "Style", "text", ...
"String", "Data:", ...
"Position", [ 0 310 60 25 ]);
t_data_table = uitable (f, "Position", [ 0 15 1000 290 ], ...
"Data", default_data, ...
"ColumnFormat", columnformat_values);
set (t_format_table, ...
"CellEditCallback", ...
@(x, y) update_column_format (y.NewData, y.Indices, ...
t_data_table, popup_options));
set (t_point_table, "CellEditCallback", ...
@(x, y) validate_point_table (x, y, t_data_table));
set (t_editable_table, "CellEditCallback", ...
@(x,y) set (t_data_table, ...
"ColumnEditable", get (t_editable_table, "Data")));
set (b_add, ...
"Callback", @(x, y) update_data (b_add, t_point_table, ...
t_type_table, t_data_table));
set (t_data_table, "CellSelectionCallback", ...
@(x, y) update_point_table (y.Indices, t_point_table));
endfunction
function validate_point_table (h, dat, t_data_table) if (! (dat.NewData > 0 && ... dat.NewData < size (get (t_data_table, "Data"), dat.Indices(1, 1)) + 1))
d = get (h, "Data"); d(dat.Indices) = 1; set (h, "Data", d); endif endfunction
function update_column_format (format, indices, t_data_table, ...
popup_options)
cf = get (t_data_table, "ColumnFormat");
if (strcmp (format, "[]"))
format = "";
elseif (strcmp (format, "pop-up"))
format = popup_options;
endif
cf{indices(1,2)} = format;
set (t_data_table, "ColumnFormat", cf);
endfunction
function update_point_table (indices, t_point_table) if (isempty (indices)) indices = [1, 1]; endif set (t_point_table, "Data", indices(1,:)); endfunction
function update_data (b_add, t_point_table, t_type_table, ...
t_data_table)
indices = get (b_add, "UserData");
if (isempty (indices))
indices = [1, 1];
endif
d = get (t_data_table, "Data");
t_type_table_data = get (t_type_table, "Data");
p = get (t_point_table, "Data");
d(p(1,2), p(1,1)) = t_type_table_data(indices(1,2));
set (t_data_table, "Data", d);
endfunction
See also: figure, uicontrol.
: hui = uimenu (property, value, …)
: hui = uimenu (h, property, value, …)
uimenu オブジェクトを作成し、そのハンドルを返します。
hが省略された場合、現在の図のトップレベル メニューが作成されます。h が指定されている場合は、hに関連するサブメニューが作成されます。
uimenu オブジェクトには、次の特定のプロパティがあります。
"accelerator"
このメニュー エントリを実行するためのキーと CTRL を含む文字列 (例: "x"CTRL+x)。
"checked"
"on"または を設定できます"off"。このメニュー エントリにマークを設定します。
"enable"
"on"または を設定できます"off"。無効にすると、メニュー エントリは選択できず、グレー表示されます。
"foregroundcolor"
メニューエントリのテキストの色の値。
"menuselectedfcn"
このメニュー エントリが実行されたときに呼び出される関数。関数文字列 (例: "myfcn")、関数ハンドル (例: @myfcn)、または関数ハンドルとコールバック関数の引数を含むセル配列 (例: {@myfcn, arg1, arg2}) のいずれかになります。
"position"
相対的なメニュー位置を含むスカラー値。最初の位置の値は 1 で、uimenu の方向に応じて左または上になります。
"separator"
"on"または を設定できます"off"。有効にすると、現在の位置の上に区切り線が描画されます。このプロパティは、最上位のエントリでは無視されます。
"text"
このメニュー エントリのテキストを含む文字列。文字"&"をマークするには、- 記号を使用できます"accelerator"(例: "E&xit")。
プロパティの完全なリストは、Uimenu Propertiesに記載されています。
例:
f = uimenu ("text", "&File", "accelerator", "f");
e = uimenu ("text", "&Edit", "accelerator", "e");
uimenu (f, "text", "Close", "accelerator", "q", ...
"menuselectedfcn", "close (gcf)");
uimenu (e, "text", "Toggle &Grid", "accelerator", "g", ...
"menuselectedfcn", "grid (gca)");
See also: figure.
: hui = uicontextmenu (property, value, …)
: hui = uicontextmenu (h, property, value, …)
uicontextmenu オブジェクトを作成し、そのハンドルを返します。
hが省略されている場合、現在の図の UI コンテキスト メニューが作成されます。使用可能な図がない場合は、まず新しい図が作成されます。
hが指定されている場合は、 hに関連する uicontextmenuが作成されます。
提供されたプロパティ値のペアは、作成された uicontextmenu オブジェクトのデフォルト値を上書きします。
プロパティの完全なリストは、Uicontextmenu Propertiesに記載されています。
例:
## create figure and uicontextmenu f = figure (); c = uicontextmenu (f);
## create menus in the context menu
m1 = uimenu ("parent", c, "label", "Menu item 1", ...
"callback", "disp('menu item 1')");
m2 = uimenu ("parent", c, "label", "Menu item 2", ...
"callback", "disp('menu item 2')");
## set the context menu for the figure
set (f, "uicontextmenu", c);
See also: figure, uimenu.
: hui = uitoolbar ()
: hui = uitoolbar (property, value, …)
: hui = uitoolbar (parent)
: hui = uitoolbar (parent, property, value, …)
uitoolbar オブジェクトを作成します。uitoolbar には、uitoggletool ボタンと uipushtool ボタンが表示されます。
親が省略されている場合は、現在の図の uitoolbar が作成されます。図が利用できない場合は、まず新しい図が作成されます。
親が指定されている場合は、親に関連する uitoolbarが作成されます。
提供されたプロパティ値のペアは、作成された uitoolbar オブジェクトのデフォルト値を上書きします。
プロパティの完全なリストは、Uitoolbar Propertiesに記載されています。
オプションの戻り値huiは、作成された uitoolbar オブジェクトへのグラフィックス ハンドルです。
例:
% create figure without a default toolbar
f = figure ("toolbar", "none");
% create empty toolbar
t = uitoolbar (f);
See also: figure, uitoolbar, uitoggletool.
: hui = uipushtool ()
: hui = uipushtool (property, value, …)
: hui = uipushtool (parent)
: hui = uipushtool (parent, property, value, …)
uipushtool オブジェクトを作成します。
uipushtools は、図のツールバーに表示されるボタンです。ボタンは、ユーザーがボタンの上にマウスを置いたときに表示される境界線付きで作成されます。画像は cdata プロパティを使用して設定できます。
親が省略されている場合、現在の図の uipushtool が作成されます。図が利用できない場合は、まず新しい図が作成されます。図は利用可能だが uitoolbar が含まれていない場合は、uitoolbar が作成されます。
親が指定されている場合は、親のuitoolbar上に uipushtool が作成されます 。
提供されたプロパティ値のペアは、作成された uipushtool オブジェクトのデフォルト値を上書きします。
プロパティの完全なリストは、Uipushtool Propertiesに記載されています。
オプションの戻り値huiは、作成された uipushtool オブジェクトへのグラフィックス ハンドルです。
例:
% create figure without a default toolbar
f = figure ("toolbar", "none");
% create empty toolbar
t = uitoolbar (f);
% create a 19x19x3 black square
img=zeros(19,19,3);
% add pushtool button to toolbar
b = uipushtool (t, "cdata", img);
See also: figure, uitoolbar, uipushtool.
: hui = uitoggletool ()
: hui = uitoggletool (property, value, …)
: hui = uitoggletool (parent)
: hui = uitoggletool (parent, property, value, …)
uitoggletool オブジェクトを作成します。
uitoggletool は、図のツールバーに表示されるトグルボタンです。ボタンは、ユーザーがボタンの上にマウスを置いたときに表示される境界線付きで作成されます。cdata プロパティを使用して画像を設定できます。
親が省略されている場合、現在の図の uitoggletool が作成されます。図が利用できない場合は、まず新しい図が作成されます。図は利用可能だが uitoolbar が含まれていない場合は、uitoolbar が作成されます。
親が指定されている場合は、親のuitoolbarに uitoggletool が作成されます 。
提供されたプロパティ値のペアは、作成された uitoggletool オブジェクトのデフォルト値を上書きします。
プロパティの完全なリストは、Uitoggletool Propertiesに記載されています。
オプションの戻り値huiは、作成された uitoggletool オブジェクトへのグラフィックス ハンドルです。
例:
% create figure without a default toolbar
f = figure ("toolbar", "none");
% create empty toolbar
t = uitoolbar (f);
% create a 19x19x3 black square
img=zeros(19,19,3);
% add uitoggletool button to toolbar
b = uitoggletool (t, "cdata", img);
See also: figure, uitoolbar, uipushtool.