Explorar o código

Merge branch 'master' into bugfix/default_slider_inverting

Dariusz Komosiński %!s(int64=5) %!d(string=hai) anos
pai
achega
68932c9526

+ 6 - 6
samples/ControlCatalog/Pages/NumericUpDownPage.xaml

@@ -50,22 +50,22 @@
         <TextBlock Grid.Row="4" Grid.Column="0" VerticalAlignment="Center" Margin="2">Text:</TextBlock>
         <TextBox Grid.Row="4" Grid.Column="1" Text="{Binding #upDown.Text}" VerticalAlignment="Center" Margin="2" />
       </Grid>
-      <Grid Grid.Row="0" Grid.Column="2" Margin="10,2,2,2" RowDefinitions="Auto,Auto,Auto,Auto,Auto" ColumnDefinitions="Auto, 120">
+      <Grid Grid.Row="0" Grid.Column="2" Margin="10,2,2,2" RowDefinitions="Auto,Auto,Auto,Auto,Auto" ColumnDefinitions="Auto, Auto">
         <TextBlock Grid.Row="0" Grid.Column="0" VerticalAlignment="Center" Margin="10,2,2,2">Minimum:</TextBlock>
         <NumericUpDown Grid.Row="0" Grid.Column="1" Value="{Binding #upDown.Minimum}"
-                       CultureInfo="{Binding #upDown.CultureInfo}" VerticalAlignment="Center" Margin="2" Width="70" HorizontalAlignment="Center"/>
+                       CultureInfo="{Binding #upDown.CultureInfo}" VerticalAlignment="Center" Margin="2" HorizontalAlignment="Center"/>
 
         <TextBlock Grid.Row="1" Grid.Column="0" VerticalAlignment="Center" Margin="10,2,2,2">Maximum:</TextBlock>
         <NumericUpDown Grid.Row="1" Grid.Column="1" Value="{Binding #upDown.Maximum}"
-                       CultureInfo="{Binding #upDown.CultureInfo}" VerticalAlignment="Center" Margin="2" Width="70" HorizontalAlignment="Center"/>
+                       CultureInfo="{Binding #upDown.CultureInfo}" VerticalAlignment="Center" Margin="2" HorizontalAlignment="Center"/>
 
         <TextBlock Grid.Row="2" Grid.Column="0" VerticalAlignment="Center" Margin="10,2,2,2">Increment:</TextBlock>
         <NumericUpDown Grid.Row="2" Grid.Column="1" Value="{Binding #upDown.Increment}" VerticalAlignment="Center"
-                       Margin="2" Width="70" HorizontalAlignment="Center"/>
+                       Margin="2" HorizontalAlignment="Center"/>
 
         <TextBlock Grid.Row="3" Grid.Column="0" VerticalAlignment="Center" Margin="10,2,2,2">Value:</TextBlock>
         <NumericUpDown Grid.Row="3" Grid.Column="1" Value="{Binding #upDown.Value}" VerticalAlignment="Center"
-                       Margin="2" Width="70" HorizontalAlignment="Center"/>
+                       Margin="2" HorizontalAlignment="Center"/>
 
       </Grid>
     </Grid>
@@ -73,7 +73,7 @@
     <StackPanel Margin="2,10,2,2" Orientation="Horizontal" Spacing="10">
       <TextBlock FontSize="14" FontWeight="Bold" VerticalAlignment="Center">Usage of NumericUpDown:</TextBlock>
       <NumericUpDown Name="upDown" Minimum="0" Maximum="10" Increment="0.5"
-                     CultureInfo="en-US" VerticalAlignment="Center" Width="100"
+                     CultureInfo="en-US" VerticalAlignment="Center"
                      Watermark="Enter text" FormatString="{Binding SelectedFormat.Value}"/>
     </StackPanel>
 

+ 18 - 4
src/Avalonia.Controls/Converters/MarginMultiplierConverter.cs

