DevFear
Topic Author
Posts: 53
Joined: 29 Jun 2022, 12:36

GetLayoutClip not found.

12 May 2023, 08:48

WPF to implement a custom element clip, you can override the GetLayoutClip method. But for some reason I can't find it in Noesis (I create a custom Panel). Is there an alternative to this approach or some other way to crop the elements? For example, elements inside the grid are cut off beyond its limit, and the WPF community advises using this method (it should return null).
Source: http://drwpf.com/blog/2007/12/28/cliptoboundsmaybe/
 
User avatar
sfernandez
Site Admin
Posts: 2991
Joined: 22 Dec 2011, 19:20

Re: GetLayoutClip not found.

12 May 2023, 11:27

The method is available in the native API but it is not yet exposed to C#. Could you please report this in our bugtracker?
In the meantime, if you just want to clip the children of your panel with a particular geometry (inside its bounds), you can use the Clip property.
 
DevFear
Topic Author
Posts: 53
Joined: 29 Jun 2022, 12:36

Re: GetLayoutClip not found.

12 May 2023, 11:32

I want a similar implementation on WPF so that the child elements are not clipped by the container (StackPanel). How can I best achieve this in C#+ Unity?
WPF it is not clipped, since the GetLayoutClip method is implemented in the class
Image
 
DevFear
Topic Author
Posts: 53
Joined: 29 Jun 2022, 12:36

Re: GetLayoutClip not found.

12 May 2023, 11:44

 
User avatar
sfernandez
Site Admin
Posts: 2991
Joined: 22 Dec 2011, 19:20

Re: GetLayoutClip not found.

12 May 2023, 11:45

Thanks for the report!

Another option if you are reimplementing the MeasureOverride/ArrangeOverride yourself, would be to inherit from the Canvas panel, which already overrides GetLayoutClip to allow children to extend outside the bounds of the panel. Could you try that?
 
DevFear
Topic Author
Posts: 53
Joined: 29 Jun 2022, 12:36

Re: GetLayoutClip not found.

12 May 2023, 16:58

Yes, it worked. After combining the Measure and Arrange logic, we got a panel that composes elements like a StackPanel, but at the same time does not cut them if they go beyond the size of the container. I attach a rough code without a scroll mechanism. (I will be glad to criticize the code)

Although the method does not look very beautiful. How long does it take you approximately to fix this kind of problem?
public class LayoutStackPanel : Canvas
	{
		public static DependencyProperty OrientationProperty;


		static LayoutStackPanel()
		{
			OrientationProperty = DependencyProperty.Register(
				nameof(Orientation),
				typeof(Orientation),
				typeof(LayoutStackPanel), new FrameworkPropertyMetadata(Orientation.Vertical, FrameworkPropertyMetadataOptions.AffectsMeasure));
		}


		public Orientation Orientation
		{
			get => (Orientation)GetValue(OrientationProperty);
			set => SetValue(OrientationProperty, value);
		}


		protected override Size MeasureOverride(Size constraint)
		{
			var children = Children;

			var size = default(Size);

			if (Orientation == Orientation.Vertical)
			{
				var avialibleSize = new Size(float.PositiveInfinity, float.PositiveInfinity);

				var count = children.Count;
				for (int i = 0; i < count; i++)
				{
					var element = children[i];
					if (element == null)
						continue;

					element.Measure(avialibleSize);

					var desiredSize = element.DesiredSize;

					size.Width = Math.Max(size.Width, desiredSize.Width);
					size.Height += desiredSize.Height;
				}
			}
			else
			{
				var avialibleSize = new Size(float.PositiveInfinity, float.PositiveInfinity);

				var count = children.Count;
				for (int i = 0; i < count; i++)
				{
					var element = children[i];
					if (element == null)
						continue;

					element.Measure(avialibleSize);

					var desiredSize = element.DesiredSize;

					size.Width += desiredSize.Width;
					size.Height = Math.Max(size.Height, desiredSize.Height);
				}
			}

			return size;
		}


		protected override Size ArrangeOverride(Size finalSize)
		{
			var children = Children;

			var finalRect = new Rect(finalSize);
			var num = 0.0f;

			if (Orientation == Orientation.Vertical)
			{
				var count = children.Count;
				for (int i = 0; i < count; i++)
				{
					var element = children[i];

					if (element != null)
					{
						finalRect.Y += num;
						finalRect.Height = element.DesiredSize.Height;
						num = finalRect.Height;

						finalRect.Width = Math.Max(finalSize.Width, element.DesiredSize.Width);

						element.Arrange(finalRect);
					}
				}
			}
			else
			{
				var count = children.Count;
				for (int i = 0; i < count; i++)
				{
					var element = children[i];

					if (element != null)
					{
						finalRect.X += num;
						finalRect.Width = element.DesiredSize.Width;
						num = finalRect.Width;

						finalRect.Height = Math.Max(finalSize.Height, element.DesiredSize.Height);

						element.Arrange(finalRect);
					}
				}
			}

			return finalSize;
		}
	}
 
User avatar
sfernandez
Site Admin
Posts: 2991
Joined: 22 Dec 2011, 19:20

Re: GetLayoutClip not found.

15 May 2023, 11:13

The code looks fine to me :)

I have included the ticket for the next 3.2.2 version. We usually release minor versions every 1-2 months, but I can't be more precise.

Who is online

Users browsing this forum: No registered users and 15 guests