35.3 UI元素

ui*系列函数与qtgraphictoolkit,尽管有一些函数可用于fltk工具包。没有对的支持gnuplot工具包。

 
:h= uifigure ()
:h= uifigure ("property",value, …)

为应用程序创建一个新的地物窗口。

可以为地物对象指定多个属性值对,但它们必须成对出现。

返回值h是已创建地物对象的图形句柄。

编程说明:属性的完整列表记录在图Properties。此函数不同于figure因为创建的图形是为应用程序开发而优化的,而不是绘图。这意味着菜单栏和工具栏等函数将被关闭。

详见: uipanel,uibuttongroup.

 
:hui= uipanel ()
:hui= uipanel (property,value, …)
:hui= uipanel (parent)
:hui= uipanel (parent,property,value, …)

创建uipanel对象。

uipanels用作容器来对其他uicontrol对象进行分组。

如果parent则会创建当前图形的uipanel。如果没有可用地物,将首先创建一个新地物。

如果parent则给出一个相对于的uipanelparent创建。

任何提供的属性值对都将覆盖已创建的uipanel对象的默认值。

完整的属性清单记录在Uipanel Properties.

可选返回值hui是createduipanel对象的图形句柄。

示例:

## 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对象进行分组。

如果parent则为当前地物创建一个uibutton组。如果没有可用地物,将首先创建一个新地物。

如果parent则给出一个相对于的uibuttongroupparent已创建。

任何提供的属性值对都将覆盖已创建的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 ]);

使用单个参数调用时h是现有uibuttongroup对象的句柄,将焦点切换到指定的uibuttongroup。此函数目前尚未实现。

详见: figure,uipanel.

 
:hui= uicontrol ()
:hui= uicontrol (property,value, …)
:hui= uicontrol (parent)
:hui= uicontrol (parent,property,value, …)
:uicontrol (h)

创建uicontrol对象并向其返回句柄。

uicontrol对象用于创建简单的交互式控件,如按钮、复选框、编辑和列表控件。

如果parent则为当前图形创建uicontrol。如果没有可用地物,将首先创建一个新地物。

如果parent则给出一个uicontrol相对于parent已创建。

任何提供的属性值对都将覆盖创建的uicontrol对象的默认值。

完整的属性清单记录在Uicontrol Properties.

创建的uicontrol类型从指定style属性如果没有提供样式属性,将创建一个按钮。

uicontrol的有效样式为:

"checkbox"

创建允许用户打开/关闭选择的复选框控件。

"edit"

创建一个编辑控件,允许用户输入单行或多行文本。

"listbox"

创建一个列表框控件,该控件显示项目列表,并允许用户选择单个或多个项目。

"popupmenu"

创建一个弹出菜单控件,显示用户单击该控件时可以选择的参数列表。

"pushbutton"

创建一个按钮控件,允许用户按下以进行操作。

"radiobutton"

创建一个单选按钮控件,用于在一组单选按钮控件中互斥输入。

"slider"

创建一个滑块控件,允许用户通过滑动控件上的旋钮从一系列值中进行选择。

"text"

创建一个静态文本控件以显示单行或多行文本。

"togglebutton"

创建一个看起来像按钮的切换按钮控件,但允许用户在两种状态之间进行选择。

注意:对于"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]);

使用单个参数调用时h是现有图标控制对象的句柄,将键盘焦点切换到指定的图标控制。因此,uicontrol对象将接收可以使用处理的键盘事件"keypressfcn"回调。

详见: figure,uipanel.

 
:hui= uitable (property,value, …)
:hui= uitable (parent,property,value, …)

创建一个uitable对象并返回一个句柄。

uitable对象用于在图形窗口中显示数据表。

如果parent则创建适用于当前图形的图形。如果没有可用地物,将首先创建一个新地物。

如果parent则给出了一个uitable相对于parent已创建。

任何提供的属性值对都将覆盖创建的合适对象的默认值。

完整的属性清单记录在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

详见: figure,uicontrol.

 
:hui= uimenu (property,value, …)
:hui= uimenu (h,property,value, …)

创建一个uimenu对象并返回其句柄。

如果h则创建当前地物的顶级菜单。如果h然后给出一个子菜单h创建。

