Skip to content

Commit 4f45f8c

Browse files
committed
Add support for UTF-32 glyphs in icon componentsgit
1 parent 20136a6 commit 4f45f8c

17 files changed

+352
-27
lines changed

src/app/dev/DevToys.Api/Tool/GUI/Components/IUIButton.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public interface IUIButton : IUIElement
5757
}
5858

5959
[DebuggerDisplay($"Id = {{{nameof(Id)}}}, Text = {{{nameof(Text)}}}")]
60-
internal sealed class UIButton : UIElement, IUIButton
60+
internal class UIButton : UIElement, IUIButton
6161
{
6262
private bool _isAccent;
6363
private bool _isHyperlink;

src/app/dev/DevToys.Api/Tool/GUI/Components/IUIDropDownButton.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public interface IUIDropDownButton : IUIElement
4747
}
4848

4949
[DebuggerDisplay($"Id = {{{nameof(Id)}}}, Text = {{{nameof(Text)}}}")]
50-
internal sealed class UIDropDownButton : UIElement, IUIDropDownButton
50+
internal class UIDropDownButton : UIElement, IUIDropDownButton
5151
{
5252
private IUIDropDownMenuItem[]? _menuItems;
5353
private string? _text;

src/app/dev/DevToys.Api/Tool/GUI/Components/IUIDropDownMenuItem.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public interface IUIDropDownMenuItem
5252
}
5353

5454
[DebuggerDisplay($"Text = {{{nameof(Text)}}}")]
55-
internal sealed class UIDropDownMenuItem : ViewModelBase, IUIDropDownMenuItem
55+
internal class UIDropDownMenuItem : ViewModelBase, IUIDropDownMenuItem
5656
{
5757
private bool _isEnabled = true;
5858
private string? _text;

src/app/dev/DevToys.Api/Tool/GUI/Components/IUIIcon.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public interface IUIIcon : IUIElement
3737
}
3838

3939
[DebuggerDisplay($"Id = {{{nameof(Id)}}}, Glyph = {{{nameof(Glyph)}}}")]
40-
internal sealed class UIIcon : UIElement, IUIIcon
40+
internal class UIIcon : UIElement, IUIIcon
4141
{
4242
private string _fontName;
4343
private char _glyph;
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
namespace DevToys.Api;
2+
3+
/// <summary>
4+
/// Provides an interface for UI components that support UTF-32 glyphs.
5+
/// </summary>
6+
public interface IUIUtf32GlyphProvider
7+
{
8+
/// <summary>
9+
/// Gets the UTF-32 code point of the glyph.
10+
/// </summary>
11+
int Utf32Glyph { get; }
12+
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
namespace DevToys.Api;
2+
3+
/// <summary>
4+
/// A component that represents an icon with a UTF-32 glyph.
5+
/// </summary>
6+
public interface IUIUtf32Icon : IUIIcon, IUIUtf32GlyphProvider
7+
{
8+
}
9+
10+
[DebuggerDisplay($"Id = {{{nameof(Id)}}}, Glyph = {{{nameof(Glyph)}}}")]
11+
internal sealed class UIUtf32Icon : UIIcon, IUIUtf32Icon
12+
{
13+
private int _utf32Glyph;
14+
15+
internal UIUtf32Icon(string? id, string fontName, int glyph)
16+
: base(id, fontName, (char)0)
17+
{
18+
_utf32Glyph = glyph;
19+
Guard.IsNotNullOrWhiteSpace(FontName);
20+
}
21+
22+
public int Utf32Glyph
23+
{
24+
get => _utf32Glyph;
25+
internal set => SetPropertyValue(ref _utf32Glyph, value, Glyph32Changed);
26+
}
27+
28+
public event EventHandler? Glyph32Changed;
29+
}
30+
31+
public static partial class GUI
32+
{
33+
34+
/// <summary>
35+
/// A component that represents an icon with a UTF-32 glyph.
36+
/// </summary>
37+
/// <param name="id">An optional unique identifier for this UI element.</param>
38+
/// <param name="fontName">The name of the font containing the icon.</param>
39+
/// <param name="glyph">The UTF-32 code point of the icon glyph.</param>
40+
public static IUIUtf32Icon Icon(string? id, string fontName, int glyph)
41+
{
42+
return new UIUtf32Icon(id, fontName, glyph);
43+
}
44+
45+
/// <summary>
46+
/// A component that represents an icon with a UTF-32 glyph.
47+
/// </summary>
48+
/// <param name="fontName">The name of the font containing the icon.</param>
49+
/// <param name="glyph">The UTF-32 code point of the icon glyph.</param>
50+
public static IUIUtf32Icon Icon(string fontName, int glyph)
51+
{
52+
return new UIUtf32Icon(null, fontName, glyph);
53+
}
54+
55+
/// <summary>
56+
/// Sets the <see cref="UIUtf32Icon.Utf32Glyph"/> of the icon.
57+
/// </summary>
58+
/// <param name="element">The <see cref="UIUtf32Icon"/> instance.</param>
59+
/// <param name="glyph">The UTF-32 code point of the icon glyph.</param>
60+
public static IUIUtf32Icon Glyph(this IUIUtf32Icon element, int glyph)
61+
{
62+
((UIUtf32Icon)element).Utf32Glyph = glyph;
63+
return element;
64+
}
65+
}
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
namespace DevToys.Api;
2+
3+
/// <summary>
4+
/// A component that represents a button, which reacts when clicking on it.
5+
/// </summary>
6+
public interface IUIUtf32IconButton : IUIButton, IUIUtf32IconProvider
7+
{
8+
}
9+
10+
[DebuggerDisplay($"Id = {{{nameof(Id)}}}, Text = {{{nameof(Text)}}}")]
11+
internal sealed class UIUtf32IconButton : UIButton, IUIUtf32IconButton
12+
{
13+
private int _iconGlyph;
14+
15+
internal UIUtf32IconButton(string? id)
16+
: base(id)
17+
{
18+
}
19+
20+
public int Utf32IconGlyph
21+
{
22+
get => _iconGlyph;
23+
internal set => SetPropertyValue(ref _iconGlyph, value, Utf32IconGlyphChanged);
24+
}
25+
public event EventHandler? Utf32IconGlyphChanged;
26+
}
27+
28+
/// <summary>
29+
/// Provides a set of extension methods for various UI components.
30+
/// </summary>
31+
public static partial class GUI
32+
{
33+
/// <summary>
34+
/// Create a component that represents a button, which reacts when clicking on it.
35+
/// </summary>
36+
/// <returns>The created <see cref="IUIButton"/> instance.</returns>
37+
public static IUIUtf32IconButton Button(string iconFontName, int iconGlyph)
38+
{
39+
return Button(null, iconFontName, iconGlyph);
40+
}
41+
42+
/// <summary>
43+
/// Create a component that represents a button, which reacts when clicking on it.
44+
/// </summary>
45+
/// <param name="id">An optional unique identifier for this UI element.</param>
46+
/// <param name="iconFontName">The name of the font containing the icon.</param>
47+
/// <param name="iconGlyph">The UTF-32 glyph corresponding to the icon in the <paramref name="iconFontName"/>.</param>
48+
/// <returns>The created <see cref="IUIUtf32IconButton"/> instance.</returns>
49+
public static IUIUtf32IconButton Button(string? id, string iconFontName, int iconGlyph)
50+
{
51+
return new UIUtf32IconButton(id).Icon(iconFontName, iconGlyph);
52+
}
53+
54+
/// <summary>
55+
/// Create a component that represents a button, which reacts when clicking on it.
56+
/// </summary>
57+
/// <param name="id">An optional unique identifier for this UI element.</param>
58+
/// <param name="iconFontName">The name of the font containing the icon.</param>
59+
/// <param name="iconGlyph">The UTF-32 glyph corresponding to the icon in the <paramref name="iconFontName"/>.</param>
60+
/// <param name="text">The text to display in the button.</param>
61+
/// <returns>The created <see cref="IUIUtf32IconButton"/> instance.</returns>
62+
public static IUIUtf32IconButton Button(string? id, string iconFontName, int iconGlyph, string text)
63+
{
64+
return (IUIUtf32IconButton)new UIUtf32IconButton(id).Icon(iconFontName, iconGlyph).Text(text);
65+
}
66+
67+
/// <summary>
68+
/// Create a component that represents a button, which reacts when clicking on it.
69+
/// </summary>
70+
/// <param name="iconFontName">The name of the font containing the icon.</param>
71+
/// <param name="iconGlyph">The UTF-32 glyph corresponding to the icon in the <paramref name="iconFontName"/>.</param>
72+
/// <param name="text">The text to display in the button.</param>
73+
/// <returns>The created <see cref="IUIUtf32IconButton"/> instance.</returns>
74+
public static IUIUtf32IconButton Button(string iconFontName, int iconGlyph, string text)
75+
{
76+
return Button(null, iconFontName, iconGlyph, text);
77+
}
78+
79+
/// <summary>
80+
/// Sets the icon of the button.
81+
/// </summary>
82+
/// <param name="element">The <see cref="IUIUtf32IconButton"/> instance.</param>
83+
/// <param name="fontName">The name of the font containing the icon.</param>
84+
/// <param name="glyph">The UTF-32 glyph corresponding to the icon in the <paramref name="fontName"/>.</param>
85+
/// <returns>The updated <see cref="IUIUtf32IconButton"/> instance.</returns>
86+
public static IUIUtf32IconButton Icon(this IUIUtf32IconButton element, string fontName, int glyph)
87+
{
88+
var button = (UIUtf32IconButton)element;
89+
button.IconFontName = fontName;
90+
button.Utf32IconGlyph = glyph;
91+
return button;
92+
}
93+
}
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
namespace DevToys.Api;
2+
3+
/// <summary>
4+
/// A component that represents a drop down button where the user can click on a menu item.
5+
/// </summary>
6+
public interface IUIUtf32IconDropDownButton : IUIDropDownButton, IUIUtf32IconProvider
7+
{
8+
}
9+
10+
[DebuggerDisplay($"Id = {{{nameof(Id)}}}, Text = {{{nameof(Text)}}}")]
11+
internal sealed class UIUtf32IconDropDownButton : UIDropDownButton, IUIUtf32IconDropDownButton
12+
{
13+
private int _utf32IconGlyph;
14+
internal UIUtf32IconDropDownButton(string? id)
15+
: base(id)
16+
{
17+
}
18+
19+
public int Utf32IconGlyph
20+
{
21+
get => _utf32IconGlyph;
22+
internal set => SetPropertyValue(ref _utf32IconGlyph, value, Utf32IconGlyphChanged);
23+
}
24+
25+
public event EventHandler? Utf32IconGlyphChanged;
26+
}
27+
28+
public static partial class GUI
29+
{
30+
/// <summary>
31+
/// Create a component that represents a drop down button where the user can click on a menu item.
32+
/// </summary>
33+
/// <param name="iconFontName">The name of the font containing the icon.</param>
34+
/// <param name="iconGlyph">The UTF-32 glyph corresponding to the icon in the <paramref name="iconFontName"/>.</param>
35+
public static IUIUtf32IconDropDownButton DropDownButton(string iconFontName, int iconGlyph)
36+
{
37+
return DropDownButton(null, iconFontName, iconGlyph);
38+
}
39+
40+
/// <summary>
41+
/// Create a component that represents a drop down button where the user can click on a menu item.
42+
/// </summary>
43+
/// <param name="id">An optional unique identifier for this UI element.</param>
44+
/// <param name="iconFontName">The name of the font containing the icon.</param>
45+
/// <param name="iconGlyph">The UTF-32 glyph corresponding to the icon in the <paramref name="iconFontName"/>.</param>
46+
public static IUIUtf32IconDropDownButton DropDownButton(string? id, string iconFontName, int iconGlyph)
47+
{
48+
return new UIUtf32IconDropDownButton(id).Icon(iconFontName, iconGlyph);
49+
}
50+
51+
/// <summary>
52+
/// Create a component that represents a drop down button where the user can click on a menu item.
53+
/// </summary>
54+
/// <param name="id">An optional unique identifier for this UI element.</param>
55+
/// <param name="iconFontName">The name of the font containing the icon.</param>
56+
/// <param name="iconGlyph">The UTF-32 glyph corresponding to the icon in the <paramref name="iconFontName"/>.</param>
57+
/// <param name="text">The text to display in the drop down button.</param>
58+
public static IUIUtf32IconDropDownButton DropDownButton(string? id, string iconFontName, int iconGlyph, string text)
59+
{
60+
return (IUIUtf32IconDropDownButton)new UIUtf32IconDropDownButton(id).Icon(iconFontName, iconGlyph).Text(text);
61+
}
62+
63+
/// <summary>
64+
/// Create a component that represents a drop down button where the user can click on a menu item.
65+
/// </summary>
66+
/// <param name="iconFontName">The name of the font containing the icon.</param>
67+
/// <param name="iconGlyph">The UTF-32 glyph corresponding to the icon in the <paramref name="iconFontName"/>.</param>
68+
/// <param name="text">The text to display in the drop down button.</param>
69+
public static IUIUtf32IconDropDownButton DropDownButton(string iconFontName, int iconGlyph, string text)
70+
{
71+
return DropDownButton(null, iconFontName, iconGlyph, text);
72+
}
73+
74+
/// <summary>
75+
/// Sets the icon of the drop down button.
76+
/// </summary>
77+
public static IUIUtf32IconDropDownButton Icon(this IUIUtf32IconDropDownButton element, string fontName, int glyph)
78+
{
79+
var button = (UIUtf32IconDropDownButton)element;
80+
button.IconFontName = fontName;
81+
button.Utf32IconGlyph = glyph;
82+
return button;
83+
}
84+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
namespace DevToys.Api;
2+
3+
/// <summary>
4+
/// A component that represents a menu item, which reacts when clicking on it.
5+
/// </summary>
6+
public interface IUIUtf32IconDropDownMenuItem : IUIDropDownMenuItem, IUIUtf32IconProvider
7+
{
8+
}
9+
10+
[DebuggerDisplay($"Text = {{{nameof(Text)}}}")]
11+
internal sealed class UIUtf32IconDropDownMenuItem : UIDropDownMenuItem, IUIUtf32IconDropDownMenuItem
12+
{
13+
private int _utf32IconGlyph;
14+
public int Utf32IconGlyph
15+
{
16+
get => _utf32IconGlyph;
17+
internal set => SetPropertyValue(ref _utf32IconGlyph, value, Utf32IconGlyphChanged);
18+
}
19+
20+
public event EventHandler? Utf32IconGlyphChanged;
21+
}
22+
23+
public static partial class GUI
24+
{
25+
/// <summary>
26+
/// Create a component that represents a menu item, which reacts when clicking on it.
27+
/// </summary>
28+
/// <param name="iconFontName">The name of the font containing the icon.</param>
29+
/// <param name="iconGlyph">The UTF-32 glyph corresponding to the icon in the <paramref name="iconFontName"/>.</param>
30+
public static IUIUtf32IconDropDownMenuItem DropDownMenuItem(string iconFontName, int iconGlyph)
31+
{
32+
return new UIUtf32IconDropDownMenuItem().Icon(iconFontName, iconGlyph);
33+
}
34+
35+
/// <summary>
36+
/// Create a component that represents a menu item, which reacts when clicking on it.
37+
/// </summary>
38+
/// <param name="iconFontName">The name of the font containing the icon.</param>
39+
/// <param name="iconGlyph">The UTF-32 glyph corresponding to the icon in the <paramref name="iconFontName"/>.</param>
40+
/// <param name="text">The text to display in the menu item.</param>
41+
public static IUIUtf32IconDropDownMenuItem DropDownMenuItem(string iconFontName, int iconGlyph, string text)
42+
{
43+
return (IUIUtf32IconDropDownMenuItem)DropDownMenuItem(iconFontName, iconGlyph).Text(text);
44+
}
45+
46+
/// <summary>
47+
/// Sets the icon of the menu item.
48+
/// </summary>
49+
public static IUIUtf32IconDropDownMenuItem Icon(this IUIUtf32IconDropDownMenuItem element, string fontName, int glyph)
50+
{
51+
var menuItem = (UIUtf32IconDropDownMenuItem)element;
52+
menuItem.IconFontName = fontName;
53+
menuItem.Utf32IconGlyph = glyph;
54+
return menuItem;
55+
}
56+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
namespace DevToys.Api;
2+
3+
/// <summary>
4+
/// Provides an interface for UI components that support UTF-32 icons.
5+
/// </summary>
6+
public interface IUIUtf32IconProvider
7+
{
8+
/// <summary>
9+
/// Gets the UTF-32 code point of the icon glyph.
10+
/// </summary>
11+
int Utf32IconGlyph { get; }
12+
}

0 commit comments

Comments
 (0)