-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
723 additions
and
2 deletions.
There are no files selected for viewing
90 changes: 90 additions & 0 deletions
90
src/Avalonia/HandyControlDemo_Avalonia/UserControl/Styles/SliderDemo.axaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
<UserControl xmlns="https://github.com/avaloniaui" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
x:Class="HandyControlDemo.UserControl.SliderDemo" | ||
xmlns:hc="https://handyorg.github.io/handycontrol" | ||
Background="{DynamicResource RegionBrush}"> | ||
<ScrollViewer> | ||
<hc:UniformSpacingPanel Margin="32" | ||
Orientation="Horizontal" | ||
Spacing="32" | ||
ClipToBounds="False" | ||
ChildWrapping="Wrap"> | ||
<hc:UniformSpacingPanel Orientation="Vertical" | ||
Spacing="32"> | ||
<Slider Width="400" | ||
IsSnapToTickEnabled="True" | ||
TickFrequency="1" | ||
Maximum="10" | ||
Value="8" /> | ||
<Slider Width="400" | ||
IsSnapToTickEnabled="True" | ||
TickFrequency="1" | ||
Maximum="10" | ||
Value="3" | ||
IsEnabled="False" /> | ||
<Slider Width="400" | ||
IsSnapToTickEnabled="True" | ||
TickFrequency="5" | ||
Maximum="100" | ||
TickPlacement="TopLeft" | ||
Value="10" /> | ||
<Slider Width="400" | ||
hc:TipElement.IsVisible="True" | ||
hc:TipElement.Placement="Top" | ||
IsSnapToTickEnabled="True" | ||
Maximum="100" | ||
Value="60" | ||
TickFrequency="10" | ||
TickPlacement="BottomRight" /> | ||
<Slider Width="400" | ||
hc:TipElement.IsVisible="True" | ||
hc:TipElement.Placement="Bottom" | ||
hc:TipElement.StringFormat="N2" | ||
TickFrequency="1" | ||
Maximum="10" | ||
Value="5" | ||
TickPlacement="Outside" /> | ||
</hc:UniformSpacingPanel> | ||
<hc:UniformSpacingPanel Spacing="32"> | ||
<Slider Height="400" | ||
IsSnapToTickEnabled="True" | ||
TickFrequency="1" | ||
Maximum="10" | ||
Value="8" | ||
Orientation="Vertical" /> | ||
<Slider Height="400" | ||
IsSnapToTickEnabled="True" | ||
TickFrequency="1" | ||
Maximum="10" | ||
Value="3" | ||
IsEnabled="False" | ||
Orientation="Vertical" /> | ||
<Slider Height="400" | ||
IsSnapToTickEnabled="True" | ||
TickFrequency="5" | ||
Maximum="100" | ||
TickPlacement="TopLeft" | ||
Value="10" | ||
Orientation="Vertical" /> | ||
<Slider Height="400" | ||
hc:TipElement.IsVisible="True" | ||
hc:TipElement.Placement="Right" | ||
IsSnapToTickEnabled="True" | ||
Maximum="100" | ||
Value="60" | ||
TickFrequency="10" | ||
TickPlacement="BottomRight" | ||
Orientation="Vertical" /> | ||
<Slider Height="400" | ||
hc:TipElement.IsVisible="True" | ||
hc:TipElement.Placement="Left" | ||
hc:TipElement.StringFormat="N2" | ||
TickFrequency="1" | ||
Maximum="10" | ||
Value="5" | ||
TickPlacement="Outside" | ||
Orientation="Vertical" /> | ||
</hc:UniformSpacingPanel> | ||
</hc:UniformSpacingPanel> | ||
</ScrollViewer> | ||
</UserControl> |
9 changes: 9 additions & 0 deletions
9
src/Avalonia/HandyControlDemo_Avalonia/UserControl/Styles/SliderDemo.axaml.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
namespace HandyControlDemo.UserControl; | ||
|
||
public partial class SliderDemo : Avalonia.Controls.UserControl | ||
{ | ||
public SliderDemo() | ||
{ | ||
InitializeComponent(); | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
src/Avalonia/HandyControl_Avalonia/Controls/Attach/ContentControlAttach.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
using Avalonia; | ||
using Avalonia.Controls; | ||
using Avalonia.Data; | ||
|
||
namespace HandyControl.Controls; | ||
|
||
public class ContentControlAttach | ||
{ | ||
public static readonly AttachedProperty<string> ContentStringFormatProperty = | ||
AvaloniaProperty.RegisterAttached<ContentControlAttach, AvaloniaObject, string>("ContentStringFormat"); | ||
|
||
public static void SetContentStringFormat(AvaloniaObject element, string value) => | ||
element.SetValue(ContentStringFormatProperty, value); | ||
|
||
public static string GetContentStringFormat(AvaloniaObject element) => | ||
element.GetValue(ContentStringFormatProperty); | ||
|
||
public static readonly AttachedProperty<object?> ContentProperty = | ||
AvaloniaProperty.RegisterAttached<ContentControlAttach, AvaloniaObject, object?>("Content"); | ||
|
||
public static void SetContent(AvaloniaObject element, object? value) => element.SetValue(ContentProperty, value); | ||
|
||
public static object? GetContent(AvaloniaObject element) => element.GetValue(ContentProperty); | ||
|
||
static ContentControlAttach() | ||
{ | ||
ContentStringFormatProperty.Changed.AddClassHandler<AvaloniaObject>(OnContentChanged); | ||
ContentProperty.Changed.AddClassHandler<AvaloniaObject>(OnContentChanged); | ||
} | ||
|
||
private static void OnContentChanged(AvaloniaObject element, AvaloniaPropertyChangedEventArgs e) | ||
{ | ||
if (element is not ContentControl contentControl) | ||
{ | ||
return; | ||
} | ||
|
||
contentControl.ClearValue(ContentControl.ContentProperty); | ||
|
||
var binding = new Binding("(ContentControlAttach.Content)") | ||
{ | ||
Source = contentControl, | ||
StringFormat = contentControl.GetValue(ContentStringFormatProperty), | ||
TypeResolver = (_, _) => typeof(ContentControlAttach) | ||
}; | ||
|
||
contentControl.Bind(ContentControl.ContentProperty, binding); | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
src/Avalonia/HandyControl_Avalonia/Controls/Attach/TipElement.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
using Avalonia; | ||
using HandyControl.Data; | ||
|
||
namespace HandyControl.Controls; | ||
|
||
public class TipElement | ||
{ | ||
public static readonly AttachedProperty<bool> IsVisibleProperty = | ||
AvaloniaProperty.RegisterAttached<TipElement, AvaloniaObject, bool>("IsVisible"); | ||
|
||
public static void SetIsVisible(AvaloniaObject element, bool value) => element.SetValue(IsVisibleProperty, value); | ||
|
||
public static bool GetIsVisible(AvaloniaObject element) => element.GetValue(IsVisibleProperty); | ||
|
||
public static readonly AttachedProperty<PlacementType> PlacementProperty = | ||
AvaloniaProperty.RegisterAttached<TipElement, AvaloniaObject, PlacementType>("Placement"); | ||
|
||
public static void SetPlacement(AvaloniaObject element, PlacementType value) => | ||
element.SetValue(PlacementProperty, value); | ||
|
||
public static PlacementType GetPlacement(AvaloniaObject element) => element.GetValue(PlacementProperty); | ||
|
||
public static readonly AttachedProperty<string> StringFormatProperty = | ||
AvaloniaProperty.RegisterAttached<TipElement, AvaloniaObject, string>("StringFormat", defaultValue: "N1"); | ||
|
||
public static void SetStringFormat(AvaloniaObject element, string value) => | ||
element.SetValue(StringFormatProperty, value); | ||
|
||
public static string GetStringFormat(AvaloniaObject element) => element.GetValue(StringFormatProperty); | ||
} |
73 changes: 73 additions & 0 deletions
73
src/Avalonia/HandyControl_Avalonia/Controls/Panel/AxleCanvas.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
using Avalonia; | ||
using Avalonia.Controls; | ||
using Avalonia.Layout; | ||
|
||
namespace HandyControl.Controls; | ||
|
||
public class AxleCanvas : Canvas | ||
{ | ||
public static readonly StyledProperty<Orientation> OrientationProperty = | ||
StackPanel.OrientationProperty.AddOwner<AxleCanvas>(new StyledPropertyMetadata<Orientation>( | ||
defaultValue: Orientation.Horizontal)); | ||
|
||
public Orientation Orientation | ||
{ | ||
get => GetValue(OrientationProperty); | ||
set => SetValue(OrientationProperty, value); | ||
} | ||
|
||
protected override Size ArrangeOverride(Size finalSize) | ||
{ | ||
foreach (Control? internalChild in Children) | ||
{ | ||
if (internalChild == null) | ||
{ | ||
continue; | ||
} | ||
|
||
double x = 0.0; | ||
double y = 0.0; | ||
|
||
if (Orientation == Orientation.Horizontal) | ||
{ | ||
x = (finalSize.Width - internalChild.DesiredSize.Width) / 2; | ||
|
||
double top = GetTop(internalChild); | ||
if (!double.IsNaN(top)) | ||
{ | ||
y = top; | ||
} | ||
else | ||
{ | ||
double bottom = GetBottom(internalChild); | ||
if (!double.IsNaN(bottom)) | ||
{ | ||
y = finalSize.Height - internalChild.DesiredSize.Height - bottom; | ||
} | ||
} | ||
} | ||
else | ||
{ | ||
y = (finalSize.Height - internalChild.DesiredSize.Height) / 2; | ||
|
||
double left = GetLeft(internalChild); | ||
if (!double.IsNaN(left)) | ||
{ | ||
x = left; | ||
} | ||
else | ||
{ | ||
double right = GetRight(internalChild); | ||
if (!double.IsNaN(right)) | ||
{ | ||
x = finalSize.Width - internalChild.DesiredSize.Width - right; | ||
} | ||
} | ||
} | ||
|
||
internalChild.Arrange(new Rect(new Point(x, y), internalChild.DesiredSize)); | ||
} | ||
|
||
return finalSize; | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
src/Avalonia/HandyControl_Avalonia/Data/Enum/PlacementType.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
namespace HandyControl.Data; | ||
|
||
public enum PlacementType | ||
{ | ||
LeftTop, | ||
Left, | ||
LeftBottom, | ||
TopLeft, | ||
Top, | ||
TopRight, | ||
RightTop, | ||
Right, | ||
RightBottom, | ||
BottomLeft, | ||
Bottom, | ||
BottomRight, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.