diff --git a/Terminal.Gui/Views/Shortcut.cs b/Terminal.Gui/Views/Shortcut.cs
index a0df78b86..45c3dea67 100644
--- a/Terminal.Gui/Views/Shortcut.cs
+++ b/Terminal.Gui/Views/Shortcut.cs
@@ -38,8 +38,6 @@
///
public class Shortcut : View, IOrientation, IDesignable
{
- private readonly OrientationHelper _orientationHelper;
-
///
/// Creates a new instance of .
///
@@ -76,7 +74,7 @@ public class Shortcut : View, IOrientation, IDesignable
CommandView = new ()
{
Width = Dim.Auto (),
- Height = Dim.Auto (DimAutoStyle.Auto, minimumContentDim: 1)
+ Height = Dim.Auto (1)
};
HelpView.Id = "_helpView";
@@ -142,45 +140,25 @@ public class Shortcut : View, IOrientation, IDesignable
///
public Shortcut () : this (Key.Empty, string.Empty, null) { }
- #region IOrientation members
-
- ///
- /// Gets or sets the for this . The default is
- /// .
- ///
- ///
- ///
- /// Horizontal orientation arranges the command, help, and key parts of each s from right to
- /// left
- /// Vertical orientation arranges the command, help, and key parts of each s from left to
- /// right.
- ///
- ///
-
- public Orientation Orientation
- {
- get => _orientationHelper.Orientation;
- set => _orientationHelper.Orientation = value;
- }
-
- ///
- public event EventHandler> OrientationChanging;
-
- ///
- public event EventHandler> OrientationChanged;
-
- /// Called when has changed.
- ///
- public void OnOrientationChanged (Orientation newOrientation)
- {
- // TODO: Determine what, if anything, is opinionated about the orientation.
- SetNeedsLayout ();
- }
-
- #endregion
+ private readonly OrientationHelper _orientationHelper;
private AlignmentModes _alignmentModes = AlignmentModes.StartToEnd | AlignmentModes.IgnoreFirstOrLast;
+ // This is used to calculate the minimum width of the Shortcut when the width is NOT Dim.Auto
+ private int? _minimumDimAutoWidth;
+
+ private Color? _savedForeColor;
+
+ ///
+ public bool EnableForDesign ()
+ {
+ Title = "_Shortcut";
+ HelpText = "Shortcut help";
+ Key = Key.F1;
+
+ return true;
+ }
+
///
/// Gets or sets the for this .
///
@@ -202,6 +180,30 @@ public class Shortcut : View, IOrientation, IDesignable
}
}
+ ///
+ protected override void Dispose (bool disposing)
+ {
+ if (disposing)
+ {
+ if (CommandView?.IsAdded == false)
+ {
+ CommandView.Dispose ();
+ }
+
+ if (HelpView?.IsAdded == false)
+ {
+ HelpView.Dispose ();
+ }
+
+ if (KeyView?.IsAdded == false)
+ {
+ KeyView.Dispose ();
+ }
+ }
+
+ base.Dispose (disposing);
+ }
+
// When one of the subviews is "empty" we don't want to show it. So we
// Use Add/Remove. We need to be careful to add them in the right order
// so Pos.Align works correctly.
@@ -225,8 +227,15 @@ public class Shortcut : View, IOrientation, IDesignable
}
}
- // This is used to calculate the minimum width of the Shortcut when the width is NOT Dim.Auto
- private int? _minimumDimAutoWidth;
+ private Thickness GetMarginThickness ()
+ {
+ if (Orientation == Orientation.Vertical)
+ {
+ return new (1, 0, 1, 0);
+ }
+
+ return new (1, 0, 1, 0);
+ }
// When layout starts, we need to adjust the layout of the HelpView and KeyView
private void OnLayoutStarted (object sender, LayoutEventArgs e)
@@ -305,18 +314,16 @@ public class Shortcut : View, IOrientation, IDesignable
}
}
- private Thickness GetMarginThickness ()
+ private bool? OnSelect (CommandContext ctx)
{
- if (Orientation == Orientation.Vertical)
+ if (CommandView.GetSupportedCommands ().Contains (Command.Select))
{
- return new (1, 0, 1, 0);
+ return CommandView.InvokeCommand (Command.Select, ctx.Key, ctx.KeyBinding);
}
- return new (1, 0, 1, 0);
+ return false;
}
- private Color? _savedForeColor;
-
private void Shortcut_Highlight (object sender, CancelEventArgs e)
{
if (e.CurrentValue.HasFlag (HighlightStyle.Pressed))
@@ -368,6 +375,43 @@ public class Shortcut : View, IOrientation, IDesignable
// TODO: Remove. This does nothing.
}
+ #region IOrientation members
+
+ ///
+ /// Gets or sets the for this . The default is
+ /// .
+ ///
+ ///
+ ///
+ /// Horizontal orientation arranges the command, help, and key parts of each s from right to
+ /// left
+ /// Vertical orientation arranges the command, help, and key parts of each s from left to
+ /// right.
+ ///
+ ///
+
+ public Orientation Orientation
+ {
+ get => _orientationHelper.Orientation;
+ set => _orientationHelper.Orientation = value;
+ }
+
+ ///
+ public event EventHandler> OrientationChanging;
+
+ ///
+ public event EventHandler> OrientationChanged;
+
+ /// Called when has changed.
+ ///
+ public void OnOrientationChanged (Orientation newOrientation)
+ {
+ // TODO: Determine what, if anything, is opinionated about the orientation.
+ SetNeedsLayout ();
+ }
+
+ #endregion
+
#region Command
private View _commandView = new ();
@@ -644,6 +688,7 @@ public class Shortcut : View, IOrientation, IDesignable
{
KeyBindings.Remove (oldKey);
}
+
KeyBindings.Remove (Key);
KeyBindings.Add (Key, KeyBindingScope | KeyBindingScope.HotKey, Command.Accept);
}
@@ -724,16 +769,6 @@ public class Shortcut : View, IOrientation, IDesignable
#endregion Accept Handling
- private bool? OnSelect (CommandContext ctx)
- {
- if (CommandView.GetSupportedCommands ().Contains (Command.Select))
- {
- return CommandView.InvokeCommand (Command.Select, ctx.Key, ctx.KeyBinding);
- }
-
- return false;
- }
-
#region Focus
///
@@ -803,38 +838,4 @@ public class Shortcut : View, IOrientation, IDesignable
}
#endregion Focus
-
- ///
- public bool EnableForDesign ()
- {
- Title = "_Shortcut";
- HelpText = "Shortcut help";
- Key = Key.F1;
-
- return true;
- }
-
- ///
- protected override void Dispose (bool disposing)
- {
- if (disposing)
- {
- if (CommandView?.IsAdded == false)
- {
- CommandView.Dispose ();
- }
-
- if (HelpView?.IsAdded == false)
- {
- HelpView.Dispose ();
- }
-
- if (KeyView?.IsAdded == false)
- {
- KeyView.Dispose ();
- }
- }
-
- base.Dispose (disposing);
- }
}
diff --git a/docfx/docs/layout.md b/docfx/docs/layout.md
index fb7d0f012..639d2d5c9 100644
--- a/docfx/docs/layout.md
+++ b/docfx/docs/layout.md
@@ -5,7 +5,7 @@ Terminal.Gui provides a rich system for how `View` objects are laid out relative
## Coordinates
* **Screen-Relative** - Describes the dimensions and characteristics of the underlying terminal. Currently Terminal.Gui only supports applications that run "full-screen", meaning they fill the entire terminal when running. As the user resizes their terminal, the `Screen` changes size and the applicaiton will be resized to fit. *Screen-Relative* means an origin (`0, 0`) at the top-left corner of the terminal. `ConsoleDriver`s operate exclusively on *Screen-Relative* coordinates.
-* **Application.Relative** - The dimensions and characteristics of the application. Because only full-screen apps are currently supported, `Application` is effectively the same as `Screen` from a layout perspective. *Application-Relative* currently means an origin (`0, 0`) at the top-left corner of the terminal. `Applicaiton.Top` is a `View` with a top-left corner fixed at the *Application.Relative* coordinate of (`0, 0`) and is the size of `Screen`.
+* **Application-Relative** - The dimensions and characteristics of the application. Because only full-screen apps are currently supported, `Application` is effectively the same as `Screen` from a layout perspective. *Application-Relative* currently means an origin (`0, 0`) at the top-left corner of the terminal. `Applicaiton.Top` is a `View` with a top-left corner fixed at the *Application.Relative* coordinate of (`0, 0`) and is the size of `Screen`.
* **Frame-Relative** - The `Frame` property of a `View` is a rectangle that describes the current location and size of the view relative to the `Superview`'s content area. *Frame-Relative* means a coordinate is relative to the top-left corner of the View in question. `View.FrameToScreen ()` and `View.ScreenToFrame ()` are helper methods for translating a *Frame-Relative* coordinate to a *Screen-Relative* coordinate and vice-versa.
* **Content-Relative** - A rectangle, with an origin of (`0, 0`) and size (defined by `View.GetContentSize()`) where the View's content exists. *Content-Relative* means a coordinate is relative to the top-left corner of the content, which is always (`0,0`). `View.ContentToScreen ()` and `View.ScreenToContent ()` are helper methods for translating a *Content-Relative* coordinate to a *Screen-Relative* coordinate and vice-versa.
* **Viewport-Relative** - A *Content-Relative* rectangle representing the subset of the View's content that is visible to the user. If `View.GetContentSize()` is larger than the Viewport, scrolling is enabled. *Viewport-Relative* means a coordinate that is bound by (`0,0`) and the size of the inner-rectangle of the View's `Padding`. The View drawing primitives (e.g. `View.Move`) take *Viewport-Relative* coordinates; `Move (0, 0)` means the `Cell` in the top-left corner of the inner rectangle of `Padding`. `View.ViewportToScreen ()` and `View.ScreenToViewport ()` are helper methods for translating a *Viewport-Relative* coordinate to a *Screen-Relative* coordinate and vice-versa. To convert a *Viewport-Relative* coordinate to a *Content-Relative* coordinate, simply subtract `Viewport.X` and/or `Viewport.Y` from the *Content-Relative* coordinate. To convert a *Viewport-Relative* coordinate to a *Frame-Relative* coordinate, subtract the point returned by `View.GetViewportOffsetFromFrame`.