ui菜单对象具有以下特定属性:

"accelerator"

包含键和CTRL的字符串,用于执行此菜单项(例如。,"x"用于CTRL+x)。

"checked"

可以设置"on""off"。在此菜单项处设置符号。

"enable"

可以设置"on""off"。如果禁用,则无法选择菜单项,并且菜单项变灰。

"foregroundcolor"

菜单项文本的颜色值。

"menuselectedfcn"

执行此菜单项时调用的函数。它可以是函数串(例如。,"myfcn"),函数句柄(例如@myfcn)或包含回调函数的函数句柄和参数的元胞数组(例如{@myfcn,arg1,arg2})。

"position"

包含相对菜单位置的标量值。第一个位置的值为1,将是左侧或顶部,具体取决于ui菜单的方向。

"separator"

可以设置"on""off"。如果启用,则在当前位置上方绘制一条分隔线。对于顶层条目,此属性将被忽略。

"text"

包含此菜单项的文本的字符串。A."&"-符号可用于符号"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)");

详见: figure.

 
:hui= uicontextmenu (property,value, …)
:hui= uicontextmenu (h,property,value, …)

创建一个uicontextmenu对象并返回其句柄。

如果h则创建当前图形的uicontextmenu。如果没有可用地物,将首先创建一个新地物。

如果h则给出一个相对于的uicontextmenuh创建。

任何提供的属性值对都将覆盖已创建的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);

详见: figure,uimenu.

 
:hui= uitoolbar ()
:hui= uitoolbar (property,value, …)
:hui= uitoolbar (parent)
:hui= uitoolbar (parent,property,value, …)

创建一个uitoolbar对象。uitoolbar显示uioggletool和uipushtool按钮。

如果parent则为当前图形创建一个uitoolbar。如果没有可用地物,将首先创建一个新地物。

如果parent则给出一个相对于的uitoolbarparent已创建。

任何提供的属性值对都将覆盖已创建的uitoolbar对象的默认值。

完整的属性清单记录在Uitoolbar Properties.

可选返回值hui是createduitoolbar对象的图形句柄。

示例:

% create figure without a default toolbar
f = figure ("toolbar", "none");
% create empty toolbar
t = uitoolbar (f);

详见: figure,uitoggletool,uipushtool.

 
:hui= uipushtool ()
:hui= uipushtool (property,value, …)
:hui= uipushtool (parent)
:hui= uipushtool (parent,property,value, …)

创建uipushtool对象。

uipushtools是显示在地物工具栏上的按钮。创建的按钮带有一个边框,当用户将鼠标悬停在按钮上时会显示该边框。可以使用cdata属性设置图像。

如果parent则为当前图形创建一个uipushtool。如果没有可用地物,将首先创建一个新地物。如果图形可用,但不包含uitoolbar,则将创建uitoolbar。

如果parent则在上创建一个uipushtoolparentuitoolbar。

任何提供的属性值对都将覆盖已创建的uipushtool对象的默认值。

完整的属性清单记录在Uipushtool Properties.

可选返回值hui是createduipushtool对象的图形句柄。

示例:

% 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);

详见: figure,uitoolbar,uitoggletool.

 
:hui= uitoggletool ()
:hui= uitoggletool (property,value, …)
:hui= uitoggletool (parent)
:hui= uitoggletool (parent,property,value, …)

创建一个uitoggletol对象。

uitoggletol是显示在图形工具栏上的切换按钮。该按钮创建时带有一个边框,当用户将鼠标悬停在该按钮上方时会显示该边框。可以使用cdata属性设置图像。

如果parent则为当前图形创建一个uitoggletol。如果没有可用地物,将首先创建一个新地物。如果图形可用,但不包含uitoolbar,则将创建uitoolbar。

如果parent则在上创建uitoggletolparentuitoolbar。

任何提供的属性值对都将覆盖已创建的uitoggletool对象的默认值。

完整的属性清单记录在Uitoggletool Properties.

可选返回值hui是createduitoggletool对象的图形句柄。

示例:

% 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);

详见: figure,uitoolbar,uipushtool.


版权所有 © 2024-2025 Octave中文网

ICP备案/许可证号:黑ICP备2024030411号-1