Modifiers Reference

Modifiers are constructor parameters shared by all Nib views. They control layout, appearance, typography, effects, and animation. Every view inherits these parameters from the base View class.

import nib

nib.Text(
    "Hello",
    font=nib.Font.TITLE,            # Typography
    foreground_color=nib.Color.BLUE, # Appearance
    padding=16,                      # Layout
    shadow_radius=4,                 # Effects
    animation=nib.Animation.spring(),# Animation
)

Each modifier is also a property: assigning it later restyles the view, the same as any other reactive property.

Colors

Anywhere a colour is accepted (foreground_color, background, fill, stroke_color, border_color, shadow_color, tint) you can pass:

nib.Color.RED                       # named: RED, BLUE, GREEN, YELLOW, ORANGE, PURPLE, PINK,
                                    # WHITE, BLACK, GRAY, CLEAR, INDIGO, CYAN, MINT, TEAL, BROWN
nib.Color.PRIMARY                   # semantic, adapt to light and dark mode: PRIMARY, SECONDARY, ACCENT
nib.Color(hex="#4287f5")            # hex, with or without "#", optional alpha as #AARRGGBB
nib.Color.rgb(66, 135, 245)         # 0 to 255
nib.Color.rgba(255, 0, 0, 0.5)      # alpha 0.0 to 1.0
nib.Color.BLUE.with_opacity(0.6)
"red"                               # a plain string: one of the names above, or a hex value
"#FF5733"

Full list and conversions: Color.

Background, border, shadow, shape

nib.VStack(
    controls=[nib.Text("Card")],
    padding=16,
    background=nib.Rectangle(
        corner_radius=12, fill="#1c1c1e", stroke_color="#2c2c2e", stroke_width=1
    ),
    shadow_color="#000000",
    shadow_radius=8,
    shadow_y=4,
)
  • background takes a colour or any view; a Rectangle with fill, stroke_color and corner_radius is the usual card.
  • border_color and border_width draw a border on the view's own bounds; combine with corner_radius for rounded borders.
  • shadow_color, shadow_radius, shadow_x, shadow_y describe a drop shadow.
  • clip_shape clips to "circle", "capsule" or a shape view: nib.Image(src="avatar.jpg", width=64, height=64, clip_shape="circle").
  • opacity is 0.0 to 1.0; scale is a uniform transform; blend_mode takes a BlendMode.
  • corner_radius takes a number of points. A shape also takes a CornerRadius for per-corner radii: nib.Rectangle(corner_radius=nib.CornerRadius.only(top_left=16, top_right=16)), with .vertical(top=16, bottom=0), .horizontal(left=12, right=0) and .all(12) as the other factories.

Spacing and size

nib.Text("Padded", padding=16)                                   # all sides
nib.Text("Padded", padding={"horizontal": 16, "vertical": 8})    # or top, bottom, leading, trailing
nib.Text("Spaced", margin=8)                                     # outside the background
nib.Text("Wide", max_width=nib.INFINITY)                         # fill the available width
nib.Rectangle(fill="red", width=100, height=50, min_width=80)

padding is inside the background; margin is outside it.

Fonts and text

nib.Text("Title", font=nib.Font.TITLE)                          # LARGE_TITLE, TITLE, TITLE2, TITLE3,
                                                                 # HEADLINE, SUBHEADLINE, BODY, CALLOUT,
                                                                 # FOOTNOTE, CAPTION, CAPTION2
nib.Text("Custom", font=nib.Font.system(18, nib.FontWeight.SEMIBOLD))
nib.Text("Brand", font=nib.Font.custom("Inter-Bold", size=16))  # a font from assets/

font_weight sets the weight of the view's font. Font files go in the assets directory.

Decorations, spacing and colour for one Text go in a TextStyle; mixed styles within one Text use AttributedString segments:

nib.Text("12:34:56", style=nib.TextStyle(monospaced_digit=True, font=nib.Font.TITLE))
nib.Text(
    strings=[
        nib.AttributedString("Status: ", style=nib.TextStyle(bold=True)),
        nib.AttributedString("Connected", color="green"),
    ]
)

Reference: Font, TextStyle and AttributedString.

Gradients

LinearGradient, RadialGradient and AngularGradient are views: use them on their own, as a background, or as a shape's fill. Points are unit coordinates, (0, 0) top-left to (1, 1) bottom-right.

