@@ -2789,12 +2789,12 @@ float Pane::CalcSnappedDimension(const bool widthOrHeight, const float dimension
2789
2789
// If requested size is already snapped, then both returned values equal this value.
2790
2790
Pane::SnapSizeResult Pane::_CalcSnappedDimension (const bool widthOrHeight, const float dimension) const
2791
2791
{
2792
- // TODO!: Again, bad. We're special-casing that the content just so happens to have a TermControl
2793
- const auto & termControl{ _content.GetRoot ().try_as <TermControl>() };
2792
+ const auto direction{ widthOrHeight ? PaneSnapDirection::Width : PaneSnapDirection::Height };
2794
2793
2795
2794
if (_IsLeaf ())
2796
2795
{
2797
- if (!termControl)
2796
+ const auto & snappable{ _content.try_as <ISnappable>() };
2797
+ if (!snappable)
2798
2798
{
2799
2799
return { dimension, dimension };
2800
2800
}
@@ -2809,8 +2809,10 @@ Pane::SnapSizeResult Pane::_CalcSnappedDimension(const bool widthOrHeight, const
2809
2809
return { minDimension, minDimension };
2810
2810
}
2811
2811
2812
- auto lower = termControl.SnapDimensionToGrid (widthOrHeight, dimension);
2813
- if (widthOrHeight)
2812
+ auto lower = snappable.SnapDownToGrid (widthOrHeight ? PaneSnapDirection::Width : PaneSnapDirection::Height,
2813
+ dimension);
2814
+
2815
+ if (direction == PaneSnapDirection::Width)
2814
2816
{
2815
2817
lower += WI_IsFlagSet (_borders, Borders::Left) ? PaneBorderSize : 0 ;
2816
2818
lower += WI_IsFlagSet (_borders, Borders::Right) ? PaneBorderSize : 0 ;
@@ -2829,8 +2831,10 @@ Pane::SnapSizeResult Pane::_CalcSnappedDimension(const bool widthOrHeight, const
2829
2831
}
2830
2832
else
2831
2833
{
2832
- const auto cellSize = termControl.CharacterDimensions ();
2833
- const auto higher = lower + (widthOrHeight ? cellSize.Width : cellSize.Height );
2834
+ const auto cellSize = snappable.GridSize ();
2835
+ const auto higher = lower + (direction == PaneSnapDirection::Width ?
2836
+ cellSize.Width :
2837
+ cellSize.Height );
2834
2838
return { lower, higher };
2835
2839
}
2836
2840
}
@@ -2873,36 +2877,41 @@ Pane::SnapSizeResult Pane::_CalcSnappedDimension(const bool widthOrHeight, const
2873
2877
// Return Value:
2874
2878
// - <none>
2875
2879
void Pane::_AdvanceSnappedDimension (const bool widthOrHeight, LayoutSizeNode& sizeNode) const
2876
- { // TODO!: Again, bad. We're special-casing that the content just so happens to have a TermControl
2877
- const auto & termControl{ _content.GetRoot ().try_as <TermControl>() };
2878
- if (_IsLeaf () && termControl)
2880
+ {
2881
+ if (_IsLeaf ())
2879
2882
{
2880
- // We're a leaf pane, so just add one more row or column (unless isMinimumSize
2881
- // is true, see below).
2882
-
2883
- if (sizeNode.isMinimumSize )
2883
+ const auto & snappable{ _content.try_as <ISnappable>() };
2884
+ if (snappable)
2884
2885
{
2885
- // If the node is of its minimum size, this size might not be snapped (it might
2886
- // be, say, half a character, or fixed 10 pixels), so snap it upward. It might
2887
- // however be already snapped, so add 1 to make sure it really increases
2888
- // (not strictly necessary but to avoid surprises).
2889
- sizeNode.size = _CalcSnappedDimension (widthOrHeight, sizeNode.size + 1 ).higher ;
2886
+ // We're a leaf pane, so just add one more row or column (unless isMinimumSize
2887
+ // is true, see below).
2888
+
2889
+ if (sizeNode.isMinimumSize )
2890
+ {
2891
+ // If the node is of its minimum size, this size might not be snapped (it might
2892
+ // be, say, half a character, or fixed 10 pixels), so snap it upward. It might
2893
+ // however be already snapped, so add 1 to make sure it really increases
2894
+ // (not strictly necessary but to avoid surprises).
2895
+ sizeNode.size = _CalcSnappedDimension (widthOrHeight,
2896
+ sizeNode.size + 1 )
2897
+ .higher ;
2898
+ }
2899
+ else
2900
+ {
2901
+ const auto cellSize = snappable.GridSize ();
2902
+ sizeNode.size += widthOrHeight ? cellSize.Width : cellSize.Height ;
2903
+ }
2890
2904
}
2891
2905
else
2892
2906
{
2893
- const auto cellSize = termControl.CharacterDimensions ();
2894
- sizeNode.size += widthOrHeight ? cellSize.Width : cellSize.Height ;
2907
+ // If we're a leaf that didn't have a TermControl, then just increment
2908
+ // by one. We have to increment by _some_ value, because this is used in
2909
+ // a while() loop to find the next bigger size we can snap to. But since
2910
+ // a non-terminal control doesn't really care what size it's snapped to,
2911
+ // we can just say "one pixel larger is the next snap point"
2912
+ sizeNode.size += 1 ;
2895
2913
}
2896
2914
}
2897
- else if (_IsLeaf ())
2898
- {
2899
- // If we're a leaf that didn't have a TermControl, then just increment
2900
- // by one. We have to increment by _some_ value, because this is used in
2901
- // a while() loop to find the next bigger size we can snap to. But since
2902
- // a non-terminal control doesn't really care what size it's snapped to,
2903
- // we can just say "one pixel larger is the next snap point"
2904
- sizeNode.size += 1 ;
2905
- }
2906
2915
else
2907
2916
{
2908
2917
// We're a parent pane, so we have to advance dimension of our children panes. In
0 commit comments