feat: initialize, setup demo. make sure MVVM works.
This commit is contained in:
37
src/Ursa.Themes.Semi/Controls/ToolBar.axaml
Normal file
37
src/Ursa.Themes.Semi/Controls/ToolBar.axaml
Normal file
@@ -0,0 +1,37 @@
|
||||
<ResourceDictionary
|
||||
xmlns="https://github.com/avaloniaui"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:u="https://irihi.tech/ursa">
|
||||
<!-- Add Resources Here -->
|
||||
<ControlTheme x:Key="{x:Type u:ToolBar}" TargetType="u:ToolBar">
|
||||
<Setter Property="ItemsPanel">
|
||||
<ItemsPanelTemplate>
|
||||
<u:ToolBarPanel/>
|
||||
</ItemsPanelTemplate>
|
||||
</Setter>
|
||||
<Setter Property="Template">
|
||||
<ControlTemplate TargetType="u:ToolBar">
|
||||
<Border
|
||||
Padding="2"
|
||||
Theme="{DynamicResource CardBorder}"
|
||||
CornerRadius="4">
|
||||
<StackPanel Orientation="{TemplateBinding Orientation}">
|
||||
<Rectangle
|
||||
Width="1"
|
||||
VerticalAlignment="Stretch"
|
||||
Margin="4 0"
|
||||
Fill="Gray" />
|
||||
<ContentPresenter Margin="4 0" Content="{TemplateBinding Header}" ContentTemplate="{TemplateBinding HeaderTemplate}" />
|
||||
<ItemsPresenter VerticalAlignment="Center" HorizontalAlignment="Left" ItemsPanel="{TemplateBinding ItemsPanel}"/>
|
||||
<Button Content="More"></Button>
|
||||
<Popup>
|
||||
<Border Theme="{DynamicResource CardBorder}">
|
||||
<StackPanel Name="{x:Static u:ToolBar.PART_OverflowPanel}"></StackPanel>
|
||||
</Border>
|
||||
</Popup>
|
||||
</StackPanel>
|
||||
</Border>
|
||||
</ControlTemplate>
|
||||
</Setter>
|
||||
</ControlTheme>
|
||||
</ResourceDictionary>
|
||||
@@ -30,5 +30,6 @@
|
||||
<ResourceInclude Source="ThemeSelector.axaml" />
|
||||
<ResourceInclude Source="Timeline.axaml" />
|
||||
<ResourceInclude Source="TwoTonePathIcon.axaml" />
|
||||
<ResourceInclude Source="ToolBar.axaml" />
|
||||
</ResourceDictionary.MergedDictionaries>
|
||||
</ResourceDictionary>
|
||||
|
||||
8
src/Ursa/Controls/ToolBar/OverflowMode.cs
Normal file
8
src/Ursa/Controls/ToolBar/OverflowMode.cs
Normal file
@@ -0,0 +1,8 @@
|
||||
namespace Ursa.Controls;
|
||||
|
||||
public enum OverflowMode
|
||||
{
|
||||
AsNeeded,
|
||||
Always,
|
||||
Never
|
||||
}
|
||||
61
src/Ursa/Controls/ToolBar/ToolBar.cs
Normal file
61
src/Ursa/Controls/ToolBar/ToolBar.cs
Normal file
@@ -0,0 +1,61 @@
|
||||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Controls.Metadata;
|
||||
using Avalonia.Controls.Presenters;
|
||||
using Avalonia.Controls.Primitives;
|
||||
using Avalonia.Controls.Templates;
|
||||
using Avalonia.Layout;
|
||||
|
||||
namespace Ursa.Controls;
|
||||
|
||||
[TemplatePart(PART_OverflowPanel, typeof(Panel))]
|
||||
public class ToolBar: HeaderedItemsControl
|
||||
{
|
||||
public const string PART_OverflowPanel = "PART_OverflowPanel";
|
||||
|
||||
internal Panel? OverflowPanel { get; private set; }
|
||||
|
||||
private static readonly ITemplate<Panel?> DefaultTemplate =
|
||||
new FuncTemplate<Panel?>(() => new ToolBarPanel() { Orientation = Orientation.Horizontal });
|
||||
|
||||
public static readonly StyledProperty<Orientation> OrientationProperty =
|
||||
StackPanel.OrientationProperty.AddOwner<ToolBar>();
|
||||
|
||||
public Orientation Orientation
|
||||
{
|
||||
get => GetValue(OrientationProperty);
|
||||
set => SetValue(OrientationProperty, value);
|
||||
}
|
||||
|
||||
public static readonly StyledProperty<int> BandProperty = AvaloniaProperty.Register<ToolBar, int>(
|
||||
nameof(Band));
|
||||
|
||||
public int Band
|
||||
{
|
||||
get => GetValue(BandProperty);
|
||||
set => SetValue(BandProperty, value);
|
||||
}
|
||||
|
||||
static ToolBar()
|
||||
{
|
||||
IsTabStopProperty.OverrideDefaultValue<ToolBar>(false);
|
||||
ItemsPanelProperty.OverrideDefaultValue<ToolBar>(DefaultTemplate);
|
||||
OrientationProperty.OverrideDefaultValue<ToolBar>(Orientation.Horizontal);
|
||||
}
|
||||
|
||||
protected override bool NeedsContainerOverride(object? item, int index, out object? recycleKey)
|
||||
{
|
||||
return NeedsContainer<Control>(item, out recycleKey);
|
||||
}
|
||||
|
||||
protected override Control CreateContainerForItemOverride(object? item, int index, object? recycleKey)
|
||||
{
|
||||
return new ContentPresenter();
|
||||
}
|
||||
|
||||
protected override void OnApplyTemplate(TemplateAppliedEventArgs e)
|
||||
{
|
||||
base.OnApplyTemplate(e);
|
||||
OverflowPanel = e.NameScope.Find<Panel>(PART_OverflowPanel);
|
||||
}
|
||||
}
|
||||
8
src/Ursa/Controls/ToolBar/ToolBarOverflowPanel.cs
Normal file
8
src/Ursa/Controls/ToolBar/ToolBarOverflowPanel.cs
Normal file
@@ -0,0 +1,8 @@
|
||||
using Avalonia.Controls;
|
||||
|
||||
namespace Ursa.Controls;
|
||||
|
||||
public class ToolBarOverflowPanel: StackPanel
|
||||
{
|
||||
|
||||
}
|
||||
34
src/Ursa/Controls/ToolBar/ToolBarPanel.cs
Normal file
34
src/Ursa/Controls/ToolBar/ToolBarPanel.cs
Normal file
@@ -0,0 +1,34 @@
|
||||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Layout;
|
||||
using Avalonia.LogicalTree;
|
||||
|
||||
namespace Ursa.Controls;
|
||||
|
||||
public class ToolBarPanel: StackPanel
|
||||
{
|
||||
private ToolBar? _parent;
|
||||
private Panel? _overflowPanel;
|
||||
|
||||
internal Panel? OverflowPanel => _overflowPanel ??= _parent?.OverflowPanel;
|
||||
internal ToolBar? ParentToolBar => _parent ??= this.TemplatedParent as ToolBar;
|
||||
|
||||
static ToolBarPanel()
|
||||
{
|
||||
OrientationProperty.OverrideDefaultValue<ToolBarPanel>(Orientation.Horizontal);
|
||||
}
|
||||
|
||||
protected override void OnAttachedToLogicalTree(LogicalTreeAttachmentEventArgs e)
|
||||
{
|
||||
base.OnAttachedToLogicalTree(e);
|
||||
_parent = this.TemplatedParent as ToolBar;
|
||||
if (_parent is null) return;
|
||||
this[!OrientationProperty] = _parent[!OrientationProperty];
|
||||
}
|
||||
|
||||
protected override Size MeasureOverride(Size availableSize)
|
||||
{
|
||||
return base.MeasureOverride(availableSize);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -17,4 +17,8 @@
|
||||
<PackageReference Include="Irihi.Avalonia.Shared" Version="0.1.2" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="Controls\Panels\" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
Reference in New Issue
Block a user