Skip to content

Commit dc2f84b

Browse files
committed
Improve theme and WelcomeDemo page
1 parent 87597c7 commit dc2f84b

File tree

5 files changed

+31
-47
lines changed

5 files changed

+31
-47
lines changed

samples/ControlsDemo/ControlsDemoApp.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ public static Visual Build(out Func<TerminalLoopResult> onUpdate)
4949
sidebarList)
5050
.Spacing(1);
5151

52+
var themeState = new State<Theme>(Theme.Default);
53+
5254
var page = new ComputedVisual(() =>
5355
{
5456
var id = selectedDemoId.Value;
@@ -64,13 +66,13 @@ public static Visual Build(out Func<TerminalLoopResult> onUpdate)
6466

6567
return demo is null
6668
? new Center().Content("No demos found.")
67-
: DemoPage.Build(demo, new DemoContext { NavigateToDemoId = NavigateToId, Log = _ => { }, Runtime = runtime });
69+
: DemoPage.Build(demo, new DemoContext { NavigateToDemoId = NavigateToId, Log = _ => { }, Runtime = runtime, Theme = themeState });
6870
}).Pad(1).HorizontalAlignment(HorizontalAlignment.Stretch).VerticalAlignment(VerticalAlignment.Stretch);
6971

7072
return new DockLayout()
7173
.Content(new HSplitter(sidebar, page).Ratio(0.16))
7274
.Bottom(new Footer().Left("Tab focus | Mouse | Resize").Right("F12 debug | Ctrl+Q quit"))
73-
.Style(DemoThemes.Dark);
75+
.Update(x => x.Set(Theme.Key, themeState.Value));
7476
}
7577

7678
private static Visual BuildSidebarList(IReadOnlyList<IControlsDemo> demos, State<string> selectedDemoId, string query)

samples/ControlsDemo/DemoContext.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
using XenoAtom.Terminal.UI.Styling;
2+
13
namespace XenoAtom.Terminal.UI.ControlsDemo;
24

35
public sealed class DemoContext
@@ -7,4 +9,6 @@ public sealed class DemoContext
79
public required Action<string> NavigateToDemoId { get; init; }
810

911
public required DemoRuntime Runtime { get; init; }
12+
13+
public required State<Theme> Theme { get; init; }
1014
}

samples/ControlsDemo/DemoPage.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ public static Visual Build(IControlsDemo demo, DemoContext context)
2020
Log = log.Add,
2121
NavigateToDemoId = context.NavigateToDemoId,
2222
Runtime = context.Runtime,
23+
Theme = context.Theme
2324
});
2425

2526
var link = BuildSourceLink(meta, log);

samples/ControlsDemo/Demos/WelcomeDemo.cs

Lines changed: 21 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -18,26 +18,12 @@ public override Visual Build(DemoContext context)
1818
{
1919
_ = context;
2020

21-
var banner = new TextFiglet("Welcome")
22-
.Font(FigletPredefinedFont.Slant)
23-
.LetterSpacing(1)
24-
.TextAlignment(TextAlignment.Left);
25-
26-
var title = new Markup("[bold]XenoAtom.Terminal.UI[/]") { Wrap = false };
27-
28-
var hints = new Markup("""
29-
[bold]Tips[/]
30-
- Use the [bold]Search[/] box to filter controls and demos.
31-
- Use [bold]Tab[/] to move focus and [bold]Mouse wheel[/] to scroll lists.
32-
- Use [bold]Ctrl+Q[/] to quit.
33-
""")
34-
{ Wrap = true };
21+
var theme = context.Theme.Value;
3522

3623
var spectrum = new Canvas()
3724
.MinHeight(6)
3825
.Painter(ctx =>
3926
{
40-
var theme = DemoThemes.Dark;
4127
var baseStyle = theme.BaseTextStyle();
4228
var width = Math.Max(1, ctx.Bounds.Width);
4329
var height = Math.Max(1, ctx.Bounds.Height);
@@ -63,18 +49,31 @@ public override Visual Build(DemoContext context)
6349
}
6450
}).HorizontalAlignment(HorizontalAlignment.Stretch).VerticalAlignment(VerticalAlignment.Stretch);
6551

52+
var banner = new TextFiglet("Welcome")
53+
.Font(FigletPredefinedFont.Slant)
54+
.LetterSpacing(1)
55+
.TextAlignment(TextAlignment.Left);
56+
//.Style(new TextFigletStyle { TextStyle = Style.None.WithForeground(theme.Scheme?.Black ?? Colors.Black) | TextStyle.Bold });
57+
58+
var title = new Markup("[bold]XenoAtom.Terminal.UI[/]") { Wrap = false };
59+
60+
var hints = new Markup("""
61+
[bold]Tips[/]
62+
- Use the [bold]Search[/] box to filter controls and demos.
63+
- Use [bold]Tab[/] to move focus and [bold]Mouse wheel[/] to scroll lists.
64+
- Use [bold]Ctrl+Q[/] to quit.
65+
""")
66+
{ Wrap = true };
67+
68+
6669
var schemePanel = BuildSchemePanel(DemoThemes.Dark);
6770

6871
return new VStack(
69-
banner,
72+
new ZStack(spectrum, banner),
7073
title,
7174
new Rule(),
7275
hints,
7376
new Rule(),
74-
new Group()
75-
.TopLeftText("Spectrum")
76-
.Padding(1)
77-
.Content(spectrum).VerticalAlignment(VerticalAlignment.Stretch).HorizontalAlignment(HorizontalAlignment.Stretch),
7877
schemePanel)
7978
.Spacing(1);
8079
}
@@ -84,7 +83,7 @@ private static Visual BuildSchemePanel(Theme theme)
8483
var scheme = theme.Scheme;
8584
if (scheme is null)
8685
{
87-
return (Visual)"[dim]No ColorScheme available for this theme.[/]";
86+
return "[dim]No ColorScheme available for this theme.[/]";
8887
}
8988

9089
var table = new Table()
@@ -126,29 +125,7 @@ void Add(string name, Color? color)
126125
private static Visual CreateSwatch(Theme theme, Color? color)
127126
{
128127
const int width = 10;
129-
const int height = 1;
130-
131-
return new Canvas()
132-
.MinWidth(width)
133-
.MaxWidth(width)
134-
.MinHeight(height)
135-
.MaxHeight(height)
136-
.Painter(ctx =>
137-
{
138-
var style = theme.BaseTextStyle();
139-
if (color is { } c && c.Kind != ColorKind.Default)
140-
{
141-
style = style.WithBackground(c);
142-
}
143-
144-
for (var y = 0; y < ctx.Bounds.Height; y++)
145-
{
146-
for (var x = 0; x < ctx.Bounds.Width; x++)
147-
{
148-
ctx.SetPixel(x, y, new Rune(' '), style);
149-
}
150-
}
151-
});
128+
return new TextBlock(new string(' ', width)).Style(TextBlockStyle.Default with { Background = color });
152129
}
153130

154131
private static string FormatColor(Color? color)

src/XenoAtom.Terminal.UI/Styling/Theme.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ public static Theme FromScheme(ColorScheme scheme, ThemeSchemeBrightness brightn
203203
inputFill = Color.RgbA(128, 128, 128, 0x04);
204204
inputFillFocused = Color.RgbA(0, 0, 0, 0x28);
205205

206-
borderStroke = Color.RgbA(255, 255, 255, 0x26);
206+
borderStroke = Color.RgbA(255, 255, 255, 0x80);
207207
focusBorderStroke = accentColor;
208208

209209
selectionFill = accentColor.WithAlpha(0x3A);

0 commit comments

Comments
 (0)