Browse Source
Conflicts: src/Avalonia.Themes.Default/ScrollBar.xaml src/Avalonia.Themes.Default/Slider.xamlpull/1136/head
17 changed files with 586 additions and 117 deletions
@ -0,0 +1,82 @@ |
|||
using System; |
|||
using Avalonia.Input; |
|||
using Avalonia.Threading; |
|||
|
|||
namespace Avalonia.Controls |
|||
{ |
|||
public class RepeatButton : Button |
|||
{ |
|||
/// <summary>
|
|||
/// Defines the <see cref="Delay"/> property.
|
|||
/// </summary>
|
|||
public static readonly StyledProperty<int> DelayProperty = |
|||
AvaloniaProperty.Register<Button, int>(nameof(Delay), 100); |
|||
|
|||
private DispatcherTimer _repeatTimer; |
|||
|
|||
/// <summary>
|
|||
/// Gets or sets the amount of time, in milliseconds, of repeating clicks.
|
|||
/// </summary>
|
|||
public int Delay |
|||
{ |
|||
get { return GetValue(DelayProperty); } |
|||
set { SetValue(DelayProperty, value); } |
|||
} |
|||
|
|||
private void StartTimer() |
|||
{ |
|||
if (_repeatTimer == null) |
|||
{ |
|||
_repeatTimer = new DispatcherTimer(); |
|||
_repeatTimer.Tick += (o, e) => OnClick(); |
|||
} |
|||
|
|||
if (_repeatTimer.IsEnabled) return; |
|||
|
|||
_repeatTimer.Interval = TimeSpan.FromMilliseconds(Delay); |
|||
_repeatTimer.Start(); |
|||
} |
|||
|
|||
private void StopTimer() |
|||
{ |
|||
_repeatTimer?.Stop(); |
|||
} |
|||
|
|||
protected override void OnKeyDown(KeyEventArgs e) |
|||
{ |
|||
base.OnKeyDown(e); |
|||
|
|||
if (e.Key == Key.Space) |
|||
{ |
|||
StartTimer(); |
|||
} |
|||
} |
|||
|
|||
protected override void OnKeyUp(KeyEventArgs e) |
|||
{ |
|||
base.OnKeyUp(e); |
|||
|
|||
StopTimer(); |
|||
} |
|||
|
|||
protected override void OnPointerPressed(PointerPressedEventArgs e) |
|||
{ |
|||
base.OnPointerPressed(e); |
|||
|
|||
if (e.MouseButton == MouseButton.Left) |
|||
{ |
|||
StartTimer(); |
|||
} |
|||
} |
|||
|
|||
protected override void OnPointerReleased(PointerReleasedEventArgs e) |
|||
{ |
|||
base.OnPointerReleased(e); |
|||
|
|||
if (e.MouseButton == MouseButton.Left) |
|||
{ |
|||
StopTimer(); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,44 @@ |
|||
<Styles xmlns="https://github.com/avaloniaui"> |
|||
<Style Selector="RepeatButton"> |
|||
<Setter Property="Background" |
|||
Value="{StyleResource ThemeControlMidBrush}" /> |
|||
<Setter Property="BorderBrush" |
|||
Value="{StyleResource ThemeBorderLightBrush}" /> |
|||
<Setter Property="BorderThickness" |
|||
Value="{StyleResource ThemeBorderThickness}" /> |
|||
<Setter Property="Foreground" |
|||
Value="{StyleResource ThemeForegroundBrush}" /> |
|||
<Setter Property="HorizontalContentAlignment" |
|||
Value="Center" /> |
|||
<Setter Property="VerticalContentAlignment" |
|||
Value="Center" /> |
|||
<Setter Property="Padding" |
|||
Value="4" /> |
|||
<Setter Property="Template"> |
|||
<ControlTemplate> |
|||
<ContentPresenter Name="PART_ContentPresenter" |
|||
Background="{TemplateBinding Background}" |
|||
BorderBrush="{TemplateBinding BorderBrush}" |
|||
BorderThickness="{TemplateBinding BorderThickness}" |
|||
Content="{TemplateBinding Content}" |
|||
ContentTemplate="{TemplateBinding ContentTemplate}" |
|||
Padding="{TemplateBinding Padding}" |
|||
TextBlock.Foreground="{TemplateBinding Foreground}" |
|||
HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}" |
|||
VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}" /> |
|||
</ControlTemplate> |
|||
</Setter> |
|||
</Style> |
|||
<Style Selector="RepeatButton:pointerover /template/ ContentPresenter"> |
|||
<Setter Property="BorderBrush" |
|||
Value="{StyleResource ThemeBorderMidBrush}" /> |
|||
</Style> |
|||
<Style Selector="RepeatButton:pressed /template/ ContentPresenter"> |
|||
<Setter Property="Background" |
|||
Value="{StyleResource ThemeControlDarkBrush}" /> |
|||
</Style> |
|||
<Style Selector="RepeatButton:disabled"> |
|||
<Setter Property="Opacity" |
|||
Value="{StyleResource ThemeDisabledOpacity}" /> |
|||
</Style> |
|||
</Styles> |
|||
@ -1,35 +1,127 @@ |
|||
<Styles xmlns="https://github.com/avaloniaui"> |
|||
<Style Selector="ScrollBar"> |
|||
<Setter Property="Template"> |
|||
<ControlTemplate> |
|||
<Border Background="{DynamicResource ThemeControlMidBrush}"> |
|||
<Track Minimum="{TemplateBinding Minimum}" |
|||
Maximum="{TemplateBinding Maximum}" |
|||
Value="{TemplateBinding Path=Value, Mode=TwoWay}" |
|||
ViewportSize="{TemplateBinding ViewportSize}" |
|||
Orientation="{TemplateBinding Orientation}"> |
|||
<Thumb Name="thumb"> |
|||
<Thumb.Template> |
|||
<ControlTemplate> |
|||
<Border Background="{DynamicResource ThemeControlDarkBrush}"/> |
|||
</ControlTemplate> |
|||
</Thumb.Template> |
|||
</Thumb> |
|||
</Track> |
|||
</Border> |
|||
</ControlTemplate> |
|||
</Setter> |
|||
</Style> |
|||
<Style Selector="ScrollBar:horizontal"> |
|||
<Setter Property="Height" Value="10"/> |
|||
</Style> |
|||
<Style Selector="ScrollBar:horizontal /template/ Thumb#thumb"> |
|||
<Setter Property="MinWidth" Value="10"/> |
|||
</Style> |
|||
<Style Selector="ScrollBar:vertical"> |
|||
<Setter Property="Width" Value="10"/> |
|||
</Style> |
|||
<Style Selector="ScrollBar:vertical /template/ Thumb#thumb"> |
|||
<Setter Property="MinHeight" Value="10"/> |
|||
</Style> |
|||
<Style Selector="ScrollBar"> |
|||
<Setter Property="Template"> |
|||
<ControlTemplate> |
|||
<Border Background="{DynamicResource ThemeControlMidBrush}"> |
|||
<Grid RowDefinitions="10,*,10"> |
|||
<RepeatButton Name="PART_LineUpButton" |
|||
Classes="repeat" |
|||
Grid.Row="0" |
|||
Grid.Column="0"> |
|||
<Path Data="M 0,4 C0,4 0,6 0,6 0,6 3.5,2.5 3.5,2.5 3.5,2.5 7,6 7,6 7,6 7,4 7,4 7,4 3.5,0.5 3.5,0.5 3.5,0.5 0,4 0,4 z" |
|||
Stretch="Uniform" |
|||
Fill="Gray" /> |
|||
</RepeatButton> |
|||
<Track Grid.Row="1" |
|||
Grid.Column="1" |
|||
Minimum="{TemplateBinding Minimum}" |
|||
Maximum="{TemplateBinding Maximum}" |
|||
Value="{TemplateBinding Path=Value, Mode=TwoWay}" |
|||
ViewportSize="{TemplateBinding ViewportSize}" |
|||
Orientation="{TemplateBinding Orientation}"> |
|||
<Track.DecreaseButton> |
|||
<RepeatButton Name="PART_PageUpButton" |
|||
Classes="repeattrack" /> |
|||
</Track.DecreaseButton> |
|||
<Track.IncreaseButton> |
|||
<RepeatButton Name="PART_PageDownButton" |
|||
Classes="repeattrack" /> |
|||
</Track.IncreaseButton> |
|||
<Thumb Name="thumb"> |
|||
<Thumb.Template> |
|||
<ControlTemplate> |
|||
<Border Background="{DynamicResource ThemeControlDarkBrush}" /> |
|||
</ControlTemplate> |
|||
</Thumb.Template> |
|||
</Thumb> |
|||
</Track> |
|||
<RepeatButton Name="PART_LineDownButton" |
|||
Classes="repeat" |
|||
Grid.Row="2" |
|||
Grid.Column="2"> |
|||
<Path Data="M 0,2.5 C0,2.5 0,0.5 0,0.5 0,0.5 3.5,4 3.5,4 3.5,4 7,0.5 7,0.5 7,0.5 7,2.5 7,2.5 7,2.5 3.5,6 3.5,6 3.5,6 0,2.5 0,2.5 z" |
|||
Stretch="Uniform" |
|||
Fill="Gray" /> |
|||
</RepeatButton> |
|||
</Grid> |
|||
</Border> |
|||
</ControlTemplate> |
|||
</Setter> |
|||
</Style> |
|||
<Style Selector="ScrollBar:horizontal"> |
|||
<Setter Property="Height" |
|||
Value="10" /> |
|||
<Setter Property="Template"> |
|||
<ControlTemplate> |
|||
<Border Background="{DynamicResource ThemeControlMidBrush}"> |
|||
<Grid ColumnDefinitions="10,*,10"> |
|||
<RepeatButton Name="PART_LineUpButton" |
|||
Classes="repeat" |
|||
Grid.Row="0" |
|||
Grid.Column="0"> |
|||
<Path Data="M 3.18,7 C3.18,7 5,7 5,7 5,7 1.81,3.5 1.81,3.5 1.81,3.5 5,0 5,0 5,0 3.18,0 3.18,0 3.18,0 0,3.5 0,3.5 0,3.5 3.18,7 3.18,7 z" |
|||
Stretch="Uniform" |
|||
Fill="Gray" /> |
|||
</RepeatButton> |
|||
<Track Grid.Row="1" |
|||
Grid.Column="1" |
|||
Minimum="{TemplateBinding Minimum}" |
|||
Maximum="{TemplateBinding Maximum}" |
|||
Value="{TemplateBinding Path=Value, Mode=TwoWay}" |
|||
ViewportSize="{TemplateBinding ViewportSize}" |
|||
Orientation="{TemplateBinding Orientation}"> |
|||
<Track.DecreaseButton> |
|||
<RepeatButton Name="PART_PageUpButton" |
|||
Classes="repeattrack" /> |
|||
</Track.DecreaseButton> |
|||
<Track.IncreaseButton> |
|||
<RepeatButton Name="PART_PageDownButton" |
|||
Classes="repeattrack" /> |
|||
</Track.IncreaseButton> |
|||
<Thumb Name="thumb"> |
|||
<Thumb.Template> |
|||
<ControlTemplate> |
|||
<Border Background="{DynamicResource ThemeControlDarkBrush}" /> |
|||
</ControlTemplate> |
|||
</Thumb.Template> |
|||
</Thumb> |
|||
</Track> |
|||
<RepeatButton Name="PART_LineDownButton" |
|||
Classes="repeat" |
|||
Grid.Row="2" |
|||
Grid.Column="2"> |
|||
<Path Data="M 1.81,7 C1.81,7 0,7 0,7 0,7 3.18,3.5 3.18,3.5 3.18,3.5 0,0 0,0 0,0 1.81,0 1.81,0 1.81,0 5,3.5 5,3.5 5,3.5 1.81,7 1.81,7 z" |
|||
Stretch="Uniform" |
|||
Fill="Gray" /> |
|||
</RepeatButton> |
|||
</Grid> |
|||
</Border> |
|||
</ControlTemplate> |
|||
</Setter> |
|||
</Style> |
|||
<Style Selector="ScrollBar:horizontal /template/ Thumb#thumb"> |
|||
<Setter Property="MinWidth" |
|||
Value="10" /> |
|||
</Style> |
|||
<Style Selector="ScrollBar:vertical"> |
|||
<Setter Property="Width" |
|||
Value="10" /> |
|||
</Style> |
|||
<Style Selector="ScrollBar:vertical /template/ Thumb#thumb"> |
|||
<Setter Property="MinHeight" |
|||
Value="10" /> |
|||
</Style> |
|||
<Style Selector="ScrollBar /template/ RepeatButton.repeat"> |
|||
<Setter Property="Padding" |
|||
Value="2" /> |
|||
<Setter Property="BorderThickness" |
|||
Value="0" /> |
|||
</Style> |
|||
<Style Selector="ScrollBar /template/ RepeatButton.repeattrack"> |
|||
<Setter Property="Template"> |
|||
<ControlTemplate> |
|||
<Border Background="{TemplateBinding Background}" /> |
|||
</ControlTemplate> |
|||
</Setter> |
|||
</Style> |
|||
</Styles> |
|||
Loading…
Reference in new issue