From 5d6fe403f5dfaaad8daaa768591e2648b3780ce0 Mon Sep 17 00:00:00 2001 From: BDisp Date: Wed, 3 Jun 2020 03:23:53 +0100 Subject: [PATCH 1/3] Fixes ColorScheme null exception # 597. (#599) --- Terminal.Gui/Views/ScrollView.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Terminal.Gui/Views/ScrollView.cs b/Terminal.Gui/Views/ScrollView.cs index 160a22d59..0d1358784 100644 --- a/Terminal.Gui/Views/ScrollView.cs +++ b/Terminal.Gui/Views/ScrollView.cs @@ -90,6 +90,9 @@ namespace Terminal.Gui { /// Region to be redrawn. public override void Redraw(Rect region) { + if (ColorScheme == null) + return; + Driver.SetAttribute (ColorScheme.Normal); if (vertical) { @@ -407,7 +410,7 @@ namespace Terminal.Gui { var savedClip = ClipToBounds (); contentView.Redraw (contentView.Bounds); vertical.Redraw (vertical.Bounds); - horizontal.Redraw (vertical.Bounds); + horizontal.Redraw (horizontal.Bounds); Driver.Clip = savedClip; Driver.SetAttribute (ColorScheme.Normal); } From fa29269ade64482c65cf657b2dfcfa68c59ba2de Mon Sep 17 00:00:00 2001 From: BDisp Date: Wed, 3 Jun 2020 03:24:11 +0100 Subject: [PATCH 2/3] Added mouse support to the StatusBar. (#598) --- Example/demo.cs | 15 ++++++++++-- Terminal.Gui/Views/StatusBar.cs | 41 ++++++++++++++++++++++++++++++++- 2 files changed, 53 insertions(+), 3 deletions(-) diff --git a/Example/demo.cs b/Example/demo.cs index 3fbad8a38..7f81d9e98 100644 --- a/Example/demo.cs +++ b/Example/demo.cs @@ -375,6 +375,17 @@ static class Demo { MessageBox.Query (50, 7, "Help", "This is a small help\nBe kind.", "Ok"); } + static void Load () + { + MessageBox.Query (50, 7, "Load", "This is a small load\nBe kind.", "Ok"); + } + + static void Save () + { + MessageBox.Query (50, 7, "Save", "This is a small save\nBe kind.", "Ok"); + } + + #region Selection Demo static void ListSelectionDemo (bool multiple) @@ -611,8 +622,8 @@ static class Demo { var statusBar = new StatusBar (new StatusItem [] { new StatusItem(Key.F1, "~F1~ Help", () => Help()), - new StatusItem(Key.F2, "~F2~ Load", null), - new StatusItem(Key.F3, "~F3~ Save", null), + new StatusItem(Key.F2, "~F2~ Load", Load), + new StatusItem(Key.F3, "~F3~ Save", Save), new StatusItem(Key.ControlQ, "~^Q~ Quit", () => { if (Quit ()) top.Running = false; }), }) { Parent = null, diff --git a/Terminal.Gui/Views/StatusBar.cs b/Terminal.Gui/Views/StatusBar.cs index 88d63a202..70618f228 100644 --- a/Terminal.Gui/Views/StatusBar.cs +++ b/Terminal.Gui/Views/StatusBar.cs @@ -185,11 +185,50 @@ namespace Terminal.Gui { { foreach (var item in Items) { if (kb.Key == item.Shortcut) { - if (item.Action != null) item.Action (); + item.Action?.Invoke (); return true; } } return false; } + + /// + public override bool MouseEvent (MouseEvent me) + { + if (me.Flags != MouseFlags.Button1Clicked) + return false; + + int pos = 1; + for (int i = 0; i < Items.Length; i++) { + if (me.X >= pos && me.X < pos + GetItemTitleLength (Items [i].Title)) { + Run (Items [i].Action); + } + pos += GetItemTitleLength (Items [i].Title) + 1; + } + return true; + } + + int GetItemTitleLength (ustring title) + { + int len = 0; + foreach (var ch in title) { + if (ch == '~') + continue; + len++; + } + + return len; + } + + void Run (Action action) + { + if (action == null) + return; + + Application.MainLoop.AddIdle (() => { + action (); + return false; + }); + } } } \ No newline at end of file From 72ee72807b67a396634a9caadb0da9aec7524959 Mon Sep 17 00:00:00 2001 From: BDisp Date: Wed, 3 Jun 2020 03:35:49 +0100 Subject: [PATCH 3/3] ColorScheme inside the View instance. Updating OnKeyDownPressUpDemo to reflect the news changes. (#594) --- FSharpExample/Program.fs | 24 +++--------------------- 1 file changed, 3 insertions(+), 21 deletions(-) diff --git a/FSharpExample/Program.fs b/FSharpExample/Program.fs index 4824df648..62202bd22 100644 --- a/FSharpExample/Program.fs +++ b/FSharpExample/Program.fs @@ -333,9 +333,9 @@ type Demo() = class end X = Pos.At(0), Y = Pos.At(0), Width = Dim.Fill () - Dim.op_Implicit(1), - Height = Dim.Fill () - Dim.op_Implicit(2) + Height = Dim.Fill () - Dim.op_Implicit(2), + ColorScheme = Colors.TopLevel ) - listView.ColorScheme <- Colors.TopLevel container.Add (listView) let KeyDownPressUp(keyEvent : KeyEvent, updown : string) = @@ -344,25 +344,7 @@ type Demo() = class end | "Down" | "Up" | "Press" -> - let mutable (msg : string) = sprintf "Key %5s : " updown - if (keyEvent.Key &&& Key.ShiftMask) <> Key.Unknown - then msg <- msg + "Shift " - if (keyEvent.Key &&& Key.CtrlMask) <> Key.Unknown - then msg <- msg + "Ctrl " - if (keyEvent.Key &&& Key.AltMask) <> Key.Unknown - then msg <- msg + "Alt " - msg <- msg + if (keyEvent.KeyValue &&& (int)Key.CharMask) > 26 then (string)keyEvent.KeyValue else (string)keyEvent.Key - list.Add (msg) - | _ -> - if (keyEvent.Key &&& Key.ShiftMask) <> Key.Unknown - then list.Add (sprintf "Key %s : Shift " updown) - else if (keyEvent.Key &&& Key.CtrlMask) <> Key.Unknown - then list.Add (sprintf "Key %s : Ctrl " updown) - else if (keyEvent.Key &&& Key.AltMask) <> Key.Unknown - then list.Add (sprintf "Key %s : Alt " updown) - else if ((int)keyEvent.KeyValue &&& (int)Key.CharMask) > 26 - then list.Add (sprintf "Key %s : %s" updown (keyEvent.KeyValue.ToString())) - else list.Add (sprintf "Key %s : %s" updown (keyEvent.Key.ToString())) + list.Add (keyEvent.ToString ()) listView.MoveDown (); container.KeyDown.Add(fun (e : View.KeyEventEventArgs) -> KeyDownPressUp (e.KeyEvent, "Down") |> ignore)