Source/Fusion/Core/Layout/Wrap.cs
/// <summary>
/// A two-dimensional grid layout whose number of columns is determined by the maximum width of the input controls.
/// </summary>
A two-dimensional grid layout whose number of columns is determined by the maximum width of the input controls.
A two - dimensional grid layout whose number of columns is determined by the maximum width of the input controls .
public static IControl GridWrap(this IObservable<IEnumerable<IControl>> controlsObservable)
		{
			return Control.BindAvailableSize(size =>
			{
				var columnsObservable = controlsObservable.Select(ctrls =>
				{
					var controls = ctrls as IControl[] ?? ctrls.ToArray();
					var maxWidth = controls
						.Select(c => c.DesiredSize.Width)
						.ToObservableEnumerable()
						.Select(l => Math.Max(1, l.IsEmpty() ? 1 : l.Max()))
						.DistinctUntilChanged();
					var controlsPerRow = Observable.CombineLatest(
						maxWidth,
						size.Width,
						(maxWidths, availableWidth) =>
						{
							var divisor = Math.Max(1, (int) (availableWidth / maxWidths));
							return (controls.Length + (divisor-1)) / divisor;
						})
						.DistinctUntilChanged();
					return controlsPerRow.Select(ctrlsPerRow => controls.Batch(ctrlsPerRow));
				})
				.Switch();
				return SubdivideHorizontally(
					columnsObservable.SelectPerElement(StackFromTop));
			});
		}
public static IControl GridWrap ( this IObservable < IEnumerable < IControl > > controlsObservable ) { return Control . BindAvailableSize ( size => { var columnsObservable = controlsObservable . Select ( ctrls => { var controls = ctrls as IControl [ ] ?? ctrls . ToArray ( ) ; var maxWidth = controls . Select ( c => c . DesiredSize . Width ) . ToObservableEnumerable ( ) . Select ( l => Math . Max ( 1 , l . IsEmpty ( ) ? 1 : l . Max ( ) ) ) . DistinctUntilChanged ( ) ; var controlsPerRow = Observable . CombineLatest ( maxWidth , size . Width , ( maxWidths , availableWidth ) => { var divisor = Math . Max ( 1 , ( int ) ( availableWidth / maxWidths ) ) ; return ( controls . Length + ( divisor - 1 ) ) / divisor ; } ) . DistinctUntilChanged ( ) ; return controlsPerRow . Select ( ctrlsPerRow => controls . Batch ( ctrlsPerRow ) ) ; } ) . Switch ( ) ; return SubdivideHorizontally ( columnsObservable . SelectPerElement ( StackFromTop ) ) ; } ) ; }
A two-dimensional grid layout whose number of columns is determined by the maximum width of the input controls.
A two - dimensional grid layout whose number of columns is determined by the maximum width of the input controls .
IObservable<IEnumerable<IControl>>
this