From 6091128c61bfa40270f23375578e46b61f56b9b0 Mon Sep 17 00:00:00 2001 From: Pilzinsel64 Date: Mon, 8 Jul 2024 05:14:16 +0000 Subject: [PATCH] Pilz.UI aktualisieren --- Pilz.UI.md | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) diff --git a/Pilz.UI.md b/Pilz.UI.md index 3e55007..5e1228d 100644 --- a/Pilz.UI.md +++ b/Pilz.UI.md @@ -102,3 +102,75 @@ Ensure you unregister your handlers from the event on Dispose or deconstructor! DialogBase.DialogClosed -= DialogBase_DialogClosed; } ``` + +# Symbols + +## Setup SymbolFactory + +Create a new directory, we call it `Symbols` here. + +![image](uploads/c2de97541c4d37acf2da07d7a8ae395e/image.png){width=188 height=275} + +Ensure you add this to the project file. This will mark all PNG files within the Symbols folder as embedded resource. + +```xml + + + +``` + +Create a new enum. It may look like the following. Ensure you only add new values to the buttom as you will introduce a breaking change to your API otherwise. + +```csharp +public enum GlobalSymbols +{ + add, + administrative_tools, + billboard, + cancel, + delete, + edit, + home, + login, + logout, + product, + project, + remove, + save, + settings, +} +``` + +The class `GlobalsymbolFactory` need to inherit from `SymbolFactory<>`. Provide your symbols enum here. You will need to overwrite `GetImageResourceAssembly` and `GetImageRessourcePath` as this parts can't be done by the base class. + +```csharp +public class GlobalSymbolFactory : SymbolFactory +{ + private static readonly string? symbolsNamespace = typeof(GlobalSymbolFactory).Namespace + ".Symbols"; + private static readonly string symbolsPathTemplate = "{0}.{1}.png"; + + public override Assembly GetImageResourceAssembly() + { + return Assembly.GetExecutingAssembly(); + } + + public override string GetImageRessourcePath(GlobalSymbols svgImage) + { + return string.Format(symbolsPathTemplate, symbolsNamespace, svgImage); + } +} +``` + +## Access symbols + +Accessing symbols esaily via an instance of your SymbolFactory implementation. You can either provide a static instance in `GlobalSymbolFactory` or create a new instance wherever you need it. Access via `GetImage`, decide wheneer you can use an `Image`. + +```csharp +// Static instance in GlobalSymbolFactory +public static ISymbolFactory Instance { get; } = new GlobalSymbolFactory(); +var img = GlobalSymbolFactory.Instance.GetImage(GlobalSymbols.billboard, SymbolSize.Default); + +// Instance on-demand +var symbols = new GlobalSymbolFactory(); +var img = symbols.GetImage(GlobalSymbols.billboard, SymbolSize.Default); +```