是否有用于使用通用布局创建用户界面的简单 octave/matlab 工具包?

Is there a simple octave/matlab toolkit for user interface creation with generic layout?

最先进

Octave 允许创建用户界面。虽然 matlab 提供了 GUIDE 用于图形设计和用户界面编辑的复杂工具,但 Octave 没有这样的工具。相反,您必须通过在 ui window 坐标系中指定数字坐标来手动放置 ui 元素。

另一方面,该领域有许多用于用户界面的布局引擎,例如 qt 甚至 x-windowsandroidhtml 的网络浏览器。所以这个问题已经解决了很多次了。

请求的解决方案

我正在寻找一种解决方案,允许在 table 或网格布局中通用放置用户界面组件。

我想象使用像 html tables 这样的布局引擎。您定义一个 table ,其中每个单元格放置一个 ui 元素。为了获得一定的灵活性,您可以创建跨越多列或多行的组合单元格。

每个单元格都应自动调整大小以至少适合内部元素并平均分布元素。布局选项允许在一个单元格中定位 ui 个元素。

当然可以通过在 table 单元格中放置一个新的 table 来创建嵌套结构。

伪代码

这里有一些伪代码如何定义 ui。

ui = cell(2,2);
addUIElement(ui, 1,1, uicontrol("style", "text", "string", "This is text"));
addUIElement(ui, 1,2, uicontrol("style", "text", "string", "This is another text"));
addUIElement(ui, 2,1, uicontrol ("style", "pushbutton", "string", "Push me");
addUIElement(ui, 2,2, uicontrol ("style", "pushbutton", "string", "Push me too");
% Create and draw the user interface
gui = CreatGui(ui); 

备注

问题

对于使用现有代码在 Octave 中实现是否有任何建议?

我不知道 'package' 可以做到这一点,但这是一个模拟简单 'layout' 方法的简短示例。
(为简洁起见省略了通常的完整性检查)。

function guitesto
  ui      = cell(2,2);
  layout  = defineLayout (size (ui));  

  ui{1,1} = uicontrol ("style", "text", "string", "This is text");
  ui{1,2} = uicontrol ("style", "text", "string", "This is another text");
  ui{2,1} = uicontrol ("style", "pushbutton", "string", "Push me");
  ui{2,2} = uicontrol ("style", "pushbutton", "string", "Push me too");

  applyLayout (ui, layout)
end

function Out = defineLayout (Gridsize)
  VGridCoords = linspace (0, 1, Gridsize(1) + 1);
  HGridCoords = linspace (0, 1, Gridsize(2) + 1);
  Out = cell();
  for Row = 1 : Gridsize(1), for Col = 1 : Gridsize(2)
    Out{Row, Col} = [HGridCoords(Col), ...
                     1 - VGridCoords(Row+1), ...
                     HGridCoords(Col+1) - HGridCoords(Col), ...
                     VGridCoords(Row+1) - VGridCoords(Row)];
  end, end
end

function applyLayout (ui, layout)
  for Row = 1 : size (ui, 1), for Col = 1: size (ui, 2)
    set (ui{Row, Col}, 'units'   , 'normalized', ...
                       'position', layout{Row, Col});
  end, end
end

未完成,'subgrids'问题留给大家,但实现起来应该不会太难。话虽如此,matlab / octave 上没有 "abstract box" 功能(有 hggroups,但那是不同的东西,我不确定它是否可以用于容纳 uicontrols),所以子网格 必须在坐标级别实施。


但是,我觉得有必要对这个问题挑剔。首先,提到了GUIDE,但我觉得这里无关紧要。除了允许您通过视觉网格直观地放置东西外,这不是布局管理器。至少不是在你暗示的意义上。

其次,没有布局管理器这样的东西。 Java 有大约十亿种不同的布局管理器可供选择(从 Flow 到 Gridded 到 Boxed 到任何东西,包括 'Absolute' 基本上就像八度)。 Html 使用特定的 'flow' 方法,因为它适合重排文本。

所以布局管理器只是一组任意规则,处理相对于绝对定位的转换,并可能处理调整大小。 Octave 已经内置了一些,例如在像素与标准化单位之间进行选择,以及每个图形对象内置的调整大小回调功能。我发现可以通过 'normalized' 单位系统非常简单地做你想做的事,而且不需要像 Java 这样复杂的布局管理器......但是如果你喜欢 'grids',然后翻译如上所示,前者到后者应该相对容易。