@@ -18,10 +18,24 @@ namespace Avalonia.Controls.Converters
 
         public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
         {
-            if (!(value is int depth))
-                return new Thickness(0);
-
-            return new Thickness(Left ? Indent * depth : 0, Top ? Indent * depth : 0, Right ? Indent * depth : 0, Bottom ? Indent * depth : 0);
+            if (value is int scalarDepth)
+            {
+                return new Thickness(
+                    Left ? Indent * scalarDepth : 0,
+                    Top ? Indent * scalarDepth : 0,
+                    Right ? Indent * scalarDepth : 0,
+                    Bottom ? Indent * scalarDepth : 0);
+            }
+            else if (value is Thickness thinknessDepth)
+            {
+                return new Thickness(
+                    Left ? Indent * thinknessDepth.Left : 0,
+                    Top ? Indent * thinknessDepth.Top : 0,
+                    Right ? Indent * thinknessDepth.Right : 0,
+                    Bottom ? Indent * thinknessDepth.Bottom : 0);
+            }
+            return new Thickness(0);
+            
         }
 
         public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)

+ 4 - 4
src/Avalonia.Themes.Fluent/Button.xaml

@@ -54,16 +54,16 @@
     <Setter Property="TextBlock.Foreground" Value="{DynamicResource ButtonForegroundPressed}" />
   </Style>
   
-  <Style Selector="Button:disabled">
+  <Style Selector="Button:disabled /template/ ContentPresenter">
     <Setter Property="Background" Value="{DynamicResource ButtonBackgroundDisabled}" />
     <Setter Property="BorderBrush" Value="{DynamicResource ButtonBorderBrushDisabled}" />
     <Setter Property="TextBlock.Foreground" Value="{DynamicResource ButtonForegroundDisabled}" />
   </Style>
 
-  <Style Selector="Button.accent">
-    <Setter Property="Foreground" Value="{DynamicResource AccentButtonForeground}" />
+  <Style Selector="Button.accent /template/ ContentPresenter">
     <Setter Property="Background" Value="{DynamicResource AccentButtonBackground}" />
     <Setter Property="BorderBrush" Value="{DynamicResource AccentButtonBorderBrush}" />
+    <Setter Property="TextBlock.Foreground" Value="{DynamicResource AccentButtonForeground}" />
   </Style>
 
   <Style Selector="Button.accent:pointerover /template/ ContentPresenter">
@@ -78,7 +78,7 @@
     <Setter Property="TextBlock.Foreground" Value="{DynamicResource AccentButtonForegroundPressed}" />
   </Style>
 
-  <Style Selector="Button.accent:disabled">
+  <Style Selector="Button.accent:disabled /template/ ContentPresenter">
     <Setter Property="Background" Value="{DynamicResource AccentButtonBackgroundDisabled}" />
     <Setter Property="BorderBrush" Value="{DynamicResource AccentButtonBorderBrushDisabled}" />
     <Setter Property="TextBlock.Foreground" Value="{DynamicResource AccentButtonForegroundDisabled}" />

+ 118 - 82
src/Avalonia.Themes.Fluent/ButtonSpinner.xaml

@@ -1,104 +1,140 @@
-<Styles xmlns="https://github.com/avaloniaui">
-  <Style Selector="ButtonSpinner">
-    <Setter Property="Background" Value="Transparent"/>
-    <Setter Property="BorderBrush" Value="{DynamicResource ThemeBorderMidBrush}"/>
-    <Setter Property="BorderThickness" Value="{DynamicResource ThemeBorderThickness}"/>
-    <Setter Property="HorizontalContentAlignment" Value="Stretch"/>
-    <Setter Property="VerticalContentAlignment" Value="Center"/>
+<Styles xmlns="https://github.com/avaloniaui"
+        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+        xmlns:sys="clr-namespace:System;assembly=netstandard"
+        xmlns:converters="clr-namespace:Avalonia.Controls.Converters;assembly=Avalonia.Controls">
+  <Design.PreviewWith>
+    <Border Padding="20"
+            Background="Black">
+      <StackPanel Spacing="20">
+        <ButtonSpinner ButtonSpinnerLocation="Right"
+                       Content="Right disabled inline spinner"
+                       AllowSpin="False" />
+        <ButtonSpinner ButtonSpinnerLocation="Left"
+                       Content="Left spinner" />
+        <ButtonSpinner ShowButtonSpinner="False"
+                       Content="Hide spinner" />
+      </StackPanel>
+    </Border>
+  </Design.PreviewWith>
+
+  <Styles.Resources>
+    <converters:MarginMultiplierConverter x:Key="ButtonSpinner_OnlyLeftThinknessConverter"
+                                          Indent="1"
+                                          Left="True" />
+    <converters:MarginMultiplierConverter x:Key="ButtonSpinner_OnlyRightThinknessConverter"
+                                          Indent="1"
+                                          Right="True" />
+
+    <StreamGeometry x:Key="ButtonSpinnerIncreaseButtonIcon">M0,9 L10,0 20,9 19,10 10,2 1,10 z</StreamGeometry>
+    <StreamGeometry x:Key="ButtonSpinnerDecreaseButtonIcon">M0,1 L10,10 20,1 19,0 10,8 1,0 z</StreamGeometry>
+  </Styles.Resources>
+
+  <!--  RepeatButton.ButtonSpinnerRepeatButton  -->
+  <Style Selector="RepeatButton.ButtonSpinnerRepeatButton">
+    <Setter Property="MinWidth" Value="34" />
+    <Setter Property="VerticalAlignment" Value="Stretch" />
   </Style>
