A Swiss Army knife for developers.
C# blazorcross-platformcsharpdesktopdesktop-appdesktop-applicationdeveloper-toolsextensiblefluentfluent-designlinuxmacosmicasyntax-highlightingtypescriptwindowswindows-10windows-11winui
Tool's UI dynamically created in WASDK
Etienne Baudoux226d25265421
diff --git a/src/app/dev/DevToys.Api/Tool/GUI/Components/IUIButton.cs b/src/app/dev/DevToys.Api/Tool/GUI/Components/IUIButton.csnew file mode 100644index 000000000..58ba08388--- /dev/null+++ b/src/app/dev/DevToys.Api/Tool/GUI/Components/IUIButton.cs@@ -0,0 +1,85 @@+namespace DevToys.Api;++/// <summary>+/// A component that represents a button, which reacts when clicking on it.+/// </summary>+public interface IUIButton : IUIElement+{+ /// <summary>+ /// Gets the text to display in the button.+ /// </summary>+ string? DisplayText { get; }++ /// <summary>+ /// Gets the action to run when the user clicks the button.+ /// </summary>+ Func<ValueTask>? OnClickAction { get; }++ /// <summary>+ /// Raised when <see cref="DisplayTextChanged"/> is changed.+ /// </summary>+ public event EventHandler? DisplayTextChanged;+}++[DebuggerDisplay($"Id = {{{nameof(Id)}}}, Text = {{{nameof(DisplayText)}}}")]+internal class UIButton : UIElement, IUIButton+{+ private string? _text;++ internal UIButton(string? id)+ : base(id)+ {+ }++ public string? DisplayText+ {+ get => _text;+ internal set+ {+ _text = value;+ DisplayTextChanged?.Invoke(this, EventArgs.Empty);+ }+ }++ public Func<ValueTask>? OnClickAction { get; internal set; }++ public event EventHandler? DisplayTextChanged;+}++public static partial class GUI+{+ /// <summary>+ /// Create component that represents a button, which reacts when clicking on it.+ /// </summary>+ public static IUIButton Button()+ {+ return Button(null);+ }++ /// <summary>+ /// Create component that represents a button, which reacts when clicking on it.+ /// </summary>+ /// <param name="id">An optional unique identifier for this UI element.</param>+ public static IUIButton Button(string? id)+ {+ return new UIButton(id);+ }++ /// <summary>+ /// Sets the <see cref="IUIButton.DisplayText"/> of the button.+ /// </summary>+ public static IUIButton Text(this IUIButton element, string? text)+ {+ ((UIButton)element).DisplayText = text;+ return element;+ }++ /// <summary>+ /// Sets the action to run when clicking on the button.+ /// </summary>+ public static IUIButton OnClick(this IUIButton element, Func<ValueTask>? actionOnClick)+ {+ ((UIButton)element).OnClickAction = actionOnClick;+ return element;+ }+}diff --git a/src/app/dev/DevToys.Api/Tool/GUI/Components/IUIElement.cs b/src/app/dev/DevToys.Api/Tool/GUI/Components/IUIElement.csnew file mode 100644index 000000000..654eddea9--- /dev/null+++ b/src/app/dev/DevToys.Api/Tool/GUI/Components/IUIElement.cs@@ -0,0 +1,122 @@+namespace DevToys.Api;++/// <summary>+/// A base interface for all UI elements.+/// </summary>+public interface IUIElement+{+ /// <summary>+ /// An optional unique identifier for this UI element.+ /// This Id can be helpful to identify some behavior related to a component in the logs of the app.+ /// </summary>+ string? Id { get; }++ /// <summary>+ /// Gets whether this element should be visible or hidden in the UI.+ /// </summary>+ bool IsVisible { get; }++ /// <summary>+ /// Gets whether this element and its children should be enabled or disabled.+ /// </summary>+ bool IsEnabled { get; }++ /// <summary>+ /// Raised when <see cref="IsVisible"/> is changed.+ /// </summary>+ event EventHandler? IsVisibleChanged;++ /// <summary>+ /// Raised when <see cref="IsEnabled"/> is changed.+ /// </summary>+ event EventHandler? IsEnabledChanged;+}++[DebuggerDisplay($"Id = {{{nameof(Id)}}}, IsVisible = {{{nameof(IsVisible)}}}, IsEnabled = {{{nameof(IsEnabled)}}}")]+internal abstract class UIElement : IUIElement+{+ private bool _isVisible = true;+ private bool _isEnabled = true;++ protected UIElement(string? id)+ {+ Id = id;+ }++ public string? Id { get; }++ public bool IsVisible+ {+ get => _isVisible;+ internal set+ {+ _isVisible = value;+ IsVisibleChanged?.Invoke(this, EventArgs.Empty);+ }+ }++ public bool IsEnabled+ {+ get => _isEnabled;+ internal set+ {+ _isEnabled = value;+ IsEnabledChanged?.Invoke(this, EventArgs.Empty);+ }+ }++ public event EventHandler? IsVisibleChanged;++ public event EventHandler? IsEnabledChanged;+}++public static partial class GUI+{+ /// <summary>+ /// Hides the element.+ /// </summary>+ public static T Hide<T>(this T element) where T : IUIElement+ {+ if (element is UIElement strongElement)+ {+ strongElement.IsVisible = false;+ }+ return element;+ }++ /// <summary>+ /// Shows the element.+ /// </summary>+ public static T Show<T>(this T element) where T : IUIElement+ {+ if (element is UIElement strongElement)+ {+ strongElement.IsVisible = true;+ }+ return element;+ }++ /// <summary>+ /// Disable the element and its child elements.+ /// </summary>+ public static T Disable<T>(this T element) where T : IUIElement+ {+ if (element is UIElement strongElement)+ {+ strongElement.IsEnabled = false;+ }+ return element;+ }++ /// <summary>+ /// Enable the element and its child elements.+ /// </summary>+ public static T Enable<T>(this T element) where T : IUIElement+ {+ if (element is UIElement strongElement)+ {+ strongElement.IsEnabled = true;+ }+ return element;+ }+}diff --git a/src/app/dev/DevToys.Api/Tool/GUI/Components/IUIStack.cs b/src/app/dev/DevToys.Api/Tool/GUI/Components/IUIStack.csnew file mode 100644index 000000000..8151a1875--- /dev/null+++ b/src/app/dev/DevToys.Api/Tool/GUI/Components/IUIStack.cs@@ -0,0 +1,111 @@+namespace DevToys.Api;++/// <summary>+/// A component that stacks child elements into a single line that can be oriented horizontally or vertically.+/// </summary>+public interface IUIStack : IUIElement+{+ /// <summary>+ /// Gets a value that indicates the dimension by which child elements are stacked.+ /// Default is horizontal.+ /// </summary>+ UIOrientation Orientation { get; }++ /// <summary>+ /// Gets the list of child elements.+ /// </summary>+ IUIElement[]? Children { get; }++ /// <summary>+ /// Raised when <see cref="Orientation"/> is changed.+ /// </summary>+ public event EventHandler? OrientationChanged;++ /// <summary>+ /// Raised when <see cref="Children"/> is changed.+ /// </summary>+ public event EventHandler? ChildrenChanged;+}++[DebuggerDisplay($"Id = {{{nameof(Id)}}}, Orientation = {{{nameof(Orientation)}}}")]+internal class UIStack : UIElement, IUIStack+{+ private UIOrientation _orientation;+ private IUIElement[]? _children;++ internal UIStack(string? id)+ : base(id)+ {+ }++ public UIOrientation Orientation+ {+ get => _orientation;+ internal set+ {+ _orientation = value;+ OrientationChanged?.Invoke(this, EventArgs.Empty);+ }+ }++ public IUIElement[]? Children+ {+ get => _children;+ internal set+ {+ _children = value;+ ChildrenChanged?.Invoke(this, EventArgs.Empty);+ }+ }++ public event EventHandler? OrientationChanged;++ public event EventHandler? ChildrenChanged;+}++public static partial class GUI+{+ /// <summary>+ /// Create a component that stacks child elements into a single line that can be oriented horizontally or vertically.+ /// </summary>+ public static IUIStack Stack()+ {+ return Stack(null);+ }++ /// <summary>+ /// Create a component that stacks child elements into a single line that can be oriented horizontally or vertically.+ /// </summary>+ /// <param name="id">An optional unique identifier for this UI element.</param>+ public static IUIStack Stack(string? id)+ {+ return new UIStack(id);+ }++ /// <summary>+ /// Organize the <see cref="IUIStack.Children"/> vertically.+ /// </summary>+ public static IUIStack Vertical(this IUIStack element)+ {+ ((UIStack)element).Orientation = UIOrientation.Vertical;+ return element;+ }++ /// <summary>+ /// Organize the <see cref="IUIStack.Children"/> horizontally.+ /// </summary>+ public static IUIStack Horizontal(this IUIStack element)+ {+ ((UIStack)element).Orientation = UIOrientation.Horizontal;+ return element;+ }++ /// <summary>+ /// Set the children to be displayed in the stack.+ /// </summary>+ public static IUIStack WithChildren(this IUIStack element, params IUIElement[] children)+ {+ ((UIStack)element).Children = children;+ return element;+ }+}diff --git a/src/app/dev/DevToys.Api/Tool/GUI/Components/IUITextInput.cs b/src/app/dev/DevToys.Api/Tool/GUI/Components/IUITextInput.csnew file mode 100644index 000000000..21ed2d50e--- /dev/null+++ b/src/app/dev/DevToys.Api/Tool/GUI/Components/IUITextInput.cs@@ -0,0 +1,22 @@+namespace DevToys.Api;++/// <summary>+/// A component that can be used to display or edit unformatted text.+/// </summary>+public interface IUITextInput : IUITitledElement+{+ /// <summary>+ /// Gets whether the user can edit the text or not.+ /// </summary>+ bool IsReadOnly { get; }++ /// <summary>+ /// Gets the text displayed or typed by the user.+ /// </summary>+ bool Text { get; }++ /// <summary>+ /// Raised when <see cref="Text"/> is changed.+ /// </summary>+ event EventHandler? TextChanged;+}diff --git a/src/app/dev/DevToys.Api/Tool/GUI/Components/IUITitledElement.cs b/src/app/dev/DevToys.Api/Tool/GUI/Components/IUITitledElement.csnew file mode 100644index 000000000..e0f37cd07--- /dev/null+++ b/src/app/dev/DevToys.Api/Tool/GUI/Components/IUITitledElement.cs@@ -0,0 +1,55 @@+namespace DevToys.Api;++/// <summary>+/// A base interface for all UI elements that can have a title / header on top of the element.+/// </summary>+public interface IUITitledElement : IUIElement+{+ /// <summary>+ /// Gets a title to display for this element.+ /// </summary>+ string? DisplayTitle { get; }++ /// <summary>+ /// Raised when <see cref="DisplayTitle"/> is changed.+ /// </summary>+ event EventHandler? DisplayTitleChanged;+}++[DebuggerDisplay($"Id = {{{nameof(Id)}}}, Title = {{{nameof(DisplayTitle)}}}")]+internal abstract class UITitledElement : UIElement, IUITitledElement+{+ private string? _title;++ protected UITitledElement(string? id)+ : base(id)+ {+ }++ public string? DisplayTitle+ {+ get => _title;+ internal set+ {+ _title = value;+ DisplayTitleChanged?.Invoke(this, EventArgs.Empty);+ }+ }++ public event EventHandler? DisplayTitleChanged;+}++public static partial class GUI+{+ /// <summary>+ /// Set the title of the element.+ /// </summary>+ public static T Title<T>(this T element, string? title) where T : IUITitledElement+ {+ if (element is UITitledElement strongElement)+ {+ strongElement.DisplayTitle = title;+ }+ return element;+ }+}diff --git a/src/app/dev/DevToys.Api/Tool/GUI/Components/UIOrientation.cs b/src/app/dev/DevToys.Api/Tool/GUI/Components/UIOrientation.csnew file mode 100644index 000000000..9eb0eadc7--- /dev/null+++ b/src/app/dev/DevToys.Api/Tool/GUI/Components/UIOrientation.cs@@ -0,0 +1,17 @@+namespace DevToys.Api;++/// <summary>+/// Defines the different orientations that a control or layout can have.+/// </summary>+public enum UIOrientation+{+ /// <summary>+ /// Control or layout should be horizontally oriented.+ /// </summary>+ Horizontal,++ /// <summary>+ /// Control or layout should be vertically oriented.+ /// </summary>+ Vertical+}diff --git a/src/app/dev/DevToys.Api/Tool/GUI/IGuiTool.cs b/src/app/dev/DevToys.Api/Tool/GUI/IGuiTool.csindex 50e2e82c2..2cdea7a4c 100644--- a/src/app/dev/DevToys.Api/Tool/GUI/IGuiTool.cs+++ b/src/app/dev/DevToys.Api/Tool/GUI/IGuiTool.cs@@ -47,5 +47,5 @@ public interface IGuiTool/// <summary>/// Gets the view for the tool./// </summary>- UIElement View { get; }+ IUIElement View { get; }}diff --git a/src/app/dev/DevToys.Api/Tool/GUI/Models/UIBase.cs b/src/app/dev/DevToys.Api/Tool/GUI/Models/UIBase.csdeleted file mode 100644index b99cc4bdf..000000000--- a/src/app/dev/DevToys.Api/Tool/GUI/Models/UIBase.cs+++ /dev/null@@ -1,22 +0,0 @@-namespace DevToys.Api;--/// <summary>-/// The base for all UI components.-/// </summary>-[DebuggerDisplay($"Id = {{{nameof(Id)}}}")]-public abstract class UIBase-{- /// <summary>- /// Creates a new instance of <see cref="AbstractUIBase"/>.- /// </summary>- /// <param name="id"><inheritdoc cref="Id"/></param>- protected UIBase(string id)- {- Id = id;- }-- /// <summary>- /// An identifier for this component.- /// </summary>- public string Id { get; }-}diff --git a/src/app/dev/DevToys.Api/Tool/GUI/Models/UIElement.cs b/src/app/dev/DevToys.Api/Tool/GUI/Models/UIElement.csdeleted file mode 100644index 0542a3326..000000000--- a/src/app/dev/DevToys.Api/Tool/GUI/Models/UIElement.cs+++ /dev/null@@ -1,56 +0,0 @@-namespace DevToys.Api;--/// <summary>-/// A base class for all UI elements.-/// </summary>-[DebuggerDisplay($"Id = {{{nameof(Id)}}}, IsVisible = {{{nameof(IsVisible)}}}, IsEnabled = {{{nameof(IsEnabled)}}}")]-public abstract class UIElement : UIBase-{- private bool _isVisible;- private bool _isEnabled;-- /// <summary>- /// Creates a new instance of a <see cref="UIElement"/>.- /// </summary>- /// <param name="id"><inheritdoc cref="Id"/></param>- protected UIElement(string id)- : base(id)- {- }-- /// <summary>- /// Gets or sets whether this element should be visible or hidden in the UI.- /// </summary>- public bool IsVisible- {- get => _isVisible;- set- {- _isVisible = value;- IsVisibleChanged?.Invoke(this, _isVisible);- }- }-- /// <summary>- /// Gets or sets whether this element and its children should be enabled or disabled.- /// </summary>- public bool IsEnabled- {- get => _isEnabled;- set- {- _isEnabled = value;- IsEnabledChanged?.Invoke(this, _isEnabled);- }- }-- /// <summary>- /// Raised when <see cref="IsVisible"/> is changed.- /// </summary>- public event EventHandler<bool>? IsVisibleChanged;-- /// <summary>- /// Raised when <see cref="IsEnabled"/> is changed.- /// </summary>- public event EventHandler<bool>? IsEnabledChanged;-}diff --git a/src/app/dev/DevToys.Api/Tool/GUI/Models/UITitledElement.cs b/src/app/dev/DevToys.Api/Tool/GUI/Models/UITitledElement.csdeleted file mode 100644index f6438791e..000000000--- a/src/app/dev/DevToys.Api/Tool/GUI/Models/UITitledElement.cs+++ /dev/null@@ -1,37 +0,0 @@-namespace DevToys.Api;--/// <summary>-/// A base class for all UI elements that can have a title / header on top of the element.-/// </summary>-[DebuggerDisplay($"Id = {{{nameof(Id)}}}, Title = {{{nameof(Title)}}}")]-public abstract class UITitledElement : UIElement-{- private string? _title;-- /// <summary>- /// Creates a new instance of a <see cref="UITitledElement"/>.- /// </summary>- /// <param name="id"><inheritdoc cref="Id"/></param>- protected UITitledElement(string id)- : base(id)- {- }-- /// <summary>- /// Gets or sets a title to display for this element.- /// </summary>- public string? Title- {- get => _title;- set- {- _title = value;- TitleChanged?.Invoke(this, _title);- }- }-- /// <summary>- /// Raised when <see cref="Title"/> is changed.- /// </summary>- public event EventHandler<string?>? TitleChanged;-}diff --git a/src/app/dev/DevToys.Core/Tools/GuiToolInstance.cs b/src/app/dev/DevToys.Core/Tools/GuiToolInstance.csindex 0621f39f1..022e87c26 100644--- a/src/app/dev/DevToys.Core/Tools/GuiToolInstance.cs+++ b/src/app/dev/DevToys.Core/Tools/GuiToolInstance.cs@@ -13,6 +13,7 @@ public sealed partial class GuiToolInstanceprivate readonly ILogger _logger;private readonly Lazy<IGuiTool, GuiToolMetadata> _guiToolDefinition;private readonly Lazy<IGuiTool> _instance;+ private readonly Lazy<IUIElement> _view;private readonly Lazy<ResourceManager?> _resourceManager;private readonly Lazy<string> _shortDisplayTitle;private readonly Lazy<string> _longDisplayTitle;@@ -39,6 +40,8 @@ public sealed partial class GuiToolInstancereturn instance;});+ _view = new(() => _instance.Value.View); // TODO: Try Catch and log?+LogInitialized(_guiToolDefinition.Metadata.InternalComponentName);}@@ -73,10 +76,10 @@ public sealed partial class GuiToolInstancepublic string GroupName => _guiToolDefinition.Metadata.GroupName;/// <summary>- /// Gets the instance of the tool.- /// Calling this property be expensive the first time as it will create the instance.+ /// Gets the view of the tool.+ /// Calling this property is expensive the first time as it will create the instance of the tool and the instance of the view./// </summary>- public IGuiTool ToolInstance => _instance.Value;+ public IUIElement View => _view.Value;private ResourceManager? GetResourceManager(Assembly? resourceManagerAssembly){diff --git a/src/app/dev/DevToys.Tools/DevToys.Tools.csproj b/src/app/dev/DevToys.Tools/DevToys.Tools.csprojindex 8c7ce9b0f..29142d607 100644--- a/src/app/dev/DevToys.Tools/DevToys.Tools.csproj+++ b/src/app/dev/DevToys.Tools/DevToys.Tools.csproj@@ -25,11 +25,20 @@<AutoGen>True</AutoGen><DependentUpon>Sample.resx</DependentUpon></Compile>+ <Compile Update="Settings\Settings.Designer.cs">+ <DependentUpon>Settings.resx</DependentUpon>+ <DesignTime>True</DesignTime>+ <AutoGen>True</AutoGen>+ </Compile></ItemGroup><ItemGroup><EmbeddedResource Update="Sample\Sample.resx"><Generator>ResXFileCodeGenerator</Generator><LastGenOutput>Sample.Designer.cs</LastGenOutput></EmbeddedResource>+ <EmbeddedResource Update="Settings\Settings.resx">+ <LastGenOutput>Settings.Designer.cs</LastGenOutput>+ <Generator>ResXFileCodeGenerator</Generator>+ </EmbeddedResource></ItemGroup></Project>\ No newline at end of filediff --git a/src/app/dev/DevToys.Tools/Properties/AdditionGlobalUsings.cs b/src/app/dev/DevToys.Tools/Properties/AdditionGlobalUsings.csnew file mode 100644index 000000000..52bb7cd80--- /dev/null+++ b/src/app/dev/DevToys.Tools/Properties/AdditionGlobalUsings.cs@@ -0,0 +1,2 @@+global using global::DevToys.Api;+global using static global::DevToys.Api.GUI;diff --git a/src/app/dev/DevToys.Tools/Sample/SampleToolFactory.cs b/src/app/dev/DevToys.Tools/Sample/SampleToolFactory.csindex 05d96ff08..7e8d71737 100644--- a/src/app/dev/DevToys.Tools/Sample/SampleToolFactory.cs+++ b/src/app/dev/DevToys.Tools/Sample/SampleToolFactory.cs@@ -56,7 +56,7 @@ internal sealed class SampleCommandLineTool : ICommandLineTool[TargetPlatform(Platform.WASM)]internal sealed class SampleGuiTool : IGuiTool{- public UIElement View => throw new NotImplementedException();+ public IUIElement View => throw new NotImplementedException();}[Export(typeof(IGuiTool))]@@ -79,7 +79,7 @@ internal sealed class SampleGuiTool : IGuiTool[TargetPlatform(Platform.WASM)]internal sealed class SampleGuiTool2 : IGuiTool{- public UIElement View => throw new NotImplementedException();+ public IUIElement View => throw new NotImplementedException();}[Export(typeof(IGuiTool))]@@ -102,7 +102,7 @@ internal sealed class SampleGuiTool2 : IGuiTool[TargetPlatform(Platform.WASM)]internal sealed class SampleGuiTool3 : IGuiTool{- public UIElement View => throw new NotImplementedException();+ public IUIElement View => throw new NotImplementedException();}[Export(typeof(IGuiTool))]@@ -125,7 +125,7 @@ internal sealed class SampleGuiTool3 : IGuiTool[TargetPlatform(Platform.WASM)]internal sealed class SampleGuiTool4 : IGuiTool{- public UIElement View => throw new NotImplementedException();+ public IUIElement View => throw new NotImplementedException();}[Export(typeof(IGuiTool))]@@ -148,7 +148,7 @@ internal sealed class SampleGuiTool4 : IGuiTool[TargetPlatform(Platform.WASM)]internal sealed class SampleGuiTool5 : IGuiTool{- public UIElement View => throw new NotImplementedException();+ public IUIElement View => throw new NotImplementedException();}[Export(typeof(IGuiTool))]@@ -171,7 +171,7 @@ internal sealed class SampleGuiTool5 : IGuiTool[TargetPlatform(Platform.WASM)]internal sealed class SampleGuiTool6 : IGuiTool{- public UIElement View => throw new NotImplementedException();+ public IUIElement View => throw new NotImplementedException();}[Export(typeof(IGuiTool))]@@ -194,7 +194,7 @@ internal sealed class SampleGuiTool6 : IGuiTool[TargetPlatform(Platform.WASM)]internal sealed class SampleGuiTool7 : IGuiTool{- public UIElement View => throw new NotImplementedException();+ public IUIElement View => throw new NotImplementedException();}[Export(typeof(IGuiTool))]@@ -217,7 +217,7 @@ internal sealed class SampleGuiTool7 : IGuiTool[TargetPlatform(Platform.WASM)]internal sealed class SampleGuiTool8 : IGuiTool{- public UIElement View => throw new NotImplementedException();+ public IUIElement View => throw new NotImplementedException();}[Export(typeof(IGuiTool))]@@ -240,7 +240,7 @@ internal sealed class SampleGuiTool8 : IGuiTool[TargetPlatform(Platform.WASM)]internal sealed class SampleGuiTool9 : IGuiTool{- public UIElement View => throw new NotImplementedException();+ public IUIElement View => throw new NotImplementedException();}[Export(typeof(IGuiTool))]@@ -263,7 +263,7 @@ internal sealed class SampleGuiTool9 : IGuiTool[TargetPlatform(Platform.WASM)]internal sealed class SampleGuiTool10 : IGuiTool{- public UIElement View => throw new NotImplementedException();+ public IUIElement View => throw new NotImplementedException();}[Export(typeof(IGuiTool))]@@ -286,7 +286,7 @@ internal sealed class SampleGuiTool10 : IGuiTool[TargetPlatform(Platform.WASM)]internal sealed class SampleGuiTool11 : IGuiTool{- public UIElement View => throw new NotImplementedException();+ public IUIElement View => throw new NotImplementedException();}[Export(typeof(IGuiTool))]@@ -309,7 +309,7 @@ internal sealed class SampleGuiTool11 : IGuiTool[TargetPlatform(Platform.WASM)]internal sealed class SampleGuiTool12 : IGuiTool{- public UIElement View => throw new NotImplementedException();+ public IUIElement View => throw new NotImplementedException();}[Export(typeof(IGuiTool))]@@ -332,7 +332,7 @@ internal sealed class SampleGuiTool12 : IGuiTool[TargetPlatform(Platform.WASM)]internal sealed class SampleGuiTool13 : IGuiTool{- public UIElement View => throw new NotImplementedException();+ public IUIElement View => throw new NotImplementedException();}[Export(typeof(IGuiTool))]@@ -355,7 +355,7 @@ internal sealed class SampleGuiTool13 : IGuiTool[TargetPlatform(Platform.WASM)]internal sealed class SampleGuiTool14 : IGuiTool{- public UIElement View => throw new NotImplementedException();+ public IUIElement View => throw new NotImplementedException();}[Export(typeof(IGuiTool))]@@ -378,7 +378,7 @@ internal sealed class SampleGuiTool14 : IGuiTool[TargetPlatform(Platform.WASM)]internal sealed class SampleGuiTool15 : IGuiTool{- public UIElement View => throw new NotImplementedException();+ public IUIElement View => throw new NotImplementedException();}[Export(typeof(IGuiTool))]@@ -401,7 +401,7 @@ internal sealed class SampleGuiTool15 : IGuiTool[TargetPlatform(Platform.WASM)]internal sealed class SampleGuiTool16 : IGuiTool{- public UIElement View => throw new NotImplementedException();+ public IUIElement View => throw new NotImplementedException();}[Export(typeof(IGuiTool))]@@ -424,7 +424,7 @@ internal sealed class SampleGuiTool16 : IGuiTool[TargetPlatform(Platform.WASM)]internal sealed class SampleGuiTool17 : IGuiTool{- public UIElement View => throw new NotImplementedException();+ public IUIElement View => throw new NotImplementedException();}[Export(typeof(GuiToolGroup))]diff --git a/src/app/dev/DevToys.Tools/Settings/Settings.Designer.cs b/src/app/dev/DevToys.Tools/Settings/Settings.Designer.csnew file mode 100644index 000000000..d6d7ee501--- /dev/null+++ b/src/app/dev/DevToys.Tools/Settings/Settings.Designer.cs@@ -0,0 +1,90 @@+//------------------------------------------------------------------------------+// <auto-generated>+// This code was generated by a tool.+// Runtime Version:4.0.30319.42000+//+// Changes to this file may cause incorrect behavior and will be lost if+// the code is regenerated.+// </auto-generated>+//------------------------------------------------------------------------------++namespace DevToys.Tools.Settings {+ using System;+++ /// <summary>+ /// A strongly-typed resource class, for looking up localized strings, etc.+ /// </summary>+ // This class was auto-generated by the StronglyTypedResourceBuilder+ // class via a tool like ResGen or Visual Studio.+ // To add or remove a member, edit your .ResX file then rerun ResGen+ // with the /str option, or rebuild your VS project.+ [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")]+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]+ [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]+ internal class Settings {++ private static global::System.Resources.ResourceManager resourceMan;++ private static global::System.Globalization.CultureInfo resourceCulture;++ [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]+ internal Settings() {+ }++ /// <summary>+ /// Returns the cached ResourceManager instance used by this class.+ /// </summary>+ [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]+ internal static global::System.Resources.ResourceManager ResourceManager {+ get {+ if (object.ReferenceEquals(resourceMan, null)) {+ global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("DevToys.Tools.Settings.Settings", typeof(Settings).Assembly);+ resourceMan = temp;+ }+ return resourceMan;+ }+ }++ /// <summary>+ /// Overrides the current thread's CurrentUICulture property for all+ /// resource lookups using this strongly typed resource class.+ /// </summary>+ [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]+ internal static global::System.Globalization.CultureInfo Culture {+ get {+ return resourceCulture;+ }+ set {+ resourceCulture = value;+ }+ }++ /// <summary>+ /// Looks up a localized string similar to Settings.+ /// </summary>+ internal static string AccessibleName {+ get {+ return ResourceManager.GetString("AccessibleName", resourceCulture);+ }+ }++ /// <summary>+ /// Looks up a localized string similar to Customize DevToys look & feel.+ /// </summary>+ internal static string Description {+ get {+ return ResourceManager.GetString("Description", resourceCulture);+ }+ }++ /// <summary>+ /// Looks up a localized string similar to Settings.+ /// </summary>+ internal static string ShortDisplayTitle {+ get {+ return ResourceManager.GetString("ShortDisplayTitle", resourceCulture);+ }+ }+ }+}diff --git a/src/app/dev/DevToys.Tools/Settings/Settings.resx b/src/app/dev/DevToys.Tools/Settings/Settings.resxnew file mode 100644index 000000000..565067b7b--- /dev/null+++ b/src/app/dev/DevToys.Tools/Settings/Settings.resx@@ -0,0 +1,129 @@+<?xml version="1.0" encoding="utf-8"?>+<root>+ <!--+ Microsoft ResX Schema++ Version 2.0++ The primary goals of this format is to allow a simple XML format+ that is mostly human readable. The generation and parsing of the+ various data types are done through the TypeConverter classes+ associated with the data types.++ Example:++ ... ado.net/XML headers & schema ...+ <resheader name="resmimetype">text/microsoft-resx</resheader>+ <resheader name="version">2.0</resheader>+ <resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>+ <resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>+ <data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>+ <data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>+ <data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">+ <value>[base64 mime encoded serialized .NET Framework object]</value>+ </data>+ <data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">+ <value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>+ <comment>This is a comment</comment>+ </data>++ There are any number of "resheader" rows that contain simple+ name/value pairs.++ Each data row contains a name, and value. The row also contains a+ type or mimetype. Type corresponds to a .NET class that support+ text/value conversion through the TypeConverter architecture.+ Classes that don't support this are serialized and stored with the+ mimetype set.++ The mimetype is used for serialized objects, and tells the+ ResXResourceReader how to depersist the object. This is currently not+ extensible. For a given mimetype the value must be set accordingly:++ Note - application/x-microsoft.net.object.binary.base64 is the format+ that the ResXResourceWriter will generate, however the reader can+ read any of the formats listed below.++ mimetype: application/x-microsoft.net.object.binary.base64+ value : The object must be serialized with+ : System.Runtime.Serialization.Formatters.Binary.BinaryFormatter+ : and then encoded with base64 encoding.++ mimetype: application/x-microsoft.net.object.soap.base64+ value : The object must be serialized with+ : System.Runtime.Serialization.Formatters.Soap.SoapFormatter+ : and then encoded with base64 encoding.++ mimetype: application/x-microsoft.net.object.bytearray.base64+ value : The object must be serialized into a byte array+ : using a System.ComponentModel.TypeConverter+ : and then encoded with base64 encoding.+ -->+ <xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">+ <xsd:import namespace="http://www.w3.org/XML/1998/namespace" />+ <xsd:element name="root" msdata:IsDataSet="true">+ <xsd:complexType>+ <xsd:choice maxOccurs="unbounded">+ <xsd:element name="metadata">+ <xsd:complexType>+ <xsd:sequence>+ <xsd:element name="value" type="xsd:string" minOccurs="0" />+ </xsd:sequence>+ <xsd:attribute name="name" use="required" type="xsd:string" />+ <xsd:attribute name="type" type="xsd:string" />+ <xsd:attribute name="mimetype" type="xsd:string" />+ <xsd:attribute ref="xml:space" />+ </xsd:complexType>+ </xsd:element>+ <xsd:element name="assembly">+ <xsd:complexType>+ <xsd:attribute name="alias" type="xsd:string" />+ <xsd:attribute name="name" type="xsd:string" />+ </xsd:complexType>+ </xsd:element>+ <xsd:element name="data">+ <xsd:complexType>+ <xsd:sequence>+ <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />+ <xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />+ </xsd:sequence>+ <xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />+ <xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />+ <xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />+ <xsd:attribute ref="xml:space" />+ </xsd:complexType>+ </xsd:element>+ <xsd:element name="resheader">+ <xsd:complexType>+ <xsd:sequence>+ <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />+ </xsd:sequence>+ <xsd:attribute name="name" type="xsd:string" use="required" />+ </xsd:complexType>+ </xsd:element>+ </xsd:choice>+ </xsd:complexType>+ </xsd:element>+ </xsd:schema>+ <resheader name="resmimetype">+ <value>text/microsoft-resx</value>+ </resheader>+ <resheader name="version">+ <value>2.0</value>+ </resheader>+ <resheader name="reader">+ <value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>+ </resheader>+ <resheader name="writer">+ <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>+ </resheader>+ <data name="AccessibleName" xml:space="preserve">+ <value>Settings</value>+ </data>+ <data name="Description" xml:space="preserve">+ <value>Customize DevToys look & feel</value>+ </data>+ <data name="ShortDisplayTitle" xml:space="preserve">+ <value>Settings</value>+ </data>+</root>\ No newline at end of filediff --git a/src/app/dev/DevToys.Tools/Settings/SettingsGuiTool.cs b/src/app/dev/DevToys.Tools/Settings/SettingsGuiTool.csnew file mode 100644index 000000000..add184146--- /dev/null+++ b/src/app/dev/DevToys.Tools/Settings/SettingsGuiTool.cs@@ -0,0 +1,66 @@+namespace DevToys.Tools.Settings;++[Export(typeof(IGuiTool))]+[Name("Settings")]+[Author("Etienne Baudoux")]+[ToolDisplayInformation(+ IconFontName = "FluentSystemIcons",+ IconGlyph = "\uF6A9",+ ResourceManagerAssemblyIdentifier = nameof(DevToysToolsResourceManagerAssemblyIdentifier),+ ResourceManagerBaseName = "DevToys.Tools.Settings.Settings",+ ShortDisplayTitleResourceName = nameof(Settings.ShortDisplayTitle),+ DescriptionResourceName = nameof(Settings.Description),+ AccessibleNameResourceName = nameof(Settings.AccessibleName))]+[MenuPlacement(MenuPlacement.Footer)]+[NotFavorable]+[NotSearchable]+[NoCompactOverlaySupport]+internal sealed class SettingsGuiTool : IGuiTool+{+ private readonly IUIButton _topLeftButton;++ private int _clickCount;++ public SettingsGuiTool()+ {+ _topLeftButton+ = Button(id: "topLeftButtonUniqueId-for-logs")+ .Text("Top Left button")+ .OnClick(OnMyButtonClickAsync);+ }++ public IUIElement View+ => Stack()+ .Vertical()+ .WithChildren(+ Stack()+ .Horizontal()+ .WithChildren(+ _topLeftButton,+ Button().Text("Top Center button"),+ Button().Text("Top Right button")),+ Stack()+ .Horizontal()+ .Disable()+ .WithChildren(+ Button().Text("Bottom Left button"),+ Button().Text("Bottom Center button").OnClick(OnBottomCenterButtonClickAsync),+ Button().Text("Bottom Right button")));++ private ValueTask OnMyButtonClickAsync()+ {+ _clickCount++;+ _topLeftButton.Text($"Clicked {_clickCount} time !");+ return ValueTask.CompletedTask;+ }++ private ValueTask OnBottomCenterButtonClickAsync()+ {+ return ValueTask.CompletedTask;+ }+}+++++diff --git a/src/app/dev/DevToys.UI.Framework/Controls/GuiTool/UIButtonPresenter.xaml b/src/app/dev/DevToys.UI.Framework/Controls/GuiTool/UIButtonPresenter.xamlnew file mode 100644index 000000000..16916c217--- /dev/null+++ b/src/app/dev/DevToys.UI.Framework/Controls/GuiTool/UIButtonPresenter.xaml@@ -0,0 +1,11 @@+<Button+ x:Class="DevToys.UI.Framework.Controls.GuiTool.UIButtonPresenter"+ xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"+ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"+ xmlns:local="using:DevToys.UI.Framework.Controls.GuiTool"+ xmlns:d="http://schemas.microsoft.com/expression/blend/2008"+ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"+ mc:Ignorable="d"+ Style="{ThemeResource DefaultButtonStyle}"+ Click="OnButton_Click">+</Button>diff --git a/src/app/dev/DevToys.UI.Framework/Controls/GuiTool/UIButtonPresenter.xaml.cs b/src/app/dev/DevToys.UI.Framework/Controls/GuiTool/UIButtonPresenter.xaml.csnew file mode 100644index 000000000..153eca18c--- /dev/null+++ b/src/app/dev/DevToys.UI.Framework/Controls/GuiTool/UIButtonPresenter.xaml.cs@@ -0,0 +1,56 @@+using DevToys.Api;+using Microsoft.UI.Xaml.Controls;++namespace DevToys.UI.Framework.Controls.GuiTool;++public sealed partial class UIButtonPresenter : Button+{+ public UIButtonPresenter()+ {+ this.InitializeComponent();++ Loaded += UIButtonPresenter_Loaded;+ Unloaded += UIButtonPresenter_Unloaded;+ }++ internal IUIButton UIButton => (IUIButton)DataContext;++ private void UIButtonPresenter_Loaded(object sender, Microsoft.UI.Xaml.RoutedEventArgs e)+ {+ UIButton.IsEnabledChanged += UIButton_IsEnabledChanged;+ UIButton.IsVisibleChanged += UIButton_IsVisibleChanged;+ UIButton.DisplayTextChanged += UIButton_DisplayTextChanged;++ IsEnabled = UIButton.IsEnabled;+ Visibility = UIButton.IsVisible ? Microsoft.UI.Xaml.Visibility.Visible : Microsoft.UI.Xaml.Visibility.Collapsed;+ Content = UIButton.DisplayText;+ }++ private void UIButtonPresenter_Unloaded(object sender, Microsoft.UI.Xaml.RoutedEventArgs e)+ {+ UIButton.IsEnabledChanged -= UIButton_IsEnabledChanged;+ UIButton.IsVisibleChanged -= UIButton_IsVisibleChanged;+ UIButton.DisplayTextChanged -= UIButton_DisplayTextChanged;+ Loaded -= UIButtonPresenter_Loaded;+ }++ private void UIButton_IsEnabledChanged(object? sender, EventArgs e)+ {+ IsEnabled = UIButton.IsEnabled;+ }++ private void UIButton_IsVisibleChanged(object? sender, EventArgs e)+ {+ Visibility = UIButton.IsVisible ? Microsoft.UI.Xaml.Visibility.Visible : Microsoft.UI.Xaml.Visibility.Collapsed;+ }++ private void UIButton_DisplayTextChanged(object? sender, EventArgs e)+ {+ Content = UIButton.DisplayText;+ }++ private void OnButton_Click(object sender, Microsoft.UI.Xaml.RoutedEventArgs e)+ {+ UIButton.OnClickAction?.Invoke(); // TODO: await? Also, Try Catch and log?+ }+}diff --git a/src/app/dev/DevToys.UI.Framework/Controls/GuiTool/UIElementPresenter.xaml b/src/app/dev/DevToys.UI.Framework/Controls/GuiTool/UIElementPresenter.xamlnew file mode 100644index 000000000..a1d147fc3--- /dev/null+++ b/src/app/dev/DevToys.UI.Framework/Controls/GuiTool/UIElementPresenter.xaml@@ -0,0 +1,46 @@+<Control+ x:Class="DevToys.UI.Framework.Controls.GuiTool.UIElementPresenter"+ xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"+ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"+ xmlns:local="using:DevToys.UI.Framework.Controls.GuiTool"+ xmlns:d="http://schemas.microsoft.com/expression/blend/2008"+ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"+ mc:Ignorable="d"+ AllowFocusOnInteraction="False"+ AllowFocusWhenDisabled="False"+ TabFocusNavigation="Local"+ TabNavigation="Local">+ <Control.Resources>+ <local:UIElementTemplateSelector x:Key="UIElementTemplateSelector">++ <!-- UIButton -->+ <local:UIElementTemplateSelector.UIButtonTemplate>+ <DataTemplate>+ <local:UIButtonPresenter/>+ </DataTemplate>+ </local:UIElementTemplateSelector.UIButtonTemplate>++ <!-- UIStack -->+ <local:UIElementTemplateSelector.UIStackTemplate>+ <DataTemplate>+ <local:UIStackPresenter/>+ </DataTemplate>+ </local:UIElementTemplateSelector.UIStackTemplate>++ </local:UIElementTemplateSelector>+ </Control.Resources>++ <Control.Template>+ <ControlTemplate TargetType="local:UIElementPresenter">+ <ContentControl+ ContentTemplateSelector="{StaticResource UIElementTemplateSelector}"+ Content="{x:Bind UIElement}"+ HorizontalContentAlignment="Stretch"+ VerticalContentAlignment="Stretch"+ AllowFocusOnInteraction="False"+ AllowFocusWhenDisabled="False"+ TabFocusNavigation="Local"+ TabNavigation="Local"/>+ </ControlTemplate>+ </Control.Template>+</Control>diff --git a/src/app/dev/DevToys.UI.Framework/Controls/GuiTool/UIElementPresenter.xaml.cs b/src/app/dev/DevToys.UI.Framework/Controls/GuiTool/UIElementPresenter.xaml.csnew file mode 100644index 000000000..8b008f8a2--- /dev/null+++ b/src/app/dev/DevToys.UI.Framework/Controls/GuiTool/UIElementPresenter.xaml.cs@@ -0,0 +1,34 @@+using DevToys.Api;+using Microsoft.UI.Xaml;+using Microsoft.UI.Xaml.Controls;++namespace DevToys.UI.Framework.Controls.GuiTool;++public sealed partial class UIElementPresenter : Control+{+ internal static UIElementPresenter Create(IUIElement element)+ {+ return new()+ {+ UIElement = element+ };+ }++ public UIElementPresenter()+ {+ InitializeComponent();+ }++ public static readonly DependencyProperty UIElementProperty =+ DependencyProperty.Register(+ nameof(UIElement),+ typeof(IUIElement),+ typeof(UIElementPresenter),+ new PropertyMetadata(null));++ public IUIElement UIElement+ {+ get => (IUIElement)GetValue(UIElementProperty);+ set => SetValue(UIElementProperty, value);+ }+}diff --git a/src/app/dev/DevToys.UI.Framework/Controls/GuiTool/UIElementTemplateSelector.cs b/src/app/dev/DevToys.UI.Framework/Controls/GuiTool/UIElementTemplateSelector.csnew file mode 100644index 000000000..ebf9c5942--- /dev/null+++ b/src/app/dev/DevToys.UI.Framework/Controls/GuiTool/UIElementTemplateSelector.cs@@ -0,0 +1,37 @@+using DevToys.Api;+using Microsoft.UI.Xaml;+using Microsoft.UI.Xaml.Controls;++namespace DevToys.UI.Framework.Controls.GuiTool;++/// <summary>+/// The template selector used to display <see cref="IUIElement"/>+/// </summary>+internal sealed class UIElementTemplateSelector : DataTemplateSelector+{+ /// <summary>+ /// The data template used to display a <see cref="IUIButton"/>.+ /// </summary>+ public DataTemplate UIButtonTemplate { get; set; } = null!;++ /// <summary>+ /// The data template used to display a <see cref="IUIStack"/>.+ /// </summary>+ public DataTemplate UIStackTemplate { get; set; } = null!;++ protected override DataTemplate SelectTemplateCore(object item, DependencyObject container)+ {+ if (item is null)+ {+ return null;+ }++ return item switch+ {+ IUIButton => UIButtonTemplate,+ IUIStack => UIStackTemplate,++ _ => throw new NotSupportedException($"Gui Tool component of type '{item.GetType().FullName}' isn't supported.")+ };+ }+}diff --git a/src/app/dev/DevToys.UI.Framework/Controls/GuiTool/UIStackPresenter.xaml b/src/app/dev/DevToys.UI.Framework/Controls/GuiTool/UIStackPresenter.xamlnew file mode 100644index 000000000..bc99c0fb5--- /dev/null+++ b/src/app/dev/DevToys.UI.Framework/Controls/GuiTool/UIStackPresenter.xaml@@ -0,0 +1,16 @@+<ContentControl+ x:Class="DevToys.UI.Framework.Controls.GuiTool.UIStackPresenter"+ xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"+ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"+ xmlns:local="using:DevToys.UI.Framework.Controls.GuiTool"+ xmlns:d="http://schemas.microsoft.com/expression/blend/2008"+ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"+ mc:Ignorable="d"+ HorizontalAlignment="Stretch"+ VerticalAlignment="Stretch">+ <StackPanel+ x:Name="StackPanel"+ HorizontalAlignment="Stretch"+ VerticalAlignment="Stretch"+ Spacing="4"/>+</ContentControl>diff --git a/src/app/dev/DevToys.UI.Framework/Controls/GuiTool/UIStackPresenter.xaml.cs b/src/app/dev/DevToys.UI.Framework/Controls/GuiTool/UIStackPresenter.xaml.csnew file mode 100644index 000000000..149d9f699--- /dev/null+++ b/src/app/dev/DevToys.UI.Framework/Controls/GuiTool/UIStackPresenter.xaml.cs@@ -0,0 +1,70 @@+using DevToys.Api;+using Microsoft.UI.Xaml.Controls;++namespace DevToys.UI.Framework.Controls.GuiTool;++public sealed partial class UIStackPresenter : ContentControl+{+ public UIStackPresenter()+ {+ this.InitializeComponent();++ Loaded += UIStackPresenter_Loaded;+ Unloaded += UIStackPresenter_Unloaded;+ }++ internal IUIStack UIStack => (IUIStack)DataContext;++ private void UIStackPresenter_Loaded(object sender, Microsoft.UI.Xaml.RoutedEventArgs e)+ {+ UIStack.IsEnabledChanged += UIButton_IsEnabledChanged;+ UIStack.IsVisibleChanged += UIButton_IsVisibleChanged;+ UIStack.OrientationChanged += UIButton_OrientationChanged;+ UIStack.ChildrenChanged += UIStack_ChildrenChanged;++ IsEnabled = UIStack.IsEnabled;+ Visibility = UIStack.IsVisible ? Microsoft.UI.Xaml.Visibility.Visible : Microsoft.UI.Xaml.Visibility.Collapsed;+ StackPanel.Orientation = UIStack.Orientation == UIOrientation.Horizontal ? Orientation.Horizontal : Orientation.Vertical;+ SetChildren();+ }++ private void UIStackPresenter_Unloaded(object sender, Microsoft.UI.Xaml.RoutedEventArgs e)+ {+ UIStack.IsEnabledChanged -= UIButton_IsEnabledChanged;+ UIStack.IsVisibleChanged -= UIButton_IsVisibleChanged;+ UIStack.OrientationChanged -= UIButton_OrientationChanged;+ Loaded -= UIStackPresenter_Loaded;+ }++ private void UIButton_IsEnabledChanged(object? sender, EventArgs e)+ {+ IsEnabled = UIStack.IsEnabled;+ }++ private void UIButton_IsVisibleChanged(object? sender, EventArgs e)+ {+ Visibility = UIStack.IsVisible ? Microsoft.UI.Xaml.Visibility.Visible : Microsoft.UI.Xaml.Visibility.Collapsed;+ }++ private void UIButton_OrientationChanged(object? sender, EventArgs e)+ {+ StackPanel.Orientation = UIStack.Orientation == UIOrientation.Horizontal ? Orientation.Horizontal : Orientation.Vertical;+ }++ private void UIStack_ChildrenChanged(object? sender, EventArgs e)+ {+ SetChildren();+ }++ private void SetChildren()+ {+ StackPanel.Children.Clear();+ if (UIStack.Children is not null)+ {+ for (int i = 0; i < UIStack.Children.Length; i++)+ {+ StackPanel.Children.Add(UIElementPresenter.Create(UIStack.Children[i]));+ }+ }+ }+}diff --git a/src/app/dev/DevToys.UI.Framework/DevToys.UI.Framework.csproj b/src/app/dev/DevToys.UI.Framework/DevToys.UI.Framework.csprojindex 9c0d31e6a..30ea3d1ba 100644--- a/src/app/dev/DevToys.UI.Framework/DevToys.UI.Framework.csproj+++ b/src/app/dev/DevToys.UI.Framework/DevToys.UI.Framework.csproj@@ -22,6 +22,10 @@</Page><PRIResource Include="**\*.resw" /><Content Include="Assets\**" />+ <None Remove="Controls\GuiTool\UIButtonPresenter.xaml" />+ <None Remove="Controls\GuiTool\UIStackPresenter.xaml" />+ <UpToDateCheckInput Remove="Controls\GuiTool\UIButtonPresenter.xaml" />+ <UpToDateCheckInput Remove="Controls\GuiTool\UIStackPresenter.xaml" /><Compile Update="**\*.xaml.cs"><DependentUpon>%(Filename)</DependentUpon></Compile>@@ -97,4 +101,10 @@<ProjectReference Include="..\DevToys.Api\DevToys.Api.csproj" /></ItemGroup>+ <ItemGroup>+ <Compile Update="Controls\GuiTool\UIStackPresenter.xaml.cs">+ <DependentUpon>UIStackPresenter.xaml</DependentUpon>+ </Compile>+ </ItemGroup>+</Project>diff --git a/src/app/dev/DevToys.UI/ViewModels/ToolPageViewModel.cs b/src/app/dev/DevToys.UI/ViewModels/ToolPageViewModel.csindex da30d3388..04905771c 100644--- a/src/app/dev/DevToys.UI/ViewModels/ToolPageViewModel.cs+++ b/src/app/dev/DevToys.UI/ViewModels/ToolPageViewModel.cs@@ -1,5 +1,6 @@using CommunityToolkit.Mvvm.ComponentModel;using CommunityToolkit.Mvvm.Input;+using DevToys.Api;using DevToys.Core.Tools;using DevToys.Core.Tools.ViewItems;using DevToys.Localization.Strings.ToolPage;@@ -30,6 +31,11 @@ internal sealed partial class ToolPageViewModel : ObservableRecipient/// </summary>internal bool IsSelectedMenuItemAFavoriteTool => _guiToolViewItem is not null && _guiToolProvider.GetToolIsFavorite(_guiToolViewItem.ToolInstance);+ /// <summary>+ /// Gets the UI of the tool.+ /// </summary>+ internal IUIElement ToolView => _guiToolViewItem?.ToolInstance.View ?? throw new InvalidOperationException();+internal void Load(GuiToolViewItem guiToolViewItem){Guard.IsNotNull(guiToolViewItem);diff --git a/src/app/dev/DevToys.UI/Views/ToolPage.xaml b/src/app/dev/DevToys.UI/Views/ToolPage.xamlindex 621b5c6b3..cc19b31f3 100644--- a/src/app/dev/DevToys.UI/Views/ToolPage.xaml+++ b/src/app/dev/DevToys.UI/Views/ToolPage.xaml@@ -12,6 +12,7 @@xmlns:i="using:Microsoft.Xaml.Interactivity"xmlns:tools="using:DevToys.Core.Tools"xmlns:strings="using:DevToys.Localization.Strings.ToolPage"+ xmlns:guiTool="using:DevToys.UI.Framework.Controls.GuiTool"mc:Ignorable="d"><Page.Resources><converters:BooleanToStringConverter x:Key="BooleanToFavoriteIconGlyph" StringIfTrue="" StringIfFalse=""/>@@ -88,6 +89,14 @@</win:AppBarButton></CommandBar></Border>++ <guiTool:UIElementPresenter+ Grid.Row="1"+ Grid.Column="0"+ Grid.ColumnSpan="2"+ HorizontalAlignment="Stretch"+ VerticalAlignment="Stretch"+ UIElement="{x:Bind ViewModel.ToolView}"/></Grid></ScrollViewer></Page>diff --git a/src/app/tests/DevToys.UnitTests/Mocks/Tools/MockIGuiTool.cs b/src/app/tests/DevToys.UnitTests/Mocks/Tools/MockIGuiTool.csindex 118102105..3e6a7e8c1 100644--- a/src/app/tests/DevToys.UnitTests/Mocks/Tools/MockIGuiTool.cs+++ b/src/app/tests/DevToys.UnitTests/Mocks/Tools/MockIGuiTool.cs@@ -19,7 +19,7 @@ namespace DevToys.UnitTests.Mocks.Tools;SearchKeywordsResourceName = nameof(MockToolResource.Title))]internal sealed class MockIGuiTool2 : IGuiTool{- public UIElement View => throw new NotImplementedException();+ public IUIElement View => throw new NotImplementedException();}[Export(typeof(IGuiTool))]@@ -38,5 +38,5 @@ internal sealed class MockIGuiTool2 : IGuiToolSearchKeywordsResourceName = nameof(MockToolResource.Title))]internal sealed class MockIGuiTool : IGuiTool{- public UIElement View => throw new NotImplementedException();+ public IUIElement View => throw new NotImplementedException();}