From 5add477fc4bde7311bb32437cfad8288f0b88ca6 Mon Sep 17 00:00:00 2001 From: tznind Date: Sat, 21 Jan 2023 09:49:46 +0000 Subject: [PATCH] WIP split container Notepad --- Terminal.Gui/Core/View.cs | 2 +- Terminal.Gui/Views/SplitView.cs | 1 + UICatalog/Scenarios/Notepad.cs | 20 ++++++++++++++++---- 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/Terminal.Gui/Core/View.cs b/Terminal.Gui/Core/View.cs index c7104fcdb..26e8a0bbb 100644 --- a/Terminal.Gui/Core/View.cs +++ b/Terminal.Gui/Core/View.cs @@ -1134,7 +1134,7 @@ namespace Terminal.Gui { /// Absolute column; screen-relative. /// Absolute row; screen-relative. /// Whether to clip the result of the ViewToScreen method, if set to , the rcol, rrow values are clamped to the screen (terminal) dimensions (0..TerminalDim-1). - internal void ViewToScreen (int col, int row, out int rcol, out int rrow, bool clipped = true) + public void ViewToScreen (int col, int row, out int rcol, out int rrow, bool clipped = true) { // Computes the real row, col relative to the screen. rrow = row + frame.Y; diff --git a/Terminal.Gui/Views/SplitView.cs b/Terminal.Gui/Views/SplitView.cs index e782824fd..6a2faa4e4 100644 --- a/Terminal.Gui/Views/SplitView.cs +++ b/Terminal.Gui/Views/SplitView.cs @@ -764,6 +764,7 @@ namespace Terminal.Gui { } Add (view); + View2 = view; LayoutSubviews (); } diff --git a/UICatalog/Scenarios/Notepad.cs b/UICatalog/Scenarios/Notepad.cs index cf9eb0113..888ffa1c2 100644 --- a/UICatalog/Scenarios/Notepad.cs +++ b/UICatalog/Scenarios/Notepad.cs @@ -46,8 +46,10 @@ namespace UICatalog.Scenarios { // Start with only a single view but support splitting to show side by side var split = new SplitView { - Width = Dim.Fill(), - Height = Dim.Fill(), + X = 0, + Y = 1, + Width = Dim.Fill (), + Height = Dim.Fill (1), }; split.View2.Visible = false; split.SetView1 (tabView); @@ -105,7 +107,9 @@ namespace UICatalog.Scenarios { }); } - var contextMenu = new ContextMenu (e.MouseEvent.X + 1, e.MouseEvent.Y + 1, items); + ((View)sender).ViewToScreen (e.MouseEvent.X, e.MouseEvent.Y, out int screenX, out int screenY,true); + + var contextMenu = new ContextMenu (screenX,screenY, items); contextMenu.Show (); e.MouseEvent.Handled = true; @@ -127,6 +131,11 @@ namespace UICatalog.Scenarios { { var split = (SplitView)sender.SuperView; + // TODO: How can SuperView sometimes be null?! + if(split == null) { + throw new NullReferenceException ("Much confusion, sender.SuperView is null"); + } + split.TrySplitView1 (out var sub); sub.Orientation = Terminal.Gui.Graphs.Orientation.Vertical; var newTabView = CreateNewTabView (); @@ -136,12 +145,15 @@ namespace UICatalog.Scenarios { private TabView CreateNewTabView () { - return new TabView () { + var tv = new TabView () { X = 0, Y = 0, Width = Dim.Fill (), Height = Dim.Fill (), }; + + tv.TabClicked += TabView_TabClicked; + return tv; } private void New ()