-  <Style Selector="ButtonSpinner /template/ RepeatButton">
-    <Setter Property="Background" Value="Transparent"/>
-    <Setter Property="BorderBrush" Value="Transparent"/>
+
+  <Style Selector="RepeatButton.ButtonSpinnerRepeatButton /template/ ContentPresenter">
+    <Setter Property="CornerRadius" Value="0" />
+    <Setter Property="BorderBrush" Value="{TemplateBinding BorderBrush}" />
   </Style>
-  <Style Selector="ButtonSpinner /template/ RepeatButton:pointerover">
-    <Setter Property="Background" Value="{DynamicResource ThemeControlMidBrush}"/>
-    <Setter Property="BorderBrush" Value="{DynamicResource ThemeBorderMidBrush}"/>
+  <Style Selector="RepeatButton.ButtonSpinnerRepeatButton:disabled">
+    <Setter Property="BorderBrush" Value="{TemplateBinding BorderBrush}" />
   </Style>
-  <Style Selector="ButtonSpinner /template/ RepeatButton#PART_IncreaseButton">
-    <Setter Property="Content">
-      <Template>
-        <Path Fill="{DynamicResource ThemeForegroundBrush}"
-              Width="8"
-              Height="4"
-              Stretch="Uniform"
-              HorizontalAlignment="Center"
-              VerticalAlignment="Center"
-              Data="M0,5 L4.5,.5 9,5 6,5 4.5,3.5 3,5 z"/>
-      </Template>
-    </Setter>
+  <Style Selector="RepeatButton.ButtonSpinnerRepeatButton:disabled > Path">
+    <Setter Property="Fill" Value="{DynamicResource RepeatButtonForegroundDisabled}" />
   </Style>
-  <Style Selector="ButtonSpinner /template/ RepeatButton#PART_DecreaseButton">
-    <Setter Property="Content">
-      <Template>
-        <Path Fill="{DynamicResource ThemeForegroundBrush}"
-              Width="8"
-              Height="4"
-              Stretch="Uniform"
-              HorizontalAlignment="Center"
-              VerticalAlignment="Center"
-              Data="M0,0 L3,0 4.5,1.5 6,0 9,0 4.5,4.5 z"/>
-      </Template>
-    </Setter>
-  </Style>
-  <Style Selector="ButtonSpinner:right">
+
+  <!--  ButtonSpinner  -->
+  <Style Selector="ButtonSpinner">
+    <Setter Property="Background" Value="Transparent" />
+    <Setter Property="Foreground" Value="{DynamicResource TextControlForeground}" />
+    <Setter Property="Padding" Value="10, 0" />
+    <Setter Property="Background" Value="{DynamicResource TextControlBackground}" />
+    <Setter Property="BorderBrush" Value="{DynamicResource TextControlBorderBrush}" />
+    <Setter Property="BorderThickness" Value="{DynamicResource TextControlBorderThemeThickness}" />
+    <Setter Property="MinHeight" Value="{DynamicResource TextControlThemeMinHeight}" />
+    <Setter Property="MinWidth" Value="{DynamicResource TextControlThemeMinWidth}" />
+    <Setter Property="FontFamily" Value="{DynamicResource ContentControlThemeFontFamily}" />
+    <Setter Property="FontSize" Value="{DynamicResource ControlContentThemeFontSize}" />
+    <Setter Property="HorizontalContentAlignment" Value="Stretch" />
+    <Setter Property="VerticalContentAlignment" Value="Center" />
     <Setter Property="Template">
       <ControlTemplate>
