diff --git a/CHANGELOG.md b/CHANGELOG.md index 02b496c..612b5a4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,6 +22,9 @@ Fixes - Fixed StaticSpriteBatch handling rotated sprites incorrectly ### MLEM.Ui +Additions +- Added Element.OnStyleInit event + Improvements - Allow for checkboxes and radio buttons to be disabled - Only set a paragraph's area dirty when a text change would cause it to change size diff --git a/MLEM.Ui/Elements/Element.cs b/MLEM.Ui/Elements/Element.cs index ab0bd07..7a44ebf 100644 --- a/MLEM.Ui/Elements/Element.cs +++ b/MLEM.Ui/Elements/Element.cs @@ -342,6 +342,10 @@ namespace MLEM.Ui.Elements { /// public GenericCallback OnAreaUpdated; /// + /// Event that is called when this element's method is called while setting the . + /// + public GenericCallback OnStyleInit; + /// /// Event that is called when the element that is currently being moused changes within the ui system. /// Note that the event fired doesn't necessarily correlate to this specific element. /// @@ -1058,6 +1062,8 @@ namespace MLEM.Ui.Elements { this.SelectionIndicator = this.SelectionIndicator.OrStyle(style.SelectionIndicator); this.ActionSound = this.ActionSound.OrStyle(style.ActionSound); this.SecondActionSound = this.SecondActionSound.OrStyle(style.ActionSound); + + this.System.InvokeOnElementStyleInit(this); } /// diff --git a/MLEM.Ui/UiSystem.cs b/MLEM.Ui/UiSystem.cs index 9c11bbc..5e4f72f 100644 --- a/MLEM.Ui/UiSystem.cs +++ b/MLEM.Ui/UiSystem.cs @@ -153,6 +153,10 @@ namespace MLEM.Ui { /// public event Element.GenericCallback OnElementAreaUpdated; /// + /// Event that is called when an 's method is called while setting its . + /// + public event Element.GenericCallback OnElementStyleInit; + /// /// Event that is invoked when the that the mouse is currently over changes /// public event Element.GenericCallback OnMousedElementChanged; @@ -190,6 +194,7 @@ namespace MLEM.Ui { public UiSystem(Game game, UiStyle style, InputHandler inputHandler = null, bool automaticViewport = true) : base(game) { this.Controls = new UiControls(this, inputHandler); this.style = style; + this.OnElementDrawn += (e, time, batch, alpha) => e.OnDrawn?.Invoke(e, time, batch, alpha); this.OnElementUpdated += (e, time) => e.OnUpdated?.Invoke(e, time); this.OnElementPressed += e => e.OnPressed?.Invoke(e); @@ -201,6 +206,7 @@ namespace MLEM.Ui { this.OnElementTouchEnter += e => e.OnTouchEnter?.Invoke(e); this.OnElementTouchExit += e => e.OnTouchExit?.Invoke(e); this.OnElementAreaUpdated += e => e.OnAreaUpdated?.Invoke(e); + this.OnElementStyleInit += e => e.OnStyleInit?.Invoke(e); this.OnMousedElementChanged += e => this.ApplyToAll(t => t.OnMousedElementChanged?.Invoke(t, e)); this.OnTouchedElementChanged += e => this.ApplyToAll(t => t.OnTouchedElementChanged?.Invoke(t, e)); this.OnSelectedElementChanged += e => this.ApplyToAll(t => t.OnSelectedElementChanged?.Invoke(t, e)); @@ -216,6 +222,7 @@ namespace MLEM.Ui { if (e.OnSecondaryPressed != null) e.SecondActionSound.Value?.Play(); }; + MlemPlatform.Current?.AddTextInputListener(game.Window, (sender, key, character) => this.ApplyToAll(e => e.OnTextInput?.Invoke(e, key, character))); if (automaticViewport) { @@ -396,6 +403,10 @@ namespace MLEM.Ui { this.OnElementAreaUpdated?.Invoke(element); } + internal void InvokeOnElementStyleInit(Element element) { + this.OnElementStyleInit?.Invoke(element); + } + internal void InvokeOnElementPressed(Element element) { this.OnElementPressed?.Invoke(element); }