mirror of
https://github.com/gui-cs/Terminal.Gui.git
synced 2025-12-26 15:57:56 +01:00
* touching publish.yml * ColorScheme->Scheme * ColorScheme->Scheme 2 * Prototype of GetAttributeForRole * Badly broke CM * Further Badly broke CM * Refactored CM big-time. View still broken * All unit test pass again. Tons added. CM is still WIP, but Schemes is not mostly refactored and working. * Actually: All unit test pass again. Tons added. CM is still WIP, but Schemes is not mostly refactored and working. * Bug fixes. DeepMemberWiseClone cleanup * Further cleanup of Scope<T>, ConfigProperty, etc. * Made ConfigManager thread safe. * WIP: Broken * WIP: new deep clone impl * WIP: new deep clone impl is done. Now fixing CM * WIP: - config.md - Working on AOT clean up - Core CM is broken; but known. * WIP * Merged. Removed CM from Application.Init * WIP * More WIP; Less broke * All CM unit tests pass... Not sure if it actually works though * All unit tests pass... Themes are broken though in UI Cat * CM Ready for review? * Fixed failures due to TextStyles PR * Working on Scheme/Attribute * Working on Scheme/Attribute 2 * Working on Scheme/Attribute 3 * Working on Scheme/Attribute 4 * Working on Scheme/Attribute 5 * Working on Scheme/Attribute 6 * Added test to show how awful memory usage is * Improved schema. Updated config.json * Nade Scope<T> concurrentdictionary and added test to prove * Made Themes ConcrurrentDictionary. Added bunches of tests * Code cleanup * Code cleanup 2 * Code cleanup 3 * Tweaking Scheme * ClearJsonErrors * ClearJsonErrors2 * Updated Attribute API * It all (mostly) works! * Skip odd unit test * Messed with Themes * Theme tweaks * Code reorg. New .md stuff * Fixed Enabled. Added mock driver * Fixed a bunch of View.Enabled related issues * Scheme -> Get/SetScheme() * Cleanup * Cleanup2 * Broke something * Fixed everything * Made CM.Enable better * Text Style Scenario * Added comments * Fixed UI Catalog Theme Changing * Fixed more dynamic CM update stuff * Warning cleanup * New Default Theme * fixed unit test * Refactoring Scheme and Attribute to fix inheritance * more unit tests * ConfigProperty is not updating schemes correctly * All unit tests pass. Code cleanup * All unit tests pass. Code cleanup2 * Fixed unit tests * Upgraded TextField and TextView * Fixed TextView !Enabled bug * More updates to TextView. More unit tests for SchemeManager * Upgraded CharMap * API docs * Fixe HexView API * upgrade HexView * Fixed shortcut KeyView * Fixed more bugs. Added new themes * updated themes * upgraded Border * Fixed themes memory usage...mostly * Fixed themes memory usage...mostly2 * Fixed themes memory usage...2 * Fixed themes memory usage...3 * Added new colors * Fixed GetHardCodedConfig bug * Added Themes Scenario - WIP * Added Themes Scenario * Tweaked Themes Scenario * Code cleanup * Fixed json schmea * updated deepdives * updated deepdives * Tweaked Themes Scenario * Made Schemes a concurrent dict * Test cleanup * Thread safe ConfigProperty tests * trying to make things more thread safe * more trying to make things more thread safe * Fixing bugs in shadowview * Fixing bugs in shadowview 2 * Refactored GetViewsUnderMouse to GetViewsUnderLocation etc... * Fixed dupe unit tests? * Added better description of layout and coordiantes to deep dive * Added better description of layout and coordiantes to deep dive * Modified tests that call v2.AddTimeout; they were returning true which means restart the timer! This was causing mac/linux unit test failures. I think * Fixed auto scheme. Broke TextView/TextField selection * Realized Attribute.IsExplicitlySet is stupid; just use nullable * Fixed Attribute. Simplified. MOre theme testing * Updated themes again * GetViewsUnderMouse to GetViewsUnderLocation broke TransparentMouse. * Fixing mouseunder bugs * rewriting... * All working again. Shadows are now slick as snot. GetViewsUnderLocation is rewritten to actually work and be readable. Tons more low-level unit tests. Margin is now actually ViewportSettings.Transparent. * Code cleanup * Code cleanup * Code cleanup of color apis * Fixed Hover/Highlight * Update Examples/UICatalog/Scenarios/AllViewsTester.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update Examples/UICatalog/Scenarios/CharacterMap/CharacterMap.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update Examples/UICatalog/Scenarios/Clipping.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Fixed race condition? * reverted * Simplified Attribute API by removing events from SetAttributeForRole * Removed recursion from GetViewsAtLocation * Removed unneeded code * Code clean up. Fixed Scheme bug. * reverted temporary disable * Adjusted scheme algo * Upgraded TextValidateField * Fixed TextValidate bugs * Tweaks * Frameview rounded border by default * API doc cleanup * Readme fix * Addressed tznind feeback * Fixed more unit test issues by protecting Application statics from being set if Application.Initialized is not true * Fixed more unit test issues by protecting Application statics from being set if Application.Initialized is not true 2 * cleanup --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
465 lines
17 KiB
C#
465 lines
17 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using Terminal.Gui;
|
|
|
|
namespace UICatalog.Scenarios;
|
|
|
|
/// <summary>
|
|
/// This Scenario demonstrates how to use Terminal.Gui's Dim and Pos Layout System.
|
|
/// </summary>
|
|
[ScenarioMetadata ("Computed Layout", "Demonstrates the Computed (Dim and Pos) Layout System.")]
|
|
[ScenarioCategory ("Layout")]
|
|
public class ComputedLayout : Scenario
|
|
{
|
|
public override void Main ()
|
|
{
|
|
Application.Init ();
|
|
|
|
Window app = new ()
|
|
{
|
|
Title = GetQuitKeyAndName ()
|
|
};
|
|
|
|
// Demonstrate using Dim to create a horizontal ruler that always measures the parent window's width
|
|
const string rule = "|123456789";
|
|
|
|
var horizontalRuler = new Label
|
|
{
|
|
X = 0,
|
|
Y = 0,
|
|
Width = Dim.Fill (),
|
|
Height = 1,
|
|
SchemeName = "Error",
|
|
Text = rule
|
|
};
|
|
|
|
app.Add (horizontalRuler);
|
|
|
|
// Demonstrate using Dim to create a vertical ruler that always measures the parent window's height
|
|
const string vrule = "|\n1\n2\n3\n4\n5\n6\n7\n8\n9\n";
|
|
|
|
var verticalRuler = new Label
|
|
{
|
|
X = 0,
|
|
Y = 0,
|
|
Width = 1,
|
|
Height = Dim.Fill (),
|
|
SchemeName = "Error",
|
|
Text = vrule
|
|
};
|
|
|
|
app.SubViewsLaidOut += (s, a) =>
|
|
{
|
|
if (horizontalRuler.Viewport.Width == 0 || horizontalRuler.Viewport.Height == 0)
|
|
{
|
|
return;
|
|
}
|
|
|
|
horizontalRuler.Text =
|
|
rule.Repeat ((int)Math.Ceiling (horizontalRuler.Viewport.Width / (double)rule.Length)) [
|
|
..horizontalRuler.Viewport.Width];
|
|
|
|
verticalRuler.Text =
|
|
vrule.Repeat ((int)Math.Ceiling (verticalRuler.Viewport.Height * 2 / (double)rule.Length))
|
|
[..(verticalRuler.Viewport.Height * 2)];
|
|
};
|
|
|
|
app.Add (verticalRuler);
|
|
|
|
// Demonstrate At - Using Pos.At to locate a view in an absolute location
|
|
var atButton = new Button { Text = "Absolute(2,1)", X = Pos.Absolute (2), Y = Pos.Absolute (1) };
|
|
app.Add (atButton);
|
|
|
|
// Throw in a literal absolute - Should function identically to above
|
|
var absoluteButton = new Button { Text = "X = 30, Y = 1", X = 30, Y = 1 };
|
|
app.Add (absoluteButton);
|
|
|
|
// Demonstrate using Dim to create a window that fills the parent with a margin
|
|
var margin = 10;
|
|
|
|
var subWin = new Window
|
|
{
|
|
X = Pos.Center (), Y = 2, Width = Dim.Fill (margin), Height = 7,
|
|
Arrangement = ViewArrangement.Movable | ViewArrangement.Resizable | ViewArrangement.Overlapped
|
|
};
|
|
|
|
subWin.Initialized += (s, a) =>
|
|
{
|
|
subWin.Title =
|
|
$"{subWin.GetType ().Name} {{X={subWin.X},Y={subWin.Y},Width={subWin.Width},Height={subWin.Height}}}";
|
|
};
|
|
app.Add (subWin);
|
|
|
|
var i = 1;
|
|
var txt = "Resize the terminal to see computed layout in action.";
|
|
List<Label> labelList = new ();
|
|
labelList.Add (new() { Text = "The lines below show different alignment" });
|
|
|
|
labelList.Add (
|
|
new()
|
|
{
|
|
TextAlignment = Alignment.Start,
|
|
Width = Dim.Fill (),
|
|
X = 0,
|
|
Y = Pos.Bottom (labelList.LastOrDefault ()),
|
|
SchemeName = "Dialog",
|
|
Text = $"{i++}-{txt}"
|
|
}
|
|
);
|
|
|
|
labelList.Add (
|
|
new()
|
|
{
|
|
TextAlignment = Alignment.End,
|
|
Width = Dim.Fill (),
|
|
X = 0,
|
|
Y = Pos.Bottom (labelList.LastOrDefault ()),
|
|
SchemeName = "Dialog",
|
|
Text = $"{i++}-{txt}"
|
|
}
|
|
);
|
|
|
|
labelList.Add (
|
|
new()
|
|
{
|
|
TextAlignment = Alignment.Center,
|
|
Width = Dim.Fill (),
|
|
X = 0,
|
|
Y = Pos.Bottom (labelList.LastOrDefault ()),
|
|
SchemeName = "Dialog",
|
|
Text = $"{i++}-{txt}"
|
|
}
|
|
);
|
|
|
|
labelList.Add (
|
|
new()
|
|
{
|
|
TextAlignment = Alignment.Fill,
|
|
Width = Dim.Fill (),
|
|
X = 0,
|
|
Y = Pos.Bottom (labelList.LastOrDefault ()),
|
|
SchemeName = "Dialog",
|
|
Text = $"{i++}-{txt}"
|
|
}
|
|
);
|
|
subWin.Add (labelList.ToArray ());
|
|
|
|
var frameView = new FrameView { X = 2, Y = Pos.Bottom (subWin), Width = 30, Height = 7 };
|
|
|
|
frameView.Initialized += (sender, args) =>
|
|
{
|
|
var fv = sender as FrameView;
|
|
|
|
fv.Title =
|
|
$"{frameView.GetType ().Name} {{X={fv.X},Y={fv.Y},Width={fv.Width},Height={fv.Height}}}";
|
|
};
|
|
i = 1;
|
|
labelList = new ();
|
|
labelList.Add (new() { Text = "The lines below show different alignment" });
|
|
|
|
labelList.Add (
|
|
new()
|
|
{
|
|
TextAlignment = Alignment.Start,
|
|
Width = Dim.Fill (),
|
|
X = 0,
|
|
Y = Pos.Bottom (labelList.LastOrDefault ()),
|
|
SchemeName = "Dialog",
|
|
Text = $"{i++}-{txt}"
|
|
}
|
|
);
|
|
|
|
labelList.Add (
|
|
new()
|
|
{
|
|
TextAlignment = Alignment.End,
|
|
Width = Dim.Fill (),
|
|
X = 0,
|
|
Y = Pos.Bottom (labelList.LastOrDefault ()),
|
|
SchemeName = "Dialog",
|
|
Text = $"{i++}-{txt}"
|
|
}
|
|
);
|
|
|
|
labelList.Add (
|
|
new()
|
|
{
|
|
TextAlignment = Alignment.Center,
|
|
Width = Dim.Fill (),
|
|
X = 0,
|
|
Y = Pos.Bottom (labelList.LastOrDefault ()),
|
|
SchemeName = "Dialog",
|
|
Text = $"{i++}-{txt}"
|
|
}
|
|
);
|
|
|
|
labelList.Add (
|
|
new()
|
|
{
|
|
TextAlignment = Alignment.Fill,
|
|
Width = Dim.Fill (),
|
|
X = 0,
|
|
Y = Pos.Bottom (labelList.LastOrDefault ()),
|
|
SchemeName = "Dialog",
|
|
Text = $"{i++}-{txt}"
|
|
}
|
|
);
|
|
frameView.Add (labelList.ToArray ());
|
|
app.Add (frameView);
|
|
|
|
frameView = new()
|
|
{
|
|
X = Pos.Right (frameView), Y = Pos.Top (frameView), Width = Dim.Fill (), Height = 7
|
|
};
|
|
|
|
frameView.Initialized += (sender, args) =>
|
|
{
|
|
var fv = sender as FrameView;
|
|
|
|
fv.Title =
|
|
$"{frameView.GetType ().Name} {{X={fv.X},Y={fv.Y},Width={fv.Width},Height={fv.Height}}}";
|
|
};
|
|
|
|
labelList = new ();
|
|
labelList.Add (new() { Text = "The lines below show different alignment" });
|
|
|
|
labelList.Add (
|
|
new()
|
|
{
|
|
TextAlignment = Alignment.Start,
|
|
Width = Dim.Fill (),
|
|
X = 0,
|
|
Y = Pos.Bottom (labelList.LastOrDefault ()),
|
|
SchemeName = "Dialog",
|
|
Text = $"{i++}-{txt}"
|
|
}
|
|
);
|
|
|
|
labelList.Add (
|
|
new()
|
|
{
|
|
TextAlignment = Alignment.End,
|
|
Width = Dim.Fill (),
|
|
X = 0,
|
|
Y = Pos.Bottom (labelList.LastOrDefault ()),
|
|
SchemeName = "Dialog",
|
|
Text = $"{i++}-{txt}"
|
|
}
|
|
);
|
|
|
|
labelList.Add (
|
|
new()
|
|
{
|
|
TextAlignment = Alignment.Center,
|
|
Width = Dim.Fill (),
|
|
X = 0,
|
|
Y = Pos.Bottom (labelList.LastOrDefault ()),
|
|
SchemeName = "Dialog",
|
|
Text = $"{i++}-{txt}"
|
|
}
|
|
);
|
|
|
|
labelList.Add (
|
|
new()
|
|
{
|
|
TextAlignment = Alignment.Fill,
|
|
Width = Dim.Fill (),
|
|
X = 0,
|
|
Y = Pos.Bottom (labelList.LastOrDefault ()),
|
|
SchemeName = "Dialog",
|
|
Text = $"{i++}-{txt}"
|
|
}
|
|
);
|
|
frameView.Add (labelList.ToArray ());
|
|
app.Add (frameView);
|
|
|
|
// Demonstrate Dim & Pos using percentages - a TextField that is 30% height and 80% wide
|
|
var textView = new TextView
|
|
{
|
|
X = Pos.Center (),
|
|
Y = Pos.Percent (50),
|
|
Width = Dim.Percent (80),
|
|
Height = Dim.Percent (10),
|
|
SchemeName = "TopLevel"
|
|
};
|
|
|
|
textView.Text =
|
|
"This TextView should horizontally & vertically centered and \n10% of the screeen height, and 80% of its width.";
|
|
app.Add (textView);
|
|
|
|
var oddballButton = new Button
|
|
{
|
|
Text = "These buttons demo convoluted PosCombine scenarios",
|
|
X = Pos.Center (),
|
|
Y = Pos.Bottom (textView) + 1
|
|
};
|
|
app.Add (oddballButton);
|
|
|
|
#region Issue2358
|
|
|
|
// Demonstrate odd-ball Combine scenarios
|
|
// Until https://github.com/gui-cs/Terminal.Gui/issues/2358 is fixed these won't work right
|
|
|
|
oddballButton = new() { Text = "Center + 0", X = Pos.Center () + 0, Y = Pos.Bottom (oddballButton) };
|
|
app.Add (oddballButton);
|
|
|
|
oddballButton = new() { Text = "Center + 1", X = Pos.Center () + 1, Y = Pos.Bottom (oddballButton) };
|
|
app.Add (oddballButton);
|
|
|
|
oddballButton = new() { Text = "0 + Center", X = 0 + Pos.Center (), Y = Pos.Bottom (oddballButton) };
|
|
app.Add (oddballButton);
|
|
|
|
oddballButton = new() { Text = "1 + Center", X = 1 + Pos.Center (), Y = Pos.Bottom (oddballButton) };
|
|
app.Add (oddballButton);
|
|
|
|
oddballButton = new() { Text = "Center - 1", X = Pos.Center () - 1, Y = Pos.Bottom (oddballButton) };
|
|
app.Add (oddballButton);
|
|
|
|
// This demonstrates nonsense: it the same as using Pos.AnchorEnd (100/2=50 + 100/2=50 = 100 - 50)
|
|
// The `- Pos.Percent(5)` is there so at least something is visible
|
|
oddballButton = new()
|
|
{
|
|
Text = "Center + Center - Percent(50)",
|
|
X = Pos.Center () + Pos.Center () - Pos.Percent (50),
|
|
Y = Pos.Bottom (oddballButton)
|
|
};
|
|
app.Add (oddballButton);
|
|
|
|
// This demonstrates nonsense: it the same as using Pos.AnchorEnd (100/2=50 + 100/2=50 = 100 - 50)
|
|
// The `- Pos.Percent(5)` is there so at least something is visible
|
|
oddballButton = new()
|
|
{
|
|
Text = "Percent(50) + Center - Percent(50)",
|
|
X = Pos.Percent (50) + Pos.Center () - Pos.Percent (50),
|
|
Y = Pos.Bottom (oddballButton)
|
|
};
|
|
app.Add (oddballButton);
|
|
|
|
// This demonstrates nonsense: it the same as using Pos.AnchorEnd (100/2=50 + 100/2=50 = 100 - 50)
|
|
// The `- Pos.Percent(5)` is there so at least something is visible
|
|
oddballButton = new()
|
|
{
|
|
Text = "Center + Percent(50) - Percent(50)",
|
|
X = Pos.Center () + Pos.Percent (50) - Pos.Percent (50),
|
|
Y = Pos.Bottom (oddballButton)
|
|
};
|
|
app.Add (oddballButton);
|
|
|
|
#endregion
|
|
|
|
// This demonstrates nonsense: Same as At(0)
|
|
oddballButton = new()
|
|
{
|
|
Text = "Center - Center - Percent(50)",
|
|
X = Pos.Center () + Pos.Center () - Pos.Percent (50),
|
|
Y = Pos.Bottom (oddballButton)
|
|
};
|
|
app.Add (oddballButton);
|
|
|
|
// This demonstrates combining Percents)
|
|
oddballButton = new()
|
|
{
|
|
Text = "Percent(40) + Percent(10)", X = Pos.Percent (40) + Pos.Percent (10), Y = Pos.Bottom (oddballButton)
|
|
};
|
|
app.Add (oddballButton);
|
|
|
|
// Demonstrate AnchorEnd - Button is anchored to bottom/right
|
|
var anchorButton = new Button { Text = "Button using AnchorEnd", Y = Pos.AnchorEnd () };
|
|
anchorButton.X = Pos.AnchorEnd ();
|
|
|
|
anchorButton.Accepting += (s, e) =>
|
|
{
|
|
// This demonstrates how to have a dynamically sized button
|
|
// Each time the button is clicked the button's text gets longer
|
|
// The call to app.LayoutSubViews causes the Computed layout to
|
|
// get updated.
|
|
anchorButton.Text += "!";
|
|
};
|
|
app.Add (anchorButton);
|
|
|
|
// Demonstrate AnchorEnd(n)
|
|
// This is intentionally convoluted to illustrate potential bugs.
|
|
var anchorEndLabel1 = new Label
|
|
{
|
|
Text = "This Label should be the 3rd to last line (AnchorEnd (3)).",
|
|
TextAlignment = Alignment.Center,
|
|
SchemeName = "Menu",
|
|
Width = Dim.Fill (5),
|
|
X = 5,
|
|
Y = Pos.AnchorEnd (3)
|
|
};
|
|
app.Add (anchorEndLabel1);
|
|
|
|
// Demonstrate DimCombine (via AnchorEnd(n) - 1)
|
|
// This is intentionally convoluted to illustrate potential bugs.
|
|
var anchorEndLabel2 = new TextField
|
|
{
|
|
Text =
|
|
"This TextField should be the 4th to last line (AnchorEnd (3) - 1).",
|
|
TextAlignment = Alignment.Start,
|
|
SchemeName = "Menu",
|
|
Width = Dim.Fill (5),
|
|
X = 5,
|
|
Y = Pos.AnchorEnd (3) - 1 // Pos.Combine
|
|
};
|
|
app.Add (anchorEndLabel2);
|
|
|
|
// Demonstrate AnchorEnd() in combination with Pos.Align to align a set of buttons centered across the
|
|
// bottom - 1
|
|
// This is intentionally convoluted to illustrate potential bugs.
|
|
var leftButton = new Button
|
|
{
|
|
Text = "Left",
|
|
X = Pos.Align (Alignment.Center),
|
|
Y = Pos.AnchorEnd () - 1
|
|
};
|
|
|
|
leftButton.Accepting += (s, e) =>
|
|
{
|
|
// This demonstrates how to have a dynamically sized button
|
|
// Each time the button is clicked the button's text gets longer
|
|
leftButton.Text += "!";
|
|
};
|
|
|
|
// show positioning vertically using Pos.AnchorEnd
|
|
var centerButton = new Button
|
|
{
|
|
Text = "Center",
|
|
X = Pos.Align (Alignment.Center),
|
|
Y = Pos.AnchorEnd (2)
|
|
};
|
|
|
|
centerButton.Accepting += (s, e) =>
|
|
{
|
|
// This demonstrates how to have a dynamically sized button
|
|
// Each time the button is clicked the button's text gets longer
|
|
centerButton.Text += "!";
|
|
};
|
|
|
|
// show positioning vertically using another window and Pos.Bottom
|
|
var rightButton = new Button
|
|
{
|
|
Text = "Right",
|
|
X = Pos.Align (Alignment.Center),
|
|
Y = Pos.Y (centerButton)
|
|
};
|
|
|
|
rightButton.Accepting += (s, e) =>
|
|
{
|
|
// This demonstrates how to have a dynamically sized button
|
|
// Each time the button is clicked the button's text gets longer
|
|
rightButton.Text += "!";
|
|
};
|
|
|
|
View [] buttons = { leftButton, centerButton, rightButton };
|
|
app.Add (leftButton);
|
|
app.Add (centerButton);
|
|
app.Add (rightButton);
|
|
|
|
Application.Run (app);
|
|
app.Dispose ();
|
|
Application.Shutdown ();
|
|
}
|
|
}
|