-        <Border Name="border"
-                Background="{TemplateBinding Background}"
+        <Border Background="{TemplateBinding Background}"
                 BorderBrush="{TemplateBinding BorderBrush}"
                 BorderThickness="{TemplateBinding BorderThickness}"
-                Margin="{TemplateBinding Padding}"
-                HorizontalAlignment="{TemplateBinding HorizontalAlignment}"
-                VerticalAlignment="{TemplateBinding VerticalAlignment}">
-          <Grid ColumnDefinitions="*,Auto">
-            <ContentPresenter Name="PART_ContentPresenter" Grid.Column="0"
+                CornerRadius="{DynamicResource ControlCornerRadius}">
+          <Grid ColumnDefinitions="Auto,*,Auto">
+            <ContentPresenter Name="PART_ContentPresenter"
+                              Grid.Column="1"
                               ContentTemplate="{TemplateBinding ContentTemplate}"
                               Content="{TemplateBinding Content}"
                               HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}"
                               VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"
-                              Padding="{TemplateBinding Padding}"/>
-            <Grid Grid.Column="1" RowDefinitions="*,*" IsVisible="{TemplateBinding ShowButtonSpinner}">
-              <RepeatButton Grid.Row="0" Name="PART_IncreaseButton"/>
-              <RepeatButton Grid.Row="1" Name="PART_DecreaseButton"/>
-            </Grid>
+                              Padding="{TemplateBinding Padding}" />
+
+            <StackPanel Name="PART_SpinnerPanel"
+                        Orientation="Horizontal"
+                        IsVisible="{TemplateBinding ShowButtonSpinner}">
+              <RepeatButton Name="PART_IncreaseButton"
+                            Classes="ButtonSpinnerRepeatButton"
+                            VerticalContentAlignment="Center"
+                            Foreground="{TemplateBinding Foreground}"
+                            BorderBrush="{TemplateBinding BorderBrush}"
+                            Background="{TemplateBinding Background}"
+                            FontSize="{TemplateBinding FontSize}">
+                <Path Fill="{TemplateBinding Foreground}"
+                      Width="16"
+                      Height="8"
+                      Stretch="Uniform"
+                      HorizontalAlignment="Center"
+                      VerticalAlignment="Center"
+                      Data="{StaticResource ButtonSpinnerIncreaseButtonIcon}" />
+              </RepeatButton>
+
+              <RepeatButton Name="PART_DecreaseButton"
+                            Classes="ButtonSpinnerRepeatButton"
+                            Foreground="{TemplateBinding Foreground}"
+                            BorderBrush="{TemplateBinding BorderBrush}"
+                            Background="{TemplateBinding Background}"
+                            VerticalContentAlignment="Center"
+                            FontSize="{TemplateBinding FontSize}">
+                <Path Fill="{TemplateBinding Foreground}"
+                      Width="16"
+                      Height="8"
+                      Stretch="Uniform"
+                      HorizontalAlignment="Center"
+                      VerticalAlignment="Center"
+                      Data="{StaticResource ButtonSpinnerDecreaseButtonIcon}" />
+              </RepeatButton>
+            </StackPanel>
           </Grid>
         </Border>
       </ControlTemplate>
     </Setter>
   </Style>
