Slint · Slint components

This page shows the Slint implementation. Slint components written for native Rust applications and the browser. Browse the catalog, run each live example, and copy the .slint source into your own app.

Checkbox

A checkbox component for binary choices. Supports labels, disabled state, and different sizes.

Install

Use on_change for requested values. The owner stores the value and calls cx.notify(). The existing on_click name remains a compatibility alias; setting either replaces the same handler, so the last call wins.

#Import

use gpui_kit::component::checkbox::Checkbox;
// Installed in ui/components. That directory is on the Slint include path, so import by file name:
import { Checkbox } from "checkbox.slint";
use iced::widget::{column, container, mouse_area, row, scrollable, svg, text};
use iced::{Alignment, Element, Length, Task, Theme};
import { signal, Text, View } from "nsh";
import { Avatar } from "./avatar";
import { Badge } from "./badge";
import { Checkbox, CheckboxGroup } from "./checkbox";
import { Icon } from "./icon";
import { tokens } from "./theme";

#Usage

GPUINo GPUI version of this example yet.
SlintNo Slint version of this example yet.
const usage = (
  <Checkbox
    checked={basicState()}
    onChange={(next) => basicState.set(next)}
    label="Accept the terms and conditions"
    description="You can change this later in settings."
  />
);

#Basic

Checkbox::new("my-checkbox")
    .label("Accept terms and conditions")
    .checked(false)
    .on_change(|checked, _, _| {
        println!("Checkbox is now: {}", checked);
    })
Checkbox {
    label: "Accept terms and conditions";
    checked: true;
}
Checkbox {
    label: "Receive product updates";
    description: "Occasional emails about new releases.";
}
Checkbox {
    label: "Indeterminate";
    indeterminate: true;
}
Checkbox {
    label: "Disabled";
    enabled: false;
}
// The four looks the Slint example opens with: the plain choice, the one
// with a supporting line, the indeterminate dash, and a disabled control.
let basic = column![
    Checkbox::new(app.terms)
        .label("Accept terms and conditions")
        .on_toggle(Message::Terms),
    Checkbox::new(app.product_updates)
        .label("Receive product updates")
        .description("Occasional emails about new releases.")
        .on_toggle(Message::ProductUpdates),
    // `indeterminate(true)` draws the minus while the box is unchecked;
    // toggling it on draws the tick, as Slint's does.
    Checkbox::new(app.some)
        .indeterminate(true)
        .label("Indeterminate")
        .on_toggle(Message::Indeterminate),
    // No message is how iced draws a control that cannot be pressed.
    Checkbox::new(false).label("Disabled"),
]
.spacing(12.0);
const basic = (
  <Checkbox
    checked={basicState()}
    onChange={(next) => basicState.set(next)}
    label="Accept the terms and conditions"
  />
);

The on_change callback is triggered when the user toggles the checkbox, receiving the new checked state.

#Default

GPUINo GPUI version of this example yet.
SlintNo Slint version of this example yet.
// Checked and unchecked options mixed freely in one column.
let default = column![
    Checkbox::new(app.default_updates)
        .label("Product updates")
        .on_toggle(Message::DefaultUpdates),
    Checkbox::new(app.default_remember)
        .label("Remember this device")
        .on_toggle(Message::DefaultRemember),
]
.spacing(12.0);
const normal = (
  <Row gap={10} style={{ flexDirection: "column", maxWidth: 420 }}>
    <Checkbox defaultChecked label="Email me about updates" description="No more than once a month." />
    <Checkbox label="Product announcements" description="New features, sent roughly each quarter." />
  </Row>
);

Checked and unchecked options can be mixed freely.

Checkbox::new("updates")
    .label("Product updates")
    .checked(false)

Checkbox::new("remember")
    .label("Remember this device")
    .checked(true)
Checkbox {
    label: "Product updates";
}
Checkbox {
    label: "Remember this device";
    checked: true;
}
NSHNo NSH version of this example yet.

