From 88584d2f04df23e971122b2d247ab8ef82bc3365 Mon Sep 17 00:00:00 2001 From: tznind Date: Tue, 18 Feb 2025 23:37:23 +0000 Subject: [PATCH] Fix ChoicesDialog - Remove TGD shadow drawing code now that it is part of main codebase - Regenerate ChoicesDialog (load/save) - Change to Dim.Auto for button Widths - Fix bug in RecursivelyIgnoreAllNonDesignableSubviews when used during loading processes that incorrectly flagged sub views as 'non designable' --- src/UI/MouseManager.cs | 5 +- src/UI/Windows/ChoicesDialog.Designer.cs | 238 ++++++++++++----------- src/UI/Windows/ChoicesDialog.cs | 53 +---- src/ViewExtensions.cs | 6 +- 4 files changed, 136 insertions(+), 166 deletions(-) diff --git a/src/UI/MouseManager.cs b/src/UI/MouseManager.cs index 430dfce2..d17e6494 100644 --- a/src/UI/MouseManager.cs +++ b/src/UI/MouseManager.cs @@ -31,7 +31,7 @@ public class MouseManager public Rectangle? SelectionBox => RectExtensions.FromBetweenPoints(this.selectionStart, this.selectionEnd); /// - /// Responds to (by changing a 'drag a box' selection area + /// Responds to (by changing a 'drag a box' selection area /// or starting a resize etc). /// /// The reported by . @@ -123,9 +123,6 @@ public void HandleMouse(MouseEventArgs m, Design viewBeingEdited) // move selection box to new mouse position this.selectionEnd = m.Position; viewBeingEdited.View.SetNeedsDraw(); - - // BUG: Method is gone, will this functionality work still without it? - // Application.DoEvents(); return; } diff --git a/src/UI/Windows/ChoicesDialog.Designer.cs b/src/UI/Windows/ChoicesDialog.Designer.cs index ca55da23..337875cb 100644 --- a/src/UI/Windows/ChoicesDialog.Designer.cs +++ b/src/UI/Windows/ChoicesDialog.Designer.cs @@ -3,121 +3,139 @@ // // This code was generated by: -// TerminalGuiDesigner v1.0.18.0 +// TerminalGuiDesigner v2.0.0.0 // Changes to this file may cause incorrect behavior and will be lost if // the code is regenerated. // // ----------------------------------------------------------------------------- -namespace TerminalGuiDesigner.UI.Windows; -using System; -using Terminal.Gui; - - -public partial class ChoicesDialog : Terminal.Gui.Window { - - private Terminal.Gui.ColorScheme dialogBackground; - - private Terminal.Gui.ColorScheme buttons; - - private Terminal.Gui.Label label1; +namespace TerminalGuiDesigner.UI.Windows { + using System; + using Terminal.Gui; + using System.Collections; + using System.Collections.Generic; + using System.Collections.ObjectModel; + using System.Drawing; - private Terminal.Gui.View buttonPanel; - private Terminal.Gui.Button btn1; - - private Terminal.Gui.Button btn2; - - private Terminal.Gui.Button btn3; - - private Terminal.Gui.Button btn4; - - private void InitializeComponent() { - this.btn4 = new Terminal.Gui.Button(); - this.btn3 = new Terminal.Gui.Button(); - this.btn2 = new Terminal.Gui.Button(); - this.btn1 = new Terminal.Gui.Button(); - this.buttonPanel = new Terminal.Gui.View(); - this.label1 = new Terminal.Gui.Label(); - this.dialogBackground = new Terminal.Gui.ColorScheme( - new Terminal.Gui.Attribute(Terminal.Gui.Color.White, Terminal.Gui.Color.DarkGray), - new Terminal.Gui.Attribute(Terminal.Gui.Color.White, Terminal.Gui.Color.DarkGray), - new Terminal.Gui.Attribute(Terminal.Gui.Color.White, Terminal.Gui.Color.DarkGray), - new Terminal.Gui.Attribute(Terminal.Gui.Color.Black, Terminal.Gui.Color.Black), - new Terminal.Gui.Attribute(Terminal.Gui.Color.White, Terminal.Gui.Color.DarkGray) - ); - this.buttons = new Terminal.Gui.ColorScheme( - new Terminal.Gui.Attribute(Terminal.Gui.Color.DarkGray, Terminal.Gui.Color.White), - new Terminal.Gui.Attribute(Terminal.Gui.Color.Red, Terminal.Gui.Color.Yellow), - new Terminal.Gui.Attribute(Terminal.Gui.Color.Black, Terminal.Gui.Color.White), - new Terminal.Gui.Attribute(Terminal.Gui.Color.Black, Terminal.Gui.Color.Black), - new Terminal.Gui.Attribute(Terminal.Gui.Color.Black, Terminal.Gui.Color.Yellow) - ); - - this.Width = Dim.Percent(85); - this.Height = Dim.Percent(85); - this.X = Pos.Center(); - this.Y = Pos.Center(); - this.ColorScheme = this.dialogBackground; - this.Modal = true; - this.Text = ""; - this.Border.BorderStyle = Terminal.Gui.LineStyle.Double; - this.TextAlignment = Terminal.Gui.Alignment.Start; - this.Title = ""; - this.label1.Width = Dim.Fill(0); - this.label1.Height = Dim.Fill(0); - this.label1.X = 0; - this.label1.Y = 1; - this.label1.Data = "label1"; - this.label1.Text = "lblMessage"; - this.label1.TextAlignment = Terminal.Gui.Alignment.Center; - this.Add(this.label1); - this.buttonPanel.Width = 50; - this.buttonPanel.Height = 2; - this.buttonPanel.X = Pos.Center(); - this.buttonPanel.Y = Pos.AnchorEnd(2); - this.buttonPanel.Data = "buttonPanel"; - this.buttonPanel.Text = ""; - this.buttonPanel.TextAlignment = Terminal.Gui.Alignment.Start; - this.Add(this.buttonPanel); - this.btn1.Width = 10; - this.btn1.Height = 2; - this.btn1.X = 0; - this.btn1.Y = Pos.AnchorEnd(2); - this.btn1.ColorScheme = this.buttons; - this.btn1.Data = "btn1"; - this.btn1.Text = "btn1"; - this.btn1.TextAlignment = Terminal.Gui.Alignment.Center; - this.btn1.IsDefault = true; - this.buttonPanel.Add(this.btn1); - this.btn2.Width = 9; - this.btn2.Height = 2; - this.btn2.X = Pos.Right(btn1) + 1; - this.btn2.Y = Pos.AnchorEnd(2); - this.btn2.ColorScheme = this.buttons; - this.btn2.Data = "btn2"; - this.btn2.Text = "btn2"; - this.btn2.TextAlignment = Terminal.Gui.Alignment.Center; - this.btn2.IsDefault = false; - this.buttonPanel.Add(this.btn2); - this.btn3.Width = 8; - this.btn3.Height = 2; - this.btn3.X = Pos.Right(btn2) + 1; - this.btn3.Y = Pos.AnchorEnd(2); - this.btn3.ColorScheme = this.buttons; - this.btn3.Data = "btn3"; - this.btn3.Text = "btn3"; - this.btn3.TextAlignment = Terminal.Gui.Alignment.Center; - this.btn3.IsDefault = false; - this.buttonPanel.Add(this.btn3); - this.btn4.Width = 8; - this.btn4.Height = 2; - this.btn4.X = Pos.Right(btn3) + 1; - this.btn4.Y = Pos.AnchorEnd(2); - this.btn4.ColorScheme = this.buttons; - this.btn4.Data = "btn4"; - this.btn4.Text = "btn4"; - this.btn4.TextAlignment = Terminal.Gui.Alignment.Center; - this.btn4.IsDefault = false; - this.buttonPanel.Add(this.btn4); + public partial class ChoicesDialog : Terminal.Gui.Window { + + private Terminal.Gui.ColorScheme dialogBackground; + + private Terminal.Gui.ColorScheme buttons; + + private Terminal.Gui.Label label1; + + private Terminal.Gui.View buttonPanel; + + private Terminal.Gui.Button btn1; + + private Terminal.Gui.Button btn2; + + private Terminal.Gui.Button btn3; + + private Terminal.Gui.Button btn4; + + private void InitializeComponent() { + this.btn4 = new Terminal.Gui.Button(); + this.btn3 = new Terminal.Gui.Button(); + this.btn2 = new Terminal.Gui.Button(); + this.btn1 = new Terminal.Gui.Button(); + this.buttonPanel = new Terminal.Gui.View(); + this.label1 = new Terminal.Gui.Label(); + this.dialogBackground = new Terminal.Gui.ColorScheme(new Terminal.Gui.Attribute(4294967295u, 4285953654u), new Terminal.Gui.Attribute(4294967295u, 4285953654u), new Terminal.Gui.Attribute(4294967295u, 4285953654u), new Terminal.Gui.Attribute(4278190080u, 4278190080u), new Terminal.Gui.Attribute(4294967295u, 4285953654u)); + this.buttons = new Terminal.Gui.ColorScheme(new Terminal.Gui.Attribute(4285953654u, 4294967295u), new Terminal.Gui.Attribute(4294901760u, 4294967040u), new Terminal.Gui.Attribute(4278190080u, 4294967295u), new Terminal.Gui.Attribute(4278190080u, 4278190080u), new Terminal.Gui.Attribute(4278190080u, 4294967040u)); + this.Width = Dim.Percent(85); + this.Height = Dim.Percent(85); + this.X = Pos.Center(); + this.Y = Pos.Center(); + this.Visible = true; + this.Arrangement = ((Terminal.Gui.ViewArrangement.Movable | Terminal.Gui.ViewArrangement.Resizable) + | Terminal.Gui.ViewArrangement.Overlapped); + this.ColorScheme = this.dialogBackground; + this.CanFocus = true; + this.ShadowStyle = Terminal.Gui.ShadowStyle.None; + this.Modal = true; + this.TextAlignment = Terminal.Gui.Alignment.Start; + this.Title = ""; + this.label1.Width = Dim.Fill(0); + this.label1.Height = Dim.Fill(0); + this.label1.X = 0; + this.label1.Y = 1; + this.label1.Visible = true; + this.label1.Arrangement = Terminal.Gui.ViewArrangement.Fixed; + this.label1.CanFocus = true; + this.label1.ShadowStyle = Terminal.Gui.ShadowStyle.None; + this.label1.Data = "label1"; + this.label1.Text = "lblMessage"; + this.label1.TextAlignment = Terminal.Gui.Alignment.Center; + this.Add(this.label1); + this.buttonPanel.Width = 50; + this.buttonPanel.Height = 2; + this.buttonPanel.X = Pos.Center(); + this.buttonPanel.Y = Pos.AnchorEnd(2); + this.buttonPanel.Visible = true; + this.buttonPanel.Arrangement = Terminal.Gui.ViewArrangement.Fixed; + this.buttonPanel.CanFocus = true; + this.buttonPanel.ShadowStyle = Terminal.Gui.ShadowStyle.None; + this.buttonPanel.Data = "buttonPanel"; + this.buttonPanel.TextAlignment = Terminal.Gui.Alignment.Start; + this.Add(this.buttonPanel); + this.btn1.Width = Dim.Auto(); + this.btn1.Height = 2; + this.btn1.X = 0; + this.btn1.Y = Pos.AnchorEnd(2); + this.btn1.Visible = true; + this.btn1.Arrangement = Terminal.Gui.ViewArrangement.Fixed; + this.btn1.ColorScheme = this.buttons; + this.btn1.CanFocus = true; + this.btn1.ShadowStyle = Terminal.Gui.ShadowStyle.Opaque; + this.btn1.Data = "btn1"; + this.btn1.Text = "btn1"; + this.btn1.TextAlignment = Terminal.Gui.Alignment.Center; + this.btn1.IsDefault = true; + this.buttonPanel.Add(this.btn1); + this.btn2.Width = Dim.Auto(); + this.btn2.Height = 2; + this.btn2.X = Pos.Right(btn1) + 1; + this.btn2.Y = Pos.AnchorEnd(2); + this.btn2.Visible = true; + this.btn2.Arrangement = Terminal.Gui.ViewArrangement.Fixed; + this.btn2.ColorScheme = this.buttons; + this.btn2.CanFocus = true; + this.btn2.ShadowStyle = Terminal.Gui.ShadowStyle.Opaque; + this.btn2.Data = "btn2"; + this.btn2.Text = "btn2"; + this.btn2.TextAlignment = Terminal.Gui.Alignment.Center; + this.btn2.IsDefault = false; + this.buttonPanel.Add(this.btn2); + this.btn3.Width = Dim.Auto(); + this.btn3.Height = 2; + this.btn3.X = Pos.Right(btn2) + 1; + this.btn3.Y = Pos.AnchorEnd(2); + this.btn3.Visible = true; + this.btn3.Arrangement = Terminal.Gui.ViewArrangement.Fixed; + this.btn3.ColorScheme = this.buttons; + this.btn3.CanFocus = true; + this.btn3.ShadowStyle = Terminal.Gui.ShadowStyle.Opaque; + this.btn3.Data = "btn3"; + this.btn3.Text = "btn3"; + this.btn3.TextAlignment = Terminal.Gui.Alignment.Center; + this.btn3.IsDefault = false; + this.buttonPanel.Add(this.btn3); + this.btn4.Width = Dim.Auto(); + this.btn4.Height = 2; + this.btn4.X = Pos.Right(btn3) + 1; + this.btn4.Y = Pos.AnchorEnd(2); + this.btn4.Visible = true; + this.btn4.Arrangement = Terminal.Gui.ViewArrangement.Fixed; + this.btn4.ColorScheme = this.buttons; + this.btn4.CanFocus = true; + this.btn4.ShadowStyle = Terminal.Gui.ShadowStyle.Opaque; + this.btn4.Data = "btn4"; + this.btn4.Text = "btn4"; + this.btn4.TextAlignment = Terminal.Gui.Alignment.Center; + this.btn4.IsDefault = false; + this.buttonPanel.Add(this.btn4); + } } } diff --git a/src/UI/Windows/ChoicesDialog.cs b/src/UI/Windows/ChoicesDialog.cs index 57d56801..07ccbd56 100644 --- a/src/UI/Windows/ChoicesDialog.cs +++ b/src/UI/Windows/ChoicesDialog.cs @@ -52,10 +52,6 @@ public ChoicesDialog(string title, string message, params string[] options) { { // add space for right hand side shadow buttons[i].Text = options[i] + " "; - - // TODO think it depends if it is default if we have to do this hack - buttons[i].Width = Dim.Auto(); - var i2 = i; @@ -63,11 +59,10 @@ public ChoicesDialog(string title, string message, params string[] options) { Result = i2; Application.RequestStop(); }; - - buttons[i].DrawComplete += (s,r) => - ChoicesDialog.PaintShadow(buttons[i2], ColorScheme); } + buttonPanel.LayoutSubviews(); + // hide other buttons for(int i=options.Length;i'); - - // draw the 'end' button symbol one in - btn.AddRune(bounds.Width - 3, 0, rightDefault); - } - - btn.AddRune(bounds.Width - 2, 0, new System.Text.Rune(']')); - btn.AddRune(0, 0, new System.Text.Rune('[')); - - var backgroundColor = backgroundScheme.Normal.Background; - - // shadow color - Driver.SetAttribute(new Terminal.Gui.Attribute(Color.Black, backgroundColor)); - - // end shadow (right) - btn.AddRune(bounds.Width - 1, 0, new System.Text.Rune('▄')); - - // leave whitespace in lower left in parent/default background color - Driver.SetAttribute(new Terminal.Gui.Attribute(Color.Black, backgroundColor)); - btn.AddRune(0, 1, new System.Text.Rune(' ')); - - // The color for rendering shadow is 'black' + parent/default background color - Driver.SetAttribute(new Terminal.Gui.Attribute(backgroundColor, Color.Black)); - - // underline shadow - for (int x = 1; x < bounds.Width; x++) - { - btn.AddRune(x, 1, new System.Text.Rune('▄')); - } - } - internal static bool Confirm(string title, string message, string okText = "Yes", string cancelText = "No") { var dlg = new ChoicesDialog(title, message, okText, cancelText); diff --git a/src/ViewExtensions.cs b/src/ViewExtensions.cs index 8d5e4ad0..3e79d115 100644 --- a/src/ViewExtensions.cs +++ b/src/ViewExtensions.cs @@ -416,11 +416,15 @@ private static void RecursivelyIgnoreAllNonDesignableSubviews(View view, List