-  <Style Selector="ButtonSpinner:left">
-    <Setter Property="Template">
-      <ControlTemplate>
-        <Border Name="border"
-                Background="{TemplateBinding Background}"
-                BorderBrush="{TemplateBinding BorderBrush}"
-                BorderThickness="{TemplateBinding BorderThickness}"
-                Margin="{TemplateBinding Padding}"
-                HorizontalAlignment="{TemplateBinding HorizontalAlignment}"
-                VerticalAlignment="{TemplateBinding VerticalAlignment}">
-          <Grid ColumnDefinitions="Auto,*">
-            <Grid Grid.Column="0" RowDefinitions="*,*" IsVisible="{TemplateBinding ShowButtonSpinner}">
-              <RepeatButton Grid.Row="0" Name="PART_IncreaseButton"/>
-              <RepeatButton Grid.Row="1" Name="PART_DecreaseButton"/>
-            </Grid>
-            <ContentPresenter Name="PART_ContentPresenter" Grid.Column="1"
-                              ContentTemplate="{TemplateBinding ContentTemplate}"
-                              Content="{TemplateBinding Content}"
-                              HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}"
-                              VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"
-                              Padding="{TemplateBinding Padding}"/>
-          </Grid>
-        </Border>
-      </ControlTemplate>
-    </Setter>
+
+  <!--  ButtonSpinnerLocation=Right  -->
+  <Style Selector="ButtonSpinner:right /template/ StackPanel#PART_SpinnerPanel">
+    <Setter Property="Grid.Column" Value="2" />
+  </Style>
+  <Style Selector="ButtonSpinner:right /template/ RepeatButton.ButtonSpinnerRepeatButton">
+    <Setter Property="BorderThickness" Value="{Binding $parent[ButtonSpinner].BorderThickness, Converter={StaticResource ButtonSpinner_OnlyLeftThinknessConverter}}" />
   </Style>
-  <Style Selector="ButtonSpinner:pointerover /template/ Border#border">
-    <Setter Property="BorderBrush" Value="{DynamicResource ThemeBorderHighBrush}"/>
+
+  <!--  ButtonSpinnerLocation=Left  -->
+  <Style Selector="ButtonSpinner:left /template/ StackPanel#PART_SpinnerPanel">
+    <Setter Property="Grid.Column" Value="0" />
   </Style>
-  <Style Selector="ButtonSpinner:focus /template/ Border#border">
-    <Setter Property="BorderBrush" Value="{DynamicResource ThemeBorderHighBrush}"/>
+  <Style Selector="ButtonSpinner:left /template/ RepeatButton.ButtonSpinnerRepeatButton">
+    <Setter Property="BorderThickness" Value="{Binding $parent[ButtonSpinner].BorderThickness, Converter={StaticResource ButtonSpinner_OnlyRightThinknessConverter}}" />
   </Style>
-  <Style Selector="ButtonSpinner:error /template/ Border#border">
-    <Setter Property="BorderBrush" Value="{DynamicResource ErrorBrush}"/>
+
+  <!--  Error state  -->
+  <Style Selector="ButtonSpinner:error">
+    <Setter Property="BorderBrush" Value="{DynamicResource ErrorBrush}" />
   </Style>
+
 </Styles>

+ 37 - 15
src/Avalonia.Themes.Fluent/NumericUpDown.xaml

@@ -1,38 +1,60 @@
-<Styles xmlns="https://github.com/avaloniaui">
+<Styles xmlns="https://github.com/avaloniaui"
+        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
+  <Design.PreviewWith>
+    <Border Padding="20"
+            Background="Black">
+      <StackPanel Spacing="20">
+        <NumericUpDown Minimum="0"
+                       Maximum="10"
+                       Increment="0.5"
+                       Width="150"
+                       Watermark="Enter text" />
+        <NumericUpDown Minimum="0"
+                       Maximum="10"
+                       Increment="0.5"
+                       Width="150"
+                       ButtonSpinnerLocation="Left"
+                       Watermark="Enter text" />
+      </StackPanel>
+    </Border>
+  </Design.PreviewWith>
+
   <Style Selector="NumericUpDown">
