Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
b74a60a
Builder::ctx and per-build base text
samitbasu Nov 8, 2026
0aa1a51
Add the shadcn/ui preset and make the primitives follow it
samitbasu Nov 8, 2026
b6dd55c
Run kittest's accessibility check in every test file
samitbasu Nov 8, 2026
2852ea2
chat_shell follows light and dark through the shadcn preset
samitbasu Nov 8, 2026
c994876
Examples run on the shadcn preset
samitbasu Nov 8, 2026
8b9b354
Accent, semantic and hover tokens; selection, popup height, Shadcn::o…
samitbasu Nov 8, 2026
afe3842
Test fit-content and wrapping segmented tracks (#18 item 4)
samitbasu Nov 8, 2026
f04ad1e
Button variants and shadcn checkbox/radio looks (#18 items 1-2)
samitbasu Nov 8, 2026
9378a12
Examples use the accent, semantic colours and Shadcn::of (#18 items 8…
samitbasu Nov 8, 2026
71a33e8
chat_shell: the mode control's pressed cell is Line on the muted comp…
samitbasu Nov 8, 2026
9ea2baf
Dark accents fill with their bright shade; hyperlinks use the ring (#…
samitbasu Nov 8, 2026
3b27fc6
controls_gallery: Button variant cells, enabled and disabled (#18 ite…
samitbasu Nov 8, 2026
5616648
Every example follows the OS theme and shows a System/Light/Dark togg…
samitbasu Nov 8, 2026
2daaebd
style::tokens read the theme before taking the data lock (#18)
samitbasu Nov 8, 2026
09eb791
controls_gallery uses the Blue accent like form (#18 item 20)
samitbasu Nov 8, 2026
cd899df
button, todo, kaolin and known_gaps follow the theme (#18 item 18)
samitbasu Nov 8, 2026
afdce0f
kaolin sidebar rows are library-sized buttons (#18 item 21)
samitbasu Nov 8, 2026
e764acb
shadcn slider: circular opaque thumb, muted track, primary range (#18…
samitbasu Nov 8, 2026
6f55d2e
hyperlink_color is primary, following shadcn's link variant (#18 item…
samitbasu Nov 8, 2026
f8fcbd5
a selectable button is shadcn's Toggle (#18 item 23)
samitbasu Nov 8, 2026
c15ffe3
kaolin: sidebar uses the background surface so the selected row shows…
samitbasu Nov 8, 2026
00fc804
style: nudge dark violet primary to 4.5:1 on the page, drop the test …
samitbasu Nov 8, 2026
14e4afb
chat_shell: details panel as a grouped form (#18 item 26)
samitbasu Nov 8, 2026
8cbf11a
snapshots: every example golden paints the page its live example does…
samitbasu Nov 8, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 53 additions & 20 deletions examples/button.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,30 @@
#[path = "common/mod.rs"]
mod common;

use bullseye::style::Tokens;
use bullseye::widget::Button;
use bullseye::{Builder, Tw, tw};
use egui::Color32;

type B<'b, 'f, A> = Builder<'b, 'f, A>;

pub const FILL: Color32 = Color32::from_gray(232);
pub const FILL_HOVER: Color32 = Color32::from_gray(218);
pub const FILL_PRESSED: Color32 = Color32::from_gray(200);
pub const FILL_SELECTED: Color32 = Color32::from_rgb(170, 196, 232);
const EDGE: Color32 = Color32::from_gray(176);
const INK: Color32 = Color32::from_gray(20);
/// The fills of a button in each state, from the theme's tokens.
#[derive(Clone, Copy, Debug)]
pub struct Fills {
pub rest: Color32,
pub hover: Color32,
pub pressed: Color32,
}

impl Fills {
pub fn of(t: &Tokens) -> Self {
Self {
rest: t.secondary,
hover: t.border,
pressed: t.ring,
}
}
}

#[derive(Default)]
pub struct State {
Expand Down Expand Up @@ -54,28 +66,48 @@ const ALIGNMENTS: [(&str, Align); 4] = [
("STRETCH", Tw::self_stretch),
];

/// A button's look. A selected one keeps its fill under the pointer.
/// A button's look.
///
/// ```html
/// <div class="flex flex-col items-center p-2 rounded border border-[#b0b0b0] text-[#141414]
/// bg-[#e8e8e8] hover:bg-[#dadada] active:bg-[#c8c8c8]">...</div>
/// <div class="... bg-[#aac4e8] active:bg-[#c8c8c8]">...</div>
/// <div class="flex flex-col items-center p-2 rounded border border-input text-foreground
/// bg-secondary hover:bg-border active:bg-ring">...</div>
/// ```
fn button(selected: bool) -> Tw {
fn button(t: &Tokens) -> Tw {
let fills = Fills::of(t);
tw().flex()
.flex_col()
.items_center()
.p(2.0)
.rounded()
.border(1.0)
.border_color(t.input)
.active(|p| p.bg(fills.pressed))
.bg(fills.rest)
.text(t.foreground)
.hover(|p| p.bg(fills.hover))
}

/// A selectable button's look, shadcn's Toggle: a selected one keeps its
/// `accent` fill under the pointer.
///
/// ```html
/// <div class="flex flex-col items-center p-2 rounded text-foreground
/// hover:bg-muted hover:text-muted-foreground">...</div>
/// <div class="... bg-accent text-accent-foreground">...</div>
/// ```
fn toggle(t: &Tokens, selected: bool) -> Tw {
let look = tw()
.flex()
.flex_col()
.items_center()
.p(2.0)
.rounded()
.border(1.0)
.border_color(EDGE)
.text(INK)
.active(|p| p.bg(FILL_PRESSED));
.sense_click();
if selected {
look.bg(FILL_SELECTED)
look.bg(t.accent).text(t.accent_foreground)
} else {
look.bg(FILL).hover(|p| p.bg(FILL_HOVER))
look.text(t.foreground)
.hover(|p| p.bg(t.muted).text(t.muted_foreground))
}
}

Expand Down Expand Up @@ -107,6 +139,7 @@ fn content<A>(b: &mut B<'_, '_, A>, title: &str) {
/// </div>
/// ```
pub fn demo(b: &mut B<'_, '_, State>, state: &State) {
let t = common::tokens(b.ctx());
b.div(
tw().flex()
.flex_col()
Expand All @@ -118,15 +151,15 @@ pub fn demo(b: &mut B<'_, '_, State>, state: &State) {
|b| {
b.div_id(
"button",
button(false),
button(&t),
common::on_click::<State>(|state| state.clicks += 1),
|b| content(b, "Button"),
);
b.text(tw(), format!("Button clicked {} times", state.clicks));
b.rule(tw().h_px(1.0).bg(EDGE));
b.rule(tw().h_px(1.0).bg(t.border));
b.div_id(
"selectable",
button(state.selected),
toggle(&t, state.selected),
common::on_click::<State>(|state| state.selected = !state.selected),
|b| content(b, "Selectable button"),
);
Expand Down
36 changes: 18 additions & 18 deletions examples/chat_shell/centre.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ type B<'b, 'f> = Builder<'b, 'f, App>;
/// The model select, in the shape of a chip.
///
/// ```html
/// <header class="flex items-center justify-between h-12 shrink-0 px-4 border-b border-[#383838]">
/// <header class="flex items-center justify-between h-12 shrink-0 px-4 border-b border-border">
/// <h2 class="text-[15px]">Refactor the tokenizer</h2>
/// <select class="rounded-lg border border-[#383838] bg-[#2b2b2b] px-2.5 py-1 text-[13px] text-[#a8a8a8]">
/// <select class="rounded-lg border border-border bg-muted px-2.5 py-1 text-[13px] text-muted-foreground">
/// <option>Assistant 1</option> <!-- Assistant 2, Assistant 3 -->
/// </select>
/// </header>
/// ```
fn top_bar(b: &mut B<'_, '_>, app: &App) {
let k = &app.theme;
let k = &Theme::of(b.ctx());
let title = app
.sessions
.iter()
Expand Down Expand Up @@ -65,7 +65,7 @@ fn top_bar(b: &mut B<'_, '_>, app: &App) {
/// ```html
/// <div class="flex flex-col gap-2.5 text-[15px] leading-6">
/// <p>Yes. Most tokens are slices of the input...</p>
/// <code class="self-start px-2 py-0.5 rounded bg-[#2b2b2b] font-mono text-[13px]">...</code>
/// <code class="self-start px-2 py-0.5 rounded bg-muted font-mono text-[13px]">...</code>
/// </div>
/// ```
fn assistant(b: &mut B<'_, '_>, k: &Theme, blocks: &[Block]) {
Expand Down Expand Up @@ -95,7 +95,7 @@ fn assistant(b: &mut B<'_, '_>, k: &Theme, blocks: &[Block]) {
}

/// ```html
/// <div class="self-end max-w-[480px] px-4 py-2.5 rounded-2xl bg-[#2b2b2b] text-[15px] leading-6">...</div>
/// <div class="self-end max-w-[480px] px-4 py-2.5 rounded-2xl bg-muted text-[15px] leading-6">...</div>
/// ```
fn user(b: &mut B<'_, '_>, k: &Theme, text: &str) {
b.div(
Expand All @@ -111,7 +111,7 @@ fn user(b: &mut B<'_, '_>, k: &Theme, text: &str) {
}

fn conversation(b: &mut B<'_, '_>, app: &App) {
let k = &app.theme;
let k = &Theme::of(b.ctx());
b.div_id(
Part::Conversation,
tw().flex()
Expand Down Expand Up @@ -149,7 +149,7 @@ fn tool_button(k: &Theme, shape: Tw) -> Tw {
.justify_center()
.size_px(32.0)
.shrink_0()
.hover(|p| p.bg(k[Tok::Hover]))
.hover(|p| p.bg(k[Tok::Line]))
}

/// The reply field is as tall as its text, from `COMPOSER_MIN_ROWS` rows to
Expand Down Expand Up @@ -185,13 +185,13 @@ fn field(b: &mut B<'_, '_>, app: &App) {
///
/// ```html
/// <div class="flex items-center gap-0.5 text-[13px]">
/// <span class="px-2.5 py-1 rounded-lg text-[#a8a8a8] hover:bg-[#2e2e2e] focus-visible:ring-2">Quick</span>
/// <span class="px-2.5 py-1 rounded-lg bg-[#333a44] text-[#ececec]">Standard</span> <!-- pressed -->
/// <span class="px-2.5 py-1 rounded-lg text-[#a8a8a8] hover:bg-[#2e2e2e]">Thorough</span>
/// <span class="px-2.5 py-1 rounded-lg text-muted-foreground hover:bg-accent focus-visible:ring-2">Quick</span>
/// <span class="px-2.5 py-1 rounded-lg bg-border text-foreground">Standard</span> <!-- pressed -->
/// <span class="px-2.5 py-1 rounded-lg text-muted-foreground hover:bg-accent">Thorough</span>
/// </div>
/// ```
fn mode(b: &mut B<'_, '_>, app: &App) {
let k = &app.theme;
let k = &Theme::of(b.ctx());
segmented(
b,
Part::Mode,
Expand All @@ -208,7 +208,7 @@ fn mode(b: &mut B<'_, '_>, app: &App) {
.rounded_lg()
.focus(|p| p.ring(2.0, k[Tok::Accent]));
match cell {
Cell::Pressed => look.bg(k[Tok::Selected]).text(k[Tok::Ink]),
Cell::Pressed => look.bg(k[Tok::Line]).text(k[Tok::Ink]),
Cell::Released => look.text(k[Tok::InkMid]).hover(|p| p.bg(k[Tok::Hover])),
}
},
Expand All @@ -221,20 +221,20 @@ fn mode(b: &mut B<'_, '_>, app: &App) {
///
/// ```html
/// <div class="flex justify-center shrink-0 px-4 pb-4">
/// <div class="flex flex-col gap-3 w-full max-w-[720px] p-3 rounded-2xl border border-[#383838] bg-[#2b2b2b]">
/// <div class="flex flex-col gap-3 w-full max-w-[720px] p-3 rounded-2xl border border-border bg-muted">
/// <textarea class="w-full px-1 resize-none bg-transparent outline-none" rows="3" placeholder="Reply…"></textarea> <!-- grows to 8 rows -->
/// <div class="flex items-center justify-between">
/// <div class="flex items-center gap-1.5">
/// <button class="size-8 rounded-lg hover:bg-[#2e2e2e]">+</button>
/// <button class="size-8 rounded-lg hover:bg-accent">+</button>
/// <div class="segmented">Quick Standard Thorough</div>
/// </div>
/// <button class="size-8 rounded-full bg-[#6f8fb3] hover:bg-[#84a2c4] disabled:opacity-50">↑</button>
/// <button class="size-8 rounded-full bg-primary hover:bg-primary/90 disabled:opacity-50">↑</button>
/// </div>
/// </div>
/// </div>
/// ```
fn composer(b: &mut B<'_, '_>, app: &App) {
let k = &app.theme;
let k = &Theme::of(b.ctx());
let send_button = |shape: Tw| {
if app.draft.trim().is_empty() {
shape.inert().opacity(Opacity::new(0.4))
Expand Down Expand Up @@ -297,7 +297,7 @@ fn composer(b: &mut B<'_, '_>, app: &App) {
}

/// ```html
/// <main class="flex flex-col grow min-w-0 overflow-hidden bg-[#1f1f1f]">
/// <main class="flex flex-col grow min-w-0 overflow-hidden bg-background">
/// <header>...</header>
/// <div class="flex flex-col items-center grow min-h-0 overflow-hidden">...</div>
/// <div class="composer">...</div>
Expand All @@ -311,7 +311,7 @@ pub fn centre(b: &mut B<'_, '_>, app: &App) {
.grow()
.min_w_0()
.overflow_hidden()
.bg(app.theme[Tok::Ground]),
.bg(Theme::of(b.ctx())[Tok::Ground]),
none,
|b| {
top_bar(b, app);
Expand Down
89 changes: 60 additions & 29 deletions examples/chat_shell/details.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@ impl TaskState {
}
}

/// A section: a small header over its rows.
/// A section: a small header over a grouped form.
///
/// ```html
/// <section class="flex flex-col gap-1.5">
/// <h3 class="text-[11px] uppercase text-[#7c7c7c]">Environment</h3>
/// ...rows
/// <h3 class="text-[11px] uppercase text-muted-foreground">Environment</h3>
/// <div class="flex flex-col rounded-lg border bg-background divide-y">...rows</div>
/// </section>
/// ```
fn section(b: &mut B<'_, '_>, k: &Theme, title: &'static str, rows: impl FnOnce(&mut B<'_, '_>)) {
Expand All @@ -62,22 +62,38 @@ fn section(b: &mut B<'_, '_>, k: &Theme, title: &'static str, rows: impl FnOnce(
.pb(0.5),
title,
);
rows(b);
b.div_id(
Part::Group,
tw().flex()
.flex_col()
.border(1.0)
.border_color(k[Tok::Line])
.rounded_lg()
.bg(k[Tok::Ground])
.divide_y(1.0, k[Tok::Line])
.overflow_hidden(),
none,
rows,
);
});
}

/// ```html
/// <div class="flex items-center justify-between gap-2 text-[13px]">
/// <span class="text-[#a8a8a8]">Branch</span><span class="truncate">main</span>
/// <div class="flex items-center justify-between gap-2 px-3 py-2 text-[13px]">
/// <span class="text-muted-foreground">Branch</span><span class="truncate">main</span>
/// </div>
/// ```
fn row(b: &mut B<'_, '_>, k: &Theme, label: &str, value: impl FnOnce(&mut B<'_, '_>)) {
b.div(
fn row(b: &mut B<'_, '_>, k: &Theme, label: &'static str, value: impl FnOnce(&mut B<'_, '_>)) {
b.div_id(
Part::Row(label),
tw().flex()
.items_center()
.justify_between()
.gap(2.0)
.px(3.0)
.py(2.0)
.role(k[Role::Small].clone()),
none,
|b| {
b.text(tw().text(k[Tok::InkMid]), label);
value(b);
Expand All @@ -86,41 +102,56 @@ fn row(b: &mut B<'_, '_>, k: &Theme, label: &str, value: impl FnOnce(&mut B<'_,
}

/// ```html
/// <div class="flex justify-between"><span>Context window</span><span>42%</span></div>
/// <div class="w-full h-1 rounded-full overflow-hidden bg-[#383838]">
/// <div class="h-full rounded-full bg-[#6f8fb3]" style="width: 42%"></div>
/// <div class="flex flex-col gap-2 px-3 py-2 text-[13px]">
/// <div class="flex justify-between"><span>Context window</span><span>42%</span></div>
/// <div class="w-full h-1 rounded-full overflow-hidden bg-border">
/// <div class="h-full rounded-full bg-primary" style="width: 42%"></div>
/// </div>
/// </div>
/// ```
fn context(b: &mut B<'_, '_>, app: &App) {
let k = &app.theme;
let k = &Theme::of(b.ctx());
let used = f32::from(app.context_used);
row(b, k, "Context window", |b| {
b.text(tw(), format!("{:.0}%", used * 100.0));
});
b.div_id(
Part::Meter,
tw().w_full()
.h_px(4.0)
.rounded_full()
.overflow_hidden()
.bg(k[Tok::Line]),
Part::Row("Context window"),
tw().flex()
.flex_col()
.gap(2.0)
.px(3.0)
.py(2.0)
.role(k[Role::Small].clone()),
none,
|b| {
b.rule(
tw().w_frac(used, 1.0)
.h_full()
b.div(tw().flex().items_center().justify_between(), |b| {
b.text(tw().text(k[Tok::InkMid]), "Context window");
b.text(tw(), format!("{:.0}%", used * 100.0));
});
b.div_id(
Part::Meter,
tw().w_full()
.h_px(4.0)
.rounded_full()
.bg(k[Tok::Accent]),
.overflow_hidden()
.bg(k[Tok::Line]),
none,
|b| {
b.rule(
tw().w_frac(used, 1.0)
.h_full()
.rounded_full()
.bg(k[Tok::Accent]),
);
},
);
},
);
}

/// ```html
/// <aside class="flex flex-col shrink-0 gap-5 p-4 bg-[#252525] overflow-hidden" style="width: 288px">...</aside>
/// <aside class="flex flex-col shrink-0 gap-5 p-4 bg-card overflow-hidden" style="width: 288px">...</aside>
/// ```
pub fn details(b: &mut B<'_, '_>, app: &App) {
let k = &app.theme;
let k = &Theme::of(b.ctx());
b.div_id(
Part::Details,
tw().flex()
Expand All @@ -147,8 +178,8 @@ pub fn details(b: &mut B<'_, '_>, app: &App) {
for (file, added, removed) in CHANGES {
row(b, k, file, |b| {
b.div(tw().flex().gap(1.5), |b| {
b.text(tw().text(k[Tok::Accent]), added);
b.text(tw().text(k[Tok::InkDim]), removed);
b.text(tw().text(k[Tok::Success]), added);
b.text(tw().text(k[Tok::Danger]), removed);
});
});
}
Expand Down
Loading
Loading