Add speaker component.

This commit is contained in:
Kolosov Alexandr 2024-04-16 17:58:51 +05:00
parent 00e5eadab1
commit 3a85bfbdd3
14 changed files with 133 additions and 34 deletions

View File

@ -1,7 +1,12 @@
using TUI.Engine.Attributes;
using TUI.Engine.Attributes.Resizings; using TUI.Engine.Attributes.Resizings;
using TUI.Engine.Rendering.Canvas;
namespace TUI.Engine.Nodes; namespace TUI.Engine.Nodes;
public interface INode : IResizable public interface INode : IResizable
{ {
} DrawContext DrawContext { get; set; }
}
public record DrawContext(ICanvas Canvas, Position Pencil, Size MaxSize);

View File

@ -55,4 +55,6 @@ public abstract class NodeBase : INode
} }
#endregion Resizing #endregion Resizing
public DrawContext? DrawContext { get; set; }
} }

View File

@ -25,6 +25,8 @@ internal sealed class ComponentCraftsman : CraftsmanBase, IDrawable<IComponent>
foreach (var line in sketch.Crop(maxSize)) foreach (var line in sketch.Crop(maxSize))
{ {
component.DrawContext = new DrawContext(_canvas, pencil, maxSize);
_canvas.SetPencil(correctedPencil); _canvas.SetPencil(correctedPencil);
_canvas.Paint(line); _canvas.Paint(line);

View File

@ -0,0 +1,50 @@
using TUI.Engine;
using TUI.Engine.Attributes;
using TUI.Engine.Components;
using TUI.Engine.Nodes;
namespace TUI.Controls.Components;
public class SpeakerComponent : ComponentBase
{
private string _message = "";
private Position? _pencil;
private SpeakerComponent()
{
}
public static SpeakerComponent Instance { get; } = new();
protected override Sketch DrawComponent(Size minSize)
{
return new Sketch(_message);
}
private void Clear()
{
_message = new string(' ', DrawContext.MaxSize.Width);
DrawContext.Canvas.Draw(Instance, _pencil, DrawContext.MaxSize);
}
public void Shout(string emoji, string message)
{
if (DrawContext is null)
{
return;
}
_pencil ??= DrawContext.Pencil with { };
Clear();
_message = emoji + Symbols.Space + message;
DrawContext.Canvas.Draw(Instance, _pencil, DrawContext.MaxSize);
Task.Delay(2000).ContinueWith(_ =>
{
Clear();
return Task.CompletedTask;
});
}
}

View File

@ -1,5 +1,4 @@
using System.Text; using System.Text;
using TUI.Engine;
using TUI.Engine.Attributes; using TUI.Engine.Attributes;
using TUI.Engine.Components; using TUI.Engine.Components;

View File

@ -1,3 +1,4 @@
using TUI.Controls.Components;
using TUI.Controls.Statics; using TUI.Controls.Statics;
using TUI.Engine.Attributes.Alignments; using TUI.Engine.Attributes.Alignments;
using TUI.Engine.Components; using TUI.Engine.Components;
@ -10,12 +11,15 @@ namespace TUI.Controls.Containers;
public class FooterContainer : ContainerBase public class FooterContainer : ContainerBase
{ {
private readonly INode _breadcrumbs; private readonly INode _breadcrumbs;
private readonly INode _speaker;
public FooterContainer(IComponent breadcrumbs) public FooterContainer(IComponent? breadcrumbs)
{ {
breadcrumbs.SetAlignment(Horizontal.Left); breadcrumbs.SetAlignment(Horizontal.Left);
breadcrumbs.SetPaddingLeft(Level.Normal); breadcrumbs.SetPaddingLeft(Level.Normal);
_breadcrumbs = breadcrumbs; _breadcrumbs = breadcrumbs;
_speaker = SpeakerComponent.Instance;
} }
public override Nodes GetNodes() public override Nodes GetNodes()
@ -23,6 +27,6 @@ public class FooterContainer : ContainerBase
var copyright = new CopyrightComponent(); var copyright = new CopyrightComponent();
copyright.SetAlignment(Horizontal.Right); copyright.SetAlignment(Horizontal.Right);
copyright.SetPaddingRight(Level.Normal); copyright.SetPaddingRight(Level.Normal);
return new Nodes { _breadcrumbs, copyright }; return new Nodes { _breadcrumbs, _speaker, copyright };
} }
} }

View File

