From ca0cd7cfae1b648ae9c424ec1c1e6748bf0fca8b Mon Sep 17 00:00:00 2001 From: Thomas Date: Fri, 23 Dec 2022 14:54:11 +0000 Subject: [PATCH] Improved scenario to allow flipping splitter orientation --- Terminal.Gui/Views/SplitContainer.cs | 2 ++ UICatalog/Scenarios/SplitContainerExample.cs | 38 ++++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/Terminal.Gui/Views/SplitContainer.cs b/Terminal.Gui/Views/SplitContainer.cs index 3a46dc77b..c7de00847 100644 --- a/Terminal.Gui/Views/SplitContainer.cs +++ b/Terminal.Gui/Views/SplitContainer.cs @@ -22,6 +22,8 @@ namespace Terminal.Gui { Setup (); + CanFocus = false; + // TODO: Actually respect collapsed statuses } diff --git a/UICatalog/Scenarios/SplitContainerExample.cs b/UICatalog/Scenarios/SplitContainerExample.cs index 8768ec494..ec46c23a2 100644 --- a/UICatalog/Scenarios/SplitContainerExample.cs +++ b/UICatalog/Scenarios/SplitContainerExample.cs @@ -1,5 +1,6 @@ using Terminal.Gui; using System; +using Terminal.Gui.Graphs; namespace UICatalog.Scenarios { [ScenarioMetadata (Name: "Split Container", Description: "Demonstrates the SplitContainer functionality")] @@ -8,6 +9,9 @@ namespace UICatalog.Scenarios { private SplitContainer splitContainer; + + private MenuItem miVertical; + /// /// Setup the scenario. /// @@ -15,6 +19,7 @@ namespace UICatalog.Scenarios { { // Scenario Window's. Win.Title = this.GetName (); + Win.Y = 1; splitContainer = new SplitContainer { Width = Dim.Fill (), @@ -23,10 +28,43 @@ namespace UICatalog.Scenarios { }; + Label lbl1; splitContainer.Panel1.Add (new Label ("Hello")); + splitContainer.Panel1.Add (lbl1 = new Label ("Type Something:"){Y=2}); + splitContainer.Panel1.Add (new TextField (){Width = Dim.Fill(),Y=2,X=Pos.Right(lbl1)+1}); + + Label lbl2; 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}); Win.Add (splitContainer); + + + var menu = new MenuBar (new MenuBarItem [] { + new MenuBarItem ("_File", new MenuItem [] { + new MenuItem ("_Quit", "", () => Quit()), + }), + new MenuBarItem ("_Options", new MenuItem [] { + miVertical = new MenuItem ("_Vertical", "", () => ToggleOrientation()) + { + Checked = splitContainer.Orientation == Orientation.Vertical, + CheckType = MenuItemCheckStyle.Checked + }}) + }); + Application.Top.Add (menu); + } + + public void ToggleOrientation() + { + + miVertical.Checked = !miVertical.Checked; + splitContainer.Orientation = miVertical.Checked ? Orientation.Vertical : Orientation.Horizontal; + } + + private void Quit () + { + Application.RequestStop (); } } } \ No newline at end of file