#Sizes

use gpui_kit::component::Sizable as _;

Checkbox::new("cb").text_xs().label("Extra Small")
Checkbox::new("cb").text_sm().label("Small")
Checkbox::new("cb").label("Medium") // default
Checkbox::new("cb").text_lg().label("Large")
GridLayout {
    horizontal-stretch: 1;
    spacing: 16px;
    Checkbox {
        horizontal-stretch: 0;
        label: "XS";
        size: ControlSize.xsmall;
        checked: true;
    }
    Checkbox {
        horizontal-stretch: 0;
        label: "SM";
        size: ControlSize.small;
        checked: true;
    }
    Checkbox {
        horizontal-stretch: 0;
        label: "MD";
        checked: true;
    }
    Checkbox {
        horizontal-stretch: 0;
        label: "LG";
        size: ControlSize.large;
        checked: true;
    }
}
// The box's side is 12 / 14 / 16 / 18 across the size ladder.
let sizes = row![
    Checkbox::new(app.size_xs)
        .size(ControlSize::XSmall)
        .label("XS")
        .on_toggle(Message::SizeXs),
    Checkbox::new(app.size_sm)
        .size(ControlSize::Small)
        .label("SM")
        .on_toggle(Message::SizeSm),
    Checkbox::new(app.size_md)
        .size(ControlSize::Medium)
        .label("MD")
        .on_toggle(Message::SizeMd),
    Checkbox::new(app.size_lg)
        .size(ControlSize::Large)
        .label("LG")
        .on_toggle(Message::SizeLg),
]
.spacing(16.0);
const sizes = (
  <Row gap={16}>
    <Checkbox size="small" defaultChecked label="Small" />
    <Checkbox defaultChecked label="Medium" />
    <Checkbox size="large" defaultChecked label="Large" />
  </Row>
);

#Controlled Checkbox

GPUINo GPUI version of this example yet.
SlintNo Slint version of this example yet.
// The value lives on the application: `on_toggle` reports the requested
// value, `update` stores it, and the next frame draws it — what Slint's
// `checked <=> root.updates` binding does.
let controlled = column![
    Checkbox::new(app.controlled)
        .label("Receive product updates")
        .on_toggle(Message::Controlled),
    muted_line(if app.controlled {
        "Subscribed"
    } else {
        "Not subscribed"
    }),
]
.spacing(8.0);
const controlledView = (
  <Checkbox
    checked={controlled()}
    onChange={(next) => controlled.set(next)}
    label={controlled() ? "Checked" : "Unchecked"}
  />
);

This complete Tested consumer recipe keeps the value on the rendering owner and applies the requested value from on_change before notifying:

use gpui_kit::component::checkbox::Checkbox;
use gpui_kit::{Context, IntoElement, Render, Window};

pub struct ControlledCheckbox {
    checked: bool,
}

impl ControlledCheckbox {
    pub fn new() -> Self {
        Self { checked: false }
    }

    pub fn is_checked(&self) -> bool {
        self.checked
    }
}

impl Render for ControlledCheckbox {
    fn render(&mut self, _: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
        Checkbox::new("marketing-emails")
            .label("Receive product updates")
            .checked(self.checked)
            .on_change(cx.listener(|this, checked, _, cx| {
                this.checked = *checked;
                cx.notify();
            }))
    }
}
Checkbox {
    label: "Receive product updates";
    checked <=> root.updates;
}
Text {
    text: root.updates ? "Subscribed" : "Not subscribed";
    color: Theme.muted-foreground;
    font-size: Theme.font-size-xs;
}
NSHNo NSH version of this example yet.

#Disabled State

use gpui_kit::component::Disableable as _;

Checkbox::new("disabled-checked")
    .label("Checked")
    .checked(true)
    .disabled(true)

Checkbox::new("disabled-unchecked")
    .label("Unchecked")
    .checked(false)
    .disabled(true)
