SIGN IN SIGN UP

* Vertical text centering on a rounded-corner `KryptonButton` (V105 LTS) (#3402)

# Fix vertical text centering on rounded `KryptonButton` (#3381)

## Summary

Fixes incorrect vertical (and overall) text alignment on `KryptonButton`
when `StateCommon.Border.Rounding` is large relative to the control’s
height—typical for wide “pill” buttons with centered short text and
large fonts. Adds a **TestForm** repro and designer assets for ongoing
verification.

**Closes:** [Issue #3381 — Vertical text centering on a rounded-corner
`KryptonButton`](https://github.com/Krypton-Suite/Standard-Toolkit/issues/3381)

---

## Problem

`RenderStandard.GetBorderDisplayPadding` computed layout insets from the
**palette** rounding value (`GetBorderRounding`) using the existing
\(\pi\)-based heuristic, but the **drawn** border path (and child clip
region in `ViewDrawSplitCanvas`) clamps rounding to what fits in the
rectangle:

text{effectiveRounding} = min(text{paletteRounding}, min(w/2,\ h/2) -
text{borderWidth})

When the palette requested a much larger rounding than the path (e.g.
very wide, short button with `Rounding = 100`), the **content layout
rectangle** no longer matched the **true interior** of the rounded
shape. Text stayed “centered” in the wrong box, which reads as text
drifting downward (or generally misaligned), especially with large fonts
and Cyrillic sample text as in the report.

---

## Solution

1. **Border display padding**
- Extended `IRenderBorder` / `RenderBase` with an overload
`GetBorderDisplayPadding(IPaletteBorder? palette, PaletteState state,
VisualOrientation orientation, Size borderOuterSize)`.
- When `borderOuterSize.Width` and `Height` are both greater than zero,
the rounding fed into the padding heuristic is **clamped** with the same
rule as `CreateBorderBackPath`, so layout matches drawing and clipping.
- The original three-argument overload remains as a **virtual**
forwarder to `borderOuterSize: Size.Empty` (legacy behaviour where outer
bounds are unknown).

2. **Call sites** Canvas / docker views that know the outer client size
now pass it into the four-argument overload: `ViewDrawSplitCanvas`,
`ViewDrawCanvas`, `ViewDrawDocker` (layout and non-child sizing paths).

3. **`RenderMaterial`** Overrides the four-argument overload and
delegates to the base implementation for override states (same rules as
before).

4. **Test harness**
- `Bug3381KryptonButtonRoundedTextCenteringDemo` (`.cs`, `.Designer.cs`,
`.resx`) with scenarios from the issue plus live controls (rounding
slider, `TextV`, font size, button height).
   - Registered on `StartScreen`.
- `TestForm.csproj`: `SubType` / `DependentUpon` for Solution Explorer
nesting.

---

## API / compatibility

| Area | Note |
|------|------|
| **`IRenderBorder`** | New member; **third-party implementations** of
`IRenderBorder` must implement the four-argument overload. | | **In-repo
renderers** | All derive from `RenderBase` / `RenderStandard`; covered
by the change. | | **Behaviour** | Three-argument call path unchanged
(equivalent to empty outer size). |

---

## Files changed (reference)

**Krypton.Toolkit**

- `Rendering/RenderDefinitions.cs` — interface overload
- `Rendering/RenderBase.cs` — virtual 3-arg + abstract 4-arg
- `Rendering/RenderStandard.cs` — clamp rounding when outer size
provided
- `Rendering/RenderMaterial.cs` — 4-arg override
- `View Draw/ViewDrawSplitCanvas.cs` — pass outer size
- `View Draw/ViewDrawCanvas.cs` — pass outer size
- `View Draw/ViewDrawDocker.cs` — pass outer size

**TestForm**

- `Bug3381KryptonButtonRoundedTextCenteringDemo.cs`
- `Bug3381KryptonButtonRoundedTextCenteringDemo.Designer.cs`
- `Bug3381KryptonButtonRoundedTextCenteringDemo.resx`
- `StartScreen.cs` — launcher entry
- `TestForm.csproj` — form subtype and `DependentUpon`

**Changelog**

- If this PR lands separately from other work, ensure
`Documents/Changelog/Changelog.md` includes a line for **#3381** under
the appropriate build section (an entry may already exist under V110
nightly—avoid duplicates).

---

## How to test (manual)

1. Build and run TestForm: `dotnet run --project "Source/Krypton
Components/TestForm/TestForm.csproj" -c Debug`
2. Open **Bug 3381 KryptonButton Rounded Text Centering** from the start
list (filter: `3381`).
3. Confirm:
- Wide short bar with **Начать** / large rounding: text visually
centered in the pill.
- Side-by-side bars: both centered; different font sizes do not skew
vertical centering incorrectly.
   - Tall narrow capsule: centered.
   - Low rounding row: baseline.
- **Live** section: sweep rounding 0–120, `TextV`, font size, and button
height; resize the form; no progressive vertical drift vs. the green
pill interior.
4. Optional: reproduce the original designer-style scenario (dock fill,
large `Rounding`, large font) in a real form and confirm alignment.

---

## Screenshots

_Add before/after screenshots or a short GIF of the TestForm demo (wide
pill + live slider) for the PR thread._

---

## Checklist

- [x] Fix aligns layout padding with border path rounding when bounds
are known
- [x] Legacy 3-arg `GetBorderDisplayPadding` preserved
- [x] TestForm demo + designer/resx + start screen entry

---

## Suggested commit / PR titles

- `Fix KryptonButton text centering with large border rounding (#3381)`
- `3381 Align border display padding with clamped rounding; add TestForm
demo`
P
Peter Wagner committed
5f47597eaab01c8057cabc3dd280aff93ea502d0
Committed by GitHub <noreply@github.com> on 5/6/2026, 7:07:35 AM