mirror of
https://github.com/gui-cs/Terminal.Gui.git
synced 2026-01-01 08:50:25 +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>
223 lines
7.3 KiB
C#
223 lines
7.3 KiB
C#
#nullable enable
|
|
using Terminal.Gui;
|
|
|
|
namespace UICatalog.Scenarios;
|
|
|
|
[ScenarioMetadata ("Text Styles", "Shows Attribute.TextStyles including bold, italic, etc...")]
|
|
[ScenarioCategory ("Text and Formatting")]
|
|
[ScenarioCategory ("Colors")]
|
|
public sealed class TestStyles : Scenario
|
|
{
|
|
private CheckBox? _drawDirectly;
|
|
|
|
public override void Main ()
|
|
{
|
|
// Init
|
|
Application.Init ();
|
|
|
|
// Setup - Create a top-level application window and configure it.
|
|
Window appWindow = new ()
|
|
{
|
|
Id = "appWindow",
|
|
Title = GetQuitKeyAndName ()
|
|
};
|
|
|
|
//appWindow.ContentSizeTracksViewport = false;
|
|
appWindow.VerticalScrollBar.AutoShow = true;
|
|
appWindow.HorizontalScrollBar.AutoShow = true;
|
|
|
|
appWindow.SubViewsLaidOut += (sender, _) =>
|
|
{
|
|
if (sender is View sendingView)
|
|
{
|
|
sendingView.SetContentSize (new Size(sendingView.GetContentSize().Width, sendingView.GetHeightRequiredForSubViews()));
|
|
}
|
|
};
|
|
|
|
appWindow.DrawingContent += OnAppWindowOnDrawingContent;
|
|
appWindow.DrawingSubViews += OnAppWindowOnDrawingSubviews;
|
|
|
|
_drawDirectly = new ()
|
|
{
|
|
Title = "_Draw styled text directly using DrawingContent vs. Buttons",
|
|
CheckedState = CheckState.UnChecked
|
|
};
|
|
|
|
appWindow.Add (_drawDirectly);
|
|
AddButtons (appWindow);
|
|
|
|
// Run - Start the application.
|
|
Application.Run (appWindow);
|
|
appWindow.Dispose ();
|
|
|
|
// Shutdown - Calling Application.Shutdown is required.
|
|
Application.Shutdown ();
|
|
}
|
|
|
|
private void AddButtons (Window appWindow)
|
|
{
|
|
var y = 1;
|
|
|
|
TextStyle [] allStyles = Enum.GetValues (typeof (TextStyle))
|
|
.Cast<TextStyle> ()
|
|
.Where (style => style != TextStyle.None)
|
|
.ToArray ();
|
|
|
|
// Add individual flags as labels
|
|
foreach (TextStyle style in allStyles)
|
|
{
|
|
y++;
|
|
|
|
var button = new Button
|
|
{
|
|
X = 0,
|
|
Y = y,
|
|
Title = $"{Enum.GetName (typeof (TextStyle), style)}",
|
|
Visible = _drawDirectly!.CheckedState != CheckState.Checked
|
|
};
|
|
|
|
button.GettingAttributeForRole += (sender, args) =>
|
|
{
|
|
if (sender is not Button buttonSender)
|
|
{
|
|
return;
|
|
}
|
|
args.NewValue = args.NewValue with { Style = style };
|
|
args.Cancel = true;
|
|
};
|
|
|
|
appWindow.Add (button);
|
|
}
|
|
|
|
// Add a blank line
|
|
y += 1;
|
|
|
|
// Generate all combinations of TextStyle (excluding individual flags)
|
|
int totalCombinations = 1 << allStyles.Length; // 2^n combinations
|
|
|
|
for (var i = 1; i < totalCombinations; i++) // Start from 1 to skip "None"
|
|
{
|
|
var combination = (TextStyle)0;
|
|
List<string> styleNames = [];
|
|
|
|
for (var bit = 0; bit < allStyles.Length; bit++)
|
|
{
|
|
if ((i & (1 << bit)) != 0)
|
|
{
|
|
combination |= allStyles [bit];
|
|
styleNames.Add (Enum.GetName (typeof (TextStyle), allStyles [bit])!);
|
|
}
|
|
}
|
|
|
|
// Skip individual flags
|
|
if (styleNames.Count == 1)
|
|
{
|
|
continue;
|
|
}
|
|
|
|
y++;
|
|
|
|
var button = new Button
|
|
{
|
|
X = 0,
|
|
Y = y,
|
|
Text = $"[{string.Join (" | ", styleNames)}]",
|
|
Visible = _drawDirectly!.CheckedState != CheckState.Checked
|
|
};
|
|
button.GettingAttributeForRole += (_, args) =>
|
|
{
|
|
args.NewValue = args.NewValue with { Style = combination };
|
|
args.Cancel = true;
|
|
};
|
|
appWindow.Add (button);
|
|
}
|
|
}
|
|
|
|
private void OnAppWindowOnDrawingSubviews (object? sender, DrawEventArgs e)
|
|
{
|
|
if (sender is not View sendingVioew)
|
|
{
|
|
return;
|
|
}
|
|
|
|
foreach (Button view in sendingVioew.SubViews.OfType<Button> ())
|
|
{
|
|
view.Visible = _drawDirectly!.CheckedState != CheckState.Checked;
|
|
}
|
|
|
|
e.Cancel = false;
|
|
}
|
|
|
|
private void OnAppWindowOnDrawingContent (object? sender, DrawEventArgs args)
|
|
{
|
|
if (sender is View { } sendingView && _drawDirectly!.CheckedState == CheckState.Checked)
|
|
{
|
|
int y = 2 - args.NewViewport.Y; // Start drawing below the checkbox
|
|
|
|
TextStyle [] allStyles = Enum.GetValues (typeof (TextStyle))
|
|
.Cast<TextStyle> ()
|
|
.Where (style => style != TextStyle.None)
|
|
.ToArray ();
|
|
|
|
// Draw individual flags, one per line
|
|
foreach (TextStyle style in allStyles)
|
|
{
|
|
string text = Enum.GetName (typeof (TextStyle), style)!;
|
|
|
|
sendingView.Move (0, y);
|
|
|
|
var attr = new Attribute (sendingView.GetAttributeForRole (VisualRole.Normal))
|
|
{
|
|
Style = style
|
|
};
|
|
sendingView.SetAttribute (attr);
|
|
sendingView.AddStr (text);
|
|
|
|
y++; // Move to the next line
|
|
}
|
|
|
|
// Add a blank line
|
|
y++;
|
|
|
|
// Generate all combinations of TextStyle (excluding individual flags)
|
|
int totalCombinations = 1 << allStyles.Length; // 2^n combinations
|
|
|
|
for (var i = 1; i < totalCombinations; i++) // Start from 1 to skip "None"
|
|
{
|
|
var combination = (TextStyle)0;
|
|
List<string> styleNames = [];
|
|
|
|
for (var bit = 0; bit < allStyles.Length; bit++)
|
|
{
|
|
if ((i & (1 << bit)) != 0)
|
|
{
|
|
combination |= allStyles [bit];
|
|
styleNames.Add (Enum.GetName (typeof (TextStyle), allStyles [bit])!);
|
|
}
|
|
}
|
|
|
|
// Skip individual flags
|
|
if (styleNames.Count == 1)
|
|
{
|
|
continue;
|
|
}
|
|
|
|
var text = $"[{string.Join (" | ", styleNames)}]";
|
|
|
|
sendingView.Move (00, y);
|
|
|
|
var attr = new Attribute (sendingView.GetAttributeForRole (VisualRole.Normal))
|
|
{
|
|
Style = combination
|
|
};
|
|
sendingView.SetAttribute (attr);
|
|
sendingView.AddStr (text);
|
|
|
|
y++; // Move to the next line
|
|
}
|
|
|
|
args.Cancel = true;
|
|
}
|
|
}
|
|
}
|