Checkbox {
    label: "Checked";
    checked: true;
    enabled: false;
}
Checkbox {
    label: "Unchecked";
    enabled: false;
}
// The two disabled looks, one on and one off.
let disabled = column![
    Checkbox::new(true).label("Checked"),
    Checkbox::new(false).label("Unchecked"),
]
.spacing(12.0);
const disabledView = (
  <Row gap={16}>
    <Checkbox disabled label="Disabled" />
    <Checkbox disabled defaultChecked label="Disabled, checked" />
    <Checkbox disabled indeterminate label="Disabled, mixed" />
  </Row>
);

#Without Label

Checkbox::new("checkbox")
    .checked(true)
Checkbox {
    checked: true;
}
// The box alone, with no line beside it.
let without_label = Checkbox::new(app.without_label).on_toggle(Message::WithoutLabel);
const withoutLabel = (
  <Row gap={10}>
    <Checkbox defaultChecked />
    <Checkbox />
    <Checkbox indeterminate />
  </Row>
);

#Labels

GPUINo GPUI version of this example yet.
SlintNo Slint version of this example yet.
// iced has one supporting slot under the label, `description`, where Slint
// nests a second `Text`. The page's wrapping and markdown children have no
// iced counterpart, so the supporting sentence is the description here.
let labels = column![
    Checkbox::new(app.label_updates)
        .label("Automatic updates")
        .description("Download updates when the application is idle.")
        .on_toggle(Message::LabelUpdates),
    Checkbox::new(app.label_notify)
        .label("Notify me when a new device signs in to my account")
        .on_toggle(Message::LabelNotify),
    Checkbox::new(app.label_terms)
        .label("Accept the terms")
        .description("Read the terms of service before continuing.")
        .on_toggle(Message::LabelTerms),
]
.spacing(12.0);
const labels = (
  <Row gap={10} style={{ flexDirection: "column", maxWidth: 420 }}>
    <Checkbox defaultChecked label="Email me about updates" description="No more than once a month." />
    <Checkbox label="Enable advanced analytics" leading={<Info />} />
  </Row>
);

Labels can wrap and include supporting content.

Checkbox::new("description")
    .label("Automatic updates")
    .child(
        div()
            .text_xs()
            .child("Download updates when the application is idle."),
    )

Checkbox::new("wrapping")
    .label("Notify me when a new device signs in to my account")

Checkbox::new("markdown")
    .label("Accept the terms")
    .child(markdown(
        "Read the [terms of service](https://github.com) before continuing.",
    ))
Checkbox {
    label: "Automatic updates";
    description: "Download updates when the application is idle.";
    checked: true;
}
Checkbox {
    label: "Notify me when a new device signs in to my account";
}
Checkbox {
    label: "Accept the terms";
    description: "Read the terms of service before continuing.";
}
NSHNo NSH version of this example yet.

#Custom Tab Order

Checkbox::new("checkbox")
    .label("Custom tab order")
    .tab_index(2)
    .tab_stop(true)
SlintNo Slint version of this example yet.
const tabOrder = (
  <Row gap={12}>
    <Checkbox defaultChecked label="First" />
    <Checkbox label="Second" />
    <Checkbox defaultChecked label="Third" />
  </Row>
);

#Checkbox List

GPUINo GPUI version of this example yet.
SlintNo Slint version of this example yet.
const list = (
  <CheckboxGroup frame style={{ width: 420, maxWidth: "100%" }}>
    <Checkbox block defaultChecked label="Design" description="Components and tokens." />
    <Checkbox block label="Engineering" description="Platform and native shells." />
    <Checkbox block defaultChecked label="Docs" description="Guides and API reference." />
  </CheckboxGroup>
);

#Invalid checkbox

