Open wbijker opened 2 years ago
I've used IDynamicComponent to achieve this. I've build a extensive API to be used as above, but the basic idea is this:
public class DynamicHeightComponent : IDynamicComponent<int>
{
public DynamicComponentComposeResult Compose(DynamicContext context)
{
var content = context.CreateElement(container =>
{
var heightPerUnit = context.AvailableSize.Height / 6;
container.Column(col =>
{
col.Item().Height(heightPerUnit * 1)...
col.Item().Height(heightPerUnit * 2)...
col.Item().Height(heightPerUnit * 3)...
});
});
return new DynamicComponentComposeResult()
{
Content = content,
HasMoreContent = false
};
}
}
Usage:
container.Dynamic(new DynamicHeightComponent(...));
Gist container my extensive API with relative, constant and auto heights: https://gist.github.com/wbijker/62fb02a2cf822ab013c33324ac095b85
It works ok, but
@wbijker I am working on a very similar feature. Would you like to take a look and provide your thoughts? Link to PR: https://github.com/QuestPDF/QuestPDF/pull/357
Also, I was thinking about an alternative to your solution. It uses the RotateLeft / RotateRight elements:
.Padding(20)
.AlignLeft()
.RotateRight() // rotate, so Row acts as Column
.Row(row =>
{
row.Spacing(20);
row.RelativeItem(1).Element(Content);
row.RelativeItem(2).Element(Content);
row.RelativeItem(3).Element(Content);
void Content(IContainer container)
{
container
.RotateLeft() // rotate back each child
.Border(1)
.Background(Placeholders.BackgroundColor())
.Padding(5)
.Text(Placeholders.Label());
}
});
The code produces the following result:
@MarcinZiabek, #357 is exactly wat I was looking for. It also caters for more advanced layout. While #357 is open I will use proposed rotate trick as mentioned above.
Describe the solution you'd like When creating a row there is an option to specify the columns's width as relative items taking a unitless parameter that serves as a proportional unit.
I would like to have the same feature for columns (vertical) containers. Something like:
Describe alternatives you've considered Currently I need to specify the height explicit and do the maths manually.
Possible in current API? More elegant way to achieve this?