-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18 from FlurinBruehwiler/temp-branch
update from release branch
- Loading branch information
Showing
5 changed files
with
143 additions
and
109 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,99 +1,140 @@ | ||
using System.Collections; | ||
|
||
namespace Flamui.Layouting; | ||
|
||
public class FlexContainer : ILayoutable | ||
{ | ||
public List<ILayoutable> Children = new(); | ||
|
||
public ParentData ParentData { get; set; } | ||
|
||
public FlexibleChildConfig? FlexibleChildConfig => null; | ||
|
||
public Dir Direction; | ||
|
||
public BoxSize Layout(BoxConstraint constraint) | ||
{ | ||
float totalFixedSize = 0; | ||
|
||
//Loop through inflexible children | ||
foreach (var child in Children) | ||
{ | ||
if (child.IsFlexible(out _)) | ||
continue; | ||
|
||
var size = child.Layout(BoxConstraint.FromDirection(Direction, 0, float.PositiveInfinity, 0, | ||
constraint.GetCrossAxis(Direction).Max)); | ||
|
||
totalFixedSize += size.GetMainAxis(Direction); | ||
} | ||
|
||
float totalPercentage = 0; | ||
|
||
//Loop through flexible children | ||
foreach (var child in Children) | ||
{ | ||
if (!child.IsFlexible(out var config)) | ||
continue; | ||
|
||
totalPercentage += config.Percentage; | ||
} | ||
|
||
//Assert that there are no flexible children if the Main Axis has Infinity as the max size!!!!! | ||
//Need to think about that... | ||
|
||
var sizePerPercentage = GetSizePerPercentage(totalPercentage, constraint.GetMainAxis(Direction).Max); | ||
|
||
Span<bool> childrenThatNeedAnotherPass = stackalloc bool[Children.Count]; | ||
|
||
for (var i = 0; i < Children.Count; i++) | ||
{ | ||
var child = Children[i]; | ||
if (!child.IsFlexible(out var config)) | ||
continue; | ||
|
||
var mainSize = config.Percentage * sizePerPercentage; | ||
|
||
if (mainSize > config.Max && mainSize < config.Min) | ||
{ | ||
var constraintMainSize = Math.Clamp(mainSize, config.Min, config.Max); | ||
totalFixedSize += mainSize; | ||
child.Layout(BoxConstraint.FromDirection(Direction, constraintMainSize, constraintMainSize, 0, | ||
constraint.GetCrossAxis(Direction).Max)); | ||
continue; | ||
} | ||
|
||
childrenThatNeedAnotherPass[i] = true; | ||
} | ||
|
||
// sizePerPercentage = GetSizePerPercentage(totalPercentage, constraint.GetCrossAxis(Dir.Horizontal).Max) | ||
|
||
for (var i = 0; i < Children.Count; i++) | ||
{ | ||
if (!childrenThatNeedAnotherPass[i]) | ||
continue; | ||
|
||
var child = Children[i]; | ||
|
||
|
||
} | ||
|
||
return new BoxSize(); | ||
} | ||
|
||
private float GetSizePerPercentage(float totalPercentage, float availableSize) | ||
{ | ||
float sizePerPercent; | ||
|
||
if (totalPercentage > 100) | ||
{ | ||
sizePerPercent = availableSize / totalPercentage; | ||
} | ||
else | ||
{ | ||
sizePerPercent = availableSize / 100; | ||
} | ||
|
||
return sizePerPercent; | ||
} | ||
} | ||
// using System.Collections; | ||
// | ||
// namespace Flamui.Layouting; | ||
// | ||
// public class FlexContainer : ILayoutable | ||
// { | ||
// public List<ILayoutable> Children = new(); | ||
// | ||
// public ParentData ParentData { get; set; } | ||
// | ||
// public FlexibleChildConfig? FlexibleChildConfig => null; | ||
// | ||
// public Dir Direction; | ||
// public SizeDefinition; | ||
// | ||
// private float GetTotalAvailableSize() | ||
// { | ||
// | ||
// } | ||
// | ||
// public BoxSize Layout(BoxConstraint constraint) | ||
// { | ||
// float totalAvailableSize = GetTotalAvailableSize(); | ||
// | ||
// float totalFixedSize = 0; | ||
// float totalPercentage = 0; | ||
// | ||
// //Loop through inflexible children | ||
// foreach (var child in Children) | ||
// { | ||
// if (child.IsFlexible(out var config)) | ||
// { | ||
// totalPercentage += config.Percentage; | ||
// continue; | ||
// } | ||
// | ||
// var size = child.Layout(BoxConstraint.FromDirection(Direction, 0, float.PositiveInfinity, 0, | ||
// constraint.GetCrossAxis(Direction).Max)); | ||
// | ||
// totalFixedSize += size.GetMainAxis(Direction); | ||
// } | ||
// | ||
// var sizePerPercentage = GetSizePerPercentage(totalPercentage, 0); | ||
// | ||
// float totalSizeOfFlexibleChildren = 0; | ||
// | ||
// //loop through all flexible children and add up size | ||
// for (var i = 0; i < Children.Count; i++) | ||
// { | ||
// var child = Children[i]; | ||
// if (!child.IsFlexible(out var config)) | ||
// continue; | ||
// | ||
// totalSizeOfFlexibleChildren += config.Percentage * sizePerPercentage; | ||
// | ||
// /* | ||
// if (mainSize > config.Max && mainSize < config.Min) | ||
// { | ||
// var constraintMainSize = Math.Clamp(mainSize, config.Min, config.Max); | ||
// totalFixedSize += mainSize; | ||
// child.Layout(BoxConstraint.FromDirection(Direction, constraintMainSize, constraintMainSize, 0, | ||
// constraint.GetCrossAxis(Direction).Max)); | ||
// continue; | ||
// } | ||
// */ | ||
// | ||
// // childrenThatNeedAnotherPass[i] = true; | ||
// } | ||
// | ||
// float remainingSize = constraint.GetMainAxis(Direction).Max - totalFixedSize; | ||
// | ||
// //if fits, apply constraints | ||
// if (totalSizeOfFlexibleChildren < remainingSize) | ||
// { | ||
// Span<bool> childrenThatNeedAnotherPass = stackalloc bool[Children.Count]; | ||
// float totalPercentage = 0; | ||
// | ||
// for (var i = 0; i < Children.Count; i++) | ||
// { | ||
// var child = Children[i]; | ||
// if (!child.IsFlexible(out var config)) | ||
// continue; | ||
// | ||
// var mainSize = config.Percentage * sizePerPercentage; | ||
// | ||
// //if doesn't fit, apply constraint | ||
// if (mainSize > config.Max || mainSize < config.Min) | ||
// { | ||
// var constraintMainSize = Math.Clamp(mainSize, config.Min, config.Max); | ||
// totalFixedSize += mainSize; | ||
// child.Layout(BoxConstraint.FromDirection(Direction, constraintMainSize, constraintMainSize, 0, | ||
// constraint.GetCrossAxis(Direction).Max)); | ||
// continue; | ||
// } | ||
// | ||
// totalPercentage += config.Percentage; | ||
// childrenThatNeedAnotherPass[i] = true; | ||
// } | ||
// | ||
// sizePerPercentage = | ||
// GetSizePerPercentage(totalPercentage, constraint.GetMainAxis(Direction).Max - totalFixedSize); | ||
// | ||
// for (var i = 0; i < Children.Count; i++) | ||
// { | ||
// if (!childrenThatNeedAnotherPass[i]) | ||
// continue; | ||
// | ||
// var child = Children[i]; | ||
// | ||
// | ||
// } | ||
// } | ||
// | ||
// // sizePerPercentage = GetSizePerPercentage(totalPercentage, constraint.GetCrossAxis(Dir.Horizontal).Max) | ||
// | ||
// | ||
// var child = Children[i]; | ||
// | ||
// | ||
// } | ||
// | ||
// return new BoxSize(); | ||
// } | ||
// | ||
// private float GetSizePerPercentage(float totalPercentage, float availableSize) | ||
// { | ||
// float sizePerPercent; | ||
// | ||
// if (totalPercentage > 100) | ||
// { | ||
// sizePerPercent = availableSize / totalPercentage; | ||
// } | ||
// else | ||
// { | ||
// sizePerPercent = availableSize / 100; | ||
// } | ||
// | ||
// return sizePerPercent; | ||
// } | ||
// } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters