Skip to content

A Swiss Army knife for developers.

Added IUISplitGrid

Etienne Baudouxa6254e89a365
diff --git a/src/app/dev/DevToys.Api/Tool/GUI/Components/IUISplitGrid.cs b/src/app/dev/DevToys.Api/Tool/GUI/Components/IUISplitGrid.cs
new file mode 100644
index 000000000..34f37ebf6
--- /dev/null
+++ b/src/app/dev/DevToys.Api/Tool/GUI/Components/IUISplitGrid.cs
@@ -0,0 +1,261 @@
+namespace DevToys.Api;
+
+/// <summary>
+/// A component that splits horizontally or vertically an area into two panes. Panes can be resized by the user.
+/// </summary>
+public interface IUISplitGrid : IUIElement
+{
+ /// <summary>
+ /// Gets the orientation of the grid gutter.
+ /// Default is <see cref="UIOrientation.Vertical"/>.
+ /// </summary>
+ UIOrientation Orientation { get; }
+
+ /// <summary>
+ /// Gets the minimum length of a cell, in pixels.
+ /// Default is 50.
+ /// </summary>
+ int MinimumCellLength { get; }
+
+ /// <summary>
+ /// Gets the length of the top or left cell.
+ /// Default is 1*. <see cref="UIGridLength.Auto"/> is not supported.
+ /// </summary>
+ UIGridLength LeftOrTopCellLength { get; }
+
+ /// <summary>
+ /// Gets the length of the right or bottom cell.
+ /// Default is 1*. <see cref="UIGridLength.Auto"/> is not supported.
+ /// </summary>
+ UIGridLength RightOrBottomCellLength { get; }
+
+ /// <summary>
+ /// Gets the element to display in the right or bottom cell, depending on the <see cref="Orientation"/>.
+ /// </summary>
+ IUIElement? RightOrBottomCellContent { get; }
+
+ /// <summary>
+ /// Gets the element to display in the top or left cell, depending on the <see cref="Orientation"/>.
+ /// </summary>
+ IUIElement? LeftOrTopCellContent { get; }
+
+ /// <summary>
+ /// Raised when <see cref="Orientation"/> is changed.
+ /// </summary>
+ event EventHandler? OrientationChanged;
+
+ /// <summary>
+ /// Raised when <see cref="MinimumCellLength"/> is changed.
+ /// </summary>
+ event EventHandler? MinimumCellLengthChanged;
+
+ /// <summary>
+ /// Raised when <see cref="LeftOrTopCellLength"/> is changed.
+ /// </summary>
+ event EventHandler? LeftOrTopCellLengthChanged;
+
+ /// <summary>
+ /// Raised when <see cref="RightOrBottomCellLength"/> is changed.
+ /// </summary>
+ event EventHandler? RightOrBottomCellLengthChanged;
+
+ /// <summary>
+ /// Raised when <see cref="RightOrBottomCellContent"/> is changed.
+ /// </summary>
+ event EventHandler? RightOrBottomCellContentChanged;
+
+ /// <summary>
+ /// Raised when <see cref="LeftOrTopCellContent"/> is changed.
+ /// </summary>
+ event EventHandler? LeftOrTopCellContentChanged;
+}
+
+[DebuggerDisplay($"Id = {{{nameof(Id)}}}, Orientation = {{{nameof(Orientation)}}}")]
+internal sealed class UISplitGrid : UIElement, IUISplitGrid
+{
+ private UIOrientation _orientation = UIOrientation.Vertical;
+ private int _minimumCellLength = 50;
+ private UIGridLength _leftOrTopCellLength = new UIGridLength(1, UIGridUnitType.Fraction);
+ private UIGridLength _rightOrBottomCellLength = new UIGridLength(1, UIGridUnitType.Fraction);
+ private IUIElement? _rightOrBottomCellContent;
+ private IUIElement? _leftOrTopCellContent;
+
+ internal UISplitGrid(string? id)
+ : base(id)
+ {
+ }
+
+ public UIOrientation Orientation
+ {
+ get => _orientation;
+ internal set => SetPropertyValue(ref _orientation, value, OrientationChanged);
+ }
+
+ public int MinimumCellLength
+ {
+ get => _minimumCellLength;
+ internal set => SetPropertyValue(ref _minimumCellLength, value, MinimumCellLengthChanged);
+ }
+
+ public UIGridLength LeftOrTopCellLength
+ {
+ get => _leftOrTopCellLength;
+ internal set => SetPropertyValue(ref _leftOrTopCellLength, value, LeftOrTopCellLengthChanged);
+ }
+
+ public UIGridLength RightOrBottomCellLength
+ {
+ get => _rightOrBottomCellLength;
+ internal set => SetPropertyValue(ref _rightOrBottomCellLength, value, RightOrBottomCellLengthChanged);
+ }
+
+ public IUIElement? RightOrBottomCellContent
+ {
+ get => _rightOrBottomCellContent;
+ internal set => SetPropertyValue(ref _rightOrBottomCellContent, value, RightOrBottomCellContentChanged);
+ }
+
+ public IUIElement? LeftOrTopCellContent
+ {
+ get => _leftOrTopCellContent;
+ internal set => SetPropertyValue(ref _leftOrTopCellContent, value, LeftOrTopCellContentChanged);
+ }
+
+ public event EventHandler? OrientationChanged;
+ public event EventHandler? MinimumCellLengthChanged;
+ public event EventHandler? LeftOrTopCellLengthChanged;
+ public event EventHandler? RightOrBottomCellLengthChanged;
+ public event EventHandler? RightOrBottomCellContentChanged;
+ public event EventHandler? LeftOrTopCellContentChanged;
+}
+
+public static partial class GUI
+{
+ /// <summary>
+ /// Create a component that splits horizontally or vertically an area into two panes. Panes can be resized by the user.
+ /// </summary>
+ public static IUISplitGrid SplitGrid()
+ {
+ return SplitGrid(null);
+ }
+
+ /// <summary>
+ /// Create a component that splits horizontally or vertically an area into two panes. Panes can be resized by the user.
+ /// </summary>
+ /// <param name="id">An optional unique identifier for this UI element.</param>
+ public static IUISplitGrid SplitGrid(string? id)
+ {
+ return new UISplitGrid(id);
+ }
+
+ /// <summary>
+ /// Split the <see cref="IUISplitGrid"/> vertically.
+ /// </summary>
+ public static IUISplitGrid Vertical(this IUISplitGrid element)
+ {
+ ((UISplitGrid)element).Orientation = UIOrientation.Vertical;
+ return element;
+ }
+
+ /// <summary>
+ /// Split the <see cref="IUISplitGrid"/> horizontally.
+ /// </summary>
+ public static IUISplitGrid Horizontal(this IUISplitGrid element)
+ {
+ ((UISplitGrid)element).Orientation = UIOrientation.Horizontal;
+ return element;
+ }
+
+ /// <summary>
+ /// Set the length of the top pane.
+ /// </summary>
+ public static IUISplitGrid TopPaneLength(this IUISplitGrid element, UIGridLength length)
+ {
+ GuardSplitGridLength(length);
+ ((UISplitGrid)element).LeftOrTopCellLength = length;
+ return element;
+ }
+
+ /// <summary>
+ /// Set the length of the left pane.
+ /// </summary>
+ public static IUISplitGrid LeftPaneLength(this IUISplitGrid element, UIGridLength length)
+ {
+ GuardSplitGridLength(length);
+ ((UISplitGrid)element).LeftOrTopCellLength = length;
+ return element;
+ }
+
+ /// <summary>
+ /// Set the length of the right pane.
+ /// </summary>
+ public static IUISplitGrid RightPaneLength(this IUISplitGrid element, UIGridLength length)
+ {
+ GuardSplitGridLength(length);
+ ((UISplitGrid)element).RightOrBottomCellLength = length;
+ return element;
+ }
+
+ /// <summary>
+ /// Set the length of the bottom pane.
+ /// </summary>
+ public static IUISplitGrid BottomPaneLength(this IUISplitGrid element, UIGridLength length)
+ {
+ GuardSplitGridLength(length);
+ ((UISplitGrid)element).RightOrBottomCellLength = length;
+ return element;
+ }
+
+ /// <summary>
+ /// Set the element to display in the top pane.
+ /// </summary>
+ public static IUISplitGrid WithTopPaneChild(this IUISplitGrid element, IUIElement? child)
+ {
+ ((UISplitGrid)element).LeftOrTopCellContent = child;
+ return element;
+ }
+
+ /// <summary>
+ /// Set the element to display in the left pane.
+ /// </summary>
+ public static IUISplitGrid WithLeftPaneChild(this IUISplitGrid element, IUIElement? child)
+ {
+ ((UISplitGrid)element).LeftOrTopCellContent = child;
+ return element;
+ }
+
+ /// <summary>
+ /// Set the element to display in the right pane.
+ /// </summary>
+ public static IUISplitGrid WithRightPaneChild(this IUISplitGrid element, IUIElement? child)
+ {
+ ((UISplitGrid)element).RightOrBottomCellContent = child;
+ return element;
+ }
+
+ /// <summary>
+ /// Set the element to display in the bottom pane.
+ /// </summary>
+ public static IUISplitGrid WithBottomPaneChild(this IUISplitGrid element, IUIElement? child)
+ {
+ ((UISplitGrid)element).RightOrBottomCellContent = child;
+ return element;
+ }
+
+ /// <summary>
+ /// Set the minimum length of a cell, in pixels.
+ /// </summary>
+ public static IUISplitGrid MinimumLength(this IUISplitGrid element, int minimumLength)
+ {
+ ((UISplitGrid)element).MinimumCellLength = minimumLength;
+ return element;
+ }
+
+ private static void GuardSplitGridLength(UIGridLength length)
+ {
+ if (length.IsAuto)
+ {
+ ThrowHelper.ThrowArgumentException(nameof(length), $"{nameof(UIGridLength)}.{nameof(UIGridLength.Auto)} is not supported in {nameof(IUISplitGrid)}.");
+ }
+ }
+}
diff --git a/src/app/dev/DevToys.Blazor/Components/UIElements/UIElementPresenter.razor b/src/app/dev/DevToys.Blazor/Components/UIElements/UIElementPresenter.razor
index c47c25172..78637b1ca 100644
--- a/src/app/dev/DevToys.Blazor/Components/UIElements/UIElementPresenter.razor
+++ b/src/app/dev/DevToys.Blazor/Components/UIElements/UIElementPresenter.razor
@@ -18,6 +18,10 @@
<UIGridPresenter UIGrid="@grid" />
break;
+ case IUISplitGrid splitGrid:
+ <UISplitGridPresenter UISplitGrid="@splitGrid" />
+ break;
+
case IUIButton button:
<UIButtonPresenter UIButton="@button" />
break;
diff --git a/src/app/dev/DevToys.Blazor/Components/UIElements/UISplitGridPresenter.razor b/src/app/dev/DevToys.Blazor/Components/UIElements/UISplitGridPresenter.razor
new file mode 100644
index 000000000..bed577cd5
--- /dev/null
+++ b/src/app/dev/DevToys.Blazor/Components/UIElements/UISplitGridPresenter.razor
@@ -0,0 +1,20 @@
+@namespace DevToys.Blazor.Components.UIElements
+@using DevToys.Api;
+@inherits ComponentBase
+
+<SplitGrid id="@UISplitGrid.Id"
+ IsVisible="@UISplitGrid.IsVisible"
+ IsEnabled="@UISplitGrid.IsEnabled"
+ HorizontalAlignment="@UISplitGrid.HorizontalAlignment"
+ VerticalAlignment="@UISplitGrid.VerticalAlignment"
+ GutterOrientation="@UISplitGrid.Orientation"
+ MinimumCellSize="@UISplitGrid.MinimumCellLength"
+ LeftOrTopCellSize="@UISplitGrid.LeftOrTopCellLength"
+ RightOrBottomCellSize="@UISplitGrid.RightOrBottomCellLength">
+ <LeftOrTopCellContent>
+ <UIElementPresenter UIElement="@UISplitGrid.LeftOrTopCellContent" />
+ </LeftOrTopCellContent>
+ <RightOrBottomCellContent>
+ <UIElementPresenter UIElement="@UISplitGrid.RightOrBottomCellContent" />
+ </RightOrBottomCellContent>
+</SplitGrid>
\ No newline at end of file
diff --git a/src/app/dev/DevToys.Blazor/Components/UIElements/UISplitGridPresenter.razor.cs b/src/app/dev/DevToys.Blazor/Components/UIElements/UISplitGridPresenter.razor.cs
new file mode 100644
index 000000000..ec0e91fa5
--- /dev/null
+++ b/src/app/dev/DevToys.Blazor/Components/UIElements/UISplitGridPresenter.razor.cs
@@ -0,0 +1,7 @@
+namespace DevToys.Blazor.Components.UIElements;
+
+public partial class UISplitGridPresenter : ComponentBase
+{
+ [Parameter]
+ public IUISplitGrid UISplitGrid { get; set; } = default!;
+}
diff --git a/src/app/dev/DevToys.Tools/Tools/Settings/SettingsGuiTool.cs b/src/app/dev/DevToys.Tools/Tools/Settings/SettingsGuiTool.cs
index 4b6a20b6d..f5e4cc277 100644
--- a/src/app/dev/DevToys.Tools/Tools/Settings/SettingsGuiTool.cs
+++ b/src/app/dev/DevToys.Tools/Tools/Settings/SettingsGuiTool.cs
@@ -118,13 +118,24 @@ internal sealed class SettingsGuiTool : IGuiTool
.OnFilesSelected(OnFilesSelected)),
Cell(
GridTestRow.InputTextBox, GridTestColumn.UniqueColumn,
- MultilineTextInput()
- .Title("Monaco editor")
- .Extendable()
- .CanCopyWhenEditable()
- .Text("{\"hello\": \"there\"}")
- .Language("json")
- .CommandBarExtraContent(Button().Text("None"))),
+ SplitGrid()
+ .Vertical()
+ .WithLeftPaneChild(
+ MultilineTextInput()
+ .Title("Monaco editor")
+ .Extendable()
+ .CanCopyWhenEditable()
+ .Text("{\"hello\": \"there\"}")
+ .Language("json")
+ .CommandBarExtraContent(Button().Text("None")))
+ .WithRightPaneChild(
+ MultilineTextInput()
+ .Title("Monaco editor")
+ .Extendable()
+ .CanCopyWhenEditable()
+ .Text("{\"hello\": \"there\"}")
+ .Language("json")
+ .CommandBarExtraContent(Button().Text("None")))),
Cell(
GridTestRow.Output, GridTestColumn.UniqueColumn,
SingleLineTextInput().Title("Read-write text input with copy").ReadOnly())),