Created
March 31, 2023 12:50
-
-
Save flew2bits/da56210804cbb5bd4dd1d3f4a48e2d57 to your computer and use it in GitHub Desktop.
Width filling component
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
public class FillSpace : IDynamicComponent<int> | |
{ | |
private readonly Func<TextSpanDescriptor, TextSpanDescriptor> _styler; | |
private readonly char _delimiter; | |
public FillSpace(Func<TextSpanDescriptor, TextSpanDescriptor> styler, char delimiter = '.') | |
{ | |
_styler = styler; | |
_delimiter = delimiter; | |
} | |
public DynamicComponentComposeResult Compose(DynamicContext context) | |
{ | |
var periodSize = context.CreateElement(x => _styler(x.Text($"{_delimiter}"))).Size; | |
var twoPeriodSize = context.CreateElement(x => _styler(x.Text($"{_delimiter}{_delimiter}"))).Size; | |
var spacingWidth = twoPeriodSize.Width - 2 * periodSize.Width; | |
var periodWidth = periodSize.Width; | |
var periodsToRender =(int) Math.Floor((context.AvailableSize.Width - periodWidth) / (spacingWidth + periodWidth)); | |
var periodString = new string(_delimiter, periodsToRender); | |
return new DynamicComponentComposeResult | |
{ | |
Content = context.CreateElement(x => _styler(x.AlignCenter().AlignBottom().Text(periodString))), | |
HasMoreContent = false | |
}; | |
} | |
public int State { get; set; } | |
} |
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
public static void ScheduleRow(this IContainer container, string times, string activity) | |
{ | |
container.Row(row => | |
{ | |
row.AutoItem().Text(times); | |
row.RelativeItem().Dynamic(new FillSpace(x => x.LetterSpacing(.25f))); | |
row.AutoItem().AlignLeft().Text(activity); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment