Skip to main content

Crate vampir

Crate vampir 

Source
Expand description

Vampir: lit controls for GPUI.

The look: surfaces carry a gradient lit from above, controls sit on that with a highlight along their top edge and a soft shadow beneath, and fields are recessed wells. lighting holds those recipes, Palette the twenty-odd colours they use, and controls the widgets built from both.

Nothing here knows about any particular application. A host stores a ControlState, implements ControlHost for its view, puts the toolkit’s handlers on its root with root, and hands controls a Palette; every control is generic over that view.

ⓘ
use vampir::{ControlHost, ControlState, controls, ButtonVariant};

struct Editor { controls: ControlState }

impl ControlHost for Editor {
    fn control_state(&self) -> &ControlState { &self.controls }
    fn control_state_mut(&mut self) -> &mut ControlState { &mut self.controls }
}

// ...inside Editor::render:
let palette = self.controls.palette();
vampir::root(div().id("root"), self, cx)
    .child(controls::button("save", "Save", ButtonVariant::Primary, true, palette, cx,
        |editor, _window, cx| editor.save(cx)))

ControlState::palette is the palette of the theme every host has by default — an app-chosen hue and saturation, and the desktop’s colour scheme — crossing over rather than cutting when they change. A host with a theme of its own builds a Palette from it instead, with Palette::from_hue_and_saturation or field by field.

Re-exports§

pub use containers::CARD_LIFT;
pub use containers::DialogButton;
pub use containers::Tab;
pub use containers::TabBarLayout;
pub use containers::arriving;
pub use containers::card;
pub use containers::card_at;
pub use containers::collapsible;
pub use containers::column;
pub use containers::dialog;
pub use containers::labelled;
pub use containers::reorder;
pub use containers::row;
pub use containers::scroll_area;
pub use containers::split_area;
pub use containers::split_handle;
pub use containers::tab_bar;
pub use containers::tab_bar_layout;
pub use controls::BadgeTone;
pub use controls::ButtonVariant;
pub use controls::CHIP_HEIGHT;
pub use controls::CONTROL_HEIGHT;
pub use controls::CONTROL_RADIUS;
pub use controls::ChipSelection;
pub use controls::Choice;
pub use controls::SliderTrack;
pub use controls::WidgetContext;
pub use controls::badge;
pub use controls::button;
pub use controls::caption;
pub use controls::checkbox;
pub use controls::chip;
pub use controls::chip_group;
pub use controls::combo;
pub use controls::fading_text;
pub use controls::glyph;
pub use controls::icon_button;
pub use controls::progress_bar;
pub use controls::radio_group;
pub use controls::scrollbar;
pub use controls::search_field;
pub use controls::segmented;
pub use controls::separator;
pub use controls::slider;
pub use controls::spinbox;
pub use controls::spinner;
pub use controls::switch;
pub use controls::text_area;
pub use controls::text_field;
pub use data::Column;
pub use data::SortDirection;
pub use data::TABLE_ROW_HEIGHT;
pub use data::TreeMove;
pub use data::TreeRow;
pub use data::flatten_tree;
pub use data::table_cell;
pub use data::table_header;
pub use data::table_row;
pub use data::tree_row;
pub use data::tree_step;
pub use easing::ease_in_cubic;
pub use easing::ease_out_cubic;
pub use easing::modal_opacity;
pub use icon::AppIcon;
pub use keyboard::Dismiss;
pub use keyboard::FocusNext;
pub use keyboard::FocusPrevious;
pub use keyboard::Key;
pub use keyboard::Orientation;
pub use keyboard::bind_keys;
pub use keyboard::edit_menu;
pub use keyboard::handle_keys;
pub use keyboard::key;
pub use keyboard::move_focus;
pub use keyboard::nudge;
pub use keyboard::nudge_stepped;
pub use keyboard::ring;
pub use keyboard::ring_for;
pub use keyboard::root;
pub use keyboard::standard_bindings;
pub use keyboard::step;
pub use lighting::glow;
pub use lighting::ground;
pub use lighting::ground_at;
pub use lighting::lit;
pub use lighting::lit_at;
pub use lighting::lit_mix;
pub use lighting::lit_stops;
pub use lighting::panel;
pub use lighting::raised;
pub use lighting::recessed;
pub use lighting::rim;
pub use lighting::shade;
pub use menu::ContextMenu;
pub use menu::MenuAction;
pub use menu::MenuIcon;
pub use menu::MenuItem;
pub use menu::context_menu;
pub use menu::menu_button;
pub use menu::menu_target;
pub use overlay::Command;
pub use overlay::Hint;
pub use overlay::SearchResult;
pub use overlay::Tooltip;
pub use overlay::command_list;
pub use overlay::command_palette;
pub use overlay::fuzzy_filter;
pub use overlay::fuzzy_score;
pub use overlay::rank_results;
pub use overlay::ranked_command_palette;
pub use overlay::ranked_search_list;
pub use overlay::search_list;
pub use palette::DEFAULT_SATURATION;
pub use palette::MAX_SATURATION;
pub use palette::Palette;
pub use scroll::SCROLL_FADE;
pub use scroll::ScrollAxis;
pub use scroll::ScrollDrag;
pub use scroll::apply_scroll_drag;
pub use scroll::scroll_fades;
pub use selection::ListSelection;
pub use selection::SelectionIntent;
pub use selection::selectable_list;
pub use shortcut::Chord;
pub use shortcut::display;
pub use shortcut::display_keystroke;
pub use shortcut::shortcut_recorder;
pub use state::COMBO_REVEAL;
pub use state::ComboId;
pub use state::ControlHost;
pub use state::ControlState;
pub use state::MOVE;
pub use state::OpenCombo;
pub use state::OpenDialog;
pub use state::OpenMenu;
pub use state::OpenPalette;
pub use state::SCHEME_FADE;
pub use state::SWITCH_SLIDE;
pub use state::TAB_DRAG_THRESHOLD;
pub use state::TabDrag;
pub use state::Tag;
pub use state::TrackAxis;
pub use state::TrackDrag;
pub use state::continue_drags;
pub use state::end_drags;
pub use state::handle_mouse;
pub use state::mouse_moved;
pub use swatch::MAX_CHROMA;
pub use swatch::Oklch;
pub use swatch::color_pad;
pub use swatch::hue_slider;
pub use swatch::hue_wheel;
pub use swatch::saturation_slider;
pub use swatch::swatch_grid;
pub use text_input::Highlighter;
pub use text_input::InputStyle;
pub use text_input::Span;
pub use text_input::TextInput;
pub use theme::DEFAULT_HUE;
pub use theme::Scheme;
pub use theme::Theme;
pub use theme::hue_picker;
pub use theme::saturation_picker;
pub use theme::scheme_picker;
pub use theme::system_dark;
pub use typography::SMALL_TEXT_SIZE;
pub use typography::TEXT_SIZE;
pub use typography::TITLE_TEXT_SIZE;
pub use typography::symbol_fonts;
pub use typography::ui_font;
pub use typography::ui_font_face;

