🎯

gpui-layout-and-style

🎯Skill

from longbridge/gpui-component

VibeIndex|
What it does

Provides CSS-like layout and styling for Rust GPUI components using type-safe, chainable methods for flexbox, sizing, colors, and spacing.

gpui-layout-and-style

Installation

Install skill:
npx skills add https://github.com/longbridge/gpui-component --skill gpui-layout-and-style
23
Last UpdatedJan 26, 2026

Skill Details

SKILL.md

Layout and styling in GPUI. Use when styling components, layout systems, or CSS-like properties.

Overview

GPUI provides CSS-like styling with Rust type safety.

Key Concepts:

  • Flexbox layout system
  • Styled trait for chaining styles
  • Size units: px(), rems(), relative()
  • Colors, borders, shadows

Quick Start

Basic Styling

```rust

use gpui::*;

div()

.w(px(200.))

.h(px(100.))

.bg(rgb(0x2196F3))

.text_color(rgb(0xFFFFFF))

.rounded(px(8.))

.p(px(16.))

.child("Styled content")

```

Flexbox Layout

```rust

div()

.flex()

.flex_row() // or flex_col() for column

.gap(px(8.))

.items_center()

.justify_between()

.children([

div().child("Item 1"),

div().child("Item 2"),

div().child("Item 3"),

])

```

Size Units

```rust

div()

.w(px(200.)) // Pixels

.h(rems(10.)) // Relative to font size

.w(relative(0.5)) // 50% of parent

.min_w(px(100.))

.max_w(px(400.))

```

Common Patterns

Centered Content

```rust

div()

.flex()

.items_center()

.justify_center()

.size_full()

.child("Centered")

```

Card Layout

```rust

div()

.w(px(300.))

.bg(cx.theme().surface)

.rounded(px(8.))

.shadow_md()

.p(px(16.))

.gap(px(12.))

.flex()

.flex_col()

.child(heading())

.child(content())

```

Responsive Spacing

```rust

div()

.p(px(16.)) // Padding all sides

.px(px(20.)) // Padding horizontal

.py(px(12.)) // Padding vertical

.pt(px(8.)) // Padding top

.gap(px(8.)) // Gap between children

```

Styling Methods

Dimensions

```rust

.w(px(200.)) // Width

.h(px(100.)) // Height

.size(px(200.)) // Width and height

.min_w(px(100.)) // Min width

.max_w(px(400.)) // Max width

```

Colors

```rust

.bg(rgb(0x2196F3)) // Background

.text_color(rgb(0xFFFFFF)) // Text color

.border_color(rgb(0x000000)) // Border color

```

Borders

```rust

.border(px(1.)) // Border width

.rounded(px(8.)) // Border radius

.rounded_t(px(8.)) // Top corners

.border_color(rgb(0x000000))

```

Spacing

```rust

.p(px(16.)) // Padding

.m(px(8.)) // Margin

.gap(px(8.)) // Gap between flex children

```

Flexbox

```rust

.flex() // Enable flexbox

.flex_row() // Row direction

.flex_col() // Column direction

.items_center() // Align items center

.justify_between() // Space between items

.flex_grow() // Grow to fill space

```

Theme Integration

```rust

div()

.bg(cx.theme().surface)

.text_color(cx.theme().foreground)

.border_color(cx.theme().border)

.when(is_hovered, |el| {

el.bg(cx.theme().hover)

})

```

Conditional Styling

```rust

div()

.when(is_active, |el| {

el.bg(cx.theme().primary)

})

.when_some(optional_color, |el, color| {

el.bg(color)

})

```

Reference Documentation

  • Complete Guide: See [reference.md](references/reference.md)

- All styling methods

- Layout strategies

- Theming, responsive design

More from this repository10

🎯
gpui-style-guide🎯Skill

Enforces consistent GPUI component design patterns by providing a comprehensive style guide for creating and reviewing Rust UI components.

🎯
gpui-async🎯Skill

Enables asynchronous operations and background tasks in GPUI, allowing seamless coordination between UI updates and concurrent computations.

🎯
gpui-event🎯Skill

Enables type-safe event handling, subscriptions, and observations for coordinating component interactions in GPUI applications.

🎯
gpui-entity🎯Skill

Manages application state through safe, concurrent entities with read, update, and weak reference capabilities for reactive and async-friendly state handling in GPUI.

🎯
gpui-focus-handle🎯Skill

Enables keyboard-driven focus management and navigation between focusable elements in GPUI user interfaces.

🎯
gpui-action🎯Skill

Defines and manages keyboard-driven actions and key bindings for declarative UI interactions in GPUI applications.

🎯
gpui-context🎯Skill

gpui-context skill from longbridge/gpui-component

🎯
gpui-test🎯Skill

Enables comprehensive testing of GPUI applications with deterministic, single-threaded test execution for UI components and async operations.

🎯
gpui-element🎯Skill

Enables low-level, performance-critical custom UI element creation with precise control over layout, painting, and interaction phases in GPUI.

🎯
gpui-global🎯Skill

Manages global application state and configuration in GPUI, enabling centralized data access and sharing across components.