-
-
Notifications
You must be signed in to change notification settings - Fork 2
Layout issue when using a BarChart in the grid #7
Copy link
Copy link
Open
Description
Hello @xoofx,
When using a BarChart inside the grid, there are issues with the layout (2/3, 1/3) is not respected, the BarChart max value ends outside the screen
You can try this sample.
using System.Diagnostics;
using System.Text;
using XenoAtom.Terminal;
using XenoAtom.Terminal.UI;
using XenoAtom.Terminal.UI.Controls;
var rnd = new Random();
// LogControl (left pane)
var log = new LogControl { MaxCapacity = 5000 }.WrapText(true);
log.AppendMarkupLine("[dim]Log started. Press Ctrl+Q to quit.[/]");
// Progress bars (right pane) — initialized with random values
var progressValues = Enumerable.Range(0, 5)
.Select(_ => new State<double>(rnd.NextDouble()))
.ToArray();
var progressLabels = new[] { "Download", "Compile", "Test", "Package", "Deploy" };
var progressStack = new VStack(new BarChart().Minimum(0.0)
.Maximum(1.0)
.ShowValues(false)
.ShowPercentages(true).Items(
progressLabels.Select((label, i) => new BarChartItem(label, 0).Value(progressValues[i].Bind.Value)))
).Spacing(1);
// Layout: Grid with 2 columns (2/3 + 1/3)
var grid = new Grid()
.Columns(
new ColumnDefinition { Width = GridLength.Star(2), MinWidth = 0 },
new ColumnDefinition { Width = GridLength.Star(1), MinWidth = 0 })
.Rows(new RowDefinition { Height = GridLength.Star(1) })
.Cell(new Group().TopLeftText("Log").Padding(1).Content(log.HorizontalAlignment(Align.Stretch)).Stretch(), 0, 0)
.Cell(new Group().TopLeftText("Progress").Padding(1).Content(progressStack).Stretch(), 0, 1)
.HorizontalAlignment(Align.Stretch)
.VerticalAlignment(Align.Stretch);
// Timing for background task
var lastLogTick = Stopwatch.GetTimestamp();
var lastProgressTick = lastLogTick;
string RandomText()
{
var len = rnd.Next(80, 201);
var sb = new StringBuilder(len);
for (var i = 0; i < len; i++)
{
// Insert a space every 5-12 chars so word-wrap can break the line
var wordLen = rnd.Next(5, 13);
if (i > 0 && i % wordLen == 0) sb.Append(' ');
else sb.Append((char)rnd.Next('a', 'z' + 1));
}
return sb.ToString();
}
Terminal.Run(grid, () =>
{
var now = Stopwatch.GetTimestamp();
// Append a random log line every ~1s
if (Stopwatch.GetElapsedTime(lastLogTick, now) >= TimeSpan.FromSeconds(1))
{
lastLogTick = now;
log.AppendLine(RandomText());
}
// Drift progress bars every ~500ms for visual interest
if (Stopwatch.GetElapsedTime(lastProgressTick, now) >= TimeSpan.FromMilliseconds(500))
{
lastProgressTick = now;
foreach (var p in progressValues)
p.Value = Math.Clamp(p.Value + (rnd.NextDouble() - 0.45) * 0.05, 0, 1);
}
return TerminalLoopResult.Continue;
});Here is a screenshot of how it renders.
Let me know if I can do something for you
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels