均分左侧导航与日志并按步骤结果显示背景色

This commit is contained in:
tfarcraw 2026-11-19 23:10:19 +08:00
parent a2c18f3439
commit cf0400b7fa
3 changed files with 29 additions and 5 deletions

View File

@ -18,8 +18,8 @@
<Border Height="60" Margin="0,2,10,10" Background="Transparent" BorderThickness="0" CornerRadius="4" Padding="6" Classes="panel">
<Image Source="{StaticResource BellwetherLogo}" Stretch="Uniform" AutomationProperties.Name="贝沃思 BELLWETHER" />
</Border>
<Grid Grid.Row="1" Margin="0,0,10,0" RowDefinitions="Auto,*">
<Border Classes="panel">
<Grid Grid.Row="1" Margin="0,0,10,0" RowDefinitions="*,*">
<Border x:Name="NavigationPanel" Margin="0,0,0,5" Classes="panel">
<ListBox ItemsSource="{Binding Navigation.Pages}" SelectedIndex="{Binding Navigation.SelectedIndex, Mode=TwoWay}">
<ListBox.Styles>
<Style Selector="ListBoxItem">
@ -33,7 +33,7 @@
</ListBox.ItemTemplate>
</ListBox>
</Border>
<Border Grid.Row="1" Margin="0,10,0,0" Padding="6" Classes="panel" x:Name="LogPanel" DataContext="{Binding Sop}">
<Border Grid.Row="1" Margin="0,5,0,0" Padding="6" Classes="panel" x:Name="LogPanel" DataContext="{Binding Sop}">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />

View File

@ -1,5 +1,14 @@
<UserControl xmlns="https://github.com/avaloniaui" xmlns:local="clr-namespace:SopHelper.VVMs.SopPage" xmlns:prism="http://prismlibrary.com/" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" x:Class="SopHelper.VVMs.SopPage.SopPage" prism:ViewModelLocator.AutoWireViewModel="True" Background="{StaticResource Bg}" xmlns:conv="using:Avalonia.Data.Converters">
<UserControl.Styles>
<Style Selector="Border.stepCard">
<Setter Property="Background" Value="{StaticResource Bg}" />
</Style>
<Style Selector="Border.stepCard.completed">
<Setter Property="Background" Value="#14532D" />
</Style>
<Style Selector="Border.stepCard.skipped">
<Setter Property="Background" Value="#7F1D1D" />
</Style>
<Style Selector="Rectangle.state4">
<Setter Property="IsVisible" Value="True" />
</Style>
@ -117,7 +126,7 @@
<ItemsControl ItemsSource="{Binding StepCards}" Margin="0,8,0,0">
<ItemsControl.ItemTemplate>
<DataTemplate>
<Border x:Name="card" Padding="8,6" Margin="0,0,0,6" Background="{StaticResource Bg}" BorderBrush="{StaticResource Line}" BorderThickness="1" Classes.state5="{Binding IsCurrent}" Classes.state6="{Binding IsCurrent}" Classes="panel">
<Border x:Name="card" Padding="8,6" Margin="0,0,0,6" BorderBrush="{StaticResource Line}" BorderThickness="1" Classes.state5="{Binding IsCurrent}" Classes.state6="{Binding IsCurrent}" Classes.completed="{Binding IsMet}" Classes.skipped="{Binding IsSkipped}" Classes="panel stepCard">
<StackPanel>
<StackPanel Orientation="Horizontal">
<TextBlock Width="28" FontWeight="Bold" Foreground="{StaticResource FgDim}" Text="{Binding StepId, StringFormat={}{0}.}" />

View File

@ -3,6 +3,7 @@ using Avalonia.Controls;
using Avalonia.Controls.ApplicationLifetimes;
using Avalonia.Headless;
using Avalonia.Media.Imaging;
using Avalonia.Media;
using Avalonia.Threading;
using Prism.Ioc;
using Prism.Dialogs;
@ -93,6 +94,7 @@ internal static class Smoke
window.WindowState=WindowState.Normal;window.Width=1180;window.Height=820;
model.ApplyRecipeCommand.Execute();await Task.Delay(100);
var log=window.FindControl<Border>("LogPanel")!;
var navigationPanel=window.FindControl<Border>("NavigationPanel")!;
var list=log.GetVisualDescendants().OfType<ListBox>().Single();
Check(ReferenceEquals(log.DataContext,model)&&ReferenceEquals(list.ItemsSource,model.Logs),"Sidebar log shares the runtime log collection");
var view=window.GetVisualDescendants().OfType<SopPage>().Single();
@ -102,9 +104,22 @@ internal static class Smoke
window.Height=height;await Task.Delay(80);window.UpdateLayout();
var logPosition=log.TranslatePoint(default,window)!.Value;
var stepsPosition=steps.TranslatePoint(default,window)!.Value;
Check(logPosition.X<180&&logPosition.Y>150&&log.Bounds.Height>200,"Log occupies the sidebar below sidebarNavigation at height "+height);
Check(logPosition.X<180&&logPosition.Y>150&&log.Bounds.Height>200,"Log occupies the sidebar below navigation at height "+height);
Check(Math.Abs(navigationPanel.Bounds.Height-log.Bounds.Height)<1,"Navigation and log have equal heights at "+height);
Check(steps.Bounds.Height>height-500&&stepsPosition.X>logPosition.X+log.Bounds.Width,"Steps fill the released right column at height "+height);
}
model.StepCards.Clear();
var completedCard=new StepCard{StepId=1,Name="已完成步骤",IsMet=true};
var skippedCard=new StepCard{StepId=2,Name="异常跳过步骤",IsSkipped=true};
model.StepCards.Add(completedCard);model.StepCards.Add(skippedCard);
await Task.Delay(80);
var cards=steps.GetVisualDescendants().OfType<Border>().Where(b=>b.Name=="card").ToArray();
Check(cards.Length==2&&cards[0].Background is ISolidColorBrush green&&green.Color==Color.Parse("#14532D")
&&cards[1].Background is ISolidColorBrush red&&red.Color==Color.Parse("#7F1D1D"),"Completed steps render green and skipped steps render red");
var greenBackground=cards[0].Background;
completedCard.IsMet=false;skippedCard.IsSkipped=false;await Task.Delay(30);
Check(!Equals(cards[0].Background,greenBackground)&&Equals(cards[0].Background,cards[1].Background),"Reset removes completion and skip background colors");
completedCard.IsMet=true;skippedCard.IsSkipped=true;await Task.Delay(30);
var screenshots=Path.GetFullPath(Path.Combine("..","scratch","screenshots"));Directory.CreateDirectory(screenshots);
using(var rendered=new RenderTargetBitmap(new PixelSize((int)window.Bounds.Width,(int)window.Bounds.Height)))
{rendered.Render(window);rendered.Save(Path.Combine(screenshots,"sidebar-log-layout.png"));}