Browse Source

Made selected cell invert first character optional as a TableStyle

Thomas Nind 4 năm trước cách đây
mục cha
commit
f536d906d4

+ 8 - 1
Terminal.Gui/Views/TableView.cs

@@ -421,7 +421,7 @@ namespace Terminal.Gui {
 				// If the cell is the selected col/row then draw the first rune in inverted colors
 				// this allows the user to track which cell is the active one during a multi cell
 				// selection or in full row select mode
-				if(current.Column.Ordinal == selectedColumn && rowToRender == selectedRow) {
+				if(Style.InvertSelectedCellFirstCharacter && current.Column.Ordinal == selectedColumn && rowToRender == selectedRow) {
 
 					if (render.Length > 0) {
 						// invert the color of the current cell for the first character
@@ -1257,6 +1257,13 @@ namespace Terminal.Gui {
 			/// </summary>
 			public bool ShowVerticalHeaderLines { get; set; } = true;
 
+			/// <summary>
+			/// True to invert the colors of the first symbol of the selected cell in the <see cref="TableView"/>.
+			/// This gives the appearance of a cursor for when the <see cref="ConsoleDriver"/> doesn't otherwise show
+			/// this
+			/// </summary>
+			public bool InvertSelectedCellFirstCharacter { get; set; } = false;
+
 			/// <summary>
 			/// Collection of columns for which you want special rendering (e.g. custom column lengths, text alignment etc)
 			/// </summary>

+ 9 - 1
UICatalog/Scenarios/TableEditor.cs

@@ -24,6 +24,7 @@ namespace UICatalog.Scenarios {
 		private MenuItem miFullRowSelect;
 		private MenuItem miExpandLastColumn;
 		private MenuItem miAlternatingColors;
+		private MenuItem miCursor;
 
 		ColorScheme redColorScheme;
 		ColorScheme redColorSchemeAlt;
@@ -61,6 +62,7 @@ namespace UICatalog.Scenarios {
 					new MenuItem ("_AllLines", "", () => ToggleAllCellLines()),
 					new MenuItem ("_NoLines", "", () => ToggleNoCellLines()),
 					miAlternatingColors = new MenuItem ("Alternating Colors", "", () => ToggleAlternatingColors()){CheckType = MenuItemCheckStyle.Checked},
+					miCursor = new MenuItem ("Invert Selected Cell First Character", "", () => ToggleInvertSelectedCellFirstCharacter()){Checked = tableView.Style.InvertSelectedCellFirstCharacter,CheckType = MenuItemCheckStyle.Checked},
 					new MenuItem ("_ClearColumnStyles", "", () => ClearColumnStyles()),
 				}),
 			});
@@ -267,8 +269,14 @@ namespace UICatalog.Scenarios {
 			}
 			tableView.SetNeedsDisplay();
 		}
-		
 
+		private void ToggleInvertSelectedCellFirstCharacter ()
+		{
+			//toggle menu item
+			miCursor.Checked = !miCursor.Checked;
+			tableView.Style.InvertSelectedCellFirstCharacter = miCursor.Checked;
+			tableView.SetNeedsDisplay ();
+		}
 		private void CloseExample ()
 		{
 			tableView.Table = null;

+ 2 - 1
UnitTests/TableViewTests.cs

@@ -500,8 +500,9 @@ namespace Terminal.Gui.Views {
 		{
 			var tv = SetUpMiniTable ();
 
-			// the thing we are testing
 			tv.Style.ExpandLastColumn = false;
+			tv.Style.InvertSelectedCellFirstCharacter = true;
+
 			// width exactly matches the max col widths
 			tv.Bounds = new Rect (0, 0, 5, 4);