Skip to content

Commit dc7a630

Browse files
committed
Add Toolbar
1 parent 86f2752 commit dc7a630

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+4607
-1
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Copyright (c) Files Community
2+
// Licensed under the MIT License.
3+
4+
namespace DevWinUI;
5+
6+
/// <summary>
7+
/// Interface to scope allowed items in the Private Item list
8+
/// </summary>
9+
public interface IToolbarItemSet
10+
{
11+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Copyright (c) Files Community
2+
// Licensed under the MIT License.
3+
4+
namespace DevWinUI;
5+
6+
/// <summary>
7+
/// Interface to scope allowed items in the Private Overflow list
8+
/// </summary>
9+
public interface IToolbarOverflowItemSet
10+
{
11+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Copyright (c) Files Community
2+
// Licensed under the MIT License.
3+
4+
namespace DevWinUI;
5+
6+
public enum OverflowBehaviors
7+
{
8+
/// <summary>
9+
/// Item will move to the overflow menu if space available is too small
10+
/// </summary>
11+
Auto,
12+
13+
/// <summary>
14+
/// Item will always appear in the overflow menu
15+
/// </summary>
16+
Always,
17+
18+
/// <summary>
19+
/// Item will never move to the overflow menu
20+
/// </summary>
21+
Never,
22+
}
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
// Copyright (c) Files Community
2+
// Licensed under the MIT License.
3+
4+
using Windows.Foundation;
5+
6+
namespace DevWinUI;
7+
8+
public partial class ToolbarLayout : NonVirtualizingLayout
9+
{
10+
private Size m_availableSize;
11+
12+
public ToolbarLayout()
13+
{
14+
15+
}
16+
17+
private int GetItemCount(NonVirtualizingLayoutContext context)
18+
{
19+
return context.Children.Count;
20+
}
21+
22+
private UIElement GetElementAt(NonVirtualizingLayoutContext context, int index)
23+
{
24+
return context.Children[index];
25+
}
26+
27+
// Measuring is performed in a single step, every element is measured, including the overflow button
28+
// item, but the total amount of space needed is only composed of the Toolbar Items
29+
protected override Size MeasureOverride(NonVirtualizingLayoutContext context, Size availableSize)
30+
{
31+
m_availableSize = availableSize;
32+
33+
Size accumulatedItemsSize = new(0, 0);
34+
35+
for (int i = 0; i < GetItemCount(context); ++i)
36+
{
37+
//var toolbarItem = (ToolbarItem)GetElementAt(context, i);
38+
//toolbarItem.Measure( availableSize );
39+
40+
if (i != 0)
41+
{
42+
//accumulatedItemsSize.Width += toolbarItem.DesiredSize.Width;
43+
//accumulatedItemsSize.Height = Math.Max( accumulatedItemsSize.Height , toolbarItem.DesiredSize.Height );
44+
}
45+
}
46+
47+
if (accumulatedItemsSize.Width > availableSize.Width)
48+
{
49+
50+
}
51+
else
52+
{
53+
54+
}
55+
56+
return accumulatedItemsSize;
57+
}
58+
59+
private void ArrangeItem(UIElement breadcrumbItem, ref float accumulatedWidths, float maxElementHeight)
60+
{
61+
}
62+
63+
// Arranging is performed in a single step, as many elements are tried to be drawn going from the last element
64+
// towards the first one, if there's not enough space, then the ellipsis button is drawn
65+
protected override Size ArrangeOverride(NonVirtualizingLayoutContext context, Size finalSize)
66+
{
67+
return finalSize;
68+
}
69+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Copyright (c) Files Community
2+
// Licensed under the MIT License.
3+
4+
namespace DevWinUI;
5+
6+
public enum ToolbarSizes
7+
{
8+
/// <summary>
9+
/// Buttons set to 32 x 32 size
10+
/// </summary>
11+
Small,
12+
13+
/// <summary>
14+
/// Buttons set to 32 x 32 size
15+
/// </summary>
16+
Medium,
17+
18+
/// <summary>
19+
/// Buttons set to 40 x 40 size
20+
/// </summary>
21+
Large,
22+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Copyright (c) Files Community
2+
// Licensed under the MIT License.
3+
4+
namespace DevWinUI;
5+
// TemplateParts
6+
[TemplatePart(Name = ToolbarItemsRepeaterPartName, Type = typeof(ItemsRepeater))]
7+
8+
// VisualStates
9+
[TemplateVisualState(Name = OverflowOnStateName, GroupName = CommonStatesGroupName)]
10+
[TemplateVisualState(Name = OverflowOffStateName, GroupName = CommonStatesGroupName)]
11+
public partial class Toolbar : Control
12+
{
13+
// TemplatePart Names
14+
internal const string ToolbarItemsRepeaterPartName = "PART_ItemsRepeater";
15+
16+
// VisualState Group Names
17+
internal const string CommonStatesGroupName = "OverflowStates";
18+
19+
// VisualState Names
20+
internal const string OverflowOnStateName = "OverflowOn";
21+
internal const string OverflowOffStateName = "OverflowOff";
22+
// ResourceDictionary Keys
23+
internal const string SmallMinWidthResourceKey = "ToolbarButtonSmallMinWidth";
24+
internal const string SmallMinHeightResourceKey = "ToolbarButtonSmallMinHeight";
25+
26+
internal const string MediumMinWidthResourceKey = "ToolbarButtonMediumMinWidth";
27+
internal const string MediumMinHeightResourceKey = "ToolbarButtonMediumMinHeight";
28+
29+
internal const string LargeMinWidthResourceKey = "ToolbarButtonLargeMinWidth";
30+
internal const string LargeMinHeightResourceKey = "ToolbarButtonLargeMinHeight";
31+
}
Lines changed: 182 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,182 @@
1+
// Copyright (c) Files Community
2+
// Licensed under the MIT License.
3+
4+
namespace DevWinUI;
5+
6+
public partial class Toolbar : Control
7+
{
8+
#region ToolbarSize (enum ToolbarSizes)
9+
10+
/// <summary>
11+
/// The backing <see cref="DependencyProperty"/> for the <see cref="ToolbarSize"/> property.
12+
/// </summary>
13+
public static readonly DependencyProperty ToolbarSizeProperty =
14+
DependencyProperty.Register(
15+
nameof(ToolbarSize),
16+
typeof(ToolbarSizes),
17+
typeof(Toolbar),
18+
new PropertyMetadata(ToolbarSizes.Medium, (d, e) => ((Toolbar)d).OnToolbarSizePropertyChanged((ToolbarSizes)e.OldValue, (ToolbarSizes)e.NewValue)));
19+
20+
21+
22+
/// <summary>
23+
/// Gets or sets an Enum value to choose from our ToolbarSizes. (Small, Medium, Large)
24+
/// </summary>
25+
public ToolbarSizes ToolbarSize
26+
{
27+
get => (ToolbarSizes)GetValue(ToolbarSizeProperty);
28+
set => SetValue(ToolbarSizeProperty, value);
29+
}
30+
31+
32+
/// <summary>
33+
/// Triggers when the ToolbarSize property changes
34+
/// </summary>
35+
/// <param name="oldValue"></param>
36+
/// <param name="newValue"></param>
37+
protected virtual void OnToolbarSizePropertyChanged(ToolbarSizes oldValue, ToolbarSizes newValue)
38+
{
39+
if (newValue != oldValue)
40+
{
41+
ToolbarSizeChanged(newValue);
42+
}
43+
}
44+
45+
#endregion
46+
47+
#region Items (IList<ToolbarItem>)
48+
49+
public static readonly DependencyProperty ItemsProperty =
50+
DependencyProperty.Register(
51+
nameof(Items),
52+
typeof(IList<ToolbarItem>),
53+
typeof(Toolbar),
54+
new PropertyMetadata(defaultValue: new List<ToolbarItem>(), (d, e) => ((Toolbar)d).OnItemsPropertyChanged((IList<ToolbarItem>)e.OldValue, (IList<ToolbarItem>)e.NewValue)));
55+
56+
57+
58+
public IList<ToolbarItem> Items
59+
{
60+
get => (IList<ToolbarItem>)GetValue(ItemsProperty);
61+
set => SetValue(ItemsProperty, value);
62+
}
63+
64+
65+
66+
private void OnItemsPropertyChanged(IList<ToolbarItem> oldItems, IList<ToolbarItem> newItems)
67+
{
68+
if (newItems != oldItems)
69+
{
70+
ItemsChanged(newItems);
71+
}
72+
}
73+
74+
#endregion
75+
76+
#region ItemTemplate (DataTemplate)
77+
78+
/// <summary>
79+
/// The backing <see cref="DependencyProperty"/> for the <see cref="ItemTemplate"/> property.
80+
/// </summary>
81+
public static readonly DependencyProperty ItemTemplateProperty =
82+
DependencyProperty.Register(
83+
nameof(ItemTemplate),
84+
typeof(DataTemplate),
85+
typeof(Toolbar),
86+
new PropertyMetadata(null, (d, e) => ((Toolbar)d).OnItemTemplatePropertyChanged((DataTemplate)e.OldValue, (DataTemplate)e.NewValue)));
87+
88+
89+
90+
/// <summary>
91+
/// Gets or sets an Enum value to choose from our ToolbarSizes. (Small, Medium, Large)
92+
/// </summary>
93+
public DataTemplate ItemTemplate
94+
{
95+
get => (DataTemplate)GetValue(ItemTemplateProperty);
96+
set => SetValue(ItemTemplateProperty, value);
97+
}
98+
99+
100+
/// <summary>
101+
/// Triggers when the Toolbar's ItemTemplate property changes
102+
/// </summary>
103+
/// <param name="oldValue"></param>
104+
/// <param name="newValue"></param>
105+
protected virtual void OnItemTemplatePropertyChanged(DataTemplate oldValue, DataTemplate newValue)
106+
{
107+
if (newValue != oldValue)
108+
{
109+
ItemTemplateChanged(newValue);
110+
}
111+
}
112+
113+
#endregion
114+
115+
#region Private ToolbarItemList
116+
117+
/// <summary>
118+
/// Identifies the protected ToolbarItemList dependency property.
119+
/// </summary>
120+
public static readonly DependencyProperty ItemListProperty =
121+
DependencyProperty.Register(
122+
nameof(ItemList),
123+
typeof(ToolbarItemList),
124+
typeof(Toolbar),
125+
new PropertyMetadata(new ToolbarItemList(), (d, e) => ((Toolbar)d).OnItemListPropertyChanged((ToolbarItemList)e.OldValue, (ToolbarItemList)e.NewValue)));
126+
127+
128+
129+
/// <summary>
130+
/// Gets or sets the protected ToolbarItemList of the control.
131+
/// </summary>
132+
private ToolbarItemList ItemList
133+
{
134+
get { return (ToolbarItemList)GetValue(ItemListProperty); }
135+
set { SetValue(ItemListProperty, value); }
136+
}
137+
138+
139+
140+
private void OnItemListPropertyChanged(ToolbarItemList oldList, ToolbarItemList newList)
141+
{
142+
if (newList != oldList)
143+
{
144+
PrivateItemListChanged(newList);
145+
}
146+
}
147+
#endregion
148+
149+
#region Private ToolbarItemOverflowList
150+
151+
/// <summary>
152+
/// Identifies the protected ToolbarItemOverflowList dependency property.
153+
/// </summary>
154+
public static readonly DependencyProperty ItemOverflowListProperty =
155+
DependencyProperty.Register(
156+
nameof(ItemOverflowList),
157+
typeof(ToolbarItemOverflowList),
158+
typeof(Toolbar),
159+
new PropertyMetadata(new ToolbarItemOverflowList(), (d, e) => ((Toolbar)d).OnItemOverflowListPropertyChanged((ToolbarItemOverflowList)e.OldValue, (ToolbarItemOverflowList)e.NewValue)));
160+
161+
162+
163+
/// <summary>
164+
/// Gets or sets the protected ToolbarItemOverflowList of the control.
165+
/// </summary>
166+
private ToolbarItemOverflowList ItemOverflowList
167+
{
168+
get { return (ToolbarItemOverflowList)GetValue(ItemOverflowListProperty); }
169+
set { SetValue(ItemOverflowListProperty, value); }
170+
}
171+
172+
173+
174+
private void OnItemOverflowListPropertyChanged(ToolbarItemOverflowList oldList, ToolbarItemOverflowList newList)
175+
{
176+
if (newList != oldList)
177+
{
178+
PrivateItemOverflowListChanged(newList);
179+
}
180+
}
181+
#endregion
182+
}

0 commit comments

Comments
 (0)