From 21c9097d523d42a2c68b84ae213f5c1ccabe704b Mon Sep 17 00:00:00 2001 From: Tig Date: Thu, 20 Jun 2024 18:02:09 -0700 Subject: [PATCH 1/2] pull squash --- Terminal.Gui/Application/Application.cs | 1 + Terminal.Gui/Drawing/Color.cs | 21 +++ Terminal.Gui/View/Adornment/Margin.cs | 214 +++++++++++++++++++++++- Terminal.Gui/View/ViewAdornments.cs | 30 ++++ Terminal.Gui/View/ViewEventArgs.cs | 15 +- Terminal.Gui/View/ViewMouse.cs | 18 +- Terminal.Gui/View/ViewSubViews.cs | 4 +- Terminal.Gui/Views/Button.cs | 11 +- Terminal.Gui/Views/ColorPicker.cs | 4 + Terminal.Gui/Views/Dialog.cs | 3 +- Terminal.Gui/Views/Window.cs | 9 + UICatalog/Resources/config.json | 2 + UICatalog/Scenarios/Adornments.cs | 7 +- UICatalog/Scenarios/Buttons.cs | 2 + UICatalog/Scenarios/ExpanderButton.cs | 1 + UICatalog/Scenarios/MarginEditor.cs | 14 ++ UICatalog/Scenarios/ThreeD.cs | 62 +++++++ UICatalog/UICatalog.cs | 3 +- UnitTests/View/NeedsDisplayTests.cs | 2 +- UnitTests/Views/LabelTests.cs | 2 +- UnitTests/Views/ToplevelTests.cs | 10 +- 21 files changed, 411 insertions(+), 24 deletions(-) create mode 100644 UICatalog/Scenarios/ThreeD.cs diff --git a/Terminal.Gui/Application/Application.cs b/Terminal.Gui/Application/Application.cs index 6656f8457..bd6956425 100644 --- a/Terminal.Gui/Application/Application.cs +++ b/Terminal.Gui/Application/Application.cs @@ -973,6 +973,7 @@ public static partial class Application if (state.Toplevel.NeedsDisplay || state.Toplevel.SubViewNeedsDisplay || state.Toplevel.LayoutNeeded || OverlappedChildNeedsDisplay ()) { + state.Toplevel.SetNeedsDisplay(); state.Toplevel.Draw (); Driver.UpdateScreen (); diff --git a/Terminal.Gui/Drawing/Color.cs b/Terminal.Gui/Drawing/Color.cs index cd0944c37..8c7b76024 100644 --- a/Terminal.Gui/Drawing/Color.cs +++ b/Terminal.Gui/Drawing/Color.cs @@ -259,6 +259,27 @@ public readonly partial record struct Color : ISpanParsable, IUtf8SpanPar } + /// + /// Gets a color that is the same hue as the current color, but with a different lightness. + /// + /// + public Color GetDarkerColor () + { + // TODO: This is a temporary implementation; just enough to show how it could work. + var hsl = ColorHelper.ColorConverter.RgbToHsl (new RGB (R, G, B)); + + var amount = .3; + if (hsl.L <= 5) + { + return DarkGray; + } + hsl.L = (byte)(hsl.L * amount); + + var rgb = ColorHelper.ColorConverter.HslToRgb (hsl); + return new (rgb.R, rgb.G, rgb.B); + + } + #region Legacy Color Names /// The black color. diff --git a/Terminal.Gui/View/Adornment/Margin.cs b/Terminal.Gui/View/Adornment/Margin.cs index ca2142fc0..b63175aa0 100644 --- a/Terminal.Gui/View/Adornment/Margin.cs +++ b/Terminal.Gui/View/Adornment/Margin.cs @@ -1,4 +1,5 @@ -namespace Terminal.Gui; +#nullable enable +namespace Terminal.Gui; /// The Margin for a . /// @@ -15,8 +16,64 @@ public class Margin : Adornment public Margin (View parent) : base (parent) { /* Do nothing; View.CreateAdornment requires a constructor that takes a parent */ + + HighlightStyle |= HighlightStyle.Pressed; + Highlight += Margin_Highlight; + LayoutStarted += Margin_LayoutStarted; } + private void Margin_LayoutStarted (object? sender, LayoutEventArgs e) + { + // Adjust the shadow such that it is drawn aligned with the Border + if (_shadow && _rightShadow is {} && _bottomShadow is {}) + { + _rightShadow.Y = Parent.Border.Thickness.Top - (Parent.Border.Thickness.Top > 2 && Parent.Border.ShowTitle ? 1 : 0); + _bottomShadow.X = Parent.Border.Thickness.Left; + } + } + + private bool _pressed; + private void Margin_Highlight (object? sender, HighlightEventArgs e) + { + if (_shadow) + { + if (_pressed && e.HighlightStyle == HighlightStyle.None) + { + Thickness = new (Thickness.Left - 1, Thickness.Top, Thickness.Right + 1, Thickness.Bottom); + + if (_rightShadow is { }) + { + _rightShadow.Visible = true; + } + + if (_bottomShadow is { }) + { + _bottomShadow.Visible = true; + } + + _pressed = false; + return; + } + + if (!_pressed && (e.HighlightStyle.HasFlag (HighlightStyle.Pressed) /*|| e.HighlightStyle.HasFlag (HighlightStyle.PressedOutside)*/)) + { + Thickness = new (Thickness.Left + 1, Thickness.Top, Thickness.Right - 1, Thickness.Bottom); + _pressed = true; + if (_rightShadow is { }) + { + _rightShadow.Visible = false; + } + + if (_bottomShadow is { }) + { + _bottomShadow.Visible = false; + } + } + } + + } + + /// /// The color scheme for the Margin. If set to , gets the 's /// scheme. color scheme. @@ -30,7 +87,7 @@ public class Margin : Adornment return base.ColorScheme; } - return Parent?.SuperView?.ColorScheme ?? Colors.ColorSchemes ["TopLevel"]; + return (Parent?.SuperView?.ColorScheme ?? Colors.ColorSchemes ["TopLevel"])!; } set { @@ -38,4 +95,157 @@ public class Margin : Adornment Parent?.SetNeedsDisplay (); } } + + private bool _shadow; + + /// + /// Gets or sets whether the Margin includes a shadow effect. The shadow is drawn on the right and bottom sides of the + /// Margin. + /// + public bool EnableShadow (bool enable) + { + if (_shadow == enable) + { + return _shadow; + } + + if (_shadow) + { + Thickness = new (Thickness.Left, Thickness.Top, Thickness.Right - 1, Thickness.Bottom - 1); + } + + _shadow = enable; + + if (_shadow) + { + Thickness = new (Thickness.Left, Thickness.Top, Thickness.Right + 1, Thickness.Bottom + 1); + } + + if (_rightShadow is { }) + { + _rightShadow.Visible = _shadow; + } + + if (_bottomShadow is { }) + { + _bottomShadow.Visible = _shadow; + } + return _shadow; + } + + private View? _bottomShadow; + private View? _rightShadow; + + /// + public override void BeginInit () + { + base.BeginInit (); + + if (Parent is null) + { + return; + } + + Attribute attr = Parent.GetNormalColor (); + + Add ( + _rightShadow = new ShadowView + { + X = Pos.AnchorEnd (1), + Y = 0, + Width = 1, + Height = Dim.Fill (), + Visible = _shadow, + Orientation = Orientation.Vertical + }, + _bottomShadow = new ShadowView + { + X = 0, + Y = Pos.AnchorEnd (1), + Width = Dim.Fill (), + Height = 1, + Visible = _shadow, + Orientation = Orientation.Horizontal + } + ); + } +} + +/// +/// Draws a shadow on the right or bottom of the view. +/// +internal class ShadowView : View +{ + // TODO: Add these to CM.Glyphs + private readonly char VERTICAL_START_GLYPH = '\u2596'; + private readonly char VERTICAL_GLYPH = '\u258C'; + private readonly char HORIZONTAL_START_GLYPH = '\u259d'; + private readonly char HORIZONTAL_GLYPH = '\u2580'; + private readonly char HORIZONTAL_END_GLYPH = '\u2598'; + + /// + /// Gets or sets the orientation of the shadow. + /// + public Orientation Orientation { get; set; } + + /// + public override Attribute GetNormalColor () + { + if (SuperView is Adornment adornment) + { + if (adornment.Parent.SuperView is { }) + { + Attribute attr = adornment.Parent.SuperView.GetNormalColor (); + return new (new Attribute (attr.Foreground.GetDarkerColor (), attr.Background)); + } + else + { + Attribute attr = Application.Top.GetNormalColor (); + return new (new Attribute (attr.Foreground.GetDarkerColor (), attr.Background)); + } + } + return base.GetNormalColor (); + } + + /// + public override void OnDrawContent (Rectangle viewport) + { + //base.OnDrawContent (viewport); + + if (Orientation == Orientation.Vertical) + { + DrawVerticalShadow (viewport); + } + else + { + DrawHorizontalShadow (viewport); + } + } + + private void DrawHorizontalShadow (Rectangle rectangle) + { + // Draw the start glyph + AddRune (0, 0, (Rune)HORIZONTAL_START_GLYPH); + + // Fill the rest of the rectangle with the glyph + for (var i = 1; i < rectangle.Width - 1; i++) + { + AddRune (i, 0, (Rune)HORIZONTAL_GLYPH); + } + + // Last is special + AddRune (rectangle.Width - 1, 0, (Rune)HORIZONTAL_END_GLYPH); + } + + private void DrawVerticalShadow (Rectangle viewport) + { + // Draw the start glyph + AddRune (0, 0, (Rune)VERTICAL_START_GLYPH); + + // Fill the rest of the rectangle with the glyph + for (var i = 1; i < viewport.Height; i++) + { + AddRune (0, i, (Rune)VERTICAL_GLYPH); + } + } } diff --git a/Terminal.Gui/View/ViewAdornments.cs b/Terminal.Gui/View/ViewAdornments.cs index 89b8ff0e7..a34cc65a7 100644 --- a/Terminal.Gui/View/ViewAdornments.cs +++ b/Terminal.Gui/View/ViewAdornments.cs @@ -59,6 +59,36 @@ public partial class View /// public Margin Margin { get; private set; } + [SerializableConfigurationProperty (Scope = typeof (ThemeScope))] + public static bool DefaultShadow { get; set; } = false; + + + private bool _shadow; + /// + /// Gets or sets whether the View is shown with a shadow effect. The shadow is drawn on the right and bottom sides of the + /// Margin. + /// + /// + /// Setting this property to will add a shadow to the right and bottom sides of the Margin. + /// The View 's will be expanded to include the shadow. + /// + public bool Shadow + { + get => _shadow; + set + { + if (_shadow == value) + { + return; + } + _shadow = value; + if (Margin is { }) + { + _shadow = Margin.EnableShadow (value); + } + } + } + /// /// The that offsets the from the . /// The Border provides the space for a visual border (drawn using diff --git a/Terminal.Gui/View/ViewEventArgs.cs b/Terminal.Gui/View/ViewEventArgs.cs index a53575f2e..879e41005 100644 --- a/Terminal.Gui/View/ViewEventArgs.cs +++ b/Terminal.Gui/View/ViewEventArgs.cs @@ -58,8 +58,11 @@ public class DrawEventArgs : EventArgs public class FocusEventArgs : EventArgs { /// Constructs. - /// The view that gets or loses focus. - public FocusEventArgs (View view) { View = view; } + /// The view that gets or loses focus. + public FocusEventArgs (View leaving, View entering) { + Leaving = leaving; + Entering = entering; + } /// /// Indicates if the current focus event has already been processed and the driver should stop notifying any other @@ -68,6 +71,10 @@ public class FocusEventArgs : EventArgs /// public bool Handled { get; set; } - /// Indicates the current view that gets or loses focus. - public View View { get; set; } + /// Indicates the view that is losing focus. + public View Leaving { get; set; } + + /// Indicates the view that is gaining focus. + public View Entering { get; set; } + } diff --git a/Terminal.Gui/View/ViewMouse.cs b/Terminal.Gui/View/ViewMouse.cs index f9352ab7d..a649a692d 100644 --- a/Terminal.Gui/View/ViewMouse.cs +++ b/Terminal.Gui/View/ViewMouse.cs @@ -335,14 +335,14 @@ public partial class View if (Viewport.Contains (mouseEvent.Position)) { - if (SetHighlight (HighlightStyle.HasFlag (HighlightStyle.Pressed) ? HighlightStyle.Pressed : HighlightStyle.None) == true) + if (this is not Adornment && SetHighlight (HighlightStyle.HasFlag (HighlightStyle.Pressed) ? HighlightStyle.Pressed : HighlightStyle.None) == true) { return true; } } else { - if (SetHighlight (HighlightStyle.HasFlag (HighlightStyle.PressedOutside) ? HighlightStyle.PressedOutside : HighlightStyle.None) == true) + if (this is not Adornment && SetHighlight (HighlightStyle.HasFlag (HighlightStyle.PressedOutside) ? HighlightStyle.PressedOutside : HighlightStyle.None) == true) { return true; @@ -533,6 +533,20 @@ public partial class View HighlightEventArgs args = new (highlight); Highlight?.Invoke (this, args); + if (args.Cancel) + { + return true; + } + + args = new (highlight); + Margin?.Highlight?.Invoke (this, args); + + //args = new (highlight); + //Border?.Highlight?.Invoke (this, args); + + //args = new (highlight); + //Padding?.Highlight?.Invoke (this, args); + return args.Cancel; } diff --git a/Terminal.Gui/View/ViewSubViews.cs b/Terminal.Gui/View/ViewSubViews.cs index e04c1c18e..99f9e119b 100644 --- a/Terminal.Gui/View/ViewSubViews.cs +++ b/Terminal.Gui/View/ViewSubViews.cs @@ -505,7 +505,7 @@ public partial class View /// true, if the event was handled, false otherwise. public virtual bool OnEnter (View view) { - var args = new FocusEventArgs (view); + var args = new FocusEventArgs (view, this); Enter?.Invoke (this, args); if (args.Handled) @@ -521,7 +521,7 @@ public partial class View /// true, if the event was handled, false otherwise. public virtual bool OnLeave (View view) { - var args = new FocusEventArgs (view); + var args = new FocusEventArgs (this, view); Leave?.Invoke (this, args); if (args.Handled) diff --git a/Terminal.Gui/Views/Button.cs b/Terminal.Gui/Views/Button.cs index 2d922a79f..5a93405e2 100644 --- a/Terminal.Gui/Views/Button.cs +++ b/Terminal.Gui/Views/Button.cs @@ -33,6 +33,12 @@ public class Button : View private readonly Rune _rightDefault; private bool _isDefault; + /// + /// Gets or sets whether s are shown with a shadow effect by default. + /// + [SerializableConfigurationProperty (Scope = typeof (ThemeScope))] + public new static bool DefaultShadow { get; set; } = false; + /// Initializes a new instance of . public Button () { @@ -44,14 +50,15 @@ public class Button : View _leftDefault = Glyphs.LeftDefaultIndicator; _rightDefault = Glyphs.RightDefaultIndicator; + Height = Dim.Auto (DimAutoStyle.Text); Width = Dim.Auto (DimAutoStyle.Text); - Height = Dim.Auto (DimAutoStyle.Text, minimumContentDim: 1); CanFocus = true; HighlightStyle |= HighlightStyle.Pressed; #if HOVER HighlightStyle |= HighlightStyle.Hover; #endif + // Override default behavior of View AddCommand (Command.HotKey, () => { @@ -64,6 +71,8 @@ public class Button : View TitleChanged += Button_TitleChanged; MouseClick += Button_MouseClick; + + Shadow = DefaultShadow; } private bool _wantContinuousButtonPressed; diff --git a/Terminal.Gui/Views/ColorPicker.cs b/Terminal.Gui/Views/ColorPicker.cs index c033cb4f0..6ad6dc305 100644 --- a/Terminal.Gui/Views/ColorPicker.cs +++ b/Terminal.Gui/Views/ColorPicker.cs @@ -107,6 +107,10 @@ public class ColorPicker : View get => (ColorName)_selectColorIndex; set { + if (value == (ColorName)_selectColorIndex) + { + return; + } var prev = (ColorName)_selectColorIndex; _selectColorIndex = (int)value; diff --git a/Terminal.Gui/Views/Dialog.cs b/Terminal.Gui/Views/Dialog.cs index 2ab97a98e..3bd0948cd 100644 --- a/Terminal.Gui/Views/Dialog.cs +++ b/Terminal.Gui/Views/Dialog.cs @@ -60,7 +60,8 @@ public class Dialog : Window /// /// By default, , , , and are /// set - /// such that the will be centered in, and no larger than 90% of the screen dimensions. + /// such that the will be centered in, and no larger than 90% of , if there is one. Otherwise, + /// it will be bound by the screen dimensions. /// public Dialog () { diff --git a/Terminal.Gui/Views/Window.cs b/Terminal.Gui/Views/Window.cs index 0a1dfe32e..8aaece296 100644 --- a/Terminal.Gui/Views/Window.cs +++ b/Terminal.Gui/Views/Window.cs @@ -14,6 +14,14 @@ namespace Terminal.Gui; /// public class Window : Toplevel { + + /// + /// Gets or sets whether all s are shown with a shadow effect by default. + /// + [SerializableConfigurationProperty (Scope = typeof (ThemeScope))] + public static bool DefaultShadow { get; set; } = false; + + /// /// Initializes a new instance of the class. /// @@ -22,6 +30,7 @@ public class Window : Toplevel CanFocus = true; ColorScheme = Colors.ColorSchemes ["Base"]; // TODO: make this a theme property BorderStyle = DefaultBorderStyle; + Shadow = DefaultShadow; // This enables the default button to be activated by the Enter key. AddCommand ( diff --git a/UICatalog/Resources/config.json b/UICatalog/Resources/config.json index 2accf1b4d..48dc2d403 100644 --- a/UICatalog/Resources/config.json +++ b/UICatalog/Resources/config.json @@ -33,6 +33,8 @@ { "UI Catalog Theme": { "Dialog.DefaultButtonAlignment": "Fill", + "Button.DefaultShadow": true, + "Window.DefaultShadow": true, "ColorSchemes": [ { "UI Catalog Scheme": { diff --git a/UICatalog/Scenarios/Adornments.cs b/UICatalog/Scenarios/Adornments.cs index cde56a8c7..8e19ecaaa 100644 --- a/UICatalog/Scenarios/Adornments.cs +++ b/UICatalog/Scenarios/Adornments.cs @@ -21,10 +21,9 @@ public class Adornments : Scenario AutoSelectViewToEdit = true, // This is for giggles, to show that the editor can be moved around. Arrangement = ViewArrangement.Movable, - X = Pos.AnchorEnd() - + X = Pos.AnchorEnd(), }; - editor.Border.Thickness = new Thickness (1, 3, 1, 1); + editor.Border.Thickness = new Thickness (1, 2, 1, 1); app.Add (editor); @@ -104,7 +103,7 @@ public class Adornments : Scenario window.Padding.Add (labelInPadding); var textFieldInPadding = new TextField - { X = Pos.Right (labelInPadding) + 1, Y = Pos.Top (labelInPadding), Width = 15, Text = "some text" }; + { X = Pos.Right (labelInPadding) + 1, Y = Pos.Top (labelInPadding), Width = 15, Text = "some text" }; textFieldInPadding.Accept += (s, e) => MessageBox.Query (20, 7, "TextField", textFieldInPadding.Text, "Ok"); window.Padding.Add (textFieldInPadding); diff --git a/UICatalog/Scenarios/Buttons.cs b/UICatalog/Scenarios/Buttons.cs index 2b51fad17..011153166 100644 --- a/UICatalog/Scenarios/Buttons.cs +++ b/UICatalog/Scenarios/Buttons.cs @@ -433,6 +433,7 @@ public class Buttons : Scenario Title = $"{CM.Glyphs.DownArrow}", WantContinuousButtonPressed = true, CanFocus = false, + Shadow = false, }; _number = new () @@ -457,6 +458,7 @@ public class Buttons : Scenario Title = $"{CM.Glyphs.UpArrow}", WantContinuousButtonPressed = true, CanFocus = false, + Shadow = false, }; CanFocus = true; diff --git a/UICatalog/Scenarios/ExpanderButton.cs b/UICatalog/Scenarios/ExpanderButton.cs index cebf9a8d4..ba2142bd5 100644 --- a/UICatalog/Scenarios/ExpanderButton.cs +++ b/UICatalog/Scenarios/ExpanderButton.cs @@ -36,6 +36,7 @@ public class ExpanderButton : Button Height = 1; NoDecorations = true; NoPadding = true; + Shadow = false; AddCommand (Command.HotKey, Toggle); AddCommand (Command.ToggleExpandCollapse, Toggle); diff --git a/UICatalog/Scenarios/MarginEditor.cs b/UICatalog/Scenarios/MarginEditor.cs index 666e47432..141aa04c1 100644 --- a/UICatalog/Scenarios/MarginEditor.cs +++ b/UICatalog/Scenarios/MarginEditor.cs @@ -13,6 +13,20 @@ public class MarginEditor : AdornmentEditor private void MarginEditor_Initialized (object sender, EventArgs e) { + var ckbShadow = new CheckBox + { + X = 0, + Y = Pos.AnchorEnd (), + SuperViewRendersLineCanvas = true, + Title = "_Shadow", + Enabled = AdornmentToEdit is { }, + }; + + ckbShadow.Toggled += (sender, args) => + { + ((Margin)AdornmentToEdit).EnableShadow (args.NewValue!.Value); + }; + Add (ckbShadow); } } \ No newline at end of file diff --git a/UICatalog/Scenarios/ThreeD.cs b/UICatalog/Scenarios/ThreeD.cs new file mode 100644 index 000000000..d66b2aee2 --- /dev/null +++ b/UICatalog/Scenarios/ThreeD.cs @@ -0,0 +1,62 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Diagnostics.Metrics; +using System.Linq; +using Terminal.Gui; + +namespace UICatalog.Scenarios; + +[ScenarioMetadata ("3D Effects Demo", "Demonstrates 3D UI Effects.")] +[ScenarioCategory ("Layout")] +public class ThreeD : Scenario +{ + public override void Main () + { + Window app = new () + { + Title = $"{Application.QuitKey} to Quit - Scenario: {GetName ()}" + }; + + + var editor = new AdornmentsEditor () + { + AutoSelectViewToEdit = true, + }; + app.Add (editor); + + Window win = new () + { + X = Pos.Right (editor), + Y = 0, + Width = Dim.Percent (30), + Height = Dim.Percent (30), + Title = "Shadow Window", + Arrangement = ViewArrangement.Movable, + }; + + var buttonInWin = new Button + { + X = Pos.Center (), + Y = Pos.Center (), Text = "Button in Window", + //Shadow = true + }; + win.Add (buttonInWin); + app.Add (win); + + var button = new Button + { + X = Pos.Right (editor) + 10, + Y = Pos.Center (), Text = "Button", + }; + app.Add (button); + + + Application.Run (app); + app.Dispose (); + + Application.Shutdown (); + + return; + } +} diff --git a/UICatalog/UICatalog.cs b/UICatalog/UICatalog.cs index 12ccb9a3b..67721a959 100644 --- a/UICatalog/UICatalog.cs +++ b/UICatalog/UICatalog.cs @@ -330,7 +330,6 @@ internal class UICatalogApp // made by Scenario.Init() above // TODO: Throw if shutdown was not called already Application.Shutdown (); - VerifyObjectsWereDisposed (); } @@ -388,6 +387,8 @@ internal class UICatalogApp public UICatalogTopLevel () { + _diagnosticFlags = View.Diagnostics; + _themeMenuItems = CreateThemeMenuItems (); _themeMenuBarItem = new ("_Themes", _themeMenuItems); diff --git a/UnitTests/View/NeedsDisplayTests.cs b/UnitTests/View/NeedsDisplayTests.cs index c3f971250..44367c105 100644 --- a/UnitTests/View/NeedsDisplayTests.cs +++ b/UnitTests/View/NeedsDisplayTests.cs @@ -14,7 +14,7 @@ public class NeedsDisplayTests () view.BeginInit(); view.EndInit(); Assert.False (view.NeedsDisplay); - Assert.False (view.SubViewNeedsDisplay); + //Assert.False (view.SubViewNeedsDisplay); } diff --git a/UnitTests/Views/LabelTests.cs b/UnitTests/Views/LabelTests.cs index 7c04bcbe6..f6267e24b 100644 --- a/UnitTests/Views/LabelTests.cs +++ b/UnitTests/Views/LabelTests.cs @@ -247,7 +247,7 @@ This TextFormatter (tf2) with fill will be cleared on rewritten. ", label.Text = "This label is rewritten."; Assert.True (label.NeedsDisplay); Assert.True (label.LayoutNeeded); - Assert.False (label.SubViewNeedsDisplay); + //Assert.False (label.SubViewNeedsDisplay); label.Draw (); tf1.Text = "This TextFormatter (tf1) is rewritten."; diff --git a/UnitTests/Views/ToplevelTests.cs b/UnitTests/Views/ToplevelTests.cs index f1a378cbf..49e09a8aa 100644 --- a/UnitTests/Views/ToplevelTests.cs +++ b/UnitTests/Views/ToplevelTests.cs @@ -1165,12 +1165,12 @@ public class ToplevelTests (ITestOutputHelper output) if (iterations == 1) { steps [0] = iterations; - Assert.Null (e.View); + Assert.Null (e.Leaving); } else { steps [3] = iterations; - Assert.Equal (diag, e.View); + Assert.Equal (diag, e.Leaving); } }; @@ -1179,7 +1179,7 @@ public class ToplevelTests (ITestOutputHelper output) // This will never be raised iterations++; isLeaveTop = true; - Assert.Equal (diag, e.View); + Assert.Equal (diag, e.Leaving); }; top.Add (vt); @@ -1205,7 +1205,7 @@ public class ToplevelTests (ITestOutputHelper output) iterations++; steps [1] = iterations; isEnterDiag = true; - Assert.Null (e.View); + Assert.Null (e.Leaving); }; vd.Leave += (s, e) => @@ -1213,7 +1213,7 @@ public class ToplevelTests (ITestOutputHelper output) iterations++; steps [2] = iterations; isLeaveDiag = true; - Assert.Equal (top, e.View); + Assert.Equal (top, e.Entering); }; diag.Add (vd); From 7b377f6405a7d394d9c667474efe3e85780c4b05 Mon Sep 17 00:00:00 2001 From: Tig Date: Thu, 20 Jun 2024 18:23:34 -0700 Subject: [PATCH 2/2] work around dimauto issue --- UICatalog/Scenarios/BorderEditor.cs | 1 + UICatalog/Scenarios/MarginEditor.cs | 4 +++- UICatalog/Scenarios/ThreeD.cs | 2 ++ 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/UICatalog/Scenarios/BorderEditor.cs b/UICatalog/Scenarios/BorderEditor.cs index 9af7e1dd3..7ba532ff4 100644 --- a/UICatalog/Scenarios/BorderEditor.cs +++ b/UICatalog/Scenarios/BorderEditor.cs @@ -32,6 +32,7 @@ public class BorderEditor : AdornmentEditor _rbBorderStyle = new RadioGroup { X = 0, + // BUGBUG: Hack until dimauto is working properly Y = Pos.Bottom (Subviews [^1]), Width = Dim.Width (Subviews [^2]) + Dim.Width (Subviews [^1]) - 1, SelectedItem = (int)(((Border)AdornmentToEdit)?.LineStyle ?? LineStyle.None), diff --git a/UICatalog/Scenarios/MarginEditor.cs b/UICatalog/Scenarios/MarginEditor.cs index 141aa04c1..81fe9ff64 100644 --- a/UICatalog/Scenarios/MarginEditor.cs +++ b/UICatalog/Scenarios/MarginEditor.cs @@ -16,7 +16,9 @@ public class MarginEditor : AdornmentEditor var ckbShadow = new CheckBox { X = 0, - Y = Pos.AnchorEnd (), + //Y = Pos.AnchorEnd(), + // BUGBUG: Hack until dimauto is working properly + Y = Pos.Bottom (Subviews [^1]), SuperViewRendersLineCanvas = true, Title = "_Shadow", diff --git a/UICatalog/Scenarios/ThreeD.cs b/UICatalog/Scenarios/ThreeD.cs index d66b2aee2..423c1e7dd 100644 --- a/UICatalog/Scenarios/ThreeD.cs +++ b/UICatalog/Scenarios/ThreeD.cs @@ -13,6 +13,8 @@ public class ThreeD : Scenario { public override void Main () { + Application.Init (); + Window app = new () { Title = $"{Application.QuitKey} to Quit - Scenario: {GetName ()}"