TextView print a portion of text in different color #3810
Replies: 2 comments 5 replies
-
Take a look at the var tv = new TextView() { Width = 20, Height = 5 };
// Get the current line
var cells = tv.GetCurrentLine();
cell[0] = new() { Rune = rune, Attribute = new Attribute (Color.Green, Color.Black) };
cell[1] = new() { Rune = rune, Attribute = new Attribute (Color.Blue, Color.Red) }; |
Beta Was this translation helpful? Give feedback.
-
Here is a simple example. Create a new Terminal.Gui project using the dotnet new template for v1:
Now update the MyView.cs file to have the following sub view. One gotcha is that (in v1) //------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by:
// TerminalGuiDesigner v1.0.17.0
// You can make changes to this file and they will not be overwritten when saving.
// </auto-generated>
// -----------------------------------------------------------------------------
namespace myproj{
using Terminal.Gui;
public partial class MyView {
public MyView() {
InitializeComponent();
button1.Clicked += () => MessageBox.Query("Hello", "Hello There!", "Ok");
+ Add(new MyCoolView()
+ {
+ Width = Dim.Fill(),
+ Height = 5,
+ });
}
}
+ class MyCoolView : View
+ {
+
+ public override void OnDrawContent(Rect viewport)
+ {
+ int x = 10;
+ int y = 3;
+
+ Driver.SetAttribute(new Attribute(Color.Green, this.ColorScheme.Normal.Background));
+
+ foreach (var ch in "Behold Green!")
+ {
+ AddRune(x++, y, ch);
+ }
+ }
+ }
}
|
Beta Was this translation helpful? Give feedback.
-
How do I print some of the text in a different color than the rest? Can anyone provide an example? All I can find in the documentation is how to change the ColorScheme which affects the entire graphical element. I just want to make some words red to be easily seen by the user.
Beta Was this translation helpful? Give feedback.
All reactions