Problem statement
Should the Element.Measure method modify the DesiredSize returned by the subclass? As far as I know, in WPF and AvaloniaUI, DesiredSize is not modified; it's limited during the Arrange phase.
So, is it possible to modify it like this?
// src/MewUI/Elements/Element.cs
public void Measure(Size availableSize)
{
if (!IsMeasureDirty && _hasMeasureConstraint && _lastMeasureConstraint == availableSize)
{
return;
}
Size measured;
using (PerformanceProfiler.Instance.SampleElement(GetType(), ProfilerSampleCategory.Measure))
{
measured = MeasureCore(availableSize);
}
/*var clamped = new Size(
double.IsPositiveInfinity(availableSize.Width)
? measured.Width
: Math.Min(measured.Width, availableSize.Width),
double.IsPositiveInfinity(availableSize.Height)
? measured.Height
: Math.Min(measured.Height, availableSize.Height));
DesiredSize = ApplyLayoutRounding(clamped);*/
DesiredSize = ApplyLayoutRounding(measured);
IsMeasureDirty = false;
_lastMeasureConstraint = availableSize;
_hasMeasureConstraint = true;
}
// src/MewUI/Elements/FrameworkElement.cs
protected override Rect GetArrangedBounds(Rect finalRect)
{
var innerSlot = finalRect.Deflate(Margin);
double availableWidth = Math.Max(0, innerSlot.Width);
double availableHeight = Math.Max(0, innerSlot.Height);
/*double arrangeWidth = !double.IsNaN(Width) ? Width : DesiredSize.Width - Margin.Left - Margin.Right;
double arrangeHeight = !double.IsNaN(Height) ? Height : DesiredSize.Height - Margin.Top - Margin.Bottom;*/
double arrangeWidth;
double arrangeHeight;
// If we have explicit size, use it; otherwise use desired (excluding margin)
if (!double.IsNaN(Width))
{
arrangeWidth = Width;
}
else
{
arrangeWidth = DesiredSize.Width - Margin.HorizontalThickness;
arrangeWidth = Math.Min(availableWidth, arrangeWidth);
}
if (!double.IsNaN(Height))
{
arrangeHeight = Height;
}
else
{
arrangeHeight = DesiredSize.Height - Margin.VerticalThickness;
arrangeHeight = Math.Min(availableHeight, arrangeHeight);
}
Why the current approach is insufficient
see above
Type of change
Behavior change
Expected impact
see above
Alternatives or tradeoffs
see above
Additional context
No response
Before submitting
Problem statement
Should the
Element.Measuremethod modify theDesiredSizereturned by the subclass? As far as I know, in WPF and AvaloniaUI,DesiredSizeis not modified; it's limited during theArrangephase.So, is it possible to modify it like this?
Why the current approach is insufficient
see above
Type of change
Behavior change
Expected impact
see above
Alternatives or tradeoffs
see above
Additional context
No response
Before submitting