Expand description
§Floem built-in Views
This module contains the basic built-in Views of Floem.
§Composing Views
The views in this module are the main building blocks for composing UIs in Floem.
There is a collection of different stacks and lists that can be used to build collections of views.
There are also basic widgets such as text inputs, labels, images, and svgs.
§Example: Counter
use floem::{reactive::*, views::*};
let mut counter = RwSignal::new(0);
v_stack((
label(move || format!("Value: {counter}")),
h_stack((
button("Increment").action(move || counter += 1),
button("Decrement").action(move || counter -= 1),
)),
));Views in Floem can also be easily refactored.
§Example: Refactored Counter
use floem::prelude::*;
let mut counter = RwSignal::new(0);
let counter_label = label(move || format!("Value: {counter}"));
let increment_button = button("Increment").action(move || counter += 1);
let decrement_button = button("Decrement").action(move || counter -= 1);
let button_stack = (increment_button, decrement_button).h_stack();
(counter_label, button_stack).v_stack();§Stacks and Lists
There are a few different stacks and lists that you can use to group your views and each is discussed here.
They are:
- basic stack
- static and always contains the same elements in the same order
- dynamic stack
- can dynamically change the elements in the stack by reactively updating the list of items provided
- virtual stack
- can dynamically change the elements in the stack
- can lazily load the items as they appear in a scroll view
There is also a basic list and a virtual list. Lists are like their stack counterparts but they also have built-in support for the selection of items: up and down using arrow keys, top and bottom control using the home and end keys, and for the “acceptance” of an item using the Enter key. You could build this manually yourself using stacks but it is common enough that it is built-in as a list.
§View Trait
The View trait is the trait that Floem uses to build and display elements.
The trait contains the methods for implementing updates, styling, layout, events, and painting.
Views are types that implement View.
Many of these types will also be built with a child that also implements View.
In this way, views can be composed together easily to create complex UIs.
This composition is the most common way to build UIs in Floem.
Creating a type and manually implementing the View trait is typically only needed for building new widgets and for special cases.
Re-exports§
pub use scroll::Scroll;pub use scroll::ScrollExt;pub use scroll::scroll;pub use text_editor::*;
Modules§
- dropdown
- A view that allows the user to select an item from a list of items.
- editor
- localization
- Localization privitives.
- resizable
- scroll
- Scroll View
- slider
- A toggle button widget. An example can be found in widget-gallery/button in the floem examples.
- text_
editor
Macros§
Structs§
- Button
- A simple Button view. See
button. - Button
Class - The style class that is applied to buttons.
- Canvas
- A Canvas view. See the docs for canvas().
- Checkbox
- A customizable checkbox view for boolean selection.
- Checkbox
Class - The style class that is applied to checkboxs.
- Clip
- A wrapper around a child View to clip painting. See
clip. - Container
- A simple wrapper around another View. See
container. - Delay
- Diff
- Drag
Resize Window Area - A view that will resize the window when the mouse is dragged. See
drag_resize_window_area. - Drag
Window Area - A view that will move the window when the mouse is dragged. See
drag_window_area. - DynStack
- Dynamic
Container - A container for a dynamically updating View. See
dyn_container - Dynamic
View - A container for a dynamically updating View. See
dyn_view - Empty
- An empty View. See
empty. - Enumerate
- Image
Style - Holds information about image position and size inside container.
- Img
- Holds the data needed for img view fn to display images.
- Label
- A View that can display text from a
String. Seelabel,text, andstatic_label. - Label
Class - The style class that is applied to labels.
- Label
Custom Style - Represents a custom style for a
Label. - Labeled
Checkbox Class - The style class that is applied to all labeled checkbox stacks.
- Labeled
Radio Button Class - List
- A list of views that support the selection of items. See
list. - List
Class - List
Item Class - Object
Position - Specifies the alignment of the element’s contents within the element’s box.
- Placeholder
Text Class - The style class that is applied to the placeholder
TextInputtext. - Radio
Button - The
RadioButtonstruct provides various methods to create and manage radio buttons. - Radio
Button Class - Radio
Button DotClass - Radio
Button DotSelected Class - Rich
Span - Rich
Span Owned - Rich
Text - Stack
- A collection of static views. See
stackandstack_from_iter. - Svg
- SvgClass
- SvgColor
- SvgStr
Fn - Tab
- Tab widget.
- TabSelector
Class - Set class to TabSelector.
- Text
Input - Text Input View.
- Text
Input Class - The style class that is applied to all
TextInputviews. - Toggle
Button - A toggle button.
- Toggle
Button Behavior - Toggle
Button Circle Rad - Toggle
Button Class - A class for styling ToggleButton view.
- Toggle
Button Custom Style - Represents a custom style for a ToggleButton.
- Toggle
Button Inset - Tooltip
- A view that displays a tooltip for its child.
- Tooltip
Class - A class for the tooltip views.
- Tooltip
Container Class - A class for the tooltip container view.
- Value
Container - A wrapper around another View that has value updates. See
value_container - Virtual
Extractor - Virtual
List - Virtual
Stack - A virtual stack that is like a
dyn_stackbut also lazily loads items for performance. Seevirtual_stack.
Enums§
- Horiz
Position - Specifies object position on horizontal axis inside the element’s box.
- Movement
- Type of cursor movement in navigation.
- Object
Fit - How the content of a replaced element, such as an img or video, should be resized to fit its container. See https://developer.mozilla.org/en-US/docs/Web/CSS/object-fit.
- SvgOr
Style - Text
Direction - Type of text direction in the file.
- Toggle
Handle Behavior - Controls the switching behavior of the switch.
The corresponding style prop is
ToggleButtonBehavior - Vert
Position - Specifies object position on vertical axis inside the element’s box.
Constants§
- DEFAULT_
CHECKBOX_ SVG - The default checkbox SVG
Traits§
- Button
Ext - A trait that adds a
buttonmethod to any type that implementsIntoView. - ClipExt
- A trait that adds a
clipmethod to any type that implementsIntoView. - Container
Ext - A trait that adds a
containermethod to any type that implementsIntoView. - Decorators
- A trait that extends the appearance and functionality of Views through styling and event handling.
- ListExt
- A trait that adds a
listmethod to any generic typeTthat implementsIntoIteratorwhereT::Itemimplements IntoView. - Rich
Text Ext - Stack
Ext - SvgCss
Prop Extractor - Tooltip
Ext - Adds a tooltip function to a type that implements
IntoView. - Virtual
Vector - A trait that can be implemented on a type so that the type can be used in a
virtual_stackorvirtual_list.
Functions§
- brush_
to_ css_ string - button
- Creates a new simple Button view with the default ButtonClass style.
- canvas
- Creates a new Canvas view that can be used for custom painting
- checkbox
- Renders a checkbox the provided checked signal. See also
Checkbox::newandCheckbox::new_rw. - clip
- A clip is a wrapper around a child View that will clip the painting of the child so that it does not show outside of the viewport of the
Clip. - container
- A simple wrapper around another View
- create_
value_ container_ signals - A convenience function that creates two signals for use in a
value_container - custom_
checkbox - Renders a checkbox using a
checkedsignal and custom SVG. See alsoCheckbox::new_rwand - custom_
labeled_ checkbox - Renders a checkbox using the a
checkedsignal and a custom SVG. See alsoCheckbox::custom_labeled_rw - drag_
resize_ window_ area - A view that will resize the window when the mouse is dragged.
- drag_
window_ area - A view that will move the window when the mouse is dragged.
- dyn_
container - A container for a dynamically updating View
- dyn_
stack - A stack whose items can be reactively updated.
- dyn_
view - A container for a dynamically updating View
- empty
- An empty View. This view can still have a size, background, border radius, and outline.
- h_stack
- A stack which defaults to
FlexDirection::Row. See alsov_stack. - h_
stack_ from_ iter - Creates a stack from an iterator of views. It defaults to
FlexDirection::Row. See alsov_stack_from_iter. - img
- A view that can display an image and controls its position.
- img_
from_ path - A view that can display an image and controls its position.
- label
- A view that can reactively display text from an item that implements
Display. See alsotextfor a non-reactive label. - labeled_
checkbox - Renders a checkbox using the provided checked signal. See also
Checkbox::labeledandCheckbox::labeled_rw. - labeled_
radio_ button - Renders a radio button that appears as selected if the signal equals the given enum value.
- list
- A list of views built from an iterator which remains static and always contains the same elements in the same order.
- radio_
button - Renders a radio button that appears as selected if the signal equals the given enum value.
Can be combined with a label and a stack with a click event (as in
examples/widget-gallery). - rich_
text - stack
- A basic stack that is built from a tuple of views which remains static and always contains the same elements in the same order.
- stack_
from_ iter - Creates a stack from an iterator of views. See also
v_stack_from_iterandh_stack_from_iter. - static_
label - A non-reactive view that can display text from an item that can be turned into a
String. See alsolabel. - svg
- tab
- A tab widget. Create tabs from static or dynamic lists.
- text
- A non-reactive view that can display text from an item that implements
Display. See alsolabel. - text_
input - Creates a TextInput view. This can be used for basic text input.
- toggle_
button - A reactive toggle button.
- tooltip
- A view that displays a tooltip for its child.
- v_stack
- A stack which defaults to
FlexDirection::Column. See alsoh_stack. - v_
stack_ from_ iter - Creates a stack from an iterator of views. It defaults to
FlexDirection::Column.See alsoh_stack_from_iter. - value_
container - A wrapper around another View that has value updates.
- virtual_
list - A view that supports virtual scrolling with item selection. Selection is done using arrow keys, home/end for top/bottom.
- virtual_
stack - A View that is like a
dyn_stackbut also lazily loads the items as they appear in a scroll view