From 8701ad83cf16c52f5a8cf987248826de7dfd2ec0 Mon Sep 17 00:00:00 2001 From: Andreas G <13819164+agaertner@users.noreply.github.com> Date: Sun, 20 Aug 2023 20:48:09 +0200 Subject: [PATCH 1/3] feat: add panel header icon --- Blish HUD/Controls/Panel.cs | 32 ++++++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/Blish HUD/Controls/Panel.cs b/Blish HUD/Controls/Panel.cs index cdb3d4eef..88dfd8473 100644 --- a/Blish HUD/Controls/Panel.cs +++ b/Blish HUD/Controls/Panel.cs @@ -1,10 +1,10 @@ -using System; -using System.ComponentModel; -using Blish_HUD.Content; +using Blish_HUD.Content; using Blish_HUD.Input; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using Newtonsoft.Json; +using System; +using System.ComponentModel; namespace Blish_HUD.Controls { @@ -57,6 +57,12 @@ public string Title { set => SetProperty(ref _title, value, true); } + protected AsyncTexture2D _icon; + public AsyncTexture2D Icon { + get => _backgroundTexture; + set => SetProperty(ref _icon, value); + } + protected AsyncTexture2D _backgroundTexture; /// @@ -202,6 +208,7 @@ private void UpdateContentRegionBounds(object sender, EventArgs e) { } private Rectangle _layoutHeaderBounds; + private Rectangle _layoutHeaderIconBounds; private Rectangle _layoutHeaderTextBounds; private Vector2 _layoutAccordionArrowOrigin; @@ -248,7 +255,19 @@ public override void RecalculateLayout() { _size.Y - topOffset - bottomOffset); _layoutHeaderBounds = new Rectangle(this.ContentRegion.Left, 0, this.ContentRegion.Width, HEADER_HEIGHT); - _layoutHeaderTextBounds = new Rectangle(_layoutHeaderBounds.Left + 10, 0, _layoutHeaderBounds.Width - 10, HEADER_HEIGHT); + + if (_icon?.HasTexture != null) { + + var iconSize = _icon.Bounds.Size.ResizeKeepAspect(HEADER_HEIGHT, HEADER_HEIGHT); + _layoutHeaderIconBounds = new Rectangle(_layoutHeaderBounds.Left + 10, 2, iconSize.X, iconSize.Y); + _layoutHeaderTextBounds = new Rectangle(_layoutHeaderIconBounds.Right + 7, 0, _layoutHeaderBounds.Width - _layoutHeaderIconBounds.Width - 10, HEADER_HEIGHT); + + } else { + + _layoutHeaderIconBounds = Rectangle.Empty; + _layoutHeaderTextBounds = new Rectangle(_layoutHeaderBounds.Left + 10, 0, _layoutHeaderBounds.Width - 10, HEADER_HEIGHT); + + } _layoutAccordionArrowOrigin = new Vector2((float)ARROW_SIZE / 2, (float)ARROW_SIZE / 2); _layoutAccordionArrowBounds = new Rectangle(_layoutHeaderBounds.Right - ARROW_SIZE, @@ -333,6 +352,11 @@ public override void PaintBeforeChildren(SpriteBatch spriteBatch, Rectangle boun _layoutHeaderBounds); } + // Panel header icon + if (_icon?.HasTexture != null) { + spriteBatch.DrawOnCtrl(this, _icon, _layoutHeaderIconBounds, Color.White); + } + // Panel header text spriteBatch.DrawStringOnCtrl(this, _title, From 5d30195420f09a13d7fa65b5996c2ed6c547344a Mon Sep 17 00:00:00 2001 From: Andreas G <13819164+agaertner@users.noreply.github.com> Date: Sun, 20 Aug 2023 20:52:40 +0200 Subject: [PATCH 2/3] fix: typo in getter --- Blish HUD/Controls/Panel.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Blish HUD/Controls/Panel.cs b/Blish HUD/Controls/Panel.cs index 88dfd8473..713b7eab5 100644 --- a/Blish HUD/Controls/Panel.cs +++ b/Blish HUD/Controls/Panel.cs @@ -59,7 +59,7 @@ public string Title { protected AsyncTexture2D _icon; public AsyncTexture2D Icon { - get => _backgroundTexture; + get => _icon; set => SetProperty(ref _icon, value); } From bd8580a946eb030925195dedaaecb52b8eca00a6 Mon Sep 17 00:00:00 2001 From: Andreas G <13819164+agaertner@users.noreply.github.com> Date: Mon, 1 Jan 2024 03:14:23 +0100 Subject: [PATCH 3/3] fix: adjust padding --- Blish HUD/Controls/Panel.cs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Blish HUD/Controls/Panel.cs b/Blish HUD/Controls/Panel.cs index 713b7eab5..2468ee583 100644 --- a/Blish HUD/Controls/Panel.cs +++ b/Blish HUD/Controls/Panel.cs @@ -258,9 +258,8 @@ public override void RecalculateLayout() { if (_icon?.HasTexture != null) { - var iconSize = _icon.Bounds.Size.ResizeKeepAspect(HEADER_HEIGHT, HEADER_HEIGHT); - _layoutHeaderIconBounds = new Rectangle(_layoutHeaderBounds.Left + 10, 2, iconSize.X, iconSize.Y); - _layoutHeaderTextBounds = new Rectangle(_layoutHeaderIconBounds.Right + 7, 0, _layoutHeaderBounds.Width - _layoutHeaderIconBounds.Width - 10, HEADER_HEIGHT); + _layoutHeaderIconBounds = new Rectangle(_layoutHeaderBounds.Left + 3, 3, HEADER_HEIGHT - 6, HEADER_HEIGHT - 6); + _layoutHeaderTextBounds = new Rectangle(_layoutHeaderIconBounds.Right + 5, 0, _layoutHeaderBounds.Width - _layoutHeaderIconBounds.Width, HEADER_HEIGHT); } else {