-    <Setter Property="Background" Value="{DynamicResource ThemeBackgroundBrush}" />
-    <Setter Property="BorderBrush" Value="{DynamicResource ThemeBorderMidBrush}"/>
-    <Setter Property="BorderThickness" Value="{DynamicResource ThemeBorderThickness}"/>
-    <Setter Property="Padding" Value="4"/>
+    <Setter Property="Foreground" Value="{DynamicResource TextControlForeground}" />
+    <Setter Property="Background" Value="{DynamicResource TextControlBackground}" />
+    <Setter Property="BorderThickness" Value="{DynamicResource TextControlBorderThemeThickness}" />
+    <Setter Property="BorderBrush" Value="{DynamicResource TextControlBorderBrush}" />
+    <Setter Property="MinHeight" Value="{DynamicResource TextControlThemeMinHeight}" />
+    <Setter Property="MinWidth" Value="{DynamicResource TextControlThemeMinWidth}" />
+    <Setter Property="FontFamily" Value="{DynamicResource ContentControlThemeFontFamily}" />
+    <Setter Property="FontSize" Value="{DynamicResource ControlContentThemeFontSize}" />
+    <Setter Property="Padding" Value="{DynamicResource TextControlThemePadding}" />
     <Setter Property="Template">
       <ControlTemplate>
         <ButtonSpinner Name="PART_Spinner"
                        Background="{TemplateBinding Background}"
                        BorderThickness="{TemplateBinding BorderThickness}"
                        BorderBrush="{TemplateBinding BorderBrush}"
+                       Padding="0"
                        HorizontalContentAlignment="Stretch"
                        VerticalContentAlignment="Stretch"
                        AllowSpin="{TemplateBinding AllowSpin}"
                        ShowButtonSpinner="{TemplateBinding ShowButtonSpinner}"
                        ButtonSpinnerLocation="{TemplateBinding ButtonSpinnerLocation}">
           <TextBox Name="PART_TextBox"
-                   BorderThickness="0"
-                   Background="{TemplateBinding Background}" 
-                   BorderBrush="{TemplateBinding BorderBrush}"
+                   Background="Transparent"
+                   BorderBrush="Transparent"
+                   Margin="-2"
                    Padding="{TemplateBinding Padding}"
                    Watermark="{TemplateBinding Watermark}"
                    DataValidationErrors.Errors="{TemplateBinding (DataValidationErrors.Errors)}"
                    IsReadOnly="{TemplateBinding IsReadOnly}"
                    Text="{TemplateBinding Text}"
                    AcceptsReturn="False"
-                   TextWrapping="NoWrap">
-          </TextBox>
+                   TextWrapping="NoWrap" />
         </ButtonSpinner>
       </ControlTemplate>
     </Setter>
   </Style>
-  <Style Selector="NumericUpDown /template/ TextBox#PART_TextBox">
-    <Setter Property="Margin" Value="4"/>
-    <Setter Property="MinWidth" Value="20"/>
-  </Style>
-</Styles>
+
+</Styles>

+ 1 - 1
src/Avalonia.Themes.Fluent/RepeatButton.xaml

@@ -54,7 +54,7 @@
     <Setter Property="TextBlock.Foreground" Value="{DynamicResource RepeatButtonForegroundPressed}" />
   </Style>
 
-  <Style Selector="RepeatButton:disabled">
+  <Style Selector="RepeatButton:disabled /template/ ContentPresenter">
     <Setter Property="Background" Value="{DynamicResource RepeatButtonBackgroundDisabled}" />
     <Setter Property="BorderBrush" Value="{DynamicResource RepeatButtonBorderBrushDisabled}" />
     <Setter Property="TextBlock.Foreground" Value="{DynamicResource RepeatButtonForegroundDisabled}" />

+ 1 - 0
src/Avalonia.Themes.Fluent/TextBox.xaml

@@ -27,6 +27,7 @@
                             Grid.ColumnSpan="2"
                             TextBlock.FontWeight="Normal"
                             TextBlock.Foreground="{DynamicResource TextControlHeaderForeground}"
+                            IsVisible="False"
                             Margin="{DynamicResource TextBoxTopHeaderMargin}" />
           
           <Border Name="border"

+ 0 - 1
src/Avalonia.Themes.Fluent/ToggleButton.xaml

@@ -40,7 +40,6 @@
     </Setter>
   </Style>
 
-  <!--  PointerOverState  -->
   <Style Selector="ToggleButton:pointerover /template/ ContentPresenter">
     <Setter Property="Background" Value="{DynamicResource ToggleButtonBackgroundPointerOver}" />
     <Setter Property="BorderBrush" Value="{DynamicResource ToggleButtonBorderBrushPointerOver}" />