fastframe-ui
Themed egui components, each with variants, sizes and theme colours. The crate loads theme files in a JSON theme format, and 21 themes come bundled with it.
Each component has a page on fastframe.dev
that runs it in the browser beside its code. To see them all locally, run the
gallery: cargo run -p fastframe-gallery. To see components together in
whole windows, run one of the gallery’s test apps:
cargo run -p fastframe-gallery -- app mail --look fastframe --dark.
[dependencies]
fastframe-ui = { git = "https://github.com/crmne/fastframe", tag = "v0.19.0" }
Use
Components are ordinary egui widgets:
use fastframe_ui::{Button, UiExt, button_styles};
fn toolbar(ui: &mut egui::Ui) {
if ui.add(Button::primary("Save")).clicked() {
// save
}
ui.add(Button::destructive("Delete").small());
ui.button_style(button_styles::Ghost, |ui| {
ui.add(Button::new("Cut"));
ui.add(Button::new("Copy"));
});
}
As in SwiftUI, a component says what it is and a style decides how it
looks. A button has a role (primary, destructive, cancel), a tint and a
size; a ButtonStyle draws it. The built-in styles draw the default
buttons; write your own by implementing ButtonStyle, and set it for one
button with .style(&MyStyle) or for everything inside a closure with
ui.button_style(MyStyle, |ui| ...). A style reads the theme’s tokens
from the ButtonConfiguration it is handed (button.tokens()), looked
up once for the button. ui.control_size(Size::Small, ...)
does the same for sizes. .tooltip("Search") shows a tooltip and, on a
button with no label (Button::icon_only), is the name screen readers
announce; .accessibility_label(...) names it when the tooltip says
more, and .chevron() adds a menu button’s chevron after the content.
One button can also leave the look’s table: .height(56.0) and
.icon_size(24.0) size it (a round icon button of any size with
Rounded::Full), and .colors(ButtonColors { .. }) draws it in its own
background and foreground, at rest and hovered, in whichever look, so a button with
colours of its own needs no style of its own.
Besides the default styles, button_styles::Pill draws a pill (filled with the
primary colour for the main action, outlined otherwise) and
button_styles::FramelessIcon { color, hover } a bare icon, at the
button’s .icon_size(..), that lights up under the pointer and shrinks a
little while pressed. Given an icon size and no height, a bare icon button
is that icon with the look’s padding round it (a 22-point icon in a
34-point button when the padding is 12), at any icon size.
Buttons keep the arrow pointer, as on macOS: only Link and Plain,
which read as links, show the pointing hand (ButtonStyle::cursor).
An Input given an .id(id) takes the keyboard from anywhere with
Input::focus(ctx, id), as a shortcut that jumps to search does.
Status bars, toolbars, sidebars, popovers and dialogs hand down the
colour they fill themselves with (environment::backdrop), so an avatar
group’s rings and a badge’s cut-out match what they sit on rather than the
page.
Text works the same way. A TextRole (title, headline, body, caption…)
says what a piece of text is, and the look’s type scale says how large
and heavy that is: Label::new("12 items").font(TextRole::Caption) for one
label, ui.text_style(TextRole::Caption, |ui| ...) for everything inside.
Text a component shows (an option, a placeholder, a section title, a
message’s author) takes an egui::RichText as well as a &str: what it
sets (a colour, a weight through .font(TextRole::Headline.font_id(ctx)),
italics) is kept, and the rest comes from the look. Labels, menu rows, tabs
and columns, drawn many times a frame, borrow a &str instead.
Transitions name a Speed (quick, standard, slow) rather than seconds, and
fastframe_ui::motion animates with the look’s durations and curves,
holding still when the app asks for reduced motion. While a screen
reader is attached, spinners, typing dots and other looping decorative
animations step at about ten frames a second, so the window’s thread stays
free to answer the reader; motion::indicator_time does the same for an
app’s own busy indicator (see below), motion::request_frame_after for
any other looping animation (a marquee, say), and
motion::screen_reader_attached says whether one is. ViewThatFits draws
the first of several layouts that fits the width, measuring each once.
Progress::paint_at(ui, rect) paints a spinner, ring or bar into a rect
without taking space, at any size and colour, for one that sits inside
something else (over a picture, in a row, round an avatar); it loops and
holds still as the widget does.
Button::show_at(ui, id, rect) draws a button at its size, centred in a
rect, without taking space or making a Ui for it, sensed as id: for a
button placed by hand, such as one in a table’s painted cell.
Button::show_in_cell(ui, id, cell) paints it the same way but senses
the whole cell, so a click at the cell’s edge presses it: what ui.add
gives in a centred, justified Ui filling the cell, pixel for pixel,
without the Ui.
let like = Button::icon_only(heart).tooltip("Like");
if like.show_in_cell(ui, cell.id.with("like"), cell.rect).clicked() {
// ...
}
Busy indicators and their frame budget
A busy indicator is drawn for as long as the work takes, often minutes,
so every frame it asks for is CPU the app spends on nothing new. The
components’ spinners, bars, shimmers, skeletons and typing dots keep to a
budget, and an app’s own indicator (a turning ring, typing dots) can keep
to the same one with motion::indicator_time(ui, fps):
- a looping
Progresssteps between still poses atmotion::STEPPED_FPS(10) frames a second, about what macOS’s own spinner steps at, in every built-in style: the spinner’s lit spoke, the ring’s arc a tenth of a turn a step, the bar’s segment a tenth of the way a step, the orbit, dots and bars; a customProgressStylesteps too unless itsframe_rateopts in to more; - one that only reads when it moves continuously, as a glyph turning along
a curve (
Progress::easeorProgress::icon), a shimmer or a skeleton’s pulse, draws at mostmotion::SMOOTH_FPS(30); - in a window in the background (not focused, minimized or covered) it holds its pose and asks for no frames at all, as egui’s text cursor stops blinking there;
- under reduced motion it draws its still pose and asks for nothing.
indicator_time returns the time to draw at: the clock snapped to the
middle of a tick of that grid, counted from the clock’s zero, so the
drawing changes only once a tick, and it asks for the next frame at the
next tick, when the drawing next changes. Every indicator on a grid shares
its frames, a 10 a second grid’s ticks are among a 30 a second one’s, and
a frame drawn between ticks for some other reason draws the same pose.
It returns None under reduced motion. Ask only while the indicator is on
screen: asking is what keeps the frames coming. An animation of the app’s
that instead asks for a frame a delay after each frame (33 ms, say) runs
on a pace of its own, and the window draws on both, so move it onto
indicator_time too.
use fastframe_ui::motion;
/// A turning ring, as Solco's: an arc going round once a second.
fn turning_ring(ui: &egui::Ui, rect: egui::Rect) {
if !ui.is_rect_visible(rect) {
return;
}
// `None` under reduced motion: draw the still pose.
let turn = motion::indicator_time(ui, motion::SMOOTH_FPS)
.map_or(0.0, |time| time.fract() as f32);
let start = turn * std::f32::consts::TAU;
let points: Vec<egui::Pos2> = (0..=24)
.map(|step| start + step as f32 / 24.0 * 4.7)
.map(|angle| rect.center() + 8.0 * egui::vec2(angle.cos(), angle.sin()))
.collect();
let stroke = egui::Stroke::new(2.0, ui.visuals().text_color());
ui.painter().add(egui::Shape::line(points, stroke));
}
ZapFast’s typing dots are the same with motion::SMOOTH_FPS, each dot
lifted by time; a spinner of its own that lights one segment at a time
asks for motion::STEPPED_FPS, or its own step rate.
motion::repaint_at(ctx, at) asks for a frame at a time on the frame
clock rather than after a delay, so a pace does not drift when a frame
starts late. egui 0.37 and later wait exactly the delay
request_repaint_after is given; 0.36 and earlier took a predicted frame
time (about 16 ms at 60 Hz) off it, so a 33 ms wait drew about 60 frames a
second. A ProgressStyle of an app’s own says how often its drawing
changes with frame_rate (10 by default), and the indicator asks for
frames at that rate.
An app’s test reads what a headless pass asked for with
motion::requested_frame(&ctx, &output): the delay until the next frame,
for any reason, and the delay a busy indicator asked for (None when
none did), so it can check that a screen keeps drawing while busy, and
that an indicator, not something else, is what keeps it drawing.
Menus are egui popups: egui::Popup::is_any_open sees an open Menu,
egui::Popup::close_id closes it, and opening another popup closes it.
Give a menu an id with .id(...) and the app can open it where it chooses,
for example on a secondary click it read over a whole row:
Menu::open_at(ctx, id, pos), or Menu::open_from_keyboard_at to focus
its first row. Menu::move_to(ctx, id, pos) moves an open menu, keeping
its focused row and open submenus, and does nothing while it is closed, so
an app can call it every frame to keep a menu beside something that moves.
Menu::rect(ctx, id), read after the menu is shown, is where its panel
drew this frame, for placing a picker or anything else beside it.
menu.header("HX Stomp", Some("connected")) opens a menu with what it
acts on, in the headline style, and a quieter aside at the row’s end;
menu.label(...) stays the muted heading of a group of rows. In a menu
whose rows have icons, a label lines up with the rows’ labels, as a macOS
section heading does, while the header and a menu.custom(...) row start
at the row’s start: the header heads the whole menu, and a custom row
(a rating, a slider) is the app’s to lay out. MenuItem::swatch(color)
puts a colour swatch where an icon goes, on a plain row or a submenu’s
(menu.submenu(MenuItem::new("Colour").swatch(orange), ...)). A row’s
shortcut is plain grey text; MenuItem::keycap() draws it on a keycap,
as Kbd does, in the look’s shape.keycap style. That KeycapStyle
outlines the caps or fills them, sets their text’s weight, and can name
their fill, border colour, corner radius and padding, so a look’s keycaps
do not depend on its tokens lining up.
A menu is as wide as its widest row, from 128 to 500 points:
Menu::width(w) (or min_width and max_width) sets its width from the
builder, its submenus take the same, and
menu.submenu(Submenu::new("Share").width(240.0), ...) gives one submenu
a width of its own.
A menu taller than the window, or than its max_height, scrolls whole;
menu.scroll_area(200.0, |menu| ...) scrolls only the rows inside it,
such as a long list of presets between a header and a Save row, and the
keyboard and type-ahead still reach those rows and scroll them into view.
Menu::show_beside(&trigger, rect, ...) hangs a menu from a larger
rectangle than its trigger, such as below a whole card from the chevron
at its end.
As in macOS and GTK, a menu stays inside the window: with no room below
its trigger or point it opens above, a context menu near the right edge
opens before its point, and a submenu with no room past its menu opens on
the menu’s other side. A separator at the start or end of a menu or
submenu is not drawn and a run of them draws as one, so rows an app adds
only sometimes need no care around their separators.
.close_on_click_outside(false) keeps an open menu
open on clicks outside it while the app says so, for example while a picker
it draws beside the menu is showing; Escape still closes it. As in macOS
and GTK menus, the keyboard (Tab, the arrows, Home, End and type-ahead)
passes over disabled rows, and a menu opened from the keyboard focuses its
first enabled row; a disabled row still shows, and a screen reader finds
it as disabled. MenuItem::focusable(true) lets a disabled row take the
focus anyway, so a screen reader lands on it and says why it is
unavailable.
Focus rings show only while the person is using the keyboard, as in macOS
and a browser’s :focus-visible: a key press (Tab, an arrow, any key) or
an assistive technology’s request turns them on, and a press of the
pointer turns them off, so a control focused by a click shows none. A
style reads state.keyboard_focused for its ring (state.focused is any
focus), and fastframe_ui::keyboard_focused(&response) answers the same
for a widget of the app’s own. Text fields keep their ring while they have
the keyboard, however they got it.
A widget of the app’s own gets the rest of what the components share from
Control: Control::new(size, Sense::click()).accessibility_label("Shuffle")
.selected(on).tooltip("Shuffle").show(ui, |painter, rect, state| ...) takes
its space, names it to screen readers, hands the painter its rect and a
ControlState (hovered, pressed, selected, enabled, keyboard-focused,
and state.fill to pick a Fill’s colour), scrolls it into view when
the keyboard reaches it, draws the look’s one focus ring and shows the
tooltip. It paints nothing else. Every component’s style gets the same
ControlState in its configuration.
A table’s filters and actions can sit on the table itself, as in a data
table: show Toolbar::new().attached() right above
Table::new(state, &columns).attached_top(true), with no item spacing between
them. The toolbar takes the table’s colour and top corners and borders
its top and sides; the table squares its top corners and its top border
divides the two, so they read as one box.
use fastframe_ui::{Column, Input, Table, TableState, Toolbar};
fn issues(ui: &mut egui::Ui, state: &mut TableState, search: &mut String) {
let columns = [Column::new("title", "Title").fill()];
ui.vertical(|ui| {
ui.spacing_mut().item_spacing.y = 0.0;
Toolbar::new().attached().show(ui, |bar| {
bar.add(Input::search(search).placeholder("Filter issues").small());
});
Table::new(state, &columns)
.attached_top(true)
.show_cells(ui, 0, |_, _| {});
});
}
Table lays out its rows with
egui_table and builds only the rows
and columns in view, so a frame of 100,000 rows costs about what one of
500 does, and it asks for no frames while nothing happens. Beyond
sorting, selection, editing and paging, each of these is one builder call
or state field, off until asked for:
Table::reorder_columns(true): drag a header to move its column. The order goes inTableState::order, besideTableState::widths; persist both.Column::fixedcolumns stay pinned at the left and move among themselves.Table::drag_rows(true): drag rows out of the table. egui’sDragAndDropcarries aTableRowswith their keys and their places in the order shown (the selection when the drag starts on a selected row), so a track twice in a playlist is two rows, and the app takes it where it lands.Table::drag_tag(tag)puts a value of the app’s own in it, such as the generation of the search that listed the rows, to tell a drop of rows that have since moved.TableDelegate::row_drag_payloadcarries a payload of the app’s own instead, androw_drag_ghostdraws what follows the pointer.Table::drop_between_rows(true): a drag over the rows shows the gap it would land in (TableStyle::paint_row_drop), andTableResponse::droppedreports that gap on release. Withdrag_rows, that reorders rows.TableDelegate::accepts_droprefuses a payload, or a gap: no line shows there, and nothing drops.Column::hide_below(width): the column leaves a table narrower thanwidth, and afillcolumn takes its room. A cell knows which columns show (TableCell::shown,TableCell::is_shown), to take in what a hidden one would have.Table::sort_cycle(SortCycle::AscendingDescending): a header click turns the sort round, never back to the rows’ own order (SortCycle::ThroughUnsorted, the default, goes ascending, descending, none).TableResponse::header_clickednames the column a sort click changed, the one whose sort it took away too.TableDelegate::headerdraws a header cell’s content (an icon, a checkbox), andTableDelegate::prefetchhears which rows are about to show and the rows just past each edge (TablePrefetch::visibleandrows), to load their pages or artwork before a scroll reaches them.Table::prefetch_rows(n)sets how many past each edge: a screenful by default, 0 for only the visible rows.TableCell::gap(ui, gap)sets the gap between a cell’s items (a title and its tag) without copying the whole style for every cell.Column::painted(): the column’s cells draw without a Ui of their own, into the row’s, clipped to the cell: for cells that paint (text, a cover, a mark) or place what they hold themselves, as a Ui per cell is most of what a table of such cells costs a frame (a third of the frame inexamples/playlist_cost.rs, a Spotifast playlist). Draw atTableCell::rectand name what senses byTableCell::id, which stays with the row as it scrolls (a button withButton::show_at, orButton::show_in_cellto sense the whole cell). A painted cell being edited gets its Ui back.Table::scrollbar_mode(ScrollbarMode::Always): the scrollbars show at rest (they show while scrolling by default), and the columns leave the vertical one its room while the rows overflow:Table::scrollbar_gap(the track’s 16 points by default).Table::scrollbar_insetstops the rows that far short of an edge a bar can show along, as egui’s floating bars keep content clear (none by default). While the columns overflow, the table grows by it (up tomax_height), so rows that fit show whole above the bar; the fixed columns run on to the bottom, as the bar runs only under the columns that scroll. A bar is a thin thumb floating over the rows, drawn in the text colour so it stands 3:1 off the rows and their hover in every built-in theme (and in a palette fromColors::from_basethat names no scrollbar colours); the pointer anywhere on the bar lights and widens it. Its track shows only where the gap or the inset leaves it room (TableScrollbar::clear), so it never covers a row.Table::scroll_to_row(row, align)andscroll_to_rows(rows, align): scroll rows into view on the frame they are asked for, as egui_table’s do:Noneas little as it takes,Some(Align::Min)at the top, sorow - 2..=rowshows a row with two above it. Never sideways. A table whose rows all fit, such as one laid out at full height (max_height(f32::INFINITY)) on a page that scrolls, scrolls the page instead, withui.scroll_to_rect, as the keys’ cursor and a drop’s auto-scroll do.Table::app_selection(true): the app keeps the selection. The rowsTableDelegate::is_selectednames show selected; clicks are only reported (TableResponse::pickedsays how: only that row, a toggle, or a range), the table leavesTableState::selectionalone, takes no focus (its rows take it, one Tab stop each) and handles none of the selection keys. Escape still cancels a cell’s edit.Selection::pick,setandtoggleapply them to aSelectionthe app keeps, if it likes.Table::one_tab_stop(true)makes such a table one Tab stop instead of its rows: it takes the focus from Tab and a click on a row, keeps it through the up and down arrows, lets Escape take it away, and handles no key, so the app reads them whileTableResponse::responsehas the focus. It draws no focus ring unless its style’spaint_focusdoes.TableDelegate::row_overlaypaints across a whole row after its cells, clipped to the rows rather than a cell: a group’s caption (“SETLISTS 2”) over a row whose cells are empty. ItsTableRowOverlaysays how far the columns are scrolled sideways and where they end.Table::row_height(height)andTable::cell_padding(padding): rows and cell padding of the table’s own, in place of the look’s for its size, for one table shown in views of their own (a library’s tall rows with artwork, its compact rows of one line).TableDelegate::column_widths(widths)decides the columns’ widths each frame, before anything is drawn: aColumnWidthswith each shown column’s width as laid out, the room they share (available) and whether the person set it (set_by_person), so an app can give the room left to one column, pin others and refit the rest to the window while keeping what the person dragged. A double click on a column’s edge fits it to its title and its widest cell in view; the person’s widths, dragged or fitted, go inTableState::widths.TableDelegate::row_response(row, &response)hears each drawn row’s own response (hovered, clicked, double or right-clicked, dragged, focused) before its cells, so an app that handles rows its own way needs no widget of its own over each one, andTableCell::hoveredtells a cell its row is under the pointer, for controls that show only there.TableResponse::clicked_columnnames the column a click on a row landed in, besideclicked,picked,secondary_clickedand a double click’sactivated, for an app that edits the cell clicked.TableDelegate::empty_state(ui)draws what an empty table shows under its header, in place of the inbox, or nothing.TableDelegate::row_label(row)names a row for screen readers. The rows of a table that keeps its own selection are one Tab stop, the table’s; withapp_selection, the table takes no Tab stop and each row is one, for the app’s keys, unless the table isone_tab_stop.
use egui::DragAndDrop;
use fastframe_ui::{Column, Table, TableRows, TableState};
fn queue(ui: &mut egui::Ui, state: &mut TableState, songs: &mut Vec<(u64, String)>) {
let columns = [
Column::new("title", "Title").fill(),
Column::new("artist", "Artist").hide_below(480.0),
];
let response = Table::new(state, &columns)
.multi_select(true)
.reorder_columns(true)
.drag_rows(true)
.drop_between_rows(true)
.show_cells(ui, songs.len(), |ui, cell| {
cell.label(ui, &songs[cell.row].1);
});
if let Some(gap) = response.dropped
&& let Some(rows) = DragAndDrop::take_payload::<TableRows>(ui.ctx())
{
// Move the songs whose keys are in `rows.keys` to `gap`.
let _ = (gap, rows);
}
}
use fastframe_ui::{
Column, ScrollbarMode, Selection, Table, TableCell, TableDelegate, TableState,
};
/// A library whose selection the app keeps.
struct Tones<'a> {
names: &'a [&'a str],
selected: &'a Selection,
}
impl TableDelegate for Tones<'_> {
fn row_count(&self) -> usize {
self.names.len()
}
fn cell(&mut self, ui: &mut egui::Ui, cell: &TableCell<'_>) {
cell.label(ui, self.names[cell.row]);
}
fn is_selected(&self, row: usize) -> bool {
self.selected.contains(row as u64)
}
}
fn library(
ui: &mut egui::Ui,
state: &mut TableState,
selected: &mut Selection,
names: &[&str],
reveal: Option<usize>,
) {
let columns = [Column::new("name", "Name").fill()];
let mut table = Table::new(state, &columns)
.multi_select(true)
.app_selection(true)
.scrollbar_mode(ScrollbarMode::Always);
if let Some(row) = reveal {
// Two rows above it, at the top.
table = table.scroll_to_rows(row.saturating_sub(2)..=row, Some(egui::Align::Min));
}
let shown = table.show(ui, &mut Tones { names, selected });
if let Some((row, pick)) = shown.picked {
selected.pick(row, pick, names.len(), |row| row as u64);
}
}
TableDelegate::is_current(row) names the current row (the song playing,
the track loaded), which the table marks whether or not it is selected.
TableDelegate::row_tint(row) tints a row from its data (a DJ’s colour
for a track, a failed analysis), with the strength in the colour’s
alpha: the style hears it as RowState::tint, and the built-in one
washes it over the row, a third as strong on a selected row.
How a table draws is a TableStyle, like every component’s: it paints
each row (a TableRowConfiguration with a RowState of selected,
hovered, striped, current, the keyboard’s cursor, the selection’s
primary row whether or not the table has the focus, and focused, so
a style can mark the primary row and soften the others while the focus
is elsewhere; TableDelegate::is_primary names it when the app keeps the
selection) and each header cell
(a TableHeaderConfiguration with the column’s sort, the pointer’s
ControlState and where its title is laid out, so an indicator can sit
after the title; a delegate’s own header content shows over it), and can
restyle or drop the marks the table puts over them: the line under the
header (across the whole table), the line beside the fixed columns, the
resize handles, lines down the resizable columns’ edges through the rows
(TableStyle::paint_column_line, none by default), where a dragged
column or row would land, the cell being edited and the scrollbars (TableScrollbar, which a style can draw as
the app’s egui scroll style does). TableStyle::paint_viewport paints
over the rows once they are drawn, with a TableViewport of where they
show, how far they are scrolled and where the columns and rows run; by
default it fades the edges there is more to scroll past, in the table’s
background, when egui’s ScrollFadeStyle asks for fades (as egui’s
scroll areas do), up and down only under the columns that scroll, as
egui_table’s fixed columns covered its fades. A row’s TableRowConfiguration also says how far the
columns are scrolled and where they end, for fills that stop there. The built-in
table_styles::Standard is the default, with the current row in a wash of
the primary colour; set another for one table with .style(&MyStyle), for
everything inside a closure with ui.table_style(MyStyle, |ui| ...), or
for the whole app with look.replace(table_styles::Standard, MyStyle).
TableResponse::header_secondary_clicked names a header right-clicked,
for a column chooser opened with Menu::open_at, and
header_clicked and header_hovered name the header clicked and the one
under the pointer, sortable or not. TableDelegate::header_tooltip
gives a header its tooltip (what the column means, or its whole title).
use fastframe_ui::{TableHeaderConfiguration, TableRowConfiguration, TableStyle};
/// The playing row outlined, and a wash under the pointer.
struct Library;
impl TableStyle for Library {
fn paint_row(&self, row: &TableRowConfiguration<'_>) {
let theme = row.theme;
let fill = if row.state.current || row.state.selected {
theme.table.active
} else if row.state.hovered {
theme.table.hover.gamma_multiply(0.45)
} else {
egui::Color32::TRANSPARENT
};
row.paint_fill(fill);
row.paint_divider(theme.table.row_border);
if row.state.current {
row.paint_outline(egui::Stroke::new(1.0, theme.primary.background));
}
}
fn paint_header(&self, header: &TableHeaderConfiguration<'_>) {
header.paint_title(None);
}
}
fastframe_ui::paint holds the painters the components draw with, for an
app painting its own surfaces the same way in its own colours: Apple’s
Messages balloon (messages_balloon, filled with fill_outline), a
raised surface with a lit top edge (raised for a frame, raised_rect
for a rectangle), a message’s delivery mark (message_status: a clock,
one tick, two equal ticks for delivered, read and played, or a failure
mark), where a line’s capitals sit (cap_middle) and the look’s keyboard
focus ring (focus_ring), so an app’s own widget rings the way the
components do. A look sets that ring in Shape::focus_ring: its width, its
gap from the control and how strongly the theme’s ring colour shows.
Looks and themes
How the components look is two choices, made apart: a look decides shape, a theme decides colour. Any look takes any theme.
use fastframe_ui::{Look, Theme};
fn setup(ctx: &egui::Context) {
// fastframe's look in its own theme...
fastframe_ui::set_look(ctx, Look::fastframe());
// ...or in another, chosen with it or later.
fastframe_ui::set_look(ctx, Look::fastframe().with_theme(Theme::blue()));
fastframe_ui::set_theme(ctx, Theme::named("Catppuccin").unwrap_or_else(Theme::neutral));
}
With nothing set, components draw the fastframe look in its own theme,
as if the app had called set_look(ctx, Look::fastframe()). Either way they follow egui’s appearance by themselves: set_look builds
the look’s tokens for light and dark once, and fastframe_ui::tokens(ctx)
picks the one egui is in (the system’s, or one the app chose with
ctx.set_theme). egui’s own Style stays the app’s; a look built with
.egui_visuals(true) also gives egui’s widgets the theme’s colours in
both appearances, and a later set_theme keeps that choice.
Looks
A Look is everything but colour, set once: one Shape for both appearances
(corners, density, type scale, motion, shadows) and a style for every
component. Components draw with their own style, else the one set around
them, else the look’s. A few choices sit in the shape for every component
to follow: shape.segment_fill marks the chosen segment of a segmented
control with a raised surface or a wash of the accent
(SegmentFill::Accent), shape.metrics.badge_height sets how tall a
count badge is, and shape.keycap (KeycapStyle { outline, weight })
draws every Kbd and every menu row’s keycap filled or bordered, in the
caption weight or its own. Kbd::outline() still outlines one keycap in
a look that fills them.
Look::fastframe(): fastframe-ui’s own, and the default: from the desktop look its apps share, with pill buttons, raised surfaces and tracked captions, laid out as macOS 14 and 15 are (fills inset from a pane’s edges, text further in, rows back to back) at shadcn’s size: 36-point controls, 14-point text, fills 12 in, text 20, pages 24. Its theme is fastframe. Its styles are infastframe_styles; the design note isdocs/research/2026-11-25-fastframe-look.md. A progress indicator that names no style spins the look’s arc; one that namesprogress_styles::Circularkeeps the default spinner, and with a value draws the look’s ring. It holds fastframe-ui’s styles only: an app with a dock sets it with the dock’s fastframe style too,Look::fastframe().replace(dock_styles::Standard, dock_styles::Fastframe).Look::signal(): another of fastframe-ui’s own, insignal_stylesand the Signal theme, spaced as fastframe is. An indicator that names no style draws the look’s dial.Look::shadcn(): shadcn/ui’s look, spaced as shadcn/ui’s own components and example apps are (36-point controls, content 16 in), with every component’s built-in style. Its theme is Neutral.-
Look::studio(): the denser, darker one, instudio_stylesand the Studio theme: a step under shadcn’s controls (32 at the default size), 13-point text, flat groups split by hairlines, its chrome one shade off the content and its cyan on what is on, chosen or focused. An indicator that names no style draws the look’s arc.In Signal and Studio, as in fastframe, an indicator that names
progress_styles::Circularkeeps the default spinner, and with a value draws the look’s ring (Studio’s gauge) at that ring’s size. Look::new(name, shape).with_shape(|s| ..).style::<Key>(..).replace(built_in, style): your own, giving a default style for a component, or replacing one of its built-in styles wherever it is drawn:.replace(button_styles::Outline, MyOutline). Each built-in names its key (environment::BuiltInStyle), so a replacement names none.
Components without a style of their own (lists, tables, trees, sidebars,
dialogs, sheets, popovers, tooltips, notifications, calendars, settings and
the rest) take the look through its shape: the type scale,
ControlSizes, Elevation (how far each surface’s shadow falls; its
colour is the theme’s ShadowColors, and Elevation::NONE is a flat
look), and Shape::metrics (fastframe_ui::metrics)
for their row heights, padding and corners, and for its edges: the text
line (content_inset), the ends of bars (bar_inset) and a page’s
padding (page_inset). docs/research/2026-11-30-spacing-references.md
lists each look’s reference values and where they come from.
Themes
A Theme is an app’s colours in a light and a dark appearance (Colors,
every colour by its theme-file name). Each look’s own:
Theme::fastframe(): stone greys (Tailwind’s stone) in light and dark, ink as the primary, and the logo’s orange only on the focus ring, the caret and selected text.Theme::neutral(): shadcn/ui’s neutral theme, ink as the primary.Theme::signal(): its look’s warm greys, ink as the primary.Theme::studio(): its look’s cool greys, cyan as the primary.
Then shadcn/ui’s colour themes on the neutral greys: orange() (the
logo’s), blue(), green(), violet(), rose() and cyan(); and the
colours Signal had before turning neutral, signal_orange(). Each keeps text on its primary at WCAG AA, and every
look’s own keeps its focus ring at 3:1 against the page.
Theme::built_in()andTheme::named("Gruvbox")(which also finds the presets): the themes a switcher lists.presets::themes(): the themes bundled with the crate, one per file, each with its light and dark forms, parsed once.Theme::from_json(json)andColors::from_json(json): any JSON theme file’s text, whole or one appearance at a time, or aThemeError. Colours a theme leaves out derive from the ones it sets, following the theme format’s rules.Colors::from_base(name, dark, &BaseColors { .. }): colours from the names every fastframe app’s palette understands (see fastframe-theme), so an app’s own palette drives the components;..BaseColors::neutral(dark)fills the ones it leaves out.popover, the raised surface (a palette file’soverlay), fills popovers, menus and dialogs, andscrim(a palette file’sshadow) dims the page under a dialog. Links take the accent’s hover under the pointer, and switches white thumbs.Theme::uniform(name, colors): one palette in both appearances, for an app whose palette is a setting of its own rather than the system’s.
Every colour is a public field, so an app can adjust a theme after loading
it. The page’s own colours (background, foreground, border,
accent, the primary to info fills and the rest) sit at the top;
each component’s sit in a group: link, group_box, list and table
(both RowColors, so colors.list = colors.table gives lists a table’s
rows), controls, tab, sidebar, bars, scrollbar, chart,
hues and shadows. A theme file still names them by its own keys
(table.head.background, sidebar.accent.foreground). Components read the result, Tokens (the theme’s Colors and the
look’s Shape for one appearance), with fastframe_ui::tokens(ctx).
Right-to-left text
egui lays a line’s shaped runs out left to right in text order, so Hebrew
and Arabic, alone or mixed with English, read in the wrong order. Every
component passes the galleys of its labels (buttons, tags, list, menu,
sidebar and table rows, settings rows, dialogs, bubbles and the rest)
through one hook, fastframe_ui::bidi::reorder, which puts each row in the
Unicode bidi algorithm’s visual order while the text stays in logical order
for copying, links and carets. Text without a right-to-left letter is not
copied.
Reordering needs glyph clusters that only the apps’ egui fork
(crmne/egui apps-0.38) gives a galley, and a library cannot see which egui
an app patches in. An app on the fork turns it on in .cargo/config.toml:
[env]
FASTFRAME_EGUI_BIDI = "1"
With stock egui, or without the variable, labels are drawn as egui lays them
out (fastframe_ui::bidi::REORDERS is false). An app’s own text goes
through the same hook:
fn paint(ui: &egui::Ui, job: egui::text::LayoutJob, at: egui::Pos2) {
let galley = fastframe_ui::bidi::layout_job(ui, job);
ui.painter().galley(at, galley, egui::Color32::WHITE);
}
bidi::label_text does the same for an egui::Label (an app’s own content
in a Tooltip::show_with_body, say), bidi::layout_field is a single-line
TextEdit layouter, and
bidi::base_rtl, message_rtl and is_rtl tell a text’s direction.
bidi::has_rtl says whether a text holds a right-to-left letter at all,
ruling out text in Latin, Greek, Cyrillic and the other scripts before
Hebrew from its bytes: reorder makes that check itself, so an app need
not scan a label before handing it over.
Licence
The crate is MIT. The bundled theme files are Apache-2.0 and the bundled icons are Lucide’s (ISC); see NOTICE for their source and attribution.
Related crates
Draws the interface, like this one:
- Dockable panels: Drag tabs to move, split or float them, drawn in the look and theme of the rest.
- Diff viewer: Unified or side by side, with word highlights and folded lines, fast on long files.
- Code editor: Line numbers, syntax colours for common languages, the current line and find.
All 27 fastframe crates, by what they do for an app.