He estado desarrollando una interfaz gráfica de usuario durante algún tiempo, lo que requiere la creación de objetos de control comunes que Mathematica carece (por ejemplo, spinner, treeview, openerbar, etc.). Uno es el multipanel, es decir, un objeto de panel que se divide en dos (o más) subpanes, donde el divisor se puede establecer con el mouse. Aquí está mi versión de un panel doble. Me gustaría escuchar su opinión e ideas sobre cómo expandirla para manejar no solo 2 sino también cualquier cantidad de subpanes, y también cómo optimizarlos. En la actualidad, para los subpanes con mucha carga, está muy rezagado, ni idea de por qué.Objeto gui de panel dividido
Options[SplitPane] = {Direction -> "Vertical",
DividerWidth -> Automatic, Paneled -> {True, True}};
SplitPane[opts___?OptionQ] :=
Module[{dummy}, SplitPane[Dynamic[dummy], opts]];
SplitPane[val_, opts___?OptionQ] := SplitPane[val, {"", ""}, opts];
SplitPane[val_, content_, opts___?OptionQ] :=
SplitPane[val, content, {100, 50}, opts];
SplitPane[Dynamic[split_, arg___], {expr1_, expr2_}, {maxX_, maxY_},
opts___?OptionQ] :=
DynamicModule[{temp, dir, d, panel, coord, max, fix, val},
{dir, d, panel} = {Direction, DividerWidth, Paneled} /. {opts} /.
Options[SplitPane];
dir = dir /. {Bottom | Top | "Vertical" -> "Vertical", _ ->
"Horizontal"};
d = d /. Automatic -> 2;
split = If[NumberQ[split], split, max/2];
val = Clip[split /. {_?NumberQ -> split, _ -> maxX/2}, {0, maxX}];
{coord, max, fix} =
Switch[dir, "Vertical", {First, maxX, maxY},
"Horizontal", {(max - Last[#]) &, maxY, maxX}];
panel = (# /. {None | False ->
Identity, _ -> (Panel[#, ImageMargins -> 0,
FrameMargins -> -1] &)}) & /@ panel;
Grid[If[dir === "Vertical",
{{
Dynamic[
panel[[1]]@
Pane[expr1, ImageSize -> {split - d, fix},
ImageSizeAction -> "Scrollable", Scrollbars -> Automatic,
AppearanceElements -> None], TrackedSymbols :> {split}],
[email protected][
MouseAppearance[
Pane[Null, ImageSize -> {d*2, fix}, ImageMargins -> -1,
FrameMargins -> -1], "FrameLRResize"],
"MouseDown" :> (temp =
[email protected]@"CellContentsAbsolute";
split =
If[Abs[temp - split] <= d \[And] 0 <= temp <= max, temp,
split]),
"MouseDragged" :> (temp =
[email protected]@"CellContentsAbsolute";
split = If[0 <= temp <= max, temp, split])],
[email protected]
panel[[2]]@
Pane[expr2, ImageSizeAction -> "Scrollable",
Scrollbars -> Automatic, AppearanceElements -> None,
ImageSize -> {max - split - d, fix}]
}},
{
[email protected]
Dynamic[panel[[1]]@
Pane[expr1, ImageSize -> {fix, split - d},
ImageSizeAction -> "Scrollable", Scrollbars -> Automatic,
AppearanceElements -> None], TrackedSymbols :> {split}],
[email protected]@EventHandler[
MouseAppearance[
Pane[Null, ImageSize -> {fix, d*2}, ImageMargins -> -1,
FrameMargins -> -1], "FrameTBResize"],
"MouseDown" :> (temp =
[email protected]@"CellContentsAbsolute";
split =
If[Abs[temp - split] <= d \[And] 0 <= temp <= max, temp,
split]),
"MouseDragged" :> (temp =
[email protected]@"CellContentsAbsolute";
split = If[0 <= temp <= max, temp, split])],
[email protected]
Dynamic[panel[[2]]@
Pane[expr2, ImageSizeAction -> "Scrollable",
Scrollbars -> Automatic,
ImageSize -> {fix, max - split - d},
AppearanceElements -> None], TrackedSymbols :> {split}]
}
], Spacings -> {0, -.1}]
];
SplitPane[val_, arg___] /; NumberQ[val] :=
Module[{x = val}, SplitPane[Dynamic[x], arg]];
pos = 300;
SplitPane[
Dynamic[pos], {Manipulate[
Plot[Sin[x (1 + a x)], {x, 0, 6}], {a, 0, 2}],
Factorial[123]}, {500, 300}]
¡Bastante impresionante! En cuanto a la optimización: ¿qué hay de usar ControlActive y/o la opción SynchronousUpdating? –
Muy buen trabajo, pero tenga en cuenta que el formato de su "pregunta" no es una buena opción para el sitio. La comunidad Mma aquí es generalmente permisiva al respecto, pero trate de formular sus preguntas de acuerdo con las reglas generales del sitio para evitar cerrar (y eliminar) los votos. –