Skip to content

Commit ea0dd89

Browse files
authored
Fix some issues with rounded borders (#16051)
* Some fixes for rounded borders * Change files * Image snaphots
1 parent 5563f8f commit ea0dd89

5 files changed

Lines changed: 60 additions & 67 deletions

File tree

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"type": "prerelease",
3+
"comment": "Some fixes for rounded borders",
4+
"packageName": "react-native-windows",
5+
"email": "30809111+acoates-ms@users.noreply.github.com",
6+
"dependentChangeType": "patch"
7+
}
668 Bytes
Loading
Loading

vnext/Microsoft.ReactNative/Fabric/Composition/BorderPrimitive.cpp

Lines changed: 53 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,18 @@ bool isColorMeaningful(
2626
void pixelRoundBorderRadii(facebook::react::BorderRadii &borderRadii, float scaleFactor) noexcept {
2727
// Always round radii down to avoid spikey circles
2828
borderRadii.topLeft = {
29-
std::floor(borderRadii.topLeft.horizontal * scaleFactor), std::floor(borderRadii.topLeft.vertical * scaleFactor)};
29+
.vertical = std::floor(borderRadii.topLeft.vertical * scaleFactor),
30+
.horizontal = std::floor(borderRadii.topLeft.horizontal * scaleFactor)};
3031
borderRadii.topRight = {
31-
std::floor(borderRadii.topRight.horizontal * scaleFactor),
32-
std::floor(borderRadii.topRight.vertical * scaleFactor)};
32+
.vertical = std::floor(borderRadii.topRight.vertical * scaleFactor),
33+
.horizontal = std::floor(borderRadii.topRight.horizontal * scaleFactor)};
3334
borderRadii.bottomLeft = {
34-
std::floor(borderRadii.bottomLeft.horizontal * scaleFactor),
35-
std::floor(borderRadii.bottomLeft.vertical * scaleFactor)};
35+
.vertical = std::floor(borderRadii.bottomLeft.vertical * scaleFactor),
36+
.horizontal = std::floor(borderRadii.bottomLeft.horizontal * scaleFactor)};
3637
borderRadii.bottomRight = {
37-
std::floor(borderRadii.bottomRight.horizontal * scaleFactor),
38-
std::floor(borderRadii.bottomRight.vertical * scaleFactor)};
38+
.vertical = std::floor(borderRadii.bottomRight.vertical * scaleFactor),
39+
.horizontal = std::floor(borderRadii.bottomRight.horizontal * scaleFactor),
40+
};
3941
}
4042

