title: Split pane gui object
body: <p>I've been developing a gui for some time, which requires the creation of common control objects that Mathematica lacks (e.g. spinner, treeview, openerbar, etc.). One is the multipanel, i.e. a pane object that is split into two (or more) subpanes, where the divider can be set by the mouse. Here is my version of a dual pane. I would like to hear your opinion and ideas about how to expand it to handle not just 2 but any number of subpanes, and also how to optimize it. At present, for heavily loaded subpanes, it lags terribly, no idea why.</p>
  
  <pre><code>Options[SplitPane] = {Direction -&gt; "Vertical", 
     DividerWidth -&gt; Automatic, Paneled -&gt; {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" -&gt; "Vertical", _ -&gt; 
         "Horizontal"};
     d = d /. Automatic -&gt; 2;
     split = If[NumberQ[split], split, max/2];
     val = Clip[split /. {_?NumberQ -&gt; split, _ -&gt; maxX/2}, {0, maxX}];
     {coord, max, fix} = 
      Switch[dir, "Vertical", {First, maxX, maxY}, 
       "Horizontal", {(max - Last[#]) &amp;, maxY, maxX}];
     panel = (# /. {None | False -&gt; 
            Identity, _ -&gt; (Panel[#, ImageMargins -&gt; 0, 
               FrameMargins -&gt; -1] &amp;)}) &amp; /@ panel;
  
     Grid[If[dir === "Vertical",
       {{
         Dynamic[
          panel[[1]]@
           Pane[expr1, ImageSize -&gt; {split - d, fix}, 
            ImageSizeAction -&gt; "Scrollable", Scrollbars -&gt; Automatic, 
            AppearanceElements -&gt; None], TrackedSymbols :&gt; {split}],
         Deploy@EventHandler[
           MouseAppearance[
            Pane[Null, ImageSize -&gt; {d*2, fix}, ImageMargins -&gt; -1, 
             FrameMargins -&gt; -1], "FrameLRResize"],
           "MouseDown" :&gt; (temp = 
              coord@MousePosition@"CellContentsAbsolute"; 
             split = 
              If[Abs[temp - split] &lt;= d \[And] 0 &lt;= temp &lt;= max, temp, 
               split]), 
           "MouseDragged" :&gt; (temp = 
              coord@MousePosition@"CellContentsAbsolute"; 
             split = If[0 &lt;= temp &lt;= max, temp, split])],
         Dynamic@
          panel[[2]]@
           Pane[expr2, ImageSizeAction -&gt; "Scrollable", 
            Scrollbars -&gt; Automatic, AppearanceElements -&gt; None, 
            ImageSize -&gt; {max - split - d, fix}]
         }},
       {
        List@
         Dynamic[panel[[1]]@
           Pane[expr1, ImageSize -&gt; {fix, split - d}, 
            ImageSizeAction -&gt; "Scrollable", Scrollbars -&gt; Automatic, 
            AppearanceElements -&gt; None], TrackedSymbols :&gt; {split}],
        List@Deploy@EventHandler[
           MouseAppearance[
            Pane[Null, ImageSize -&gt; {fix, d*2}, ImageMargins -&gt; -1, 
             FrameMargins -&gt; -1], "FrameTBResize"],
           "MouseDown" :&gt; (temp = 
              coord@MousePosition@"CellContentsAbsolute"; 
             split = 
              If[Abs[temp - split] &lt;= d \[And] 0 &lt;= temp &lt;= max, temp, 
               split]), 
           "MouseDragged" :&gt; (temp = 
              coord@MousePosition@"CellContentsAbsolute"; 
             split = If[0 &lt;= temp &lt;= max, temp, split])],
        List@
         Dynamic[panel[[2]]@
           Pane[expr2, ImageSizeAction -&gt; "Scrollable", 
            Scrollbars -&gt; Automatic, 
            ImageSize -&gt; {fix, max - split - d}, 
            AppearanceElements -&gt; None], TrackedSymbols :&gt; {split}]
        }
       ], Spacings -&gt; {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}]
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/ukQ2H.png" alt="SplitPane output"></p>