Skip to content

aivi.px

A domain type for pixel dimensions. Wraps Int to give pixel values a distinct type identity so they cannot be accidentally mixed with unrelated integers.

Import

aivi
use aivi.px (
    Px
    px
)

Overview

NameTypeDescription
Pxdomain over IntA pixel dimension
pxInt -> PxConstruct a Px value
zeroPxZero pixels
addPxPx -> Px -> PxAdd two pixel values
subPxPx -> Px -> PxSubtract pixel values
scalePxPx -> Float -> PxScale a pixel value by a float factor
maxPxPx -> Px -> PxLarger of two pixel values
minPxPx -> Px -> PxSmaller of two pixel values

Usage

Construct Px values with px n and pass them into widget attributes that accept Int by using the GTK bridge's carrier-unwrapping (widget attributes accept Px values directly — the bridge handles unwrapping automatically).

aivi
use aivi.px (
    Px
    px
    addPx
)

type Layout = {
    iconSize: Px,
    padding: Px
}

value layout : Layout = {
    iconSize: px 48,
    padding: px 12
}

Arithmetic

aivi
use aivi.px (
    Px
    px
    addPx
    subPx
    scalePx
    maxPx
)

value base : Px = px 8
value larger : Px = addPx base base
value smaller : Px = subPx base (px 2)
value half : Px = scalePx base 0.5
value capped : Px = maxPx base (px 16)

(c) 2026 by Andreas Herd