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

Extracted calculation of values to be rendered from OverUnderBox.CreateRenderChoices into its own method, for a more generative approach #471

Merged
merged 1 commit into from
Oct 5, 2023
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
38 changes: 29 additions & 9 deletions src/XamlMath.Shared/Boxes/OverUnderBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,21 +35,27 @@ public OverUnderBox(Box baseBox, Box delimiterBox, Box? scriptBox, double kern,
// True to draw delimeter and script over base; false to draw under base.
public bool Over { get; }

public override void RenderTo(IElementRenderer renderer, double x, double y)
private record struct RenderChoices(
double TranslationX,
double TranslationY,
double YPosition);
private RenderChoices CreateRenderChoices(double x, double y)
{
renderer.RenderElement(this.BaseBox, x, y);

if (this.Over)
{
// Draw delimeter and script boxes over base box.
var centerY = y - this.BaseBox.Height - this.DelimiterBox.Width;
var translationX = x + this.DelimiterBox.Width / 2;
var translationY = centerY + this.DelimiterBox.Width / 2;

RenderDelimiter(translationX, translationY);
return new(

// Draw script box as superscript.
RenderScriptBox(centerY - this.Kern - this.ScriptBox!.Depth); // Nullable TODO: This probably needs null checking
TranslationX: translationX,
TranslationY: translationY,

// Draw script box as superscript.
YPosition: centerY - this.Kern - this.ScriptBox!.Depth // Nullable TODO: This probably needs null checking
);
}
else
{
Expand All @@ -58,11 +64,25 @@ public override void RenderTo(IElementRenderer renderer, double x, double y)
var translationX = x + this.DelimiterBox.Width / 2;
var translationY = centerY - this.DelimiterBox.Width / 2;

RenderDelimiter(translationX, translationY);
return new(

TranslationX: translationX,
TranslationY: translationY,

// Draw script box as subscript.
RenderScriptBox(centerY + this.Kern + this.ScriptBox!.Height); // Nullable TODO: This probably needs null checking
// Draw script box as subscript.
YPosition: centerY + this.Kern + this.ScriptBox!.Height // Nullable TODO: This probably needs null checking
);
}
}

public override void RenderTo(IElementRenderer renderer, double x, double y)
{
var renderChoices = CreateRenderChoices(x, y);

renderer.RenderElement(this.BaseBox, x, y);

RenderDelimiter(renderChoices.TranslationX, renderChoices.TranslationY);
RenderScriptBox(renderChoices.YPosition);

void RenderDelimiter(double translationX, double translationY)
{
Expand Down
Loading