Skip to content

Latest commit

 

History

History
86 lines (65 loc) · 3.11 KB

TextBlock.doc.md

File metadata and controls

86 lines (65 loc) · 3.11 KB

TextBlock

public sealed class TextBlock : UIElement

You can find its source code in TextBlock.cs

Building

To build TextBlock you should use TextBlockBuilder. (Its source code is in TextBlockBuilder.cs)
public sealed class TextBlockBuilder : IUIElementBuilder<TextBlock>

Here is an example:

using Sunnyyssh.ConsoleUI;

var appBuilder = new ApplicationBuilder(
    new ApplicationSettings() { DefaultForeground = Color.Gray }); // app builder init.

var textBlockBuilder = new TextBlockBuilder(30, 10)
{
    Background = Color.Transparent, // It will have a background of ubnderlying.
    Foreground = Color.Default, // It will have a default foreground color (sepcified by ApplicationSettings).
    WordWrap = true, // Words should be wrapped.
    TextHorizontalAligning = HorizontalAligning.Center,
    TextVerticalAligning = VerticalAligning.Center
};

var app = appBuilder
    .Add(textBlockBuilder, Position.LeftTop, out var builtTextBlock) // Add textBlockBuilder at left top position.
    .Build(); // Application builds.

builtTextBlock.WaitInitialization(); // Waits till it's initialized. (Actually, it won't wait because it's built with application).
var textBlock = builtTextBlock.Element; // Gettings built TextBlock instance.
// Every second TextBlock's text will be updated to the current time.
using var timer = new Timer(_ => textBlock.Text = $"{DateTime.Now:T}", null, 0, 1000);

app.Run();
// It's waiting because timer will be disposed otherwise. (Just delete to check).
app.Wait();

It runs to this:

Also you can do the same by using binding:

using Sunnyyssh.ConsoleUI;
using Sunnyyssh.ConsoleUI.Binding;

var appBuilder = new ApplicationBuilder(
    new ApplicationSettings() { DefaultForeground = Color.Gray }); // app builder init.

var textBlockBuilder = new TextBlockBuilder(30, 10)
{
    Background = Color.Transparent, // It will have a background of ubnderlying.
    Foreground = Color.Default, // It will have a default foreground color (sepcified by ApplicationSettings).
    WordWrap = true, // Words should be wrapped.
    TextHorizontalAligning = HorizontalAligning.Center,
    TextVerticalAligning = VerticalAligning.Center
};

var app = appBuilder
    .Add(textBlockBuilder, Position.LeftTop, out var builtTextBlock) // Add textBlockBuilder at left top position.
    .Build(); // Application builds.

builtTextBlock.WaitInitialization(); // Waits till it's initialized. (Actually, it won't wait because it's built with application).
var textBlock = builtTextBlock.Element; // Gettings built TextBlock instance.

var observableText = new ObservableObject<string?>(null);
textBlock.Observe(observableText); // TextBlock will observe content.

// Every second observable value will be updated to the current time.
using var timer = new Timer(_ => observableText.Value = $"{DateTime.Now:T}", null, 0, 1000);

app.Run();
// It's waiting because timer will be disposed otherwise. (Just delete to check).
app.Wait();