Added simpler adornments sceanario

This commit is contained in:
Tig Kindel
2024-03-05 14:53:21 -07:00
parent d6e4a5b0bc
commit ef8dc48838
4 changed files with 69 additions and 4 deletions

View File

@@ -95,6 +95,8 @@ public class Adornment : View
/// <inheritdoc/>
public override void BoundsToScreen (int col, int row, out int rcol, out int rrow, bool clipped = true)
{
rcol = 0;
rrow = 0;
// Adornments are *Children* of a View, not SubViews. Thus View.BoundsToScreen will not work.
// To get the screen-relative coordinates of a Adornment, we need to know who
// the Parent is
@@ -102,7 +104,7 @@ public class Adornment : View
rrow = row + parentFrame.Y;
rcol = col + parentFrame.X;
// We now have rcol/rrow in coordinates relative to our View's SuperView. If our View's SuperView has
// We now have rcol/rrow in coordinates relative to our Parent View's SuperView. If our Parent View's SuperView has
// a SuperView, keep going...
Parent?.SuperView?.BoundsToScreen (rcol, rrow, out rcol, out rrow, clipped);
}
@@ -163,6 +165,11 @@ public class Adornment : View
return;
}
if (Parent is Label)
{
}
Rectangle screenBounds = BoundsToScreen (Frame);
Attribute normalAttr = GetNormalColor ();

View File

@@ -538,10 +538,10 @@ public partial class View
while (super is { })
{
if (super is Adornment ador)
if (super is Adornment)
{
// TODO: Move this into Adornment somehow to remove coupling.
ador.BoundsToScreen (rx, ry, out rx, out ry);
super.BoundsToScreen (rx, ry, out rx, out ry);
}
boundsOffset = super.GetBoundsOffset ();

View File

@@ -0,0 +1,56 @@
using Terminal.Gui;
namespace UICatalog.Scenarios;
[ScenarioMetadata ("Adornment Experiments", "Playground for Adornment experiments")]
[ScenarioCategory ("Controls")]
public class AdornmentExperiments : Scenario
{
private ConsoleDriver.DiagnosticFlags _diagnosticFlags;
public override void Init ()
{
Application.Init ();
ConfigurationManager.Themes.Theme = Theme;
ConfigurationManager.Apply ();
Application.Top.ColorScheme = Colors.ColorSchemes [TopLevelColorScheme];
_diagnosticFlags = ConsoleDriver.Diagnostics;
ConsoleDriver.Diagnostics = ConsoleDriver.DiagnosticFlags.FramePadding;
}
private View _frameView;
public override void Setup ()
{
_frameView = new View ()
{
Title = "Frame View",
X = 0,
Y = 0,
Width = Dim.Percent(90),
Height = Dim.Percent (90),
CanFocus = true,
};
Application.Top.Add (_frameView);
_frameView.Initialized += FrameView_Initialized;
Application.Top.Closed += (s, e) => ConsoleDriver.Diagnostics = _diagnosticFlags;
}
private void FrameView_Initialized (object sender, System.EventArgs e)
{
_frameView.Border.Thickness = new (1, 1, 1, 1);
_frameView.Padding.Thickness = new (0, 10, 0, 0);
_frameView.Padding.ColorScheme = Colors.ColorSchemes ["Error"];
var label = new Label ()
{
Text = "In Padding",
X = Pos.Center (),
Y = 0,
BorderStyle = LineStyle.Dashed
};
_frameView.Padding.Add (label);
}
}

View File

@@ -97,8 +97,10 @@ public class Adornments : Scenario
var btnButtonInPadding = new Button { X = Pos.Center (), Y = 1, Text = "_Button in Padding" };
btnButtonInPadding.Accept += (s, e) => MessageBox.Query (20, 7, "Hi", "Button in Padding Pressed!", "Ok");
//btnButtonInPadding.BorderStyle = LineStyle.Dashed;
btnButtonInPadding.BorderStyle = LineStyle.Dashed;
btnButtonInPadding.Border.Thickness = new (3,3,3,3);
view.Padding.Add (btnButtonInPadding);
btnButtonInPadding.Border.CloseButton.Visible = true;
view.Border.CloseButton.Visible = true;
view.Border.CloseButton.Accept += (s, e) =>