SplitView.cs 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using Terminal.Gui.Graphs;
  5. namespace Terminal.Gui {
  6. /// <summary>
  7. /// A <see cref="View"/> consisting of a moveable bar that divides
  8. /// the display area into resizeable views.
  9. /// </summary>
  10. public class SplitView : View {
  11. SplitView parentSplitView;
  12. /// TODO: Might be able to make Border virtual and override here
  13. /// To make this more API friendly
  14. /// <summary>
  15. /// Use this field instead of Border to create an integrated
  16. /// Border in which lines connect with subviews and splitters
  17. /// seamlessly
  18. /// </summary>
  19. public BorderStyle IntegratedBorder { get; set; }
  20. public class Tile {
  21. public View View { get; internal set; }
  22. public int MinSize { get; set; }
  23. public string Title { get; set; }
  24. public Tile ()
  25. {
  26. View = new View () { Width = Dim.Fill (), Height = Dim.Fill () };
  27. Title = string.Empty;
  28. MinSize = 0;
  29. }
  30. }
  31. List<Tile> tiles;
  32. private List<Pos> splitterDistances;
  33. private List<SplitContainerLineView> splitterLines;
  34. /// <summary>
  35. /// The sub sections hosted by the view
  36. /// </summary>
  37. public IReadOnlyCollection<Tile> Tiles => tiles.AsReadOnly ();
  38. /// <summary>
  39. /// The splitter locations. Note that there will be N-1 splitters where
  40. /// N is the number of <see cref="Tiles"/>.
  41. /// </summary>
  42. public IReadOnlyCollection<Pos> SplitterDistances => splitterDistances.AsReadOnly ();
  43. private Orientation orientation = Orientation.Vertical;
  44. /// <summary>
  45. /// Creates a new instance of the SplitContainer class.
  46. /// </summary>
  47. public SplitView () : this (2)
  48. {
  49. }
  50. public SplitView (int tiles)
  51. {
  52. CanFocus = true;
  53. RebuildForTileCount (tiles);
  54. }
  55. /// <summary>
  56. /// Invoked when the <see cref="SplitterDistance"/> is changed
  57. /// </summary>
  58. public event SplitterEventHandler SplitterMoved;
  59. /// <summary>
  60. /// Raises the <see cref="SplitterMoved"/> event
  61. /// </summary>
  62. protected virtual void OnSplitterMoved (int idx)
  63. {
  64. SplitterMoved?.Invoke (this, new SplitterEventArgs (this, idx, splitterDistances [idx]));
  65. }
  66. /// <summary>
  67. /// Scraps all <see cref="Tiles"/> and creates <paramref name="count"/> new tiles
  68. /// in orientation <see cref="Orientation"/>
  69. /// </summary>
  70. /// <param name="count"></param>
  71. public void RebuildForTileCount (int count)
  72. {
  73. tiles = new List<Tile> ();
  74. // TODO: keep these if growing
  75. splitterDistances = new List<Pos> ();
  76. splitterLines = new List<SplitContainerLineView> ();
  77. RemoveAll ();
  78. tiles.Clear ();
  79. splitterDistances.Clear ();
  80. if (count == 0) {
  81. return;
  82. }
  83. for (int i = 0; i < count; i++) {
  84. var tile = new Tile ();
  85. tiles.Add (tile);
  86. Add (tile.View);
  87. if (i > 0) {
  88. var currentPos = Pos.Percent ((100 / count) * i);
  89. splitterDistances.Add (currentPos);
  90. var line = new SplitContainerLineView (this, i-1);
  91. Add (line);
  92. splitterLines.Add (line);
  93. }
  94. }
  95. LayoutSubviews ();
  96. }
  97. /// <summary>
  98. /// Orientation of the dividing line (Horizontal or Vertical).
  99. /// </summary>
  100. public Orientation Orientation {
  101. get { return orientation; }
  102. set {
  103. orientation = value;
  104. LayoutSubviews ();
  105. }
  106. }
  107. public override void LayoutSubviews ()
  108. {
  109. var contentArea = Bounds;
  110. if (HasBorder ()) {
  111. // TODO: Bound with Max/Min
  112. contentArea = new Rect (
  113. contentArea.X + 1,
  114. contentArea.Y + 1,
  115. Math.Max (0, contentArea.Width - 2),
  116. Math.Max (0, contentArea.Height - 2));
  117. } else if (HasAnyTitles () && IsRootSplitContainer ()) {
  118. // TODO: Bound with Max/Min
  119. contentArea = new Rect (
  120. contentArea.X,
  121. contentArea.Y + 1,
  122. contentArea.Width,
  123. Math.Max (0, contentArea.Height - 1));
  124. }
  125. Setup (contentArea);
  126. base.LayoutSubviews ();
  127. }
  128. /// <summary>
  129. /// <para>Distance Horizontally or Vertically to the splitter line when
  130. /// neither view is collapsed.
  131. /// </para>
  132. /// <para>Only absolute values (e.g. 10) and percent values (i.e. <see cref="Pos.Percent(float)"/>)
  133. /// are supported for this property.</para>
  134. /// </summary>
  135. public void SetSplitterPos (int idx, Pos value)
  136. {
  137. if (!(value is Pos.PosAbsolute) && !(value is Pos.PosFactor)) {
  138. throw new ArgumentException ($"Only Percent and Absolute values are supported. Passed value was {value.GetType ().Name}");
  139. }
  140. splitterDistances [idx] = value;
  141. GetRootSplitContainer ().LayoutSubviews ();
  142. OnSplitterMoved (idx);
  143. }
  144. /// <inheritdoc/>
  145. public override bool OnEnter (View view)
  146. {
  147. Driver.SetCursorVisibility (CursorVisibility.Invisible);
  148. return base.OnEnter (view);
  149. }
  150. /// <inheritdoc/>
  151. public override void Redraw (Rect bounds)
  152. {
  153. var childTitles = new List<ChildSplitterLine> ();
  154. Driver.SetAttribute (ColorScheme.Normal);
  155. Clear ();
  156. base.Redraw (bounds);
  157. var lc = new LineCanvas ();
  158. var allLines = GetAllChildSplitContainerLineViewRecursively (this);
  159. if (IsRootSplitContainer ()) {
  160. if (HasBorder ()) {
  161. lc.AddLine (new Point (0, 0), bounds.Width - 1, Orientation.Horizontal, IntegratedBorder);
  162. lc.AddLine (new Point (0, 0), bounds.Height - 1, Orientation.Vertical, IntegratedBorder);
  163. lc.AddLine (new Point (bounds.Width - 1, bounds.Height - 1), -bounds.Width + 1, Orientation.Horizontal, IntegratedBorder);
  164. lc.AddLine (new Point (bounds.Width - 1, bounds.Height - 1), -bounds.Height + 1, Orientation.Vertical, IntegratedBorder);
  165. }
  166. foreach (var line in allLines.Where (l => l.Visible)) {
  167. bool isRoot = splitterLines.Contains (line);
  168. line.ViewToScreen (0, 0, out var x1, out var y1);
  169. var origin = ScreenToView (x1, y1);
  170. var length = line.Orientation == Orientation.Horizontal ?
  171. line.Frame.Width - 1 :
  172. line.Frame.Height - 1;
  173. if (!isRoot) {
  174. if (line.Orientation == Orientation.Horizontal) {
  175. origin.X -= 1;
  176. } else {
  177. origin.Y -= 1;
  178. }
  179. length += 2;
  180. childTitles.Add (
  181. new ChildSplitterLine (line));
  182. }
  183. lc.AddLine (origin, length, line.Orientation, IntegratedBorder);
  184. }
  185. }
  186. Driver.SetAttribute (ColorScheme.Normal);
  187. lc.Draw (this, bounds);
  188. // Redraw the lines so that focus/drag symbol renders
  189. foreach (var line in allLines) {
  190. line.DrawSplitterSymbol ();
  191. }
  192. foreach (var child in childTitles) {
  193. child.DrawTitles ();
  194. }
  195. // Draw Titles over Border
  196. for (int i = 0; i < tiles.Count; i++) {
  197. var tile = tiles [i];
  198. if (tile.View.Visible && tile.Title.Length > 0) {
  199. var screen = i == 0 ?
  200. ViewToScreen (new Rect (0, 0, bounds.Width, 1)) :
  201. ViewToScreen (splitterLines [i - 1].Frame);
  202. Driver.SetAttribute (tile.View.HasFocus ? ColorScheme.HotNormal : ColorScheme.Normal);
  203. Driver.DrawWindowTitle (new Rect (screen.X, screen.Y, tile.View.Frame.Width, 0), tile.Title, 0, 0, 0, 0);
  204. }
  205. }
  206. }
  207. /// <summary>
  208. /// Converts <see cref="View1"/> from a regular <see cref="View"/>
  209. /// container to a new nested <see cref="SplitView"/>. If <see cref="View1"/>
  210. /// is already a <see cref="SplitView"/> then returns false.
  211. /// </summary>
  212. /// <remarks>After successful splitting, the returned container's <see cref="View1"/>
  213. /// will contain the original content and <see cref="View1Title"/> (if any) while
  214. /// <see cref="View2"/> will be empty and available for adding to.
  215. /// for adding to.</remarks>
  216. /// <param name="result">The new <see cref="SplitView"/> now showing in
  217. /// <see cref="View1"/> or the existing one if it was already been converted before.</param>
  218. /// <returns><see langword="true"/> if a <see cref="View"/> was converted to a new nested
  219. /// <see cref="SplitView"/>. <see langword="false"/> if it was already a nested
  220. /// <see cref="SplitView"/></returns>
  221. public bool TrySplitView(int idx, out SplitView result)
  222. {
  223. // when splitting a view into 2 sub views we will need to migrate
  224. // the title too
  225. var tile = tiles [idx];
  226. var title = tile.Title;
  227. View toMove = tile.View;
  228. if (toMove is SplitView existing) {
  229. result = existing;
  230. return false;
  231. }
  232. var newContainer = new SplitView {
  233. Width = Dim.Fill (),
  234. Height = Dim.Fill (),
  235. parentSplitView = this,
  236. };
  237. // Take everything out of the View we are moving
  238. var childViews = toMove.Subviews.ToArray();
  239. toMove.RemoveAll ();
  240. // Remove the view itself and replace it with the new SplitContainer
  241. Remove (toMove);
  242. Add (newContainer);
  243. tile.View = newContainer;
  244. var newTileView1 = newContainer.tiles [0].View;
  245. // Add the original content into the first view of the new container
  246. foreach (var childView in childViews) {
  247. newTileView1.Add (childView);
  248. }
  249. result = newContainer;
  250. return true;
  251. }
  252. private List<SplitContainerLineView> GetAllChildSplitContainerLineViewRecursively (View v)
  253. {
  254. var lines = new List<SplitContainerLineView> ();
  255. foreach (var sub in v.Subviews) {
  256. if (sub is SplitContainerLineView s) {
  257. if (s.Parent.GetRootSplitContainer () == this) {
  258. lines.Add (s);
  259. }
  260. } else {
  261. lines.AddRange (GetAllChildSplitContainerLineViewRecursively (sub));
  262. }
  263. }
  264. return lines;
  265. }
  266. private bool IsRootSplitContainer ()
  267. {
  268. // TODO: don't want to layout subviews since the parent recursively lays them all out
  269. return parentSplitView == null;
  270. }
  271. private SplitView GetRootSplitContainer ()
  272. {
  273. SplitView root = this;
  274. while (root.parentSplitView != null) {
  275. root = root.parentSplitView;
  276. }
  277. return root;
  278. }
  279. private void Setup (Rect bounds)
  280. {
  281. if (bounds.IsEmpty) {
  282. return;
  283. }
  284. for (int i = 0; i < splitterLines.Count; i++) {
  285. var line = splitterLines[i];
  286. line.Orientation = Orientation;
  287. line.Width = orientation == Orientation.Vertical
  288. ? 1 : Dim.Fill ();
  289. line.Height = orientation == Orientation.Vertical
  290. ? Dim.Fill () : 1;
  291. line.LineRune = orientation == Orientation.Vertical ?
  292. Driver.VLine : Driver.HLine;
  293. if (orientation == Orientation.Vertical) {
  294. line.X = splitterDistances [i];
  295. line.Y = 0;
  296. }
  297. else {
  298. line.Y = splitterDistances [i];
  299. line.X = 0;
  300. }
  301. }
  302. RespectMinimumTileSizes ();
  303. for (int i = 0; i < tiles.Count; i++) {
  304. var tile = tiles [i];
  305. // TODO: Deal with lines being Visibility false
  306. if (Orientation == Orientation.Vertical) {
  307. tile.View.X = i == 0 ? bounds.X : Pos.Right (splitterLines [i - 1]);
  308. tile.View.Y = bounds.Y;
  309. tile.View.Height = bounds.Height;
  310. // Take a copy so it is const for the lamda
  311. int i2 = i;
  312. // if it is not the last tile then fill horizontally right to next line
  313. tile.View.Width = i + 1 < tiles.Count
  314. ? new Dim.DimFunc (
  315. () => splitterDistances [i2].Anchor (bounds.Width))
  316. : Dim.Fill (HasBorder () ? 1 : 0);
  317. } else {
  318. tile.View.X = bounds.X;
  319. tile.View.Y = i == 0 ? 0 : Pos.Bottom (splitterLines [i - 1]);
  320. tile.View.Width = bounds.Width;
  321. // Take a copy so it is const for the lamda
  322. int i2 = i;
  323. // if it is not the last tile then fill vertically down to next line
  324. tile.View.Height = i + 1 < tiles.Count
  325. ? new Dim.DimFunc (
  326. () => splitterDistances [i2].Anchor (bounds.Height))
  327. : Dim.Fill (HasBorder () ? 1 : 0);
  328. }
  329. }
  330. }
  331. private void RespectMinimumTileSizes ()
  332. {
  333. // TODO: implement this
  334. /*
  335. // if we are not yet initialized then we don't know
  336. // how big we are and therefore cannot sensibly calculate
  337. // how big the views will be with a given SplitterDistance
  338. if (!IsInitialized) {
  339. return pos;
  340. }
  341. var view1MinSize = View1MinSize;
  342. var view2MinSize = View2MinSize;
  343. // how much space is there?
  344. var availableSpace = Orientation == Orientation.Horizontal
  345. ? this.Bounds.Height
  346. : this.Bounds.Width;
  347. // if there is a border then there is less space
  348. // for the views so we need to make size restrictions
  349. // tighter.
  350. if (HasBorder ()) {
  351. view1MinSize++;
  352. view2MinSize++;
  353. }
  354. // we probably haven't finished layout even if IsInitialized is true :(
  355. if (availableSpace <= 0) {
  356. return pos;
  357. }
  358. var idealPosition = pos.Anchor (availableSpace);
  359. // bad position because not enough space for View1
  360. if (idealPosition < view1MinSize) {
  361. // TODO: we should preserve Absolute/Percent status here not just force it to absolute
  362. return (Pos)Math.Min (view1MinSize, availableSpace);
  363. }
  364. // bad position because not enough space for View2
  365. if (availableSpace - idealPosition <= view2MinSize) {
  366. // TODO: we should preserve Absolute/Percent status here not just force it to absolute
  367. // +1 is to allow space for the splitter
  368. return (Pos)Math.Max (availableSpace - (view2MinSize + 1), 0);
  369. }
  370. // this splitter position is fine, there is enough space for everyone
  371. return pos;*/
  372. }
  373. private class SplitContainerLineView : LineView {
  374. public SplitView Parent { get; private set; }
  375. public int Idx { get; }
  376. Point? dragPosition;
  377. Pos dragOrignalPos;
  378. public Point? moveRuneRenderLocation;
  379. public SplitContainerLineView (SplitView parent, int idx)
  380. {
  381. CanFocus = true;
  382. TabStop = true;
  383. this.Parent = parent;
  384. Idx = idx;
  385. base.AddCommand (Command.Right, () => {
  386. return MoveSplitter (1, 0);
  387. });
  388. base.AddCommand (Command.Left, () => {
  389. return MoveSplitter (-1, 0);
  390. });
  391. base.AddCommand (Command.LineUp, () => {
  392. return MoveSplitter (0, -1);
  393. });
  394. base.AddCommand (Command.LineDown, () => {
  395. return MoveSplitter (0, 1);
  396. });
  397. AddKeyBinding (Key.CursorRight, Command.Right);
  398. AddKeyBinding (Key.CursorLeft, Command.Left);
  399. AddKeyBinding (Key.CursorUp, Command.LineUp);
  400. AddKeyBinding (Key.CursorDown, Command.LineDown);
  401. }
  402. public override bool ProcessKey (KeyEvent kb)
  403. {
  404. if (!CanFocus || !HasFocus) {
  405. return base.ProcessKey (kb);
  406. }
  407. var result = InvokeKeybindings (kb);
  408. if (result != null)
  409. return (bool)result;
  410. return base.ProcessKey (kb);
  411. }
  412. public override void PositionCursor ()
  413. {
  414. base.PositionCursor ();
  415. var location = moveRuneRenderLocation ??
  416. new Point (Bounds.Width / 2, Bounds.Height / 2);
  417. Move (location.X, location.Y);
  418. }
  419. public override bool OnEnter (View view)
  420. {
  421. Driver.SetCursorVisibility (CursorVisibility.Default);
  422. PositionCursor ();
  423. return base.OnEnter (view);
  424. }
  425. public override void Redraw (Rect bounds)
  426. {
  427. base.Redraw (bounds);
  428. DrawSplitterSymbol ();
  429. }
  430. public void DrawSplitterSymbol ()
  431. {
  432. if (CanFocus && HasFocus) {
  433. var location = moveRuneRenderLocation ??
  434. new Point (Bounds.Width / 2, Bounds.Height / 2);
  435. AddRune (location.X, location.Y, Driver.Diamond);
  436. }
  437. }
  438. public override bool MouseEvent (MouseEvent mouseEvent)
  439. {
  440. if (!CanFocus) {
  441. return true;
  442. }
  443. if (!dragPosition.HasValue && (mouseEvent.Flags == MouseFlags.Button1Pressed)) {
  444. // Start a Drag
  445. SetFocus ();
  446. Application.EnsuresTopOnFront ();
  447. if (mouseEvent.Flags == MouseFlags.Button1Pressed) {
  448. dragPosition = new Point (mouseEvent.X, mouseEvent.Y);
  449. dragOrignalPos = Orientation == Orientation.Horizontal ? Y : X;
  450. Application.GrabMouse (this);
  451. if (Orientation == Orientation.Horizontal) {
  452. } else {
  453. moveRuneRenderLocation = new Point (0, Math.Max (1, Math.Min (Bounds.Height - 2, mouseEvent.Y)));
  454. }
  455. }
  456. return true;
  457. } else if (
  458. dragPosition.HasValue &&
  459. (mouseEvent.Flags == (MouseFlags.Button1Pressed | MouseFlags.ReportMousePosition))) {
  460. // Continue Drag
  461. // how far has user dragged from original location?
  462. if (Orientation == Orientation.Horizontal) {
  463. int dy = mouseEvent.Y - dragPosition.Value.Y;
  464. Parent.splitterDistances [Idx] = Offset (Y, dy);
  465. moveRuneRenderLocation = new Point (mouseEvent.X, 0);
  466. } else {
  467. int dx = mouseEvent.X - dragPosition.Value.X;
  468. Parent.splitterDistances [Idx] = Offset (X, dx);
  469. moveRuneRenderLocation = new Point (0, Math.Max (1, Math.Min (Bounds.Height - 2, mouseEvent.Y)));
  470. }
  471. Parent.SetNeedsDisplay ();
  472. return true;
  473. }
  474. if (mouseEvent.Flags.HasFlag (MouseFlags.Button1Released) && dragPosition.HasValue) {
  475. // End Drag
  476. Application.UngrabMouse ();
  477. Driver.UncookMouse ();
  478. FinalisePosition (
  479. dragOrignalPos,
  480. Orientation == Orientation.Horizontal ? Y : X);
  481. dragPosition = null;
  482. moveRuneRenderLocation = null;
  483. }
  484. return false;
  485. }
  486. private bool MoveSplitter (int distanceX, int distanceY)
  487. {
  488. if (Orientation == Orientation.Vertical) {
  489. // Cannot move in this direction
  490. if (distanceX == 0) {
  491. return false;
  492. }
  493. var oldX = X;
  494. FinalisePosition (oldX, (Pos)Offset (X, distanceX));
  495. return true;
  496. } else {
  497. // Cannot move in this direction
  498. if (distanceY == 0) {
  499. return false;
  500. }
  501. var oldY = Y;
  502. FinalisePosition (oldY, (Pos)Offset (Y, distanceY));
  503. return true;
  504. }
  505. }
  506. private Pos Offset (Pos pos, int delta)
  507. {
  508. var posAbsolute = pos.Anchor (Orientation == Orientation.Horizontal ?
  509. Parent.Bounds.Height : Parent.Bounds.Width);
  510. return posAbsolute + delta;
  511. }
  512. /// <summary>
  513. /// <para>
  514. /// Moves <see cref="Parent"/> <see cref="SplitView.SplitterDistance"/> to
  515. /// <see cref="Pos"/> <paramref name="newValue"/> preserving <see cref="Pos"/> format
  516. /// (absolute / relative) that <paramref name="oldValue"/> had.
  517. /// </para>
  518. /// <remarks>This ensures that if splitter location was e.g. 50% before and you move it
  519. /// to absolute 5 then you end up with 10% (assuming a parent had 50 width). </remarks>
  520. /// </summary>
  521. /// <param name="oldValue"></param>
  522. /// <param name="newValue"></param>
  523. private void FinalisePosition (Pos oldValue, Pos newValue)
  524. {
  525. if (oldValue is Pos.PosFactor) {
  526. if (Orientation == Orientation.Horizontal) {
  527. Parent.SetSplitterPos(Idx, ConvertToPosFactor (newValue, Parent.Bounds.Height));
  528. } else {
  529. Parent.SetSplitterPos (Idx, ConvertToPosFactor (newValue, Parent.Bounds.Width));
  530. }
  531. } else {
  532. Parent.SetSplitterPos (Idx, newValue);
  533. }
  534. }
  535. /// <summary>
  536. /// <para>
  537. /// Determines the absolute position of <paramref name="p"/> and
  538. /// returns a <see cref="Pos.PosFactor"/> that describes the percentage of that.
  539. /// </para>
  540. /// <para>Effectively turning any <see cref="Pos"/> into a <see cref="Pos.PosFactor"/>
  541. /// (as if created with <see cref="Pos.Percent(float)"/>)</para>
  542. /// </summary>
  543. /// <param name="p">The <see cref="Pos"/> to convert to <see cref="Pos.Percent(float)"/></param>
  544. /// <param name="parentLength">The Height/Width that <paramref name="p"/> lies within</param>
  545. /// <returns></returns>
  546. private Pos ConvertToPosFactor (Pos p, int parentLength)
  547. {
  548. // calculate position in the 'middle' of the cell at p distance along parentLength
  549. float position = p.Anchor (parentLength) + 0.5f;
  550. return new Pos.PosFactor (position / parentLength);
  551. }
  552. }
  553. private bool HasBorder ()
  554. {
  555. return IntegratedBorder != BorderStyle.None;
  556. }
  557. private bool HasAnyTitles ()
  558. {
  559. return tiles.Any (t => t.Title.Length > 0);
  560. }
  561. private class ChildSplitterLine {
  562. readonly SplitContainerLineView currentLine;
  563. internal ChildSplitterLine (SplitContainerLineView currentLine)
  564. {
  565. this.currentLine = currentLine;
  566. }
  567. internal void DrawTitles ()
  568. {
  569. //TODO: Implement this
  570. /*if(currentLine.Orientation == Orientation.Horizontal)
  571. {
  572. var screenRect = currentLine.ViewToScreen (
  573. new Rect(0,0,currentLine.Frame.Width,currentLine.Frame.Height));
  574. Driver.DrawWindowTitle (screenRect, currentLine.Parent.View2Title, 0, 0, 0, 0);
  575. }*/
  576. }
  577. }
  578. }
  579. /// <summary>
  580. /// Provides data for <see cref="SplitContainer"/> events.
  581. /// </summary>
  582. public class SplitterEventArgs : EventArgs {
  583. /// <summary>
  584. /// Creates a new instance of the <see cref="SplitterEventArgs"/> class.
  585. /// </summary>
  586. /// <param name="splitContainer"></param>
  587. /// <param name="splitterDistance"></param>
  588. public SplitterEventArgs (SplitView splitContainer, int idx, Pos splitterDistance)
  589. {
  590. SplitterDistance = splitterDistance;
  591. SplitContainer = splitContainer;
  592. Idx = idx;
  593. }
  594. /// <summary>
  595. /// New position of the <see cref="SplitView.SplitterDistance"/>
  596. /// </summary>
  597. public Pos SplitterDistance { get; }
  598. /// <summary>
  599. /// Container (sender) of the event.
  600. /// </summary>
  601. public SplitView SplitContainer { get; }
  602. /// <summary>
  603. /// The splitter that is being moved (use when <see cref="SplitContainer"/>
  604. /// has more than 2 panels).
  605. /// </summary>
  606. public int Idx { get; }
  607. }
  608. /// <summary>
  609. /// Represents a method that will handle splitter events.
  610. /// </summary>
  611. public delegate void SplitterEventHandler (object sender, SplitterEventArgs e);
  612. }