Files
Shigure/UI/UiCardPanel.cs
waynebian01 da2eeb3b39 Refactor UI components for improved theming and accessibility
- Updated UiCardPanel to use UiTheme.CardCornerRadius for consistent corner styling.
- Modified UiPillTab to enable TabStop and set AccessibleRole to PageTab, enhancing keyboard navigation.
- Implemented keyboard handling in UiPillTab for Enter and Space keys to trigger click events.
- Enhanced focus visuals in UiPillTab with focus rectangle drawing.
- Introduced new constants in UiTheme for CardPadding, PageGap, ActionButtonHeight, GridRowHeight, TabBarHeight, CardCornerRadius, and ControlCornerRadius for better layout management.
- Updated UnitEditorForm to utilize new theming constants and improved layout with UiCardPanel for better visual structure.
- Refined action button styling in UnitEditorForm for consistent button sizes and margins.
- Adjusted labeled row height in UnitEditorForm for better alignment.
2026-08-25 15:58:44 +08:00

86 lines
2.3 KiB
C#

using System.ComponentModel;
using System.Drawing.Drawing2D;
namespace Shigure;
internal sealed class UiCardPanel : TableLayoutPanel
{
private Color _fillColor = UiTheme.SurfaceRaised;
private int _cornerRadius = UiTheme.CardCornerRadius;
public UiCardPanel()
{
SetStyle(
ControlStyles.AllPaintingInWmPaint
| ControlStyles.OptimizedDoubleBuffer
| ControlStyles.ResizeRedraw
| ControlStyles.SupportsTransparentBackColor,
true);
BackColor = Color.Transparent;
}
[Browsable(false)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public Color FillColor
{
get => _fillColor;
set
{
if (_fillColor == value)
{
return;
}
_fillColor = value;
Invalidate();
}
}
[Browsable(false)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public int CornerRadius
{
get => _cornerRadius;
set
{
var next = Math.Max(0, value);
if (_cornerRadius == next)
{
return;
}
_cornerRadius = next;
Invalidate();
}
}
protected override void OnPaintBackground(PaintEventArgs e)
{
base.OnPaintBackground(e);
if (ClientSize.Width <= 1 || ClientSize.Height <= 1)
{
return;
}
using var path = UiTheme.CreateRoundedRectanglePath(ClientRectangle, UiTheme.Scale(this, CornerRadius));
using var fill = new SolidBrush(FillColor);
e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
e.Graphics.FillPath(fill, path);
}
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
if (ClientSize.Width <= 1 || ClientSize.Height <= 1)
{
return;
}
var bounds = Rectangle.Inflate(ClientRectangle, -1, -1);
using var path = UiTheme.CreateRoundedRectanglePath(bounds, UiTheme.Scale(this, CornerRadius));
using var outline = new Pen(UiTheme.Border);
e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
e.Graphics.DrawPath(outline, path);
}
}