-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for UTF-32 glyphs in icon componentsgit (#1435)
- Loading branch information
Showing
17 changed files
with
352 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
src/app/dev/DevToys.Api/Tool/GUI/Components/IUIUtf32GlyphProvider.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
namespace DevToys.Api; | ||
|
||
/// <summary> | ||
/// Provides an interface for UI components that support UTF-32 glyphs. | ||
/// </summary> | ||
public interface IUIUtf32GlyphProvider | ||
{ | ||
/// <summary> | ||
/// Gets the UTF-32 code point of the glyph. | ||
/// </summary> | ||
int Utf32Glyph { get; } | ||
} |
65 changes: 65 additions & 0 deletions
65
src/app/dev/DevToys.Api/Tool/GUI/Components/IUIUtf32Icon.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
namespace DevToys.Api; | ||
|
||
/// <summary> | ||
/// A component that represents an icon with a UTF-32 glyph. | ||
/// </summary> | ||
public interface IUIUtf32Icon : IUIIcon, IUIUtf32GlyphProvider | ||
{ | ||
} | ||
|
||
[DebuggerDisplay($"Id = {{{nameof(Id)}}}, Glyph = {{{nameof(Glyph)}}}")] | ||
internal sealed class UIUtf32Icon : UIIcon, IUIUtf32Icon | ||
{ | ||
private int _utf32Glyph; | ||
|
||
internal UIUtf32Icon(string? id, string fontName, int glyph) | ||
: base(id, fontName, (char)0) | ||
{ | ||
_utf32Glyph = glyph; | ||
Guard.IsNotNullOrWhiteSpace(FontName); | ||
} | ||
|
||
public int Utf32Glyph | ||
{ | ||
get => _utf32Glyph; | ||
internal set => SetPropertyValue(ref _utf32Glyph, value, Glyph32Changed); | ||
} | ||
|
||
public event EventHandler? Glyph32Changed; | ||
} | ||
|
||
public static partial class GUI | ||
{ | ||
|
||
/// <summary> | ||
/// A component that represents an icon with a UTF-32 glyph. | ||
/// </summary> | ||
/// <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 UTF-32 code point of the icon glyph.</param> | ||
public static IUIUtf32Icon Icon(string? id, string fontName, int glyph) | ||
{ | ||
return new UIUtf32Icon(id, fontName, glyph); | ||
} | ||
|
||
/// <summary> | ||
/// A component that represents an icon with a UTF-32 glyph. | ||
/// </summary> | ||
/// <param name="fontName">The name of the font containing the icon.</param> | ||
/// <param name="glyph">The UTF-32 code point of the icon glyph.</param> | ||
public static IUIUtf32Icon Icon(string fontName, int glyph) | ||
{ | ||
return new UIUtf32Icon(null, fontName, glyph); | ||
} | ||
|
||
/// <summary> | ||
/// Sets the <see cref="UIUtf32Icon.Utf32Glyph"/> of the icon. | ||
/// </summary> | ||
/// <param name="element">The <see cref="UIUtf32Icon"/> instance.</param> | ||
/// <param name="glyph">The UTF-32 code point of the icon glyph.</param> | ||
public static IUIUtf32Icon Glyph(this IUIUtf32Icon element, int glyph) | ||
{ | ||
((UIUtf32Icon)element).Utf32Glyph = glyph; | ||
return element; | ||
} | ||
} |
93 changes: 93 additions & 0 deletions
93
src/app/dev/DevToys.Api/Tool/GUI/Components/IUIUtf32IconButton.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
namespace DevToys.Api; | ||
|
||
/// <summary> | ||
/// A component that represents a button, which reacts when clicking on it. | ||
/// </summary> | ||
public interface IUIUtf32IconButton : IUIButton, IUIUtf32IconProvider | ||
{ | ||
} | ||
|
||
[DebuggerDisplay($"Id = {{{nameof(Id)}}}, Text = {{{nameof(Text)}}}")] | ||
internal sealed class UIUtf32IconButton : UIButton, IUIUtf32IconButton | ||
{ | ||
private int _iconGlyph; | ||
|
||
internal UIUtf32IconButton(string? id) | ||
: base(id) | ||
{ | ||
} | ||
|
||
public int Utf32IconGlyph | ||
{ | ||
get => _iconGlyph; | ||
internal set => SetPropertyValue(ref _iconGlyph, value, Utf32IconGlyphChanged); | ||
} | ||
public event EventHandler? Utf32IconGlyphChanged; | ||
} | ||
|
||
/// <summary> | ||
/// Provides a set of extension methods for various UI components. | ||
/// </summary> | ||
public static partial class GUI | ||
{ | ||
/// <summary> | ||
/// Create a component that represents a button, which reacts when clicking on it. | ||
/// </summary> | ||
/// <returns>The created <see cref="IUIButton"/> instance.</returns> | ||
public static IUIUtf32IconButton Button(string iconFontName, int iconGlyph) | ||
{ | ||
return Button(null, iconFontName, iconGlyph); | ||
} | ||
|
||
/// <summary> | ||
/// Create a component that represents a button, which reacts when clicking on it. | ||
/// </summary> | ||
/// <param name="id">An optional unique identifier for this UI element.</param> | ||
/// <param name="iconFontName">The name of the font containing the icon.</param> | ||
/// <param name="iconGlyph">The UTF-32 glyph corresponding to the icon in the <paramref name="iconFontName"/>.</param> | ||
/// <returns>The created <see cref="IUIUtf32IconButton"/> instance.</returns> | ||
public static IUIUtf32IconButton Button(string? id, string iconFontName, int iconGlyph) | ||
{ | ||
return new UIUtf32IconButton(id).Icon(iconFontName, iconGlyph); | ||
} | ||
|
||
/// <summary> | ||
/// Create a component that represents a button, which reacts when clicking on it. | ||
/// </summary> | ||
/// <param name="id">An optional unique identifier for this UI element.</param> | ||
/// <param name="iconFontName">The name of the font containing the icon.</param> | ||
/// <param name="iconGlyph">The UTF-32 glyph corresponding to the icon in the <paramref name="iconFontName"/>.</param> | ||
/// <param name="text">The text to display in the button.</param> | ||
/// <returns>The created <see cref="IUIUtf32IconButton"/> instance.</returns> | ||
public static IUIUtf32IconButton Button(string? id, string iconFontName, int iconGlyph, string text) | ||
{ | ||
return (IUIUtf32IconButton)new UIUtf32IconButton(id).Icon(iconFontName, iconGlyph).Text(text); | ||
} | ||
|
||
/// <summary> | ||
/// Create a component that represents a button, which reacts when clicking on it. | ||
/// </summary> | ||
/// <param name="iconFontName">The name of the font containing the icon.</param> | ||
/// <param name="iconGlyph">The UTF-32 glyph corresponding to the icon in the <paramref name="iconFontName"/>.</param> | ||
/// <param name="text">The text to display in the button.</param> | ||
/// <returns>The created <see cref="IUIUtf32IconButton"/> instance.</returns> | ||
public static IUIUtf32IconButton Button(string iconFontName, int iconGlyph, string text) | ||
{ | ||
return Button(null, iconFontName, iconGlyph, text); | ||
} | ||
|
||
/// <summary> | ||
/// Sets the icon of the button. | ||
/// </summary> | ||
/// <param name="element">The <see cref="IUIUtf32IconButton"/> instance.</param> | ||
/// <param name="fontName">The name of the font containing the icon.</param> | ||
/// <param name="glyph">The UTF-32 glyph corresponding to the icon in the <paramref name="fontName"/>.</param> | ||
/// <returns>The updated <see cref="IUIUtf32IconButton"/> instance.</returns> | ||
public static IUIUtf32IconButton Icon(this IUIUtf32IconButton element, string fontName, int glyph) | ||
{ | ||
var button = (UIUtf32IconButton)element; | ||
button.IconFontName = fontName; | ||
button.Utf32IconGlyph = glyph; | ||
return button; | ||
} | ||
} |
84 changes: 84 additions & 0 deletions
84
src/app/dev/DevToys.Api/Tool/GUI/Components/IUIUtf32IconDropDownButton.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
namespace DevToys.Api; | ||
|
||
/// <summary> | ||
/// A component that represents a drop down button where the user can click on a menu item. | ||
/// </summary> | ||
public interface IUIUtf32IconDropDownButton : IUIDropDownButton, IUIUtf32IconProvider | ||
{ | ||
} | ||
|
||
[DebuggerDisplay($"Id = {{{nameof(Id)}}}, Text = {{{nameof(Text)}}}")] | ||
internal sealed class UIUtf32IconDropDownButton : UIDropDownButton, IUIUtf32IconDropDownButton | ||
{ | ||
private int _utf32IconGlyph; | ||
internal UIUtf32IconDropDownButton(string? id) | ||
: base(id) | ||
{ | ||
} | ||
|
||
public int Utf32IconGlyph | ||
{ | ||
get => _utf32IconGlyph; | ||
internal set => SetPropertyValue(ref _utf32IconGlyph, value, Utf32IconGlyphChanged); | ||
} | ||
|
||
public event EventHandler? Utf32IconGlyphChanged; | ||
} | ||
|
||
public static partial class GUI | ||
{ | ||
/// <summary> | ||
/// Create a component that represents a drop down button where the user can click on a menu item. | ||
/// </summary> | ||
/// <param name="iconFontName">The name of the font containing the icon.</param> | ||
/// <param name="iconGlyph">The UTF-32 glyph corresponding to the icon in the <paramref name="iconFontName"/>.</param> | ||
public static IUIUtf32IconDropDownButton DropDownButton(string iconFontName, int iconGlyph) | ||
{ | ||
return DropDownButton(null, iconFontName, iconGlyph); | ||
} | ||
|
||
/// <summary> | ||
/// Create a component that represents a drop down button where the user can click on a menu item. | ||
/// </summary> | ||
/// <param name="id">An optional unique identifier for this UI element.</param> | ||
/// <param name="iconFontName">The name of the font containing the icon.</param> | ||
/// <param name="iconGlyph">The UTF-32 glyph corresponding to the icon in the <paramref name="iconFontName"/>.</param> | ||
public static IUIUtf32IconDropDownButton DropDownButton(string? id, string iconFontName, int iconGlyph) | ||
{ | ||
return new UIUtf32IconDropDownButton(id).Icon(iconFontName, iconGlyph); | ||
} | ||
|
||
/// <summary> | ||
/// Create a component that represents a drop down button where the user can click on a menu item. | ||
/// </summary> | ||
/// <param name="id">An optional unique identifier for this UI element.</param> | ||
/// <param name="iconFontName">The name of the font containing the icon.</param> | ||
/// <param name="iconGlyph">The UTF-32 glyph corresponding to the icon in the <paramref name="iconFontName"/>.</param> | ||
/// <param name="text">The text to display in the drop down button.</param> | ||
public static IUIUtf32IconDropDownButton DropDownButton(string? id, string iconFontName, int iconGlyph, string text) | ||
{ | ||
return (IUIUtf32IconDropDownButton)new UIUtf32IconDropDownButton(id).Icon(iconFontName, iconGlyph).Text(text); | ||
} | ||
|
||
/// <summary> | ||
/// Create a component that represents a drop down button where the user can click on a menu item. | ||
/// </summary> | ||
/// <param name="iconFontName">The name of the font containing the icon.</param> | ||
/// <param name="iconGlyph">The UTF-32 glyph corresponding to the icon in the <paramref name="iconFontName"/>.</param> | ||
/// <param name="text">The text to display in the drop down button.</param> | ||
public static IUIUtf32IconDropDownButton DropDownButton(string iconFontName, int iconGlyph, string text) | ||
{ | ||
return DropDownButton(null, iconFontName, iconGlyph, text); | ||
} | ||
|
||
/// <summary> | ||
/// Sets the icon of the drop down button. | ||
/// </summary> | ||
public static IUIUtf32IconDropDownButton Icon(this IUIUtf32IconDropDownButton element, string fontName, int glyph) | ||
{ | ||
var button = (UIUtf32IconDropDownButton)element; | ||
button.IconFontName = fontName; | ||
button.Utf32IconGlyph = glyph; | ||
return button; | ||
} | ||
} |
56 changes: 56 additions & 0 deletions
56
src/app/dev/DevToys.Api/Tool/GUI/Components/IUIUtf32IconDropDownMenuItem.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
namespace DevToys.Api; | ||
|
||
/// <summary> | ||
/// A component that represents a menu item, which reacts when clicking on it. | ||
/// </summary> | ||
public interface IUIUtf32IconDropDownMenuItem : IUIDropDownMenuItem, IUIUtf32IconProvider | ||
{ | ||
} | ||
|
||
[DebuggerDisplay($"Text = {{{nameof(Text)}}}")] | ||
internal sealed class UIUtf32IconDropDownMenuItem : UIDropDownMenuItem, IUIUtf32IconDropDownMenuItem | ||
{ | ||
private int _utf32IconGlyph; | ||
public int Utf32IconGlyph | ||
{ | ||
get => _utf32IconGlyph; | ||
internal set => SetPropertyValue(ref _utf32IconGlyph, value, Utf32IconGlyphChanged); | ||
} | ||
|
||
public event EventHandler? Utf32IconGlyphChanged; | ||
} | ||
|
||
public static partial class GUI | ||
{ | ||
/// <summary> | ||
/// Create a component that represents a menu item, which reacts when clicking on it. | ||
/// </summary> | ||
/// <param name="iconFontName">The name of the font containing the icon.</param> | ||
/// <param name="iconGlyph">The UTF-32 glyph corresponding to the icon in the <paramref name="iconFontName"/>.</param> | ||
public static IUIUtf32IconDropDownMenuItem DropDownMenuItem(string iconFontName, int iconGlyph) | ||
{ | ||
return new UIUtf32IconDropDownMenuItem().Icon(iconFontName, iconGlyph); | ||
} | ||
|
||
/// <summary> | ||
/// Create a component that represents a menu item, which reacts when clicking on it. | ||
/// </summary> | ||
/// <param name="iconFontName">The name of the font containing the icon.</param> | ||
/// <param name="iconGlyph">The UTF-32 glyph corresponding to the icon in the <paramref name="iconFontName"/>.</param> | ||
/// <param name="text">The text to display in the menu item.</param> | ||
public static IUIUtf32IconDropDownMenuItem DropDownMenuItem(string iconFontName, int iconGlyph, string text) | ||
{ | ||
return (IUIUtf32IconDropDownMenuItem)DropDownMenuItem(iconFontName, iconGlyph).Text(text); | ||
} | ||
|
||
/// <summary> | ||
/// Sets the icon of the menu item. | ||
/// </summary> | ||
public static IUIUtf32IconDropDownMenuItem Icon(this IUIUtf32IconDropDownMenuItem element, string fontName, int glyph) | ||
{ | ||
var menuItem = (UIUtf32IconDropDownMenuItem)element; | ||
menuItem.IconFontName = fontName; | ||
menuItem.Utf32IconGlyph = glyph; | ||
return menuItem; | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
src/app/dev/DevToys.Api/Tool/GUI/Components/IUIUtf32IconProvider.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
namespace DevToys.Api; | ||
|
||
/// <summary> | ||
/// Provides an interface for UI components that support UTF-32 icons. | ||
/// </summary> | ||
public interface IUIUtf32IconProvider | ||
{ | ||
/// <summary> | ||
/// Gets the UTF-32 code point of the icon glyph. | ||
/// </summary> | ||
int Utf32IconGlyph { get; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.