<Page x:Class="头罩视野.Views.PageTest"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
      xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
      mc:Ignorable="d" 
      Background="#F0F2F5"
      d:DesignHeight="768" d:DesignWidth="1024"   
      Title="PageTest" Loaded="Page_Loaded" Unloaded="Page_Unloaded">

    <Page.Resources>
        <!-- 全局字体 -->
        <FontFamily x:Key="DefaultFont">Segoe UI, Microsoft YaHei</FontFamily>

        <!-- 标题样式 -->
        <Style x:Key="MainTitleStyle" TargetType="TextBlock">
            <Setter Property="FontFamily" Value="{StaticResource DefaultFont}"/>
            <Setter Property="FontSize" Value="26"/>
            <Setter Property="FontWeight" Value="SemiBold"/>
            <Setter Property="Foreground" Value="#2C3E50"/>
            <Setter Property="HorizontalAlignment" Value="Center"/>
            <Setter Property="Margin" Value="0,15,0,15"/>
        </Style>

        <!-- 标签样式（宽度减少） -->
        <Style x:Key="LabelStyle" TargetType="TextBlock">
            <Setter Property="FontFamily" Value="{StaticResource DefaultFont}"/>
            <Setter Property="FontSize" Value="15"/>
            <Setter Property="Foreground" Value="#5D6D7E"/>
            <Setter Property="VerticalAlignment" Value="Center"/>
            <Setter Property="Margin" Value="0,0,8,0"/>
            <Setter Property="Width" Value="90"/>
        </Style>

        <!-- 单位样式 -->
        <Style x:Key="UnitStyle" TargetType="TextBlock">
            <Setter Property="FontFamily" Value="{StaticResource DefaultFont}"/>
            <Setter Property="FontSize" Value="13"/>
            <Setter Property="Foreground" Value="#7F8C8D"/>
            <Setter Property="VerticalAlignment" Value="Center"/>
            <Setter Property="Margin" Value="5,0,0,0"/>
            <Setter Property="FontStyle" Value="Italic"/>
        </Style>

        <!-- 文本框样式（宽度减少） -->
        <Style x:Key="TextBoxStyle" TargetType="TextBox">
            <Setter Property="Height" Value="32"/>
            <Setter Property="Width" Value="140"/>
            <Setter Property="FontSize" Value="15"/>
            <Setter Property="TextAlignment" Value="Center"/>
            <Setter Property="VerticalContentAlignment" Value="Center"/>
            <Setter Property="BorderBrush" Value="#BDC3C7"/>
            <Setter Property="BorderThickness" Value="1"/>
            <Setter Property="Background" Value="#FFFFFF"/>
            <Setter Property="Foreground" Value="#2C3E50"/>
            <Setter Property="Padding" Value="5,2"/>
            <Style.Triggers>
                <Trigger Property="IsFocused" Value="True">
                    <Setter Property="BorderBrush" Value="#3498DB"/>
                </Trigger>
            </Style.Triggers>
        </Style>

        <!-- 卡片样式 -->
        <Style x:Key="CardStyle" TargetType="Border">
            <Setter Property="Background" Value="#FFFFFF"/>
            <Setter Property="CornerRadius" Value="8"/>
            <Setter Property="Effect">
                <Setter.Value>
                    <DropShadowEffect BlurRadius="12" ShadowDepth="2" Opacity="0.1" Color="#000000"/>
                </Setter.Value>
            </Setter>
        </Style>

        <!-- 底部导航按钮样式 -->
        <Style x:Key="TabButtonStyle" TargetType="Button">
            <Setter Property="Background" Value="#2C3E50"/>
            <Setter Property="FontFamily" Value="{StaticResource DefaultFont}"/>
            <Setter Property="FontSize" Value="16"/>
            <Setter Property="Foreground" Value="#ECF0F1"/>
            <Setter Property="Height" Value="48"/>
            <Setter Property="FontWeight" Value="SemiBold"/>
            <Setter Property="BorderBrush" Value="#34495E"/>
            <Setter Property="BorderThickness" Value="0,1,0,0"/>
            <Setter Property="Cursor" Value="Hand"/>
            <Style.Triggers>
                <Trigger Property="IsMouseOver" Value="True">
                    <Setter Property="Background" Value="#34495E"/>
                    <Setter Property="Foreground" Value="#FFFFFF"/>
                </Trigger>
            </Style.Triggers>
        </Style>

        <!-- 控制按钮样式 -->
        <Style x:Key="CtrlButtonStyle" TargetType="Button">
            <Setter Property="Height" Value="36"/>
            <Setter Property="Width" Value="100"/>
            <Setter Property="FontSize" Value="14"/>
            <Setter Property="FontWeight" Value="SemiBold"/>
            <Setter Property="Foreground" Value="White"/>
            <Setter Property="Cursor" Value="Hand"/>
            <Setter Property="BorderThickness" Value="0"/>
            <Style.Triggers>
                <Trigger Property="IsMouseOver" Value="True">
                    <Setter Property="Opacity" Value="0.85"/>
                </Trigger>
            </Style.Triggers>
        </Style>
    </Page.Resources>

    <Grid Margin="20,0,20,10">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
            <RowDefinition Height="Auto"/>
        </Grid.RowDefinitions>

        <!-- 顶部标题 -->
        <Grid Grid.Row="0" Margin="0,0,0,10">
            <TextBlock Style="{StaticResource MainTitleStyle}" Text="头罩视野测试系统" HorizontalAlignment="Center"/>
        </Grid>

        <!-- 参数区：使用两行布局，避免过宽 -->
        <Border Grid.Row="1" Style="{StaticResource CardStyle}" Padding="15,12" Margin="0,0,0,20">
            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                </Grid.RowDefinitions>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto"/>
                    <ColumnDefinition Width="*"/>
                </Grid.ColumnDefinitions>

                <!-- 第一行参数：分辨角度、当前角度 -->
                <StackPanel Grid.Row="0" Grid.Column="0" Orientation="Horizontal" Margin="0,5,0,5">
                    <StackPanel Orientation="Horizontal" Margin="0,0,20,0">
                        <TextBlock Text="分辨角度：" Style="{StaticResource LabelStyle}"/>
                        <TextBox Name="fbspeed" Style="{StaticResource TextBoxStyle}" GotFocus="fbspeed_GotFocus"/>
                        <TextBlock Text="°" Style="{StaticResource UnitStyle}"/>
                    </StackPanel>
                    <StackPanel Orientation="Horizontal">
                        <TextBlock Text="当前角度：" Style="{StaticResource LabelStyle}"/>
                        <TextBox Name="dqangle" Style="{StaticResource TextBoxStyle}" GotFocus="dqangle_GotFocus"/>
                        <TextBlock Text="°" Style="{StaticResource UnitStyle}"/>
                    </StackPanel>
                </StackPanel>

                <!-- 第二行参数：转动速度（单独一行） -->
                <StackPanel Grid.Row="1" Grid.Column="0" Orientation="Horizontal" Margin="0,5,0,5">
                    <TextBlock Text="转动速度：" Style="{StaticResource LabelStyle}"/>
                    <TextBox Name="zdangle" Style="{StaticResource TextBoxStyle}" GotFocus="zdangle_GotFocus"/>
                    <TextBlock Text="°/s" Style="{StaticResource UnitStyle}"/>
                </StackPanel>

                <!-- 右侧：模式切换和指示灯，垂直居中 -->
                <StackPanel Grid.Row="0" Grid.RowSpan="2" Grid.Column="1" 
                            Orientation="Horizontal" HorizontalAlignment="Right" VerticalAlignment="Center" Margin="10,0,0,0">
                    <ToggleButton x:Name="tbTest" FontSize="13" Width="90" Height="28"
                                  Background="#E0E0E0" Margin="0,0,12,0"
                                  Checked="TbTest_Checked" Unchecked="TbTest_Unchecked">
                        <ToggleButton.Template>
                            <ControlTemplate TargetType="ToggleButton">
                                <Border x:Name="border" CornerRadius="4" Background="{TemplateBinding Background}" BorderThickness="0">
                                    <ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center"/>
                                </Border>
                                <ControlTemplate.Triggers>
                                    <Trigger Property="IsChecked" Value="True">
                                        <Setter TargetName="border" Property="Background" Value="#3A6B4B"/>
                                        <Setter Property="Foreground" Value="White"/>
                                    </Trigger>
                                </ControlTemplate.Triggers>
                            </ControlTemplate>
                        </ToggleButton.Template>
                        空白测试
                    </ToggleButton>
                    <TextBlock Text="当前模式：" VerticalAlignment="Center" Margin="0,0,6,0" FontSize="13" Foreground="#5D6D7E"/>
                    <TextBlock x:Name="当前模式" Text="空白测试" VerticalAlignment="Center" FontSize="13" FontWeight="Bold" Foreground="#3A6B4B" Margin="0,0,15,0"/>
                    <StackPanel Orientation="Horizontal" VerticalAlignment="Center">
                        <Ellipse x:Name="led0" Width="18" Height="18" Fill="LightGray" Stroke="#BDC3C7" Margin="3,0"/>
                        <Ellipse x:Name="led1" Width="18" Height="18" Fill="LightGray" Stroke="#BDC3C7" Margin="3,0"/>
                    </StackPanel>
                </StackPanel>
            </Grid>
        </Border>

        <!-- 数据区：两列卡片 -->
        <Grid Grid.Row="2" Margin="0,0,0,20">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*"/>
                <ColumnDefinition Width="*"/>
            </Grid.ColumnDefinitions>

            <!-- 左侧卡片 -->
            <Border Grid.Column="0" Style="{StaticResource CardStyle}" Padding="20,15" Margin="0,0,10,0">
                <StackPanel>
                    <StackPanel Orientation="Horizontal" Margin="0,0,0,15">
                        <TextBlock Text="左目视野面积：" Style="{StaticResource LabelStyle}" Width="110"/>
                        <TextBox Name="zmsyarea" Style="{StaticResource TextBoxStyle}" Width="150"/>
                        <TextBlock Text="cm²" Style="{StaticResource UnitStyle}"/>
                    </StackPanel>
                    <StackPanel Orientation="Horizontal" Margin="0,0,0,15">
                        <TextBlock Text="双目视野面积：" Style="{StaticResource LabelStyle}" Width="110"/>
                        <TextBox Name="smsyarea" Style="{StaticResource TextBoxStyle}" Width="150"/>
                        <TextBlock Text="cm²" Style="{StaticResource UnitStyle}"/>
                    </StackPanel>
                    <StackPanel Orientation="Horizontal">
                        <TextBlock Text="总视野面积：" Style="{StaticResource LabelStyle}" Width="110"/>
                        <TextBox Name="zsyareaNum" Style="{StaticResource TextBoxStyle}" Width="150"/>
                        <TextBlock Text="cm²" Style="{StaticResource UnitStyle}"/>
                    </StackPanel>
                </StackPanel>
            </Border>

            <!-- 右侧卡片 -->
            <Border Grid.Column="1" Style="{StaticResource CardStyle}" Padding="20,15" Margin="10,0,0,0">
                <StackPanel>
                    <StackPanel Orientation="Horizontal" Margin="0,0,0,15">
                        <TextBlock Text="右目视野面积：" Style="{StaticResource LabelStyle}" Width="110"/>
                        <TextBox Name="ymsyarea" Style="{StaticResource TextBoxStyle}" Width="150"/>
                        <TextBlock Text="cm²" Style="{StaticResource UnitStyle}"/>
                    </StackPanel>
                    <StackPanel Orientation="Horizontal" Margin="0,0,0,15">
                        <TextBlock Text="下方视野：" Style="{StaticResource LabelStyle}" Width="110"/>
                        <TextBox Name="xfsyarea" Style="{StaticResource TextBoxStyle}" Width="150"/>
                        <TextBlock Text="°" Style="{StaticResource UnitStyle}"/>
                    </StackPanel>
                    <StackPanel Orientation="Horizontal" Margin="0,0,0,15">
                        <TextBlock Text="双目视野保存率：" Style="{StaticResource LabelStyle}" Width="110"/>
                        <TextBox Name="sybhl" Style="{StaticResource TextBoxStyle}" Width="150"/>
                        <TextBlock Text="%" Style="{StaticResource UnitStyle}"/>
                    </StackPanel>
                    <StackPanel Orientation="Horizontal">
                        <TextBlock Text="总视野保存率：" Style="{StaticResource LabelStyle}" Width="110"/>
                        <TextBox Name="zsysaveSum" Style="{StaticResource TextBoxStyle}" Width="150"/>
                        <TextBlock Text="%" Style="{StaticResource UnitStyle}"/>
                    </StackPanel>
                </StackPanel>
            </Border>
        </Grid>

        <!-- 控制按钮区 -->
        <Grid Grid.Row="3" Margin="0,0,0,20">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto"/>
                <ColumnDefinition Width="Auto"/>
                <ColumnDefinition Width="Auto"/>
                <ColumnDefinition Width="*"/>
                <ColumnDefinition Width="Auto"/>
                <ColumnDefinition Width="Auto"/>
            </Grid.ColumnDefinitions>
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="Auto"/>
            </Grid.RowDefinitions>

            <Button Grid.Row="0" Grid.Column="0" Grid.RowSpan="2" Content="复位" 
                    Style="{StaticResource CtrlButtonStyle}" Background="#4A6D8C" Margin="5" Click="Button_Click_Reset"/>
            <Button Grid.Row="0" Name="btnLeft" Grid.Column="1" Content="左眼开" 
                    Style="{StaticResource CtrlButtonStyle}" Background="#4A6D8C" Margin="5" Click="Button_Click_left"/>
            <Button Grid.Row="0" Grid.Column="2" Content="反转" 
                    Style="{StaticResource CtrlButtonStyle}" Background="#4A6D8C" Margin="5" 
                    PreviewMouseLeftButtonDown="Button_Click_ResDown" PreviewMouseLeftButtonUp="Button_Click_ResUp"/>
            <Button Grid.Row="1" Name="btnRight" Grid.Column="1" Content="右眼开" 
                    Style="{StaticResource CtrlButtonStyle}" Background="#4A6D8C" Margin="5" Click="Button_Click_Right"/>
            <Button Grid.Row="1" Grid.Column="2" Content="正转" 
                    Style="{StaticResource CtrlButtonStyle}" Background="#4A6D8C" Margin="5" 
                    PreviewMouseLeftButtonDown="Button_Click_ForDown" PreviewMouseLeftButtonUp="Button_Click_ForUp"/>
            <Button Grid.Row="0" Grid.Column="4" Name="ButtonTest" Grid.RowSpan="2" Content="测试" 
                    Style="{StaticResource CtrlButtonStyle}" Background="#27AE60" Margin="5" Click="Button_Click_Test"/>
            <Button Grid.Row="0" Grid.Column="5" Grid.RowSpan="2" Content="停止" 
                    Style="{StaticResource CtrlButtonStyle}" Background="#E74C3C" Margin="5" Click="Button_Click_Stop"/>
        </Grid>

        <!-- 弹性空间 -->
        <Grid Grid.Row="4" Background="Transparent"/>

        <!-- 底部导航栏 -->
        <Grid Grid.Row="5" VerticalAlignment="Bottom">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*"/>
                <ColumnDefinition Width="*"/>
                <ColumnDefinition Width="*"/>
            </Grid.ColumnDefinitions>
            <Button x:Name="btnNavHome" Style="{StaticResource TabButtonStyle}" Grid.Column="0" Content="主页" Click="GoHome"/>
            <Button  x:Name="btnNavTest" Style="{StaticResource TabButtonStyle}" Grid.Column="1" Content="测试界面" Click="GoTest"/>
            <Button x:Name="btnNavRecord" Style="{StaticResource TabButtonStyle}" Grid.Column="2" Content="记录画面" Click="GoView"/>
        </Grid>
    </Grid>
</Page>