@ -1,6 +1,4 @@
using TUI.Engine.Attributes.Alignments;
using TUI.Engine.Attributes.Orientations; using TUI.Engine.Attributes.Orientations;
using TUI.Engine.Components;
using TUI.Engine.Containers; using TUI.Engine.Containers;
using TUI.Engine.Nodes; using TUI.Engine.Nodes;

View File

@ -1,37 +1,11 @@
using System.Diagnostics;
using TUI.Controls.Components; using TUI.Controls.Components;
using TUI.Controls.Containers; using TUI.Controls.Containers;
using TUI.Controls.Layouts; using TUI.Controls.Layouts;
using TUI.Controls.Statics;
using TUI.Domain;
using TUI.Engine;
using TUI.Engine.Rendering.Canvas; using TUI.Engine.Rendering.Canvas;
using TUI.Providers.Dependencies;
using TUI.Store; using TUI.Store;
namespace TUI.Pages; namespace TUI.Pages;
interface IPage
{
void Open();
void Render();
void Bind();
}
public abstract class PageBase : IPage
{
public void Open()
{
Debugger.Log(0, "Event", $"Open page ${GetType().UnderlyingSystemType.Name}\n");
Bind();
Render();
}
public abstract void Render();
public abstract void Bind();
}
public class DependenciesPage : PageBase public class DependenciesPage : PageBase
{ {
private DependenciesStore _store; private DependenciesStore _store;

8
src/TUI/Pages/IPage.cs Normal file
View File

@ -0,0 +1,8 @@
namespace TUI.Pages;
interface IPage
{
void Open();
void Render();
void Bind();
}

17
src/TUI/Pages/PageBase.cs Normal file
View File

@ -0,0 +1,17 @@
using System.Diagnostics;
namespace TUI.Pages;
public abstract class PageBase : IPage
{
public void Open()
{
Debugger.Log(0, "Event", $"Open page ${GetType().UnderlyingSystemType.Name}\n");
Bind();
Render();
}
public abstract void Render();
public abstract void Bind();
}

View File

@ -0,0 +1,33 @@
using TUI.Controls.Common;
using TUI.Controls.Components;
using TUI.Controls.Containers;
using TUI.Controls.Layouts;
using TUI.Controls.Statics;
using TUI.Engine.Attributes;
using TUI.Engine.Rendering.Canvas;
namespace TUI.Pages;
public class WelcomePage : PageBase
{
public override void Render()
{
ICanvas canvas = new ConsoleCanvas();
var header = new StubComponent(new Size(1, 1));
var logo = new LogoComponent();
var breadCrumbs = new BreadCrumbsComponent();
var footer = new FooterContainer(breadCrumbs);
var layout = new DashboardLayout(header, logo, footer);
canvas.Draw(layout);
}
public override void Bind()
{
}
}

View File

@ -6,9 +6,12 @@ Console.CursorVisible = false;
// var settings = Settings.Init(); // var settings = Settings.Init();
var welcomePage = new WelcomePage();
welcomePage.Open();
Thread.Sleep(2000);
var dependenciesPage = new DependenciesPage(); var dependenciesPage = new DependenciesPage();
dependenciesPage.Open(); dependenciesPage.Open();
// display.OpenDeps(settings.Projects[0]); // display.OpenDeps(settings.Projects[0]);
var key = new ConsoleKeyInfo('1', ConsoleKey.NoName, false, false, false); var key = new ConsoleKeyInfo('1', ConsoleKey.NoName, false, false, false);

View File

@ -1,3 +1,4 @@
using TUI.Controls.Components;
using TUI.Domain; using TUI.Domain;
using TUI.Providers.Dependencies; using TUI.Providers.Dependencies;
@ -12,8 +13,12 @@ public class DependenciesStore
public void Bind() public void Bind()
{ {
var repo = new DependencyRepository(); var repo = new DependencyRepository();
ConventionDependencies = repo.ReadConventions("javascript"); ConventionDependencies = repo.ReadConventions("javascript");
SpeakerComponent.Instance.Shout("🤔", "Prepare javascript conventions");
Projects = repo.ReadProjects("javascript"); Projects = repo.ReadProjects("javascript");
SpeakerComponent.Instance.Shout("🤩", "Prepare javascript projects");
} }
// private readonly static Dictionary<string, Package> Packages = new(); // private readonly static Dictionary<string, Package> Packages = new();

View File

@ -1,4 +1,3 @@
using Pastel;
using TUI.Engine; using TUI.Engine;