nib.VStack(
    controls=[nib.Text("Gradient card", foreground_color=nib.Color.WHITE)],
    padding=24,
    corner_radius=16,
    background=nib.LinearGradient(colors=["#667eea", "#764ba2"], start=(0, 0), end=(1, 1)),
)

nib.LinearGradient(stops=[(0.0, "#FF0000"), (0.5, "#FFFF00"), (1.0, "#0000FF")], height=60)
nib.RadialGradient(colors=["white", "black"], center=(0.5, 0.5), start_radius=0, end_radius=100, width=200, height=200)
nib.AngularGradient(colors=["red", "yellow", "green", "cyan", "blue", "purple", "red"], width=200, height=200)

Reference: Gradients.

Complete Modifier Table

Layout

Parameter Type Default Description Details
width float None Fixed width in points. Layout
height float None Fixed height in points. Layout
min_width float None Minimum width in points. Layout
min_height float None Minimum height in points. Layout
max_width float | str None Maximum width in points, or "infinity". Layout
max_height float | str None Maximum height in points, or "infinity". Layout
padding float | dict None Inner spacing (inside background). Layout
margin float | dict None Outer spacing (outside background). Layout

Appearance

Parameter Type Default Description Details
foreground_color Color | str None Text and content color. Appearance
background Color | str | View None Background color or view. Appearance
fill Color | str None Shape fill color. Appearance
stroke Color | str None Shape stroke color. Appearance
stroke_width float None Shape stroke thickness. Appearance
opacity float None View transparency (0.0--1.0). Appearance
corner_radius float | CornerRadius None Rounded corners in points. Appearance
clip_shape str | View None Clip view to shape. Appearance
visible bool True Show or hide view entirely. Appearance

Typography

Parameter Type Default Description Details
font Font | str None Font configuration. Typography
font_weight FontWeight | str None Text weight. Typography

Effects

Parameter Type Default Description Details
shadow_color Color | str None Drop shadow color. Effects
shadow_radius float None Drop shadow blur radius. Effects
shadow_x float None Drop shadow horizontal offset. Effects
shadow_y float None Drop shadow vertical offset. Effects
border_color Color | str None Border color. Effects
border_width float None Border width in points. Effects
blend_mode BlendMode | str None Layer blending mode. Effects
scale float None Scale transform factor. Effects
offset Offset None Position offset (x, y). Effects
animation Animation None Animation for property changes. Effects
content_transition ContentTransition | str None How content changes animate. Effects
transition Transition | str | TransitionConfig None How view appears/disappears. Effects

Interaction

Parameter Type Default Description
on_drop Callable[[list[str]], None] None Callback for drag-and-drop file handling.
on_hover Callable[[bool], None] None Callback when mouse enters/exits the view.
on_click Callable[[], None] None Callback when the view is clicked.
tooltip str | View None Tooltip text shown on hover.
overlay View None View rendered on top of this view.
context_menu list[View] None Right-click context menu items. Accepts Button, Toggle, Picker, Divider, Text, ShareLink. See Menus.

Drag and drop

on_drop makes a view a drop target. The callback receives one list of strings when the user drops something on the view:

Dropped item String
A file or folder from Finder Its absolute path, e.g. /Users/me/Desktop/report.pdf
A link The URL, e.g. https://example.com
Selected text The text

The items of one drop can mix kinds.

import os
import nib

def main(app: nib.App):
    app.title = "Drop Zone"
    app.icon = nib.SFSymbol("arrow.down.doc")

    status = nib.Text("Drop files here", foreground_color=nib.Color.GRAY)

    def handle_drop(items: list[str]):
        paths = [p for p in items if os.path.isabs(p) and os.path.exists(p)]
        folders = [p for p in paths if os.path.isdir(p)]
        status.content = f"{len(paths)} file(s), {len(folders)} folder(s)"

    app.build(
        nib.VStack(
            controls=[
                nib.SFSymbol("arrow.down.circle", font=nib.Font.system(48)),
                status,
            ],
            spacing=16,
            padding=32,
            on_drop=handle_drop,
            border_color="gray",
            border_width=1,
            corner_radius=12,
        )
    )

nib.run(main)

The Drop Zone example combines on_drop with the clipboard, a hotkey and a notification.