Browse Source

Made selected cell first character inverted colors
This allows users to tell which cell is driving navigation etc in multi cell selections

Thomas Nind 4 years ago
parent
commit
93e5d7fc0c
1 changed files with 21 additions and 2 deletions
  1. 21 2
      Terminal.Gui/Views/TableView.cs

+ 21 - 2
Terminal.Gui/Views/TableView.cs

@@ -414,9 +414,28 @@ namespace Terminal.Gui {
 				var representation = GetRepresentation(val,colStyle);
 				var scheme = (colStyle?.ColorGetter?.Invoke(rowToRender,val)) ?? rowScheme;
 
-				Driver.SetAttribute (isSelectedCell ? scheme.HotFocus : scheme.Normal);
+				var cellColor = isSelectedCell? scheme.HotFocus: scheme.Normal;
+
+				var render = TruncateOrPad (val, representation, current.Width, colStyle);
 				
-				Driver.AddStr (TruncateOrPad(val,representation, current.Width, colStyle));
+				// 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 (render.Length > 0) {
+						// invert the color of the current cell for the first character
+						Driver.SetAttribute (Driver.MakeAttribute (cellColor.Background, cellColor.Foreground));
+						Driver.AddRune (render [0]);
+
+						Driver.SetAttribute (cellColor);
+						Driver.AddStr (render.Substring (1));
+					}
+				}
+				else {
+					Driver.SetAttribute (cellColor);
+					Driver.AddStr (render);
+				}
 
 				// Reset color scheme to normal for drawing separators if we drew text with custom scheme
 				if(scheme != rowScheme) {