diff options
| author | Jake Mannens <jake@asger.xyz> | 2023-09-06 12:22:27 +1000 |
|---|---|---|
| committer | Jake Mannens <jake@asger.xyz> | 2025-08-20 00:52:04 +1000 |
| commit | ad9e63035809ce65054df80bde95572b993de415 (patch) | |
| tree | 2f6220be39691f1a0226e7613d08519a59bbdc55 /Services/DialogService.cs | |
| parent | 3824edb778789ba4fac3318fbcf5722c3093e487 (diff) | |
Added DialogService to manage dialog z-indexes
Diffstat (limited to 'Services/DialogService.cs')
| -rw-r--r-- | Services/DialogService.cs | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/Services/DialogService.cs b/Services/DialogService.cs new file mode 100644 index 0000000..5967d95 --- /dev/null +++ b/Services/DialogService.cs @@ -0,0 +1,39 @@ +using HyperBooru.Pages.Component; + +namespace HyperBooru.Services; + +public interface IDialogService { + public void Register(Dialog dialog); + public void Unregister(Dialog dialog); + public void BumpZIndex(Dialog dialog); +} + +public class DialogService : IDialogService { + private const int MinZLevel = 900; + + private List<Dialog> dialogs = new(); + + public void Register(Dialog dialog) { + if(!dialogs.Contains(dialog)) + dialogs.Add(dialog); + + dialog.ZIndex = dialogs.Count() - 1 + MinZLevel; + } + + public void Unregister(Dialog dialog) { + dialogs.Remove(dialog); + for(int i = 0; i < dialogs.Count(); i++) + dialogs[i].ZIndex = i + MinZLevel; + } + + public void BumpZIndex(Dialog dialog) { + if(!dialogs.Contains(dialog)) + return; + + dialogs.Remove(dialog); + dialogs.Add(dialog); + + for(int i = 0; i < dialogs.Count(); i++) + dialogs[i].ZIndex = i + MinZLevel; + } +}
\ No newline at end of file |