GPUINo GPUI version of this example yet.
SlintNo Slint version of this example yet.
const invalidView = (
  <Column gap={8}>
    <Checkbox label="Accept the terms" variant="card" style={{ width: 300, borderColor: tokens.danger }} />
    <Row gap={6}>
      <Icon name="circle-alert" size={12} color={tokens.danger} />
      <Text style={{ fontSize: 11, color: tokens.danger }}>You must accept the terms to continue.</Text>
    </Row>
    {invalid() ? null : null}
  </Column>
);

#Indeterminate checkbox

GPUINo GPUI version of this example yet.
SlintNo Slint version of this example yet.
const indeterminate = (
  <Checkbox indeterminate label="Indeterminate state" />
);

#Colored checkbox

GPUINo GPUI version of this example yet.
SlintNo Slint version of this example yet.
const colored = (
  <Column gap={8}>
    <Checkbox defaultChecked color={tokens.info} label="Blue checkbox" />
    <Checkbox defaultChecked color={tokens.success} label="Green checkbox" />
    <Checkbox defaultChecked color={tokens.warning} label="Yellow checkbox" />
  </Column>
);

#Circle checkbox

GPUINo GPUI version of this example yet.
SlintNo Slint version of this example yet.
const circle = (
  <Row gap={16}>
    <Checkbox shape="circle" defaultChecked label="Circle checkbox" />
    <Checkbox shape="circle" label="Circle unchecked" />
  </Row>
);

#Checkbox group

GPUINo GPUI version of this example yet.
SlintNo Slint version of this example yet.
const group = (
  <CheckboxGroup label="Notification Settings" style={{ width: 360, maxWidth: "100%" }}>
    <Checkbox label="Email notifications" checked={cardChannels().email} onChange={(next) => cardChannels.update((value) => ({ ...value, email: next }))} />
    <Checkbox label="SMS notifications" checked={cardChannels().sms} onChange={(next) => cardChannels.update((value) => ({ ...value, sms: next }))} />
    <Checkbox label="Push notifications" checked={cardChannels().push} onChange={(next) => cardChannels.update((value) => ({ ...value, push: next }))} />
  </CheckboxGroup>
);

#Card checkbox with group

GPUINo GPUI version of this example yet.
SlintNo Slint version of this example yet.
const cardWithGroup = (
  <Checkbox
    variant="card"
    block
    checked={enableNotifications()}
    onChange={(next) => enableNotifications.set(next)}
    label="Enable notifications"
    description="You can enable or disable notifications at any time."
    style={{ width: 380, maxWidth: "100%" }}
  />
);

#Checkbox group in a frame

GPUINo GPUI version of this example yet.
SlintNo Slint version of this example yet.
const framed = (
  <CheckboxGroup
    frame
    label="Notification Settings"
    style={{ width: 360, maxWidth: "100%" }}
  >
    <Checkbox variant="card" block checked={cardChannels().push} onChange={(next) => cardChannels.update((value) => ({ ...value, push: next }))} label="Push notifications" />
    <Checkbox variant="card" block checked={cardChannels().email} onChange={(next) => cardChannels.update((value) => ({ ...value, email: next }))} label="Email notifications" />
    <Checkbox variant="card" block checked={cardChannels().sms} onChange={(next) => cardChannels.update((value) => ({ ...value, sms: next }))} label="SMS notifications" />
  </CheckboxGroup>
);

#Card checkbox group with icons

GPUINo GPUI version of this example yet.
SlintNo Slint version of this example yet.
const iconCards = (
  <CheckboxGroup frame style={{ width: 380, maxWidth: "100%" }}>
    <Checkbox variant="card" block icon="bell" checked={cardChannels().push} onChange={(next) => cardChannels.update((value) => ({ ...value, push: next }))} label="Push notifications" />
    <Checkbox variant="card" block icon="mail" checked={cardChannels().email} onChange={(next) => cardChannels.update((value) => ({ ...value, email: next }))} label="Email notifications" />
    <Checkbox variant="card" block icon="message-circle" checked={cardChannels().sms} onChange={(next) => cardChannels.update((value) => ({ ...value, sms: next }))} label="SMS notifications" />
  </CheckboxGroup>
);

