Browse Source

Change UICatalog to use SplitContainer

tznind 2 years ago
parent
commit
dd246b74ae
1 changed files with 41 additions and 24 deletions
  1. 41 24
      UICatalog/UICatalog.cs

+ 41 - 24
UICatalog/UICatalog.cs

@@ -1,4 +1,4 @@
-using NStack;
+using NStack;
 using System;
 using System;
 using System.Collections.Generic;
 using System.Collections.Generic;
 using System.Diagnostics;
 using System.Diagnostics;
@@ -151,9 +151,9 @@ namespace UICatalog {
 			public MenuItem miIsMouseDisabled;
 			public MenuItem miIsMouseDisabled;
 			public MenuItem miHeightAsBuffer;
 			public MenuItem miHeightAsBuffer;
 
 
-			public FrameView LeftPane;
+			public FrameView ContentPane;
+			public SplitContainer SplitContainer;
 			public ListView CategoryListView;
 			public ListView CategoryListView;
-			public FrameView RightPane;
 			public ListView ScenarioListView;
 			public ListView ScenarioListView;
 
 
 			public StatusItem Capslock;
 			public StatusItem Capslock;
@@ -201,24 +201,29 @@ namespace UICatalog {
 					}),
 					}),
 					new StatusItem(Key.F10, "~F10~ Hide/Show Status Bar", () => {
 					new StatusItem(Key.F10, "~F10~ Hide/Show Status Bar", () => {
 						StatusBar.Visible = !StatusBar.Visible;
 						StatusBar.Visible = !StatusBar.Visible;
-						LeftPane.Height = Dim.Fill(StatusBar.Visible ? 1 : 0);
-						RightPane.Height = Dim.Fill(StatusBar.Visible ? 1 : 0);
+						ContentPane.Height = Dim.Fill(StatusBar.Visible ? 1 : 0);
 						LayoutSubviews();
 						LayoutSubviews();
 						SetChildNeedsDisplay();
 						SetChildNeedsDisplay();
 					}),
 					}),
 					DriverName,
 					DriverName,
 				};
 				};
 
 
-				LeftPane = new FrameView ("Categories") {
+				ContentPane = new FrameView ("Categories") {
 					X = 0,
 					X = 0,
 					Y = 1, // for menu
 					Y = 1, // for menu
-					Width = 25,
+					Width = Dim.Fill (),
 					Height = Dim.Fill (1),
 					Height = Dim.Fill (1),
 					CanFocus = true,
 					CanFocus = true,
 					Shortcut = Key.CtrlMask | Key.C
 					Shortcut = Key.CtrlMask | Key.C
 				};
 				};
-				LeftPane.Title = $"{LeftPane.Title} ({LeftPane.ShortcutTag})";
-				LeftPane.ShortcutAction = () => LeftPane.SetFocus ();
+				
+				ContentPane.ShortcutAction = () => ContentPane.SetFocus ();
+
+				SplitContainer = new SplitContainer {
+					Width = Dim.Fill (0),
+					Height = Dim.Fill (0),
+					SplitterDistance = 25
+				};
 
 
 				CategoryListView = new ListView (_categories) {
 				CategoryListView = new ListView (_categories) {
 					X = 0,
 					X = 0,
@@ -229,21 +234,19 @@ namespace UICatalog {
 					CanFocus = true,
 					CanFocus = true,
 				};
 				};
 				CategoryListView.OpenSelectedItem += (a) => {
 				CategoryListView.OpenSelectedItem += (a) => {
-					RightPane.SetFocus ();
+					ScenarioListView.SetFocus ();
 				};
 				};
 				CategoryListView.SelectedItemChanged += CategoryListView_SelectedChanged;
 				CategoryListView.SelectedItemChanged += CategoryListView_SelectedChanged;
-				LeftPane.Add (CategoryListView);
+				ContentPane.Add (SplitContainer);
 
 
-				RightPane = new FrameView ("Scenarios") {
-					X = 25,
-					Y = 1, // for menu
-					Width = Dim.Fill (),
-					Height = Dim.Fill (1),
-					CanFocus = true,
-					Shortcut = Key.CtrlMask | Key.S
+				SplitContainer.Panel1.Add (CategoryListView);
+
+				SetTitlePaddingToAlignScenariosHeader ();
+
+				SplitContainer.SplitterMoved += (s, e) => {
+					SetTitlePaddingToAlignScenariosHeader ();
 				};
 				};
-				RightPane.Title = $"{RightPane.Title} ({RightPane.ShortcutTag})";
-				RightPane.ShortcutAction = () => RightPane.SetFocus ();
+
 
 
 				ScenarioListView = new ListView () {
 				ScenarioListView = new ListView () {
 					X = 0,
 					X = 0,
@@ -255,12 +258,11 @@ namespace UICatalog {
 				};
 				};
 
 
 				ScenarioListView.OpenSelectedItem += ScenarioListView_OpenSelectedItem;
 				ScenarioListView.OpenSelectedItem += ScenarioListView_OpenSelectedItem;
-				RightPane.Add (ScenarioListView);
+				SplitContainer.Panel2.Add (ScenarioListView);
 
 
 				KeyDown += KeyDownHandler;
 				KeyDown += KeyDownHandler;
 				Add (MenuBar);
 				Add (MenuBar);
-				Add (LeftPane);
-				Add (RightPane);
+				Add (ContentPane);
 				Add (StatusBar);
 				Add (StatusBar);
 
 
 				Loaded += LoadedHandler;
 				Loaded += LoadedHandler;
@@ -270,6 +272,21 @@ namespace UICatalog {
 				ScenarioListView.SelectedItem = _cachedScenarioIndex;
 				ScenarioListView.SelectedItem = _cachedScenarioIndex;
 			}
 			}
 
 
+			private void SetTitlePaddingToAlignScenariosHeader ()
+			{ 
+				// Pos.Anchor is internal so we have to use reflection to access it
+				var anchor = typeof (Pos).GetMethod ("Anchor", BindingFlags.Instance | BindingFlags.NonPublic);
+				var splitterWidth = (int)anchor.Invoke (
+					SplitContainer.SplitterDistance, new object [] { SplitContainer.Bounds.Width}
+					);
+
+				var newTitle = $"Categories ({ContentPane.ShortcutTag})";
+				newTitle = newTitle.PadRight (splitterWidth + 1, (char)Driver.HLine);
+				newTitle += "Scenarios";
+
+				ContentPane.Title = newTitle;				
+			}
+
 			void LoadedHandler ()
 			void LoadedHandler ()
 			{
 			{
 				Application.HeightAsBuffer = _heightAsBuffer;
 				Application.HeightAsBuffer = _heightAsBuffer;
@@ -287,7 +304,7 @@ namespace UICatalog {
 					_isFirstRunning = false;
 					_isFirstRunning = false;
 				}
 				}
 				if (!_isFirstRunning) {
 				if (!_isFirstRunning) {
-					RightPane.SetFocus ();
+					ScenarioListView.SetFocus ();
 				}
 				}
 				Loaded -= LoadedHandler;
 				Loaded -= LoadedHandler;
 			}
 			}