Fixed force16color logic

This commit is contained in:
Tigger Kindel
2023-10-10 12:27:08 -06:00
committed by Tig
parent c9ce86578c
commit c133369578
3 changed files with 15 additions and 7 deletions

View File

@@ -253,7 +253,7 @@ namespace Terminal.Gui {
/// Gets or sets the <see cref="Color"/> using a legacy 16-color <see cref="ColorNames"/> value.
/// </summary>
/// <remarks>
/// Get returns the closest 24-bit color value. Set sets the RGB value using a hard-coded map.
/// Get returns the <see cref="ColorName"/> of the closest 24-bit color value. Set sets the RGB value using a hard-coded map.
/// </remarks>
public ColorNames ColorName {
get => FindClosestColor (this.Value);

View File

@@ -38,10 +38,10 @@ namespace UICatalog.Scenarios {
var cbUseTrueColor = new CheckBox ("Use true color") {
X = x,
Y = y++,
Checked = Application.Driver.Force16Colors,
Checked = !Application.Driver.Force16Colors,
Enabled = canTrueColor,
};
cbUseTrueColor.Toggled += (_, evt) => Application.Driver.Force16Colors = evt.NewValue ?? false;
cbUseTrueColor.Toggled += (_, evt) => Application.Driver.Force16Colors = !evt.NewValue ?? false;
Win.Add (cbUseTrueColor);
var btnOpenImage = new Button ("Open Image") {
@@ -60,11 +60,16 @@ namespace UICatalog.Scenarios {
btnOpenImage.Clicked += (_, _) => {
var ofd = new OpenDialog ("Open Image") { AllowsMultipleSelection = false };
var ofd = new OpenDialog ("Open Image") { AllowsMultipleSelection = false, };
Application.Run (ofd);
if (ofd.Canceled)
if (ofd.Path is not null) {
Directory.SetCurrentDirectory (Path.GetFullPath(Path.GetDirectoryName(ofd.Path)!));
}
if (ofd.Canceled) {
return;
}
var path = ofd.FilePaths [0];

View File

@@ -117,6 +117,7 @@ namespace UICatalog {
scenario.Theme = _cachedTheme;
scenario.TopLevelColorScheme = _topLevelColorScheme;
scenario.Init ();
Application.Driver.Force16Colors = _force16Colors;
scenario.Setup ();
scenario.Run ();
scenario.Dispose ();
@@ -231,6 +232,7 @@ namespace UICatalog {
static Scenario? _selectedScenario = null;
static bool _useSystemConsole = false;
static bool _force16Colors = false;
static ConsoleDriver.DiagnosticFlags _diagnosticFlags;
static bool _isFirstRunning = true;
static string _topLevelColorScheme = string.Empty;
@@ -532,12 +534,13 @@ namespace UICatalog {
{
List<MenuItem> menuItems = new List<MenuItem> ();
miForce16Colors = new MenuItem {
Title = "Force 16 _Colors"
Title = "Force 16 _Colors",
Checked = _force16Colors
};
miForce16Colors.Shortcut = Key.CtrlMask | Key.AltMask | (Key)miForce16Colors!.Title!.Substring (10, 1) [0];
miForce16Colors.CheckType |= MenuItemCheckStyle.Checked;
miForce16Colors.Action += () => {
miForce16Colors.Checked = Application.Driver.Force16Colors = (bool)!miForce16Colors.Checked!;
miForce16Colors.Checked = _force16Colors = Application.Driver.Force16Colors = (bool)!miForce16Colors.Checked!;
Application.Refresh ();
};
menuItems.Add (miForce16Colors);