4143
void scaleAndPixelRoundBorderWidths(
@@ -268,30 +270,14 @@ RoundedPathParameters GenerateRoundedPathParameters(
268270
return result;
269271
}
270272

271-
float totalTopRadius = baseRadius.topLeft.horizontal + baseRadius.topRight.horizontal;
272-
float totalRightRadius = baseRadius.topRight.vertical + baseRadius.bottomRight.vertical;
273-
float totalBottomRadius = baseRadius.bottomRight.horizontal + baseRadius.bottomLeft.horizontal;
274-
float totalLeftRadius = baseRadius.bottomLeft.vertical + baseRadius.topLeft.vertical;
275-
276-
float maxHorizontalRadius = std::max(totalTopRadius, totalBottomRadius);
277-
float maxVerticalRadius = std::max(totalLeftRadius, totalRightRadius);
278-
279-
double totalWidth = inset.left + inset.right + pathSize.width;
280-
double totalHeight = inset.top + inset.bottom + pathSize.height;
281-
282-
float scaleHoriz = static_cast<float>(maxHorizontalRadius / totalWidth);
283-
float scaleVert = static_cast<float>(maxVerticalRadius / totalHeight);
284-
285-
float maxScale = std::max(1.0f, std::max(scaleHoriz, scaleVert));
286-
287-
result.topLeftRadiusX = std::max(0.0f, baseRadius.topLeft.horizontal / maxScale - inset.left);
288-
result.topLeftRadiusY = std::max(0.0f, baseRadius.topLeft.vertical / maxScale - inset.top);
289-
result.topRightRadiusX = std::max(0.0f, baseRadius.topRight.horizontal / maxScale - inset.right);
290-
result.topRightRadiusY = std::max(0.0f, baseRadius.topRight.vertical / maxScale - inset.top);
291-
result.bottomRightRadiusX = std::max(0.0f, baseRadius.bottomRight.horizontal / maxScale - inset.right);
292-
result.bottomRightRadiusY = std::max(0.0f, baseRadius.bottomRight.vertical / maxScale - inset.bottom);
293-
result.bottomLeftRadiusX = std::max(0.0f, baseRadius.bottomLeft.horizontal / maxScale - inset.left);
294-
result.bottomLeftRadiusY = std::max(0.0f, baseRadius.bottomLeft.vertical / maxScale - inset.bottom);
273+
result.topLeftRadiusX = std::max(0.0f, baseRadius.topLeft.horizontal - inset.left);
274+
result.topLeftRadiusY = std::max(0.0f, baseRadius.topLeft.vertical - inset.top);
275+
result.topRightRadiusX = std::max(0.0f, baseRadius.topRight.horizontal - inset.right);
276+
result.topRightRadiusY = std::max(0.0f, baseRadius.topRight.vertical - inset.top);
277+
result.bottomRightRadiusX = std::max(0.0f, baseRadius.bottomRight.horizontal - inset.right);
278+
result.bottomRightRadiusY = std::max(0.0f, baseRadius.bottomRight.vertical - inset.bottom);
279+
result.bottomLeftRadiusX = std::max(0.0f, baseRadius.bottomLeft.horizontal - inset.left);
280+
result.bottomLeftRadiusY = std::max(0.0f, baseRadius.bottomLeft.vertical - inset.bottom);
295281

296282
return result;
297283
}
@@ -473,8 +459,8 @@ void SetBorderLayerProperties(
473459
/*
474460
else
475461
{
476-
SetBorderLayerPropertiesCommon(theme, comContext, layer, shape, borderTexture, textureRect,
477-
anchorPoint, anchorOffset, strokeWidth, borderColor, borderStyle);
462+
SetBorderLayerPropertiesCommon(theme, compContext, layer, shape, borderTexture, textureRect,
463+
anchorPoint, anchorOffset, size, relativeSizeAdjustment, strokeWidth, borderColor, borderStyle);
478464
}
479465
*/
480466
}
@@ -516,11 +502,11 @@ void DrawAllBorderLayers(
516502
spTextures[0], // Target Layer, Source Texture, Target Texture
517503
{0,
518504
0,
519-
borderRadii.topLeft.vertical + borderWidths.left,
520-
borderRadii.topLeft.horizontal + borderWidths.top}, // Texture Left, Top, Width, Height
505+
borderRadii.topLeft.horizontal + borderWidths.left,
506+
borderRadii.topLeft.vertical + borderWidths.top}, // Texture Left, Top, Width, Height
521507
{AnchorPosition::Left, AnchorPosition::Top}, // Layer Anchor Point
522508
{0, 0}, // Layer Anchor Offset
523-
{borderRadii.topLeft.vertical + borderWidths.left, borderRadii.topLeft.horizontal + borderWidths.top}, // size
509+
{borderRadii.topLeft.horizontal + borderWidths.left, borderRadii.topLeft.vertical + borderWidths.top}, // size
524510
{0.0f, 0.0f}, // relativeSize
525511
std::max(borderWidths.left, borderWidths.top),
526512
borderColors.left ? borderColors.left : borderColors.top,
@@ -533,13 +519,13 @@ void DrawAllBorderLayers(
533519
spBorderLayers[1],
534520
shape,
535521
spTextures[1],
536-
{borderRadii.topLeft.vertical + borderWidths.left,
522+
{borderRadii.topLeft.horizontal + borderWidths.left,
537523
0,
538-
textureWidth - (borderRadii.topRight.vertical + borderWidths.right),
524+
textureWidth - (borderRadii.topRight.horizontal + borderWidths.right),
539525
borderWidths.top},
540526
{AnchorPosition::Left, AnchorPosition::Top},
541-
{borderRadii.topLeft.vertical + borderWidths.left, 0},
542-
{-(borderRadii.topLeft.vertical + borderWidths.left + borderRadii.topRight.vertical + borderWidths.right),
527+
{borderRadii.topLeft.horizontal + borderWidths.left, 0},
528+
{-(borderRadii.topLeft.horizontal + borderWidths.left + borderRadii.topRight.horizontal + borderWidths.right),
543529
borderWidths.top}, // size
544530
{1.0f, 0.0f}, // relativeSize
545531
borderWidths.top,
@@ -553,13 +539,13 @@ void DrawAllBorderLayers(
553539
spBorderLayers[2],
554540
shape,
555541
spTextures[2],
556-
{textureWidth - (borderRadii.topRight.vertical + borderWidths.right),
542+
{textureWidth - (borderRadii.topRight.horizontal + borderWidths.right),
557543
0,
558544
textureWidth,
559-
borderRadii.topRight.horizontal + borderWidths.top},
545+
borderRadii.topRight.vertical + borderWidths.top},
560546
{AnchorPosition::Right, AnchorPosition::Top},
561-
{-(borderRadii.topRight.vertical + borderWidths.right), 0},
562-
{borderRadii.topRight.vertical + borderWidths.right, borderRadii.topRight.horizontal + borderWidths.top},
547+
{-(borderRadii.topRight.horizontal + borderWidths.right), 0},
548+
{borderRadii.topRight.horizontal + borderWidths.right, borderRadii.topRight.vertical + borderWidths.top},
563549
{0.0f, 0.0f},
564550
std::max(borderWidths.right, borderWidths.top),
565551
borderColors.right ? borderColors.right : borderColors.top,
@@ -573,14 +559,14 @@ void DrawAllBorderLayers(
573559
shape,
574560
spTextures[3],
575561
{textureWidth - borderWidths.right,
576-
borderWidths.top + borderRadii.topRight.horizontal,
562+
borderWidths.top + borderRadii.topRight.vertical,
577563
textureWidth,
578-
textureHeight - (borderWidths.bottom + borderRadii.bottomRight.horizontal)},
564+
textureHeight - (borderWidths.bottom + borderRadii.bottomRight.vertical)},
579565
{AnchorPosition::Right, AnchorPosition::Top},
580-
{-borderWidths.right, borderWidths.top + borderRadii.topRight.horizontal},
566+
{-borderWidths.right, borderWidths.top + borderRadii.topRight.vertical},
581567
{borderWidths.right,
582-
-(borderWidths.top + borderRadii.topRight.horizontal + borderWidths.bottom +
583-
borderRadii.bottomRight.horizontal)}, // size
568+
-(borderWidths.top + borderRadii.topRight.vertical + borderWidths.bottom +
569+
borderRadii.bottomRight.vertical)}, // size
584570
{0.0f, 1.0f},
585571
borderWidths.right,
586572
borderColors.right,
@@ -593,14 +579,14 @@ void DrawAllBorderLayers(
593579
spBorderLayers[4],
594580
shape,
595581
spTextures[4],
596-
{textureWidth - (borderWidths.right + borderRadii.bottomRight.vertical),
597-
textureHeight - (borderWidths.bottom + borderRadii.bottomRight.horizontal),
582+
{textureWidth - (borderWidths.right + borderRadii.bottomRight.horizontal),
583+
textureHeight - (borderWidths.bottom + borderRadii.bottomRight.vertical),
598584
textureWidth,
599585
textureHeight},
600586
{AnchorPosition::Right, AnchorPosition::Bottom},
601-
{-(borderWidths.right + borderRadii.bottomRight.vertical),
602-
-(borderWidths.bottom + borderRadii.bottomRight.horizontal)},
603-
{borderWidths.right + borderRadii.bottomRight.vertical, borderWidths.bottom + borderRadii.bottomRight.horizontal},
587+
{-(borderWidths.right + borderRadii.bottomRight.horizontal),
588+
-(borderWidths.bottom + borderRadii.bottomRight.vertical)},
589+
{borderWidths.right + borderRadii.bottomRight.horizontal, borderWidths.bottom + borderRadii.bottomRight.vertical},
604590
{0, 0},
605591
std::max(borderWidths.right, borderWidths.bottom),
606592
borderColors.right ? borderColors.right : borderColors.bottom,
@@ -613,13 +599,14 @@ void DrawAllBorderLayers(
613599
spBorderLayers[5],
614600
shape,
615601
spTextures[5],
616-
{borderWidths.left + borderRadii.bottomLeft.vertical,
602+
{borderWidths.left + borderRadii.bottomLeft.horizontal,
617603
textureHeight - borderWidths.bottom,
618-
textureWidth - (borderWidths.right + borderRadii.bottomRight.vertical),
604+
textureWidth - (borderWidths.right + borderRadii.bottomRight.horizontal),
619605
textureHeight},
620606
{AnchorPosition::Left, AnchorPosition::Bottom},
621-
{borderWidths.left + borderRadii.bottomLeft.vertical, -borderWidths.bottom},
622-
{-(borderWidths.right + borderRadii.bottomLeft.vertical + borderWidths.left + borderRadii.bottomRight.vertical),
607+
{borderWidths.left + borderRadii.bottomLeft.horizontal, -borderWidths.bottom},
608+
{-(borderWidths.right + borderRadii.bottomLeft.horizontal + borderWidths.left +
609+
borderRadii.bottomRight.horizontal),
623610
borderWidths.bottom},
624611
{1.0f, 0.0f},
625612
borderWidths.bottom,
@@ -634,12 +621,12 @@ void DrawAllBorderLayers(
634621
shape,
635622
spTextures[6],
636623
{0,
637-
textureHeight - (borderWidths.bottom + borderRadii.bottomLeft.horizontal),
638-
borderWidths.left + borderRadii.bottomLeft.vertical,
624+
textureHeight - (borderWidths.bottom + borderRadii.bottomLeft.vertical),
625+
borderWidths.left + borderRadii.bottomLeft.horizontal,
639626
textureHeight},
640627
{AnchorPosition::Left, AnchorPosition::Bottom},
641-
{0, -(borderWidths.bottom + borderRadii.bottomLeft.horizontal)},
642-
{borderWidths.left + borderRadii.bottomLeft.vertical, borderWidths.bottom + borderRadii.bottomLeft.horizontal},
628+
{0, -(borderWidths.bottom + borderRadii.bottomLeft.vertical)},
629+
{borderWidths.left + borderRadii.bottomLeft.horizontal, borderWidths.bottom + borderRadii.bottomLeft.vertical},
643630
{0, 0},
644631
std::max(borderWidths.left, borderWidths.bottom),
645632
borderColors.left ? borderColors.left : borderColors.bottom,
@@ -653,13 +640,13 @@ void DrawAllBorderLayers(
653640
shape,
654641
spTextures[7],
655642
{0,
656-
borderWidths.top + borderRadii.topLeft.horizontal,
643+
borderWidths.top + borderRadii.topLeft.vertical,
657644
borderWidths.left,
658-
textureHeight - (borderWidths.bottom + borderRadii.bottomLeft.horizontal)},
645+
textureHeight - (borderWidths.bottom + borderRadii.bottomLeft.vertical)},
659646
{AnchorPosition::Left, AnchorPosition::Top},
660-
{0, borderWidths.top + borderRadii.topLeft.horizontal},
647+
{0, borderWidths.top + borderRadii.topLeft.vertical},
661648
{borderWidths.left,
662-
-(borderWidths.top + borderRadii.topLeft.horizontal + borderWidths.bottom + borderRadii.bottomLeft.horizontal)},
649+
-(borderWidths.top + borderRadii.topLeft.vertical + borderWidths.bottom + borderRadii.bottomLeft.vertical)},
663650
{0, 1},
664651
borderWidths.left,
665652
borderColors.left,

vnext/Microsoft.ReactNative/Fabric/Composition/CompositionContextHelper.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2208,7 +2208,6 @@ struct CompContext : winrt::implements<
22082208
winrt::com_ptr<ID3D11Device> m_d3dDevice;
22092209
winrt::com_ptr<ID2D1Device> m_d2dDevice;
22102210
typename TTypeRedirects::CompositionGraphicsDevice m_compositionGraphicsDevice{nullptr};
2211-
winrt::com_ptr<ID3D11DeviceContext> m_d3dDeviceContext;
22122211
};
22132212

22142213
winrt::Microsoft::ReactNative::Composition::Experimental::ISpriteVisual

0 commit comments

Comments
 (0)