Skip to content

Commit

Permalink
Merge pull request #906 from agaertner/feature/panel-title-icon
Browse files Browse the repository at this point in the history
feat: add panel header icon
  • Loading branch information
dlamkins authored Apr 2, 2024
2 parents 0f17f0e + 6569e71 commit 3fb24bd
Showing 1 changed file with 27 additions and 4 deletions.
31 changes: 27 additions & 4 deletions Blish HUD/Controls/Panel.cs
Original file line number Diff line number Diff line change
@@ -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 {

Expand Down Expand Up @@ -57,6 +57,12 @@ public string Title {
set => SetProperty(ref _title, value, true);
}

protected AsyncTexture2D _icon;
public AsyncTexture2D Icon {
get => _icon;
set => SetProperty(ref _icon, value);
}

protected AsyncTexture2D _backgroundTexture;

/// <summary>
Expand Down Expand Up @@ -202,6 +208,7 @@ private void UpdateContentRegionBounds(object sender, EventArgs e) {
}

private Rectangle _layoutHeaderBounds;
private Rectangle _layoutHeaderIconBounds;
private Rectangle _layoutHeaderTextBounds;

private Vector2 _layoutAccordionArrowOrigin;
Expand Down Expand Up @@ -248,7 +255,18 @@ 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) {

_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 {

_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,
Expand Down Expand Up @@ -333,6 +351,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,
Expand Down

0 comments on commit 3fb24bd

Please sign in to comment.