Modules§

color
Colour maths for building a crate::Palette.
containers
Things that hold other things: a tab bar, a split divider, a collapsible section, a modal dialog, a scrolling area, a card, and the rows and columns a page is laid out in.
controls
The controls: buttons, a switch, a spin box, text field and area, pop-up menus, sliders and overlay scrollbars.
data
Rows of data: a tree and a sortable table header.
easing
Easing curves, and the fade helper the pop-up panels share.
icon
The application icon.
keyboard
What a key press means to a control that has focus.
lighting
Lighting: the few gradient, highlight and shadow recipes that give surfaces and controls a lit, physical feel.
menu
Right-click context menus.
overlay
Things that float above the view: tooltips and a command palette, and the search field with results that the palette is built from.
palette
The colours the controls draw with.
scroll
Scrolling: overlay-scrollbar geometry, thumb dragging, and the fade that keeps a scroll edge from slicing whatever is passing it.
selection
A selectable list and the host-owned selection it edits.
shortcut
Shortcut recorder: a field that captures the next key chord.
state
The mutable bits the controls need between frames.
swatch
Colour picking: hue and saturation sliders, a chroma and lightness pad, and a grid of preset swatches.
text_input
Text input entity: single-line fields and wrapped multi-line areas, with selection, IME composition, undo and a system clipboard.
theme
The theme a host has when it has none of its own: a hue and saturation, a colour scheme that follows the desktop until someone chooses otherwise, and the palette derived from them — cross-fading rather than cutting when any changes.
typography
Type: the face the toolkit’s text is set in, and the three sizes it uses.