Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Views module docs #620

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
14 changes: 7 additions & 7 deletions examples/animations/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ fn app_view() -> impl IntoView {
let animation = RwSignal::new(
Animation::new()
.duration(5.seconds())
.keyframe(0, |kf| kf.computed_style())
.keyframe(50, |kf| {
kf.style(|s| s.background(Color::BLACK).size(30, 30))
.keyframe(0, |f| f.computed_style())
.keyframe(50, |f| {
f.style(|s| s.background(Color::BLACK).size(30, 30))
.ease_in()
})
.keyframe(100, |kf| {
kf.style(|s| s.background(Color::AQUAMARINE).size(10, 300))
.keyframe(100, |f| {
f.style(|s| s.background(Color::AQUAMARINE).size(10, 300))
.ease_out()
})
.repeat(true)
Expand All @@ -36,8 +36,8 @@ fn app_view() -> impl IntoView {
.style(|s| s.background(Color::BLUE).size(50, 100))
.animation(move |_| animation.get())
.animation(move |a| {
a.keyframe(100, |kf| {
kf.style(|s| s.border(5).border_color(Color::PURPLE))
a.keyframe(100, |f| {
f.style(|s| s.border(5).border_color(Color::PURPLE))
})
.duration(5.seconds())
.repeat(true)
Expand Down
2 changes: 1 addition & 1 deletion examples/counter/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use floem::{
peniko::Color,
reactive::{create_signal, SignalGet, SignalUpdate},
unit::UnitExt,
views::{dyn_view, Decorators, LabelClass, LabelCustomStyle},
views::{dyn_view::*, Decorators, LabelClass, LabelCustomStyle},
IntoView, View,
};

Expand Down
2 changes: 1 addition & 1 deletion examples/dropped_file/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use floem::{
event::EventListener,
keyboard::{Key, Modifiers, NamedKey},
unit::UnitExt,
views::{dyn_view, Decorators},
views::{dyn_view::*, Decorators},
IntoView, View,
};

Expand Down
4 changes: 3 additions & 1 deletion examples/editor/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ use floem::{
core::{command::EditCommand, editor::EditType, selection::Selection},
text::{default_dark_color, SimpleStyling},
},
stack, text_editor, Decorators,
stack,
text_editor::*,
Decorators,
},
IntoView, View,
};
Expand Down
3 changes: 2 additions & 1 deletion examples/flight_booker/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
use std::fmt::Display;

use floem::views::radio_button::RadioButton;
use floem::views::StackExt;
use floem::{
peniko::Color,
reactive::{create_rw_signal, RwSignal, SignalGet, SignalUpdate},
unit::UnitExt,
views::{button, dyn_container, empty, text, text_input, v_stack, Decorators, RadioButton},
views::{button, dyn_container, empty, text, text_input, v_stack, Decorators},
IntoView,
};
use strum::IntoEnumIterator;
Expand Down
5 changes: 1 addition & 4 deletions examples/layout/src/draggable_sidebar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@ use floem::{
peniko::Color,
reactive::{create_rw_signal, create_signal, SignalGet, SignalUpdate},
style::{CursorStyle, Position},
views::{
container, h_stack, label, scroll, virtual_stack, Decorators, VirtualDirection,
VirtualItemSize,
},
views::{container, h_stack, label, scroll, virtual_stack::*, Decorators},
IntoView, View,
};

Expand Down
5 changes: 1 addition & 4 deletions examples/layout/src/holy_grail.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@ use floem::{
peniko::Color,
reactive::{create_rw_signal, SignalGet},
style::Position,
views::{
container, h_stack, label, scroll, v_stack, virtual_stack, Decorators, VirtualDirection,
VirtualItemSize,
},
views::{container, h_stack, label, scroll, v_stack, virtual_stack::*, Decorators},
IntoView, View,
};

Expand Down
5 changes: 1 addition & 4 deletions examples/layout/src/left_sidebar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@ use floem::{
peniko::Color,
reactive::{create_rw_signal, SignalGet},
style::Position,
views::{
container, h_stack, label, scroll, v_stack, virtual_stack, Decorators, VirtualDirection,
VirtualItemSize,
},
views::{container, h_stack, label, scroll, v_stack, virtual_stack::*, Decorators},
IntoView, View,
};

Expand Down
5 changes: 1 addition & 4 deletions examples/layout/src/right_sidebar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@ use floem::{
peniko::Color,
reactive::{create_rw_signal, SignalGet},
style::Position,
views::{
container, h_stack, label, scroll, v_stack, virtual_stack, Decorators, VirtualDirection,
VirtualItemSize,
},
views::{container, h_stack, label, scroll, v_stack, virtual_stack::*, Decorators},
IntoView, View,
};

Expand Down
2 changes: 1 addition & 1 deletion examples/layout/src/tab_navigation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use floem::{
reactive::{create_signal, ReadSignal, SignalGet, SignalUpdate, WriteSignal},
style::{CursorStyle, Position},
text::Weight,
views::{container, h_stack, label, scroll, tab, v_stack, Decorators},
views::{container, h_stack, label, scroll, tab::*, v_stack, Decorators},
IntoView, View,
};

Expand Down
2 changes: 1 addition & 1 deletion examples/stacks/src/virtual_stack.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use floem::{
reactive::{create_rw_signal, SignalGet, SignalUpdate},
views::{scroll, virtual_stack, ButtonClass, Decorators, VirtualDirection, VirtualItemSize},
views::{scroll, virtual_stack::*, ButtonClass, Decorators},
IntoView,
};

Expand Down
4 changes: 3 additions & 1 deletion examples/syntax-editor/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ use floem::{
core::{editor::EditType, selection::Selection},
text::WrapMethod,
},
stack, text_editor, Decorators,
stack,
text_editor::*,
Decorators,
},
};
use floem::{IntoView, View};
Expand Down
2 changes: 1 addition & 1 deletion examples/view-transition/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ impl ViewSwitcher {
.style(|s| s.padding(8))
.animation(|a| {
a.view_transition()
.keyframe(0, |kf| kf.style(|s| s.padding(0)))
.keyframe(0, |f| f.style(|s| s.padding(0)))
})
}
}
Expand Down
4 changes: 1 addition & 3 deletions examples/virtual_list/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
use floem::{
reactive::{create_signal, SignalGet},
unit::UnitExt,
views::{
container, label, scroll, virtual_list, Decorators, VirtualDirection, VirtualItemSize,
},
views::{container, label, scroll, virtual_list::virtual_list, virtual_stack::*, Decorators},
IntoView,
};

Expand Down
2 changes: 1 addition & 1 deletion examples/widget-gallery/src/buttons.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use floem::{
peniko::Color,
style::CursorStyle,
views::{button, toggle_button, Decorators, ToggleHandleBehavior},
views::{button, toggle_button::*, Decorators},
IntoView,
};

Expand Down
13 changes: 5 additions & 8 deletions examples/widget-gallery/src/checkbox.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
use floem::{
reactive::{RwSignal, SignalGet},
views::{checkbox, labeled_checkbox, Checkbox, Decorators},
IntoView,
};
use checkbox::Checkbox;
use floem::prelude::*;

use crate::form::{form, form_item};

Expand All @@ -15,18 +12,18 @@ pub fn checkbox_view() -> impl IntoView {
Checkbox::new_rw(is_checked).style(|s| s.margin(5.0))
}),
form_item("Disabled Checkbox:".to_string(), width, move || {
checkbox(move || is_checked.get())
Checkbox::new(move || is_checked.get())
.style(|s| s.margin(5.0))
.disabled(|| true)
}),
form_item("Labelled Checkbox:".to_string(), width, move || {
Checkbox::new_labeled_rw(is_checked, || "Check me!")
Checkbox::labeled_rw(is_checked, || "Check me!")
}),
form_item(
"Disabled Labelled Checkbox:".to_string(),
width,
move || {
labeled_checkbox(move || is_checked.get(), || "Check me!").disabled(|| true)
Checkbox::labeled(move || is_checked.get(), || "Check me!").disabled(|| true)
},
),
)
Expand Down
2 changes: 1 addition & 1 deletion examples/widget-gallery/src/labels.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use floem::{
peniko::Color,
text::{Style as FontStyle, Weight},
views::{label, static_label, tooltip, Decorators},
views::{label, static_label, tooltip::*, Decorators},
IntoView,
};

Expand Down
5 changes: 2 additions & 3 deletions examples/widget-gallery/src/lists.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@ use floem::{
style::JustifyContent,
text::Weight,
views::{
button, container, h_stack, h_stack_from_iter, label, list, scroll, stack, v_stack,
v_stack_from_iter, virtual_list, Checkbox, Decorators, VirtualDirection, VirtualItemSize,
VirtualVector,
button, checkbox::Checkbox, container, h_stack, h_stack_from_iter, label, list, scroll,
stack, v_stack, v_stack_from_iter, virtual_list::*, virtual_stack::*, Decorators,
},
IntoView,
};
Expand Down
10 changes: 2 additions & 8 deletions examples/widget-gallery/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,10 @@ pub mod slider;
use floem::{
event::{Event, EventListener, EventPropagation},
keyboard::{Key, NamedKey},
peniko::Color,
reactive::{create_signal, SignalGet, SignalUpdate},
prelude::*,
style::{Background, CursorStyle, Transition},
unit::{DurationUnitExt, UnitExt},
views::{
button, h_stack, label, scroll, stack, tab, v_stack, virtual_stack, Decorators,
VirtualDirection, VirtualItemSize,
},
IntoView, View,
};
use virtual_stack::*;

fn app_view() -> impl IntoView {
let tabs: im::Vector<&str> = vec![
Expand Down
2 changes: 1 addition & 1 deletion examples/widget-gallery/src/radio_buttons.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::fmt::Display;
use floem::{
reactive::RwSignal,
style_class,
views::{Decorators, RadioButton, StackExt as _},
views::{radio_button::RadioButton, Decorators, StackExt as _},
IntoView,
};
use strum::IntoEnumIterator;
Expand Down
16 changes: 8 additions & 8 deletions src/animate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -421,28 +421,28 @@ impl Animation {
self.run_on_create(true)
.run_on_remove(true)
.initial_state(AnimStateCommand::Stop)
.keyframe(0, |kf| kf.computed_style().ease(Spring::gentle()))
.keyframe(100, |kf| kf.computed_style().ease(Spring::gentle()))
.keyframe(0, |f| f.computed_style().ease(Spring::gentle()))
.keyframe(100, |f| f.computed_style().ease(Spring::gentle()))
}

/// Quickly set an animation to be a view transition and override the default easing function on keyframes 0 and 100.
pub fn view_transition_with_ease(self, ease: impl Easing + 'static + Clone) -> Self {
self.view_transition()
.keyframe(0, |kf| kf.computed_style().ease(ease.clone()))
.keyframe(100, |kf| kf.computed_style().ease(ease.clone()))
.keyframe(0, |f| f.computed_style().ease(ease.clone()))
.keyframe(100, |f| f.computed_style().ease(ease.clone()))
}

/// Quickly set an animation to be a view transition and set the animation to animate from scale 0% to the "normal" computed style of a view (the view with no animations applied).
pub fn scale_effect(self) -> Self {
self.view_transition()
.keyframe(0, |kf| kf.style(|s| s.scale(0.pct())))
.keyframe(0, |f| f.style(|s| s.scale(0.pct())))
.debug_name("Scale the width and height from zero to the default")
}

/// Quickly set an animation to be a view transition and set the animation to animate from size(0, 0) to the "normal" computed style of a view (the view with no animations applied).
pub fn scale_size_effect(self) -> Self {
self.view_transition()
.keyframe(0, |kf| kf.style(|s| s.size(0, 0)))
.keyframe(0, |f| f.style(|s| s.size(0, 0)))
.debug_name("Scale the width and height from zero to the default")
}
}
Expand Down Expand Up @@ -503,8 +503,8 @@ impl Animation {
) -> Self {
let frame = key_frame(KeyFrame::new(frame_id));
let frame_style = frame.style.clone();
if let Some(kf) = self.key_frames.insert(frame_id, frame) {
if let KeyFrameStyle::Style(style) = kf.style {
if let Some(f) = self.key_frames.insert(frame_id, frame) {
if let KeyFrameStyle::Style(style) = f.style {
for prop in style.style_props() {
self.cache.remove_prop(prop, frame_id);
}
Expand Down
7 changes: 2 additions & 5 deletions src/inspector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,10 @@ use crate::app_state::AppState;
use crate::context::StyleCx;
use crate::event::{Event, EventListener, EventPropagation};
use crate::id::ViewId;
use crate::prelude::*;
use crate::profiler::profiler;
use crate::style::{Style, StyleClassRef, StylePropRef, Transition};
use crate::view::{IntoView, View};
use crate::view_state::ChangeFlags;
use crate::views::{
button, container, dyn_container, empty, h_stack, img_dynamic, scroll, stack, static_label,
tab, text, text_input, v_stack, v_stack_from_iter, Decorators, Label,
};
use crate::window::WindowConfig;
use crate::{new_window, style, Clipboard};
use floem_reactive::{
Expand All @@ -19,6 +15,7 @@ use floem_reactive::{
use floem_winit::keyboard::{self, NamedKey};
use floem_winit::window::WindowId;
use image::DynamicImage;
use img::img_dynamic;
use peniko::kurbo::{Point, Rect, Size};
use peniko::Color;
use slotmap::Key;
Expand Down
21 changes: 16 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,13 +153,13 @@
//! .style(|s| s.background(Color::RED).size(500, 100))
//! .animation(move |a| {
//! a.duration(5.seconds())
//! .keyframe(0, |kf| kf.computed_style())
//! .keyframe(50, |kf| {
//! kf.style(|s| s.background(Color::BLACK).size(30, 30))
//! .keyframe(0, |f| f.computed_style())
//! .keyframe(50, |f| {
//! f.style(|s| s.background(Color::BLACK).size(30, 30))
//! .ease_in()
//! })
//! .keyframe(100, |kf| {
//! kf.style(|s| s.background(Color::AQUAMARINE).size(10, 300))
//! .keyframe(100, |f| {
//! f.style(|s| s.background(Color::AQUAMARINE).size(10, 300))
//! .ease_out()
//! })
//! .auto_reverse(true)
Expand Down Expand Up @@ -228,3 +228,14 @@ pub use taffy;
pub use view::{recursively_layout_view, AnyView, IntoView, View};
pub use window::{close_window, new_window};
pub use window_id::{Urgency, WindowIdExt};

pub mod prelude {
pub use crate::unit::{DurationUnitExt, UnitExt};
pub use crate::view_tuple::ViewTuple;
pub use crate::views::*;
pub use crate::{IntoView, View};
pub use floem_reactive::{
create_rw_signal, create_signal, RwSignal, SignalGet, SignalTrack, SignalUpdate, SignalWith,
};
pub use peniko::Color;
}
15 changes: 6 additions & 9 deletions src/theme.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
use crate::{
style::{Background, CursorStyle, Foreground, Style, Transition},
unit::{DurationUnitExt, UnitExt},
views::{
dropdown::{self},
scroll,
slider::{self, SliderClass},
ButtonClass, CheckboxClass, LabelClass, LabelCustomStyle, LabeledCheckboxClass,
LabeledRadioButtonClass, ListClass, ListItemClass, PlaceholderTextClass, RadioButtonClass,
RadioButtonDotClass, TextInputClass, ToggleButtonCircleRad, ToggleButtonClass,
ToggleButtonInset, TooltipClass,
},
views::*,
};
use checkbox::{CheckboxClass, LabeledCheckboxClass};
use peniko::{Brush, Color};
use radio_button::{LabeledRadioButtonClass, RadioButtonClass, RadioButtonDotClass};
use slider::SliderClass;
use std::rc::Rc;
use taffy::style::AlignItems;
use toggle_button::{ToggleButtonCircleRad, ToggleButtonClass, ToggleButtonInset};
use tooltip::TooltipClass;

pub(crate) struct Theme {
pub(crate) background: Color,
Expand Down
Loading
Loading