Description
The Center
field of the LengthUnit
enum represents a length unit that positions an element in the middle of its parent along the appropriate axis. This is typically used in UI layout to center elements horizontally or vertically within their parent container.
Usage
Use the Center
unit when you want to align an element to the center of its parent. This can be particularly useful in responsive design where elements need to be dynamically centered based on the parent container's size.
Example
// Example of using LengthUnit.Center in a UI component
public class MyPanel : Panel
{
public MyPanel()
{
Style.Width = Length.Percent(100);
Style.Height = Length.Percent(100);
Style.JustifyContent = Justify.Center;
Style.AlignItems = Align.Center;
var centeredElement = Add.Panel();
centeredElement.Style.Width = Length.Pixels(200);
centeredElement.Style.Height = Length.Pixels(100);
centeredElement.Style.Margin = LengthUnit.Center;
}
}