Browse Source

Keyboard resizing of split container mostly working

tznind 2 years ago
parent
commit
e430ad8eab
2 changed files with 53 additions and 2 deletions
  1. 50 2
      Terminal.Gui/Views/SplitContainer.cs
  2. 3 0
      UICatalog/Scenarios/SplitContainerExample.cs

+ 50 - 2
Terminal.Gui/Views/SplitContainer.cs

@@ -223,10 +223,58 @@ namespace Terminal.Gui {
 			// TODO: Make focusable and allow moving with keyboard
 			public SplitContainerLineView(SplitContainer parent)
 			{
-				CanFocus = true;	
+				CanFocus = true;
 				this.parent = parent;
+
+				base.AddCommand (Command.Right, () => {
+					if (Orientation == Orientation.Vertical) {
+						parent.SplitterDistance = Offset (X, 1);
+						return true;
+					}
+					return false;
+				});
+
+				base.AddCommand (Command.Left, () => {
+					if (Orientation == Orientation.Vertical) {
+						parent.SplitterDistance = Offset (X, -1);
+						return true;
+					}
+					return false;
+				});
+
+				base.AddCommand (Command.LineUp, () => {
+					if (Orientation == Orientation.Horizontal) {
+						parent.SplitterDistance = Offset (Y, -1);
+						return true;
+					}
+					return false;
+				});
+
+				base.AddCommand (Command.LineDown, () => {
+					if (Orientation == Orientation.Horizontal) {
+						parent.SplitterDistance = Offset (Y, 1);
+						return true;
+					}
+					return false;
+				});
+
+				AddKeyBinding (Key.CursorRight, Command.Right);
+				AddKeyBinding (Key.CursorLeft, Command.Left);
+				AddKeyBinding (Key.CursorUp, Command.LineUp);
+				AddKeyBinding (Key.CursorDown, Command.LineDown);
+			}
+
+
+			///<inheritdoc/>
+			public override bool ProcessKey (KeyEvent kb)
+			{
+				var result = InvokeKeybindings (kb);
+				if (result != null)
+					return (bool)result;
+
+				return base.ProcessKey (kb);
 			}
-			
+
 			///<inheritdoc/>
 			public override bool MouseEvent (MouseEvent mouseEvent)
 			{

+ 3 - 0
UICatalog/Scenarios/SplitContainerExample.cs

@@ -37,6 +37,9 @@ namespace UICatalog.Scenarios {
 			splitContainer.Panel2.Add (new Label ("World"));
 			splitContainer.Panel2.Add (lbl2 = new Label ("Type Here Too:"){Y=2});
 			splitContainer.Panel2.Add (new TextField (){Width = Dim.Fill(),Y=2,X=Pos.Right(lbl2)+1});
+			splitContainer.Panel2.Add (new Label ("Here is a Text box:") { Y = 4 });
+			splitContainer.Panel2.Add (new TextView () { Y = 5, Width = Dim.Fill(), Height = Dim.Fill(), AllowsTab = false});
+
 
 			Win.Add (splitContainer);