Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add panel header icon #906

Merged
merged 5 commits into from
Apr 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading