Padding

Creates space inside a widget around its child.

Basic Usage

Padding(InsetsAll(16), Text("Padded text"))

Insets Helper Functions

Function Description Example
InsetsAll(dp) Uniform padding on all sides InsetsAll(16)
InsetsSymmetric(h, v) Symmetric horizontal and vertical padding InsetsSymmetric(24, 12)
InsetsOnly(top, right, bottom, left) Specific padding for each side InsetsOnly(8, 16, 8, 16)

Insets Struct

You can also create an Insets struct directly:

Insets{
    Top:    float32,
    Right:  float32,
    Bottom: float32,
    Left:   float32,
}

Examples

// Uniform padding on all sides
Padding(InsetsAll(16), Text("16dp on all sides"))

// Symmetric padding (horizontal: 24, vertical: 12)
Padding(InsetsSymmetric(24, 12), Text("Symmetric padding"))

// Custom padding for each side
Padding(InsetsOnly(8, 16, 8, 16), Text("Custom padding"))

// Padding around a button
Padding(InsetsAll(8), Button("Padded Button"))

// Nested padding
Padding(InsetsAll(16),
    Padding(InsetsAll(8), Text("Double padded")),
)

// Padding inside a container
Container(
    Padding(InsetsAll(16), Text("Padded content")),
    Background(Blue),
)

Margin

Margin is an alias for Padding in LinnUI (they work the same way):

Margin(InsetsAll(8), child)