Skip to content

A Swiss Army knife for developers.

Added UISelectDropDownListPresenter, UISettingGroupPresenter, UISettingPresenter, UISwitchPresenter

Etienne Baudouxfe1e4d5fe28b
diff --git a/src/app/dev/DevToys.Api/Tool/GUI/Components/IUIIcon.cs b/src/app/dev/DevToys.Api/Tool/GUI/Components/IUIIcon.cs
index abdf12e35..8aef559f1 100644
--- a/src/app/dev/DevToys.Api/Tool/GUI/Components/IUIIcon.cs
+++ b/src/app/dev/DevToys.Api/Tool/GUI/Components/IUIIcon.cs
@@ -13,7 +13,7 @@ public interface IUIIcon : IUIElement
/// <summary>
/// Gets the glyph corresponding to the icon in the <see cref="FontName"/>.
/// </summary>
- string Glyph { get; }
+ char Glyph { get; }
/// <summary>
/// Gets the size of the icon.
@@ -40,16 +40,15 @@ public interface IUIIcon : IUIElement
internal sealed class UIIcon : UIElement, IUIIcon
{
private string _fontName;
- private string _glyph;
+ private char _glyph;
private int _size = 16;
- internal UIIcon(string? id, string fontName, string glyph)
+ internal UIIcon(string? id, string fontName, char glyph)
: base(id)
{
_fontName = fontName;
_glyph = glyph;
Guard.IsNotNullOrWhiteSpace(FontName);
- Guard.IsNotNullOrWhiteSpace(Glyph);
}
public string FontName
@@ -62,14 +61,10 @@ internal sealed class UIIcon : UIElement, IUIIcon
}
}
- public string Glyph
+ public char Glyph
{
get => _glyph;
- internal set
- {
- Guard.IsNotNullOrWhiteSpace(value);
- SetPropertyValue(ref _glyph, value, GlyphChanged);
- }
+ internal set => SetPropertyValue(ref _glyph, value, GlyphChanged);
}
public int Size
@@ -90,7 +85,7 @@ public static partial class GUI
/// </summary>
/// <param name="fontName">The name of the font containing the icon.</param>
/// <param name="glyph">The glyph corresponding to the icon</param>
- public static IUIIcon Icon(string fontName, string glyph)
+ public static IUIIcon Icon(string fontName, char glyph)
{
return Icon(id: null, fontName, glyph);
}
@@ -101,7 +96,7 @@ public static partial class GUI
/// <param name="id">An optional unique identifier for this UI element.</param>
/// <param name="fontName">The name of the font containing the icon.</param>
/// <param name="glyph">The glyph corresponding to the icon</param>
- public static IUIIcon Icon(string? id, string fontName, string glyph)
+ public static IUIIcon Icon(string? id, string fontName, char glyph)
{
return new UIIcon(id, fontName, glyph);
}
@@ -118,7 +113,7 @@ public static partial class GUI
/// <summary>
/// Sets the <see cref="IUIIcon.FontName"/> of the icon.
/// </summary>
- public static IUIIcon Glyph(this IUIIcon element, string glyph)
+ public static IUIIcon Glyph(this IUIIcon element, char glyph)
{
((UIIcon)element).Glyph = glyph;
return element;
diff --git a/src/app/dev/DevToys.Api/Tool/GUI/Components/IUIDropDownList.cs b/src/app/dev/DevToys.Api/Tool/GUI/Components/IUISelectDropDownList.cs
similarity index 74%
rename from src/app/dev/DevToys.Api/Tool/GUI/Components/IUIDropDownList.cs
rename to src/app/dev/DevToys.Api/Tool/GUI/Components/IUISelectDropDownList.cs
index b07a3dcb1..fdd116581 100644
--- a/src/app/dev/DevToys.Api/Tool/GUI/Components/IUIDropDownList.cs
+++ b/src/app/dev/DevToys.Api/Tool/GUI/Components/IUISelectDropDownList.cs
@@ -3,7 +3,7 @@
/// <summary>
/// A component that represents a drop down list where the user can select one item in it.
/// </summary>
-public interface IUIDropDownList : IUITitledElement
+public interface IUISelectDropDownList : IUITitledElement
{
/// <summary>
/// Gets the list of items displayed in the drop down list.
@@ -32,12 +32,12 @@ public interface IUIDropDownList : IUITitledElement
}
[DebuggerDisplay($"Id = {{{nameof(Id)}}}, Title = {{{nameof(Title)}}}")]
-internal sealed class UIDropDownList : UITitledElement, IUIDropDownList
+internal sealed class UISelectDropDownList : UITitledElement, IUISelectDropDownList
{
private IUIDropDownListItem[]? _items;
private IUIDropDownListItem? _selectedItem;
- internal UIDropDownList(string? id)
+ internal UISelectDropDownList(string? id)
: base(id)
{
}
@@ -74,35 +74,35 @@ public static partial class GUI
/// <summary>
/// A component that represents a drop down list where the user can select one item in it.
/// </summary>
- public static IUIDropDownList DropDownList()
+ public static IUISelectDropDownList SelectDropDownList()
{
- return DropDownList(null);
+ return SelectDropDownList(null);
}
/// <summary>
/// A component that represents a drop down list where the user can select one item in it.
/// </summary>
/// <param name="id">An optional unique identifier for this UI element.</param>
- public static IUIDropDownList DropDownList(string? id)
+ public static IUISelectDropDownList SelectDropDownList(string? id)
{
- return new UIDropDownList(id);
+ return new UISelectDropDownList(id);
}
/// <summary>
- /// Sets the <see cref="IUIDropDownList.Items"/> of the drop down list.
+ /// Sets the <see cref="IUISelectDropDownList.Items"/> of the drop down list.
/// </summary>
- public static IUIDropDownList WithItems(this IUIDropDownList element, params IUIDropDownListItem[] items)
+ public static IUISelectDropDownList WithItems(this IUISelectDropDownList element, params IUIDropDownListItem[] items)
{
- ((UIDropDownList)element).Items = items;
+ ((UISelectDropDownList)element).Items = items;
return element;
}
/// <summary>
/// Sets the action to run when selecting an item in the drop down list.
/// </summary>
- public static IUIDropDownList OnItemSelected(this IUIDropDownList element, Func<IUIDropDownListItem?, ValueTask>? onItemSelectedAction)
+ public static IUISelectDropDownList OnItemSelected(this IUISelectDropDownList element, Func<IUIDropDownListItem?, ValueTask>? onItemSelectedAction)
{
- ((UIDropDownList)element).OnItemSelectedAction = onItemSelectedAction;
+ ((UISelectDropDownList)element).OnItemSelectedAction = onItemSelectedAction;
return element;
}
@@ -110,9 +110,9 @@ public static partial class GUI
/// Sets the <see cref="IUIDropDownListItem"/> that should be selected in the drop down list.
/// If <paramref name="item"/> is null or does not exist in the list, no item will be selected.
/// </summary>
- public static IUIDropDownList Select(this IUIDropDownList element, IUIDropDownListItem? item)
+ public static IUISelectDropDownList Select(this IUISelectDropDownList element, IUIDropDownListItem? item)
{
- var dropDownList = (UIDropDownList)element;
+ var dropDownList = (UISelectDropDownList)element;
if (item is not null && dropDownList.Items is not null && !dropDownList.Items.Contains(item))
{
dropDownList.SelectedItem = null;
@@ -129,9 +129,9 @@ public static partial class GUI
/// Sets the <see cref="IUIDropDownListItem"/> that should be selected in the drop down list, using its index in the list.
/// If <paramref name="index"/> smaller or greater than the amount of items in the list, no item will be selected.
/// </summary>
- public static IUIDropDownList Select(this IUIDropDownList element, int index)
+ public static IUISelectDropDownList Select(this IUISelectDropDownList element, int index)
{
- var dropDownList = (UIDropDownList)element;
+ var dropDownList = (UISelectDropDownList)element;
if (dropDownList.Items is null || index < 0 || index > dropDownList.Items.Length - 1)
{
diff --git a/src/app/dev/DevToys.Api/Tool/GUI/Components/IUISetting.cs b/src/app/dev/DevToys.Api/Tool/GUI/Components/IUISetting.cs
index 5fc30a7d5..633b87cea 100644
--- a/src/app/dev/DevToys.Api/Tool/GUI/Components/IUISetting.cs
+++ b/src/app/dev/DevToys.Api/Tool/GUI/Components/IUISetting.cs
@@ -102,7 +102,7 @@ public static partial class GUI
/// <summary>
/// Sets the <see cref="IUISetting.Icon"/> of the setting.
/// </summary>
- public static IUISetting Icon(this IUISetting element, string fontName, string glyph)
+ public static IUISetting Icon(this IUISetting element, string fontName, char glyph)
{
((UISetting)element).Icon = Icon(fontName, glyph);
return element;
@@ -153,7 +153,7 @@ public static partial class GUI
}
/// <summary>
- /// Sets a <see cref="IUIDropDownList"/> to <see cref="IUISetting.InteractiveElement"/> and automatically associate the
+ /// Sets a <see cref="IUISelectDropDownList"/> to <see cref="IUISetting.InteractiveElement"/> and automatically associate the
/// given <paramref name="settingDefinition"/> to the switch state.
/// </summary>
/// <param name="settingsProvider">The settings provider used for handling the given <paramref name="settingDefinition"/>.</param>
@@ -169,8 +169,8 @@ public static partial class GUI
var settingElement = (UISetting)element;
- IUIDropDownList dropDownList
- = DropDownList()
+ IUISelectDropDownList dropDownList
+ = SelectDropDownList()
.WithItems(dropDownListItems);
T currentSettingValue = settingsProvider.GetSetting(settingDefinition);
diff --git a/src/app/dev/DevToys.Api/Tool/GUI/Components/IUISettingGroup.cs b/src/app/dev/DevToys.Api/Tool/GUI/Components/IUISettingGroup.cs
index 684a948ab..b0254e662 100644
--- a/src/app/dev/DevToys.Api/Tool/GUI/Components/IUISettingGroup.cs
+++ b/src/app/dev/DevToys.Api/Tool/GUI/Components/IUISettingGroup.cs
@@ -73,7 +73,7 @@ public static partial class GUI
/// <summary>
/// Sets the <see cref="IUISettingGroup.Icon"/> of the setting.
/// </summary>
- public static IUISettingGroup Icon(this IUISettingGroup element, string fontName, string glyph)
+ public static IUISettingGroup Icon(this IUISettingGroup element, string fontName, char glyph)
{
((UISettingGroup)element).Icon = Icon(fontName, glyph);
return element;
@@ -101,7 +101,7 @@ public static partial class GUI
}
/// <summary>
- /// Sets a <see cref="IUIDropDownList"/> to <see cref="IUISetting.InteractiveElement"/> and automatically associate the
+ /// Sets a <see cref="IUISelectDropDownList"/> to <see cref="IUISetting.InteractiveElement"/> and automatically associate the
/// given <paramref name="settingDefinition"/> to the switch state.
/// </summary>
/// <param name="settingsProvider">The settings provider used for handling the given <paramref name="settingDefinition"/>.</param>
diff --git a/src/app/dev/DevToys.Api/Tool/GUI/Components/IUIStack.cs b/src/app/dev/DevToys.Api/Tool/GUI/Components/IUIStack.cs
index bd1071346..5bfc16688 100644
--- a/src/app/dev/DevToys.Api/Tool/GUI/Components/IUIStack.cs
+++ b/src/app/dev/DevToys.Api/Tool/GUI/Components/IUIStack.cs
@@ -7,10 +7,16 @@ public interface IUIStack : IUIElement
{
/// <summary>
/// Gets a value that indicates the dimension by which child elements are stacked.
- /// Default is horizontal.
+ /// Default is <see cref="UIOrientation.Horizontal"/>.
/// </summary>
UIOrientation Orientation { get; }
+ /// <summary>
+ /// Gets a value that indicates the space between stacked elements.
+ /// Default is <see cref="UISpacing.Small"/>.
+ /// </summary>
+ UISpacing Spacing { get; }
+
/// <summary>
/// Gets the list of child elements.
/// </summary>
@@ -21,6 +27,11 @@ public interface IUIStack : IUIElement
/// </summary>
public event EventHandler? OrientationChanged;
+ /// <summary>
+ /// Raised when <see cref="Spacing"/> is changed.
+ /// </summary>
+ public event EventHandler? SpacingChanged;
+
/// <summary>
/// Raised when <see cref="Children"/> is changed.
/// </summary>
@@ -30,7 +41,8 @@ public interface IUIStack : IUIElement
[DebuggerDisplay($"Id = {{{nameof(Id)}}}, Orientation = {{{nameof(Orientation)}}}")]
internal sealed class UIStack : UIElement, IUIStack
{
- private UIOrientation _orientation;
+ private UIOrientation _orientation = UIOrientation.Horizontal;
+ private UISpacing _spacing = UISpacing.Small;
private IUIElement[]? _children;
internal UIStack(string? id)
@@ -44,6 +56,12 @@ internal sealed class UIStack : UIElement, IUIStack
internal set => SetPropertyValue(ref _orientation, value, OrientationChanged);
}
+ public UISpacing Spacing
+ {
+ get => _spacing;
+ internal set => SetPropertyValue(ref _spacing, value, SpacingChanged);
+ }
+
public IUIElement[]? Children
{
get => _children;
@@ -52,6 +70,8 @@ internal sealed class UIStack : UIElement, IUIStack
public event EventHandler? OrientationChanged;
+ public event EventHandler? SpacingChanged;
+
public event EventHandler? ChildrenChanged;
}
@@ -100,4 +120,31 @@ public static partial class GUI
((UIStack)element).Children = children;
return element;
}
+
+ /// <summary>
+ /// Set a small spacing between children.
+ /// </summary>
+ public static IUIStack SmallSpacing(this IUIStack element)
+ {
+ ((UIStack)element).Spacing = UISpacing.Small;
+ return element;
+ }
+
+ /// <summary>
+ /// Set a medium spacing between children.
+ /// </summary>
+ public static IUIStack MediumSpacing(this IUIStack element)
+ {
+ ((UIStack)element).Spacing = UISpacing.Medium;
+ return element;
+ }
+
+ /// <summary>
+ /// Set a large spacing between children.
+ /// </summary>
+ public static IUIStack LargeSpacing(this IUIStack element)
+ {
+ ((UIStack)element).Spacing = UISpacing.Large;
+ return element;
+ }
}
diff --git a/src/app/dev/DevToys.Api/Tool/GUI/Components/IUIToolView.cs b/src/app/dev/DevToys.Api/Tool/GUI/Components/IUIToolView.cs
deleted file mode 100644
index b5c23d72e..000000000
--- a/src/app/dev/DevToys.Api/Tool/GUI/Components/IUIToolView.cs
+++ /dev/null
@@ -1,6 +0,0 @@
-namespace DevToys.Api.Tool.GUI.Components;
-
-public interface IUIToolView : IUIElement
-{
-
-}
diff --git a/src/app/dev/DevToys.Api/Tool/GUI/Components/UIOrientation.cs b/src/app/dev/DevToys.Api/Tool/GUI/Components/UIOrientation.cs
index d3cd90ef5..12d2f5eb5 100644
--- a/src/app/dev/DevToys.Api/Tool/GUI/Components/UIOrientation.cs
+++ b/src/app/dev/DevToys.Api/Tool/GUI/Components/UIOrientation.cs
@@ -8,10 +8,10 @@ public enum UIOrientation
/// <summary>
/// Element or layout should be horizontally oriented.
/// </summary>
- Horizontal,
+ Horizontal = 0,
/// <summary>
/// Element or layout should be vertically oriented.
/// </summary>
- Vertical
+ Vertical = 1
}
diff --git a/src/app/dev/DevToys.Api/Tool/GUI/Components/UISpacing.cs b/src/app/dev/DevToys.Api/Tool/GUI/Components/UISpacing.cs
new file mode 100644
index 000000000..24d375794
--- /dev/null
+++ b/src/app/dev/DevToys.Api/Tool/GUI/Components/UISpacing.cs
@@ -0,0 +1,22 @@
+namespace DevToys.Api;
+
+/// <summary>
+/// Defines the different spacing to apply between element in the layout.
+/// </summary>
+public enum UISpacing
+{
+ /// <summary>
+ /// A small space between element. Use this space between elements of a same group.
+ /// </summary>
+ Small = 0,
+
+ /// <summary>
+ /// A medium space between element. Use this space to separate groups of elements.
+ /// </summary>
+ Medium = 1,
+
+ /// <summary>
+ /// A large space between element. Use this space to separate sections.
+ /// </summary>
+ Large = 2
+}
diff --git a/src/app/dev/DevToys.Blazor/Assets/sass/theme/windows/dark.scss b/src/app/dev/DevToys.Blazor/Assets/sass/theme/windows/dark.scss
index 7c2d3ada3..e11ed8d9b 100644
--- a/src/app/dev/DevToys.Blazor/Assets/sass/theme/windows/dark.scss
+++ b/src/app/dev/DevToys.Blazor/Assets/sass/theme/windows/dark.scss
@@ -337,4 +337,7 @@
--info-bar-border: var(--card-stroke-color-default);
--info-bar-border-thickness: 1px;
--info-bar-border-corner-radius: var(--control-corner-radius);
+
+ /* UISettingGroup */
+ --ui-setting-group-presenter-inner-ui-setting-background-color: transparent;
}
diff --git a/src/app/dev/DevToys.Blazor/Components/BasicInput/Button/Button.razor b/src/app/dev/DevToys.Blazor/Components/BasicInput/Button/Button.razor
index 0e3521736..1501a592b 100644
--- a/src/app/dev/DevToys.Blazor/Components/BasicInput/Button/Button.razor
+++ b/src/app/dev/DevToys.Blazor/Components/BasicInput/Button/Button.razor
@@ -23,7 +23,8 @@
style="@(Style)"
tabindex="0"
@ref=Element
- @attributes="AdditionalAttributes">
+ @attributes="AdditionalAttributes"
+ @onclick:stopPropagation="@IsActuallyEnabled">
@ChildContent
</button>
</Container>
diff --git a/src/app/dev/DevToys.Blazor/Components/BasicInput/ToggleSwitch/ToggleSwitch.razor b/src/app/dev/DevToys.Blazor/Components/BasicInput/ToggleSwitch/ToggleSwitch.razor
index 64bf40f59..0b67ef1c6 100644
--- a/src/app/dev/DevToys.Blazor/Components/BasicInput/ToggleSwitch/ToggleSwitch.razor
+++ b/src/app/dev/DevToys.Blazor/Components/BasicInput/ToggleSwitch/ToggleSwitch.razor
@@ -30,7 +30,7 @@
tabindex="0"
class="toggle-switch @(FinalCssClasses)"
checked="@IsOn"
- disabled="@(!IsActuallyEnabled)"
+ disabled="@(!IsActuallyEnabled)"
@onclick:preventDefault="@(!IsActuallyEnabled)"
@onchange="OnChange"
@attributes="AdditionalAttributes" />
diff --git a/src/app/dev/DevToys.Blazor/Components/Layout/Expander/Expander.razor b/src/app/dev/DevToys.Blazor/Components/Layout/Expander/Expander.razor
index 5a35fc683..e386e730d 100644
--- a/src/app/dev/DevToys.Blazor/Components/Layout/Expander/Expander.razor
+++ b/src/app/dev/DevToys.Blazor/Components/Layout/Expander/Expander.razor
@@ -16,7 +16,7 @@
PaddingBottom="@PaddingBottom"
IsEnabled="@IsActuallyEnabled"
IsVisible="@IsVisible"
- Class="expander">
+ Class="@($"expander {FinalCssClasses}")">
<Card data-expanded="@IsExpanded.ToString().ToLower()"
aria-label="Toggle Expander"
aria-expanded="@IsExpanded.ToString()"
diff --git a/src/app/dev/DevToys.Blazor/Components/Layout/Expander/Expander.razor.scss b/src/app/dev/DevToys.Blazor/Components/Layout/Expander/Expander.razor.scss
index 3baec54f3..b46dbf2f9 100644
--- a/src/app/dev/DevToys.Blazor/Components/Layout/Expander/Expander.razor.scss
+++ b/src/app/dev/DevToys.Blazor/Components/Layout/Expander/Expander.razor.scss
@@ -49,8 +49,8 @@
@include transition(0ms linear 250ms max-height);
.expander-content {
- @include flex($direction: row, $align: center, $justify: between);
@include typography-body;
+ display: block;
min-height: 72px;
margin-top: 0;
border-radius: var(--control-corner-radius);
diff --git a/src/app/dev/DevToys.Blazor/Components/Layout/StackPanel/StackPanel.razor.cs b/src/app/dev/DevToys.Blazor/Components/Layout/StackPanel/StackPanel.razor.cs
index 45a46d630..117274533 100644
--- a/src/app/dev/DevToys.Blazor/Components/Layout/StackPanel/StackPanel.razor.cs
+++ b/src/app/dev/DevToys.Blazor/Components/Layout/StackPanel/StackPanel.razor.cs
@@ -8,8 +8,8 @@ public partial class StackPanel : StyledComponentBase
.Build();
protected string? StyleValue => new StyleBuilder()
- .AddStyle("column-gap", HorizontalGap.ToPx(), () => HorizontalGap.HasValue)
- .AddStyle("row-gap", VerticalGap.ToPx(), () => VerticalGap.HasValue)
+ .AddStyle("column-gap", Spacing.ToPx())
+ .AddStyle("row-gap", Spacing.ToPx())
.AddStyle("flex-wrap", "wrap", () => Wrap)
.AddStyle(Style)
.Build();
@@ -27,16 +27,10 @@ public partial class StackPanel : StyledComponentBase
public bool Wrap { get; set; } = false;
/// <summary>
- /// Gets or sets the gap between horizontally stacked components (in pixels).
+ /// Gets or sets the space between stacked components (in pixels).
/// </summary>
[Parameter]
- public int? HorizontalGap { get; set; } = 4;
-
- /// <summary>
- /// Gets or sets the gap between vertically stacked components (in pixels).
- /// </summary>
- [Parameter]
- public int? VerticalGap { get; set; } = 4;
+ public int Spacing { get; set; } = 4;
/// <summary>
/// Gets or sets the content to be rendered inside the component.
diff --git a/src/app/dev/DevToys.Blazor/Components/UIElements/UIElementPresenter.razor b/src/app/dev/DevToys.Blazor/Components/UIElements/UIElementPresenter.razor
index 70420667d..21800d772 100644
--- a/src/app/dev/DevToys.Blazor/Components/UIElements/UIElementPresenter.razor
+++ b/src/app/dev/DevToys.Blazor/Components/UIElements/UIElementPresenter.razor
@@ -14,6 +14,22 @@
<UIButtonPresenter UIButton="@button" />
break;
+ case IUISettingGroup settingGroup:
+ <UISettingGroupPresenter UISettingGroup="@settingGroup" />
+ break;
+
+ case IUISetting setting:
+ <UISettingPresenter UISetting="@setting" />
+ break;
+
+ case IUISwitch @switch:
+ <UISwitchPresenter UISwitch="@(@switch)" />
+ break;
+
+ case IUISelectDropDownList selectDropDownList:
+ <UISelectDropDownListPresenter UISelectDropDownList="@selectDropDownList" />
+ break;
+
default:
throw new NotSupportedException($"Gui Tool component of type '{UIElement.GetType().FullName}' isn't supported.");
}
diff --git a/src/app/dev/DevToys.Blazor/Components/UIElements/UIElementPresenter.razor.cs b/src/app/dev/DevToys.Blazor/Components/UIElements/UIElementPresenter.razor.cs
index 514448a25..acf849ad0 100644
--- a/src/app/dev/DevToys.Blazor/Components/UIElements/UIElementPresenter.razor.cs
+++ b/src/app/dev/DevToys.Blazor/Components/UIElements/UIElementPresenter.razor.cs
@@ -26,5 +26,6 @@ public partial class UIElementPresenter : ComponentBase, IDisposable
{
Guard.IsAssignableToType<INotifyPropertyChanged>(UIElement);
((INotifyPropertyChanged)UIElement).PropertyChanged -= UIElementPresenter_PropertyChanged;
+ GC.SuppressFinalize(this);
}
}
diff --git a/src/app/dev/DevToys.Blazor/Components/UIElements/UISelectDropDownListPresenter.razor b/src/app/dev/DevToys.Blazor/Components/UIElements/UISelectDropDownListPresenter.razor
new file mode 100644
index 000000000..f92002a90
--- /dev/null
+++ b/src/app/dev/DevToys.Blazor/Components/UIElements/UISelectDropDownListPresenter.razor
@@ -0,0 +1,17 @@
+@namespace DevToys.Blazor.Components.UIElements
+@using DevToys.Api;
+@inherits ComponentBase
+
+<ComboBox id="@UISelectDropDownList.Id"
+ IsVisible="@UISelectDropDownList.IsVisible"
+ IsEnabled="@UISelectDropDownList.IsEnabled"
+ HorizontalAlignment="@UISelectDropDownList.HorizontalAlignment"
+ VerticalAlignment="@UISelectDropDownList.VerticalAlignment"
+ Header="@UISelectDropDownList.Title"
+ @bind-SelectedIndex="@SelectedIndex"
+ Items="@UISelectDropDownList.Items"
+ Context="item">
+ <ItemTemplate>
+ <TextBlock Text="@item.Text"/>
+ </ItemTemplate>
+</ComboBox>
\ No newline at end of file
diff --git a/src/app/dev/DevToys.Blazor/Components/UIElements/UISelectDropDownListPresenter.razor.cs b/src/app/dev/DevToys.Blazor/Components/UIElements/UISelectDropDownListPresenter.razor.cs
new file mode 100644
index 000000000..565d9e1a0
--- /dev/null
+++ b/src/app/dev/DevToys.Blazor/Components/UIElements/UISelectDropDownListPresenter.razor.cs
@@ -0,0 +1,47 @@
+namespace DevToys.Blazor.Components.UIElements;
+
+public partial class UISelectDropDownListPresenter : ComponentBase, IDisposable
+{
+ private int _selectedIndex = -1;
+
+ [Parameter]
+ public IUISelectDropDownList UISelectDropDownList { get; set; } = default!;
+
+ [Parameter]
+ public int SelectedIndex { get; set; }
+
+ protected override void OnInitialized()
+ {
+ base.OnInitialized();
+ UISelectDropDownList.SelectedItemChanged += UISelectDropDownList_SelectedItemChanged;
+ }
+
+ protected override void OnParametersSet()
+ {
+ base.OnParametersSet();
+ if (_selectedIndex != SelectedIndex)
+ {
+ _selectedIndex = SelectedIndex;
+ UISelectDropDownList.Select(SelectedIndex);
+ }
+ }
+
+ private void UISelectDropDownList_SelectedItemChanged(object? sender, EventArgs e)
+ {
+ if (UISelectDropDownList.Items is not null && UISelectDropDownList.SelectedItem is not null)
+ {
+ SelectedIndex = Array.IndexOf(UISelectDropDownList.Items, UISelectDropDownList.SelectedItem);
+ }
+ else
+ {
+ SelectedIndex = -1;
+ UISelectDropDownList.Select(-1);
+ }
+ }
+
+ public void Dispose()
+ {
+ UISelectDropDownList.SelectedItemChanged -= UISelectDropDownList_SelectedItemChanged;
+ GC.SuppressFinalize(this);
+ }
+}
diff --git a/src/app/dev/DevToys.Blazor/Components/UIElements/UISettingGroupPresenter.razor b/src/app/dev/DevToys.Blazor/Components/UIElements/UISettingGroupPresenter.razor
new file mode 100644
index 000000000..8276e15ef
--- /dev/null
+++ b/src/app/dev/DevToys.Blazor/Components/UIElements/UISettingGroupPresenter.razor
@@ -0,0 +1,34 @@
+@namespace DevToys.Blazor.Components.UIElements
+@using DevToys.Api;
+@inherits ComponentBase
+
+<Expander id="@UISettingGroup.Id"
+ Class="ui-setting-group-presenter"
+ IsVisible="@UISettingGroup.IsVisible"
+ IsEnabled="@UISettingGroup.IsEnabled"
+ HorizontalAlignment="@UISettingGroup.HorizontalAlignment"
+ VerticalAlignment="@UISettingGroup.VerticalAlignment"
+ Title="@UISettingGroup.Title"
+ Description="@UISettingGroup.Description"
+ IconGlyph="@(UISettingGroup.Icon?.Glyph ?? '\0')"
+ IconFontFamily="@UISettingGroup.Icon?.FontName">
+ <Control>
+ @if (UISettingGroup.InteractiveElement is not null)
+ {
+ <UIElementPresenter UIElement="@UISettingGroup.InteractiveElement" />
+ }
+ </Control>
+ <ChildContent>
+ <StackPanel Orientation="UIOrientation.Vertical"
+ HorizontalAlignment="UIHorizontalAlignment.Stretch"
+ Style="@(UISettingGroup.ChildrenAreAllSettings ? "row-gap: 0px !important" : string.Empty)">
+ @if (UISettingGroup.Children is not null)
+ {
+ for (int i = 0; i < UISettingGroup.Children.Length; i++)
+ {
+ <UIElementPresenter UIElement="@UISettingGroup.Children[i]" />
+ }
+ }
+ </StackPanel>
+ </ChildContent>
+</Expander>
\ No newline at end of file
diff --git a/src/app/dev/DevToys.Blazor/Components/UIElements/UISettingGroupPresenter.razor.cs b/src/app/dev/DevToys.Blazor/Components/UIElements/UISettingGroupPresenter.razor.cs
new file mode 100644
index 000000000..939c53ab9
--- /dev/null
+++ b/src/app/dev/DevToys.Blazor/Components/UIElements/UISettingGroupPresenter.razor.cs
@@ -0,0 +1,7 @@
+namespace DevToys.Blazor.Components.UIElements;
+
+public partial class UISettingGroupPresenter : ComponentBase
+{
+ [Parameter]
+ public IUISettingGroup UISettingGroup { get; set; } = default!;
+}
diff --git a/src/app/dev/DevToys.Blazor/Components/UIElements/UISettingGroupPresenter.razor.scss b/src/app/dev/DevToys.Blazor/Components/UIElements/UISettingGroupPresenter.razor.scss
new file mode 100644
index 000000000..de761848f
--- /dev/null
+++ b/src/app/dev/DevToys.Blazor/Components/UIElements/UISettingGroupPresenter.razor.scss
@@ -0,0 +1,5 @@
+.ui-setting-group-presenter {
+ .ui-setting-presenter {
+ background-color: var(--ui-setting-group-presenter-inner-ui-setting-background-color);
+ }
+}
diff --git a/src/app/dev/DevToys.Blazor/Components/UIElements/UISettingPresenter.razor b/src/app/dev/DevToys.Blazor/Components/UIElements/UISettingPresenter.razor
new file mode 100644
index 000000000..9fe3b730f
--- /dev/null
+++ b/src/app/dev/DevToys.Blazor/Components/UIElements/UISettingPresenter.razor
@@ -0,0 +1,21 @@
+@namespace DevToys.Blazor.Components.UIElements
+@using DevToys.Api;
+@inherits ComponentBase
+
+<Card id="@UISetting.Id"
+ Class="ui-setting-presenter"
+ IsVisible="@UISetting.IsVisible"
+ IsEnabled="@UISetting.IsEnabled"
+ HorizontalAlignment="@UISetting.HorizontalAlignment"
+ VerticalAlignment="@UISetting.VerticalAlignment"
+ Title="@UISetting.Title"
+ Description="@UISetting.Description"
+ IconGlyph="@(UISetting.Icon?.Glyph ?? '\0')"
+ IconFontFamily="@UISetting.Icon?.FontName">
+ <Control>
+ @if (UISetting.InteractiveElement is not null)
+ {
+ <UIElementPresenter UIElement="@UISetting.InteractiveElement" />
+ }
+ </Control>
+</Card>
\ No newline at end of file
diff --git a/src/app/dev/DevToys.Blazor/Components/UIElements/UISettingPresenter.razor.cs b/src/app/dev/DevToys.Blazor/Components/UIElements/UISettingPresenter.razor.cs
new file mode 100644
index 000000000..b51e929f5
--- /dev/null
+++ b/src/app/dev/DevToys.Blazor/Components/UIElements/UISettingPresenter.razor.cs
@@ -0,0 +1,7 @@
+namespace DevToys.Blazor.Components.UIElements;
+
+public partial class UISettingPresenter : ComponentBase
+{
+ [Parameter]
+ public IUISetting UISetting { get; set; } = default!;
+}
diff --git a/src/app/dev/DevToys.Blazor/Components/UIElements/UIStackPresenter.razor b/src/app/dev/DevToys.Blazor/Components/UIElements/UIStackPresenter.razor
index a6119eff4..7f2cadc04 100644
--- a/src/app/dev/DevToys.Blazor/Components/UIElements/UIStackPresenter.razor
+++ b/src/app/dev/DevToys.Blazor/Components/UIElements/UIStackPresenter.razor
@@ -7,7 +7,8 @@
IsEnabled="@UIStack.IsEnabled"
HorizontalAlignment="@UIStack.HorizontalAlignment"
VerticalAlignment="@UIStack.VerticalAlignment"
- Orientation="@UIStack.Orientation">
+ Orientation="@UIStack.Orientation"
+ Spacing="@(UIStack.Spacing == UISpacing.Small ? 4 : (UIStack.Spacing == UISpacing.Medium ? 8 : 12))">
@if (UIStack.Children is not null)
{
for (int i = 0; i < UIStack.Children.Length; i++)
diff --git a/src/app/dev/DevToys.Blazor/Components/UIElements/UISwitchPresenter.razor b/src/app/dev/DevToys.Blazor/Components/UIElements/UISwitchPresenter.razor
new file mode 100644
index 000000000..61e4e8d57
--- /dev/null
+++ b/src/app/dev/DevToys.Blazor/Components/UIElements/UISwitchPresenter.razor
@@ -0,0 +1,13 @@
+@namespace DevToys.Blazor.Components.UIElements
+@using DevToys.Api;
+@inherits ComponentBase
+
+<!-- TODO: Localize -->
+<ToggleSwitch id="@UISwitch.Id"
+ IsVisible="@UISwitch.IsVisible"
+ IsEnabled="@UISwitch.IsEnabled"
+ HorizontalAlignment="@UISwitch.HorizontalAlignment"
+ VerticalAlignment="@UISwitch.VerticalAlignment"
+ Text="@(UISwitch.IsOn ? (UISwitch.OnText ?? "On") : (UISwitch.OffText ?? "Off"))"
+ IsOn="@UISwitch.IsOn"
+ OnCheckedChanged="@OnCheckedChanged"/>
\ No newline at end of file
diff --git a/src/app/dev/DevToys.Blazor/Components/UIElements/UISwitchPresenter.razor.cs b/src/app/dev/DevToys.Blazor/Components/UIElements/UISwitchPresenter.razor.cs
new file mode 100644
index 000000000..ed2a31f6d
--- /dev/null
+++ b/src/app/dev/DevToys.Blazor/Components/UIElements/UISwitchPresenter.razor.cs
@@ -0,0 +1,19 @@
+namespace DevToys.Blazor.Components.UIElements;
+
+public partial class UISwitchPresenter : ComponentBase
+{
+ [Parameter]
+ public IUISwitch UISwitch { get; set; } = default!;
+
+ private void OnCheckedChanged(bool value)
+ {
+ if (value)
+ {
+ UISwitch.On();
+ }
+ else
+ {
+ UISwitch.Off();
+ }
+ }
+}
diff --git a/src/app/dev/DevToys.Tools/Tools/Settings/SettingsGuiTool.cs b/src/app/dev/DevToys.Tools/Tools/Settings/SettingsGuiTool.cs
index 7a17951fb..7f9012f07 100644
--- a/src/app/dev/DevToys.Tools/Tools/Settings/SettingsGuiTool.cs
+++ b/src/app/dev/DevToys.Tools/Tools/Settings/SettingsGuiTool.cs
@@ -50,7 +50,7 @@ internal sealed class SettingsGuiTool : IGuiTool
.Vertical()
.WithChildren(
SettingGroup()
- .Icon("FluentSystemIcons", "\uF6A9")
+ .Icon("FluentSystemIcons", '\uF6A9')
.Title("Title")
.Description("Description")
.Handle(
@@ -89,8 +89,8 @@ internal sealed class SettingsGuiTool : IGuiTool
.WithChildren(
Button().Text("Bottom Left button"),
Button().Text("Bottom Center button").OnClick(OnBottomCenterButtonClickAsync),
- Button().Text("Bottom Right button")),
- SingleLineTextInput().CanCopyWhenEditable());
+ Button().Text("Bottom Right button"))//,
+ /*SingleLineTextInput().CanCopyWhenEditable()*/);
public void OnDataReceived(string dataTypeName, object? parsedData)
{