#Custom positioned checkbox

GPUINo GPUI version of this example yet.
SlintNo Slint version of this example yet.
const featureCards = () => {
  const items = [
    { id: "payments", label: "Payments", description: "Receive payments from your customers", icon: "circle-dollar-sign" },
    { id: "invoices", label: "Invoices", description: "Create and send invoices to your customers", icon: "file-text" },
    { id: "billing", label: "Billing", description: "Manage your billing and subscriptions", icon: "credit-card" },
    { id: "reports", label: "Reports", description: "View your reports and analytics", icon: "bar-chart-3" },
  ];
  return (
    <Row gap={8} style={{ flexWrap: "wrap", width: 380, maxWidth: "100%" }}>
      {items.map((item) => (
        <Checkbox
          variant="icon"
          icon={item.icon as never}
          block
          checked={cards()[item.id]}
          onChange={(next) => cards.update((value) => ({ ...value, [item.id]: next }))}
          label={item.label}
          description={item.description}
          style={{ width: 184 }}
        />
      ))}
    </Row>
  );
};

#Avatar based card checkbox

GPUINo GPUI version of this example yet.
SlintNo Slint version of this example yet.
const avatarCard = (
  <Checkbox
    variant="card"
    block
    icon="user"
    checked={true}
    onChange={() => {}}
    leading={<Avatar name="Emma Wilson" size="sm" />}
    label="Emma Wilson"
    description="@emmawilson"
    style={{ width: 380, maxWidth: "100%" }}
  />
);

#Payment method card checkbox

GPUINo GPUI version of this example yet.
SlintNo Slint version of this example yet.
const paymentCard = (
  <Checkbox
    variant="card"
    block
    onChange={() => {}}
    checked
    leading={
      <View style={{ flexDirection: "row" }}>
        <View style={{ width: 22, height: 22, borderRadius: 11, backgroundColor: tokens.warning, marginEnd: -6 }} />
        <View style={{ width: 22, height: 22, borderRadius: 11, backgroundColor: tokens.danger, opacity: 0.9 }} />
      </View>
    }
    label="Mastercard ending in 8888"
    description="Expires 09/25"
    style={{ width: 380, maxWidth: "100%" }}
  />
);

#Checkbox with label and tooltip info

GPUINo GPUI version of this example yet.
SlintNo Slint version of this example yet.
const withInfo = (
  <Checkbox label="Enable advanced analytics" leading={<Info />} />
);

#Checkbox with feature badge

GPUINo GPUI version of this example yet.
SlintNo Slint version of this example yet.
const badges = (
  <Column gap={8}>
    <Checkbox checked={features().ai} onChange={(next) => features.update((value) => ({ ...value, ai: next }))} label="AI-powered suggestions" badge="NEW" />
    <Checkbox checked={features().beta} onChange={(next) => features.update((value) => ({ ...value, beta: next }))} label="Beta feature access" badge="BETA" />
  </Column>
);

#Checkbox group with badge

GPUINo GPUI version of this example yet.
SlintNo Slint version of this example yet.
const badgeGroups = (
  <Column gap={8} style={{ width: 340, maxWidth: "100%" }}>
    <Checkbox variant="card" block label="AI-powered suggestions" badge="NEW" />
    <Checkbox variant="card" block label="Beta feature access" badge="BETA" />
  </Column>
);

#Inline horizontal checkbox group

GPUINo GPUI version of this example yet.
SlintNo Slint version of this example yet.
const inline = (
  <Row gap={14}>
    <Checkbox defaultChecked label="Read" />
    <Checkbox label="Write" />
    <Checkbox defaultChecked label="Delete" />
  </Row>
);

#Nested checkbox group

v_flex()
    .gap_2()
    .child(Checkbox::new("cb1").label("Option 1").checked(true))
    .child(Checkbox::new("cb2").label("Option 2").checked(false))
    .child(Checkbox::new("cb3").label("Option 3").checked(false))
Checkbox {
    label: "Option 1";
    checked: true;
}
Checkbox {
    label: "Option 2";
}
Checkbox {
    label: "Option 3";
}
// Independent choices: each box carries its own value.
let list = column![
    Checkbox::new(app.option_1)
        .label("Option 1")
        .on_toggle(Message::Option1),
    Checkbox::new(app.option_2)
        .label("Option 2")
        .on_toggle(Message::Option2),
    Checkbox::new(app.option_3)
        .label("Option 3")
        .on_toggle(Message::Option3),
]
.spacing(12.0);
const nested = () => (
  <View style={{ gap: 6, width: 420, maxWidth: "100%" }}>
    <Checkbox
      checked={permissions().admin}
      indeterminate={!permissions().admin && permissions().userManagement}
      onChange={(next) =>
        permissions.set(
          next
            ? { admin: true, userManagement: true, viewUsers: true, createUsers: true, editUsers: true, roleManagement: true, viewRoles: true, assignRoles: true }
            : { admin: false, userManagement: false, viewUsers: false, createUsers: false, editUsers: false, roleManagement: false, viewRoles: false, assignRoles: false },
        )
      }
      label="Administration"
    >
      {childRows().map((row) => (
        <View style={{ gap: 4 }}>
          <Checkbox
            checked={permissions()[row.value] ?? false}
            onChange={(next) => permissions.update((value) => ({ ...value, [row.value]: next }))}
            label={row.label}
          >
            {row.children.map((child) => (
              <Checkbox
                checked={permissions()[child] ?? false}
                onChange={(next) => permissions.update((value) => ({ ...value, [child]: next }))}
                label={{
                  viewUsers: "View Users",
                  createUsers: "Create Users",
                  editUsers: "Edit Users",
                  viewRoles: "View Roles",
                  assignRoles: "Assign Roles",
                }[child] ?? child}
              />
            ))}
          </Checkbox>
        </View>
      ))}
    </Checkbox>
  </View>
);

#Form Integration

struct FormView {
    agree_terms: bool,
    subscribe: bool,
}

v_flex()
    .gap_3()
    .child(
        Checkbox::new("terms")
            .label("I agree to the terms and conditions")
            .checked(self.agree_terms)
            .on_change(cx.listener(|view, checked, _, cx| {
                view.agree_terms = *checked;
                cx.notify();
            }))
    )
    .child(
        Checkbox::new("subscribe")
            .label("Subscribe to newsletter")
            .checked(self.subscribe)
            .on_change(cx.listener(|view, checked, _, cx| {
                view.subscribe = *checked;
                cx.notify();
            }))
    )
Checkbox {
    label: "I agree to the terms and conditions";
    checked <=> root.terms;
}
Checkbox {
    label: "Subscribe to newsletter";
    checked <=> root.newsletter;
}
// Two boxes of one form, each with its own value on the owner.
let form = column![
    Checkbox::new(app.form_terms)
        .label("I agree to the terms and conditions")
        .on_toggle(Message::FormTerms),
    Checkbox::new(app.form_newsletter)
        .label("Subscribe to newsletter")
        .on_toggle(Message::FormNewsletter),
]
.spacing(12.0);
NSHNo NSH version of this example yet.

#API Reference

#Styling

Implements Sizable and Disableable traits:

  • text_xs() - Extra small text
  • text_sm() - Small text
  • text_base() - Base text (default)
  • text_lg() - Large text
  • disabled(bool) - Disabled state

#Checkbox

A binary choice. Mirrors GPUI Component's `Checkbox`: a label, optional description, indeterminate dash, sizes, and a disabled state.

NameKindTypeDefault
checkedin-outbool
indeterminateinbool
labelinstring
descriptioninstring
enabledinbooltrue
sizeinControlSizeControlSize.medium
changedcallback(checked: bool)