Expand description
Crabshell’s widgets, styles, layout, text layout, hit testing and invalidation.
A bar is described with widgets and turned into a live Window:
use crabshell_reactive::Runtime;
use crabshell_ui::prelude::*;
const BAR: Style = Style::new()
.background(Color::rgb(0x1e, 0x1e, 0x2e))
.color(Color::rgb(0xcd, 0xd6, 0xf4));
let runtime = Runtime::current();
let cx = Cx::new(runtime.new_owner());
let count = cx.signal(0);
let bar = PanelWindow::new(&Output::new("DP-1"))
.anchors(Edge::Top | Edge::Left | Edge::Right)
.height(30)
.style(BAR)
.child(
Row::new().gap(8).padding(4, 8).child(
Button::new(Text::new(move || format!("clicked {} times", count.get())))
.on_click(move |_cx| count.update(|n| *n += 1)),
),
);
// The platform does the rest once per event-loop iteration.
let window = Window::new(&cx, bar);
let mut text = TextSystem::new();
window.set_size(Size::new(1920.0, 30.0));
runtime.flush(); // bindings run
window.layout(&mut text);
let _damage = window.take_damage(); // what the renderer repaints§How it fits together
- Widgets are descriptions.
Window::newturns them into a tree of nodes, each with its own reactive owner. A property given a closure becomes an effect that writes the node when a signal it read changes. - Each property is a layout property (text, font, padding, gap, size,
children) or a paint property (colors, background, border, opacity,
radius). A paint change records the widget’s area as damage. A layout
change marks the window for
Window::layout, which records the old and new area of every widget that moved or changed. TextSystemloads only the fonts fontconfig matches for the families styles name, plus fallbacks for missing characters. EachTextkeeps one cosmic-text buffer that layout measures and the renderer draws.- Pointer events go to
Window::pointer_motionand friends. Hit testing finds the deepestButtonunder the pointer, and its handlers run with no borrow held, insidecatch_unwind. - Dropping a
Windowdisposes its owner, freeing every node, binding and handler it made.
Modules§
- prelude
- What a bar’s code needs, in one
use.
Structs§
- Adjust
- How a popup may move or shrink to stay on its output, combined with
|, asxdg_positioner’s constraint adjustments. The compositor flips first, then slides, then resizes. - Anchors
- The edges a window is anchored to. Combine edges with
|:Edge::Top | Edge::Left | Edge::Right. - Border
- A border drawn inside a widget’s edge. It takes no layout space.
- Button
- A clickable box around one child, which it centers.
- Capture
Frame - A captured frame, as a view keeps it.
- Capture
Request - One view the platform captures for, from
Window::captures. - Capture
View - A screencopy view’s frame, ready to draw.
- Color
- An sRGB color with straight (not premultiplied) alpha.
- Column
- Lays its children out top to bottom, like a CSS flexbox column.
- Cx
- The context widget code runs in.
- Element
- What a
Widgetturns into: plain data, with every child already turned into its element. Only this crate’s widgets create one. - Field
State - The focused text field, as an input method needs it.
- Floating
Config - What the platform needs to show a floating window.
- Floating
Window - A window like an application’s, which the compositor places, tiles or
floats: a launcher, a settings panel, a picture viewer. Show one with
cx.floatingfrom thecrabshellcrate. Every property takes a value or a closure. - Font
- A font: family, size and weight.
- Gradient
- Colors that blend into each other across a widget’s box, drawn over its background with the same corners.
- Icon
- An icon, drawn as a square.
- Icon
Pixels - Raw icon pixels: ARGB32 in network byte order (A, R, G, B bytes), row by row, as the StatusNotifierItem spec sends them.
- Icon
View - An icon, ready to draw.
- Image
- A picture from a PNG, JPEG, GIF (its first frame), WebP or SVG file, drawn at a fixed size.
- Image
View - An image, ready to draw.
- Input
View - A text field, ready to draw: the selection behind the text, then the text, then the caret.
- KeyEvent
- A key press, or a repeat of a key held down.
- List
View - A scrolling list of rows of one height that builds only the rows in
view, so a list of thousands costs what a screenful does. Offsets are
f32, which stays exact to about 16 million pixels: some 700,000 rows of 24 pixels. It follows a list of items aschildren_keyeddoes: each row is kept while its item’s key stays in the list. - Lock
- A
SessionLockas the platform holds it: whether the config wants the session locked, what the compositor says, and each output’s lock surface. Dropping it disposes its owner, which frees everything it made. - Margins
- Space between a window and the output edges it is anchored to, in logical pixels. Edges the window isn’t anchored to ignore theirs.
- Menu
- A vertical list of buttons, one per entry, as a popup menu shows them.
- Menu
Entry - One entry of a
Menu. - Modifiers
- The modifier keys held.
- Node
View - One node of a laid-out window: a widget, or the window itself at the root. Draw it, then its children in order, so later ones are on top.
- Output
- A monitor, as the compositor names it.
- Padding
- Space between a widget’s edge and its content, in logical pixels, on each side.
- Panel
Window - A bar: a layer-shell surface on one output with one child.
- Placement
- Where a popup goes next to the widget that opened it. Unset parts keep the defaults: below the widget from a horizontal bar, beside it from a vertical bar or another popup, flipped or slid to stay on the output.
- Point
- A point in logical pixels, measured from the window’s top-left corner.
- Popup
Window - A popup: a window next to the widget that opened it, sized to fit its
one child. Open one with
Cx::open_popup. - Preedit
- Text an input method is composing, shown at the caret, underlined, until it commits or drops it.
- Prop
- A widget property: either a value set once, or a binding that reruns whenever a signal it read changes.
- Rect
- A rectangle in logical pixels: its top-left corner and its size.
- Region
- An area of a window in logical pixels, built from rectangles, rounded
rectangles and ellipses joined with
union,subtract,intersectandxor, applied in the order they are called. - Row
- Lays its children out left to right, like a CSS flexbox row.
- Screencopy
View - Shows what an output or a window shows, captured by the compositor,
in the box its style’s
widthandheightgive it, as anImageshows a picture. It draws nothing until the first frame arrives. - Scroll
View - A box that shows part of its child, which may be taller, and scrolls it with the mouse wheel or touchpad. Children are cut to the box. Give it a height through its style, or let its parent size it.
- Session
Lock - A lock screen: while
lockedis true, the compositor shows only its surfaces, one covering each output, and nothing else gets input. Lock withcx.session_lockfrom thecrabshellcrate. Every property takes a value or a closure. - Shadow
- A shadow cast by a widget’s box, as CSS’s
box-shadow: the box’s shape moved byxandy, grown byspreadand blurred overblurlogical pixels. Unlike CSS’s, it is drawn under the box too, so a translucent background shows it through, unless it iscut_out. - Size
- A width and height in logical pixels.
- Spacer
- Takes the space left over in a
RoworColumn. Several spacers share it equally. - Stack
- Draws its children on top of each other in one cell, each stretched to the size of the largest. Later children are on top.
- Style
- How a widget looks. Every field is optional, and an unset field falls back
to the widget’s default: no background, black text in
Font::DEFAULT, no padding, square corners, no border, fully opaque. - Surface
Config - What the platform needs to set up the window’s layer surface.
- Text
- A line of text.
- Text
Input - A one-line text field. It takes the keyboard focus when clicked, when
Tab reaches it, or when
focussays so, and edits the text in a shared signal: typing writes it, and setting it changes what the field shows. Arrows, Home and End move the caret, Shift selects, Ctrl moves and deletes by word, and Ctrl+A selects everything. Keys it doesn’t use, such as Up, Down and Escape, go on to the window’son_key. - Text
System - The fonts every window measures and draws text with.
- Text
View - Laid-out text, ready to draw. Lines can stick out of the node’s rectangle when it is too small for them; draw them unclipped, as CSS does. The window’s damage covers them.
- Transition
- How long an animation takes and how it moves. Copy it into styles and constants like a color.
- Window
- A live window: the tree of nodes built from a
PanelWindow. - Window
View - A window’s laid-out tree, borrowed for reading. Get one from
Window::view.
Enums§
- Align
- How a
RoworColumnplaces children across its direction: up and down in a row, left and right in a column. - Capture
Source - What a
ScreencopyViewshows. - Clipboard
- What a key asks of the clipboard.
- Content
- What a node draws besides its background and border.
- Cursor
Shape - The cursor the platform should show.
- Easing
- How an animation moves from its start to its end: what fraction of the way it has gone at each fraction of its time.
- Edge
- An edge of the output.
- Fit
- How an
Imagefills its box when their shapes differ, as CSS’sobject-fit. - Gradient
Shape - Which way a
Gradient’s colors run. - Icon
Source - What an
Iconshows. - Justify
- How a
RoworColumnplaces children along its direction when they don’t fill it. - Key
- A key, as the keyboard layout names it.
- Keyboard
Focus - Whether and when a window takes the keyboard.
- Layer
- The layer-shell layer a window is drawn in, from bottom to top.
- Menu
Toggle - What a toggling menu entry shows.
- Pointer
Button - A pointer button.
- Scroll
Delta - One scroll event on the vertical axis, as
wl_pointerreports it. Positive values scroll down. - Window
Request - What a widget asked of the floating window it is in. Moving and
resizing need a pointer button held, so ask from a button’s
on_press; asked otherwise, they are ignored.
Traits§
- Animate
- A value an animation can move between two of:
lerpgives the valuetof the way fromselftoto, wheretmay stray a little past 0 or 1 for an easing that overshoots. - Into
Prop - Anything a widget property accepts: a value of type
T, or a closure that returns one. - Widget
- Something that can be placed in a window: one of this crate’s widgets, or a type of your own that is made of them.
Functions§
- advance_
animations - Advances every running animation to
now, writing their values, and returns whether any still runs. Each one starts at the first call after it began, sonowthere is its time 0. One that panics is logged and dropped. - animating
- Whether an animation is running, so the platform should advance the
clock soon.
falsemeans nothing moves and nothing needs waking.