pub struct WindowView<State> { /* private fields */ }Expand description
A view representing a window.
Implementations§
Source§impl<State> WindowView<State>
impl<State> WindowView<State>
Sourcepub fn with_options(
self,
f: impl FnOnce(WindowOptions<State>) -> WindowOptions<State>,
) -> Self
pub fn with_options( self, f: impl FnOnce(WindowOptions<State>) -> WindowOptions<State>, ) -> Self
Modify window options in-place.
Examples found in repository?
examples/transparent_window.rs (lines 45-48)
24fn app_logic(state: &mut AppState) -> impl Iterator<Item = WindowView<AppState>> + use<> {
25 let base_color = Color::new([0., 0., 0., state.alpha]);
26
27 let root_view = flex_col((
28 FlexSpacer::Flex(1.),
29 flex_row((
30 text_button("-", |state: &mut AppState| {
31 state.alpha = (state.alpha - 0.25).max(0.);
32 }),
33 text_button("+", |state: &mut AppState| {
34 state.alpha = (state.alpha + 0.25).min(1.);
35 }),
36 ))
37 .gap(10.px()),
38 FlexSpacer::Flex(1.),
39 ))
40 .padding(20.);
41
42 std::iter::once(
43 xilem::window(state.window_id, "Transparency Demo", root_view)
44 .with_base_color(base_color)
45 .with_options(|o| {
46 o.with_transparent(true)
47 .on_close(|state: &mut AppState| state.is_running = false)
48 }),
49 )
50}More examples
examples/multiple_windows.rs (line 69)
33fn app_logic(state: &mut State) -> impl Iterator<Item = WindowView<State>> + use<> {
34 std::iter::once(
35 window(
36 state.main_window_id,
37 "Multiple windows",
38 flex_col((
39 label(format!(
40 "{:#?}",
41 state
42 .counters
43 .values()
44 .map(|counter| (&counter.name, counter.value))
45 .collect::<BTreeMap<_, _>>()
46 )),
47 text_input(
48 state.new_counter_name.clone(),
49 |state: &mut State, new_name| {
50 state.new_counter_name = new_name;
51 },
52 ),
53 text_button("Add".to_string(), |state: &mut State| {
54 if state
55 .counters
56 .values()
57 .any(|counter| counter.name == state.new_counter_name)
58 {
59 // TODO: show error if name already exists
60 return;
61 }
62 let name = std::mem::take(&mut state.new_counter_name);
63 state
64 .counters
65 .insert(WindowId::next(), Counter { name, value: 0 });
66 }),
67 )),
68 )
69 .with_options(|o| o.on_close(|state: &mut State| state.running = false)),
70 )
71 .chain(
72 state
73 .counters
74 .iter()
75 .map(|(window_id, Counter { name, value })| {
76 let window_id = *window_id;
77 window(
78 window_id,
79 name,
80 flex_col((
81 label(format!("count: {value}")),
82 text_button("+".to_string(), move |state: &mut State| {
83 state.counters.get_mut(&window_id).unwrap().value += 1;
84 }),
85 text_button("-".to_string(), move |state: &mut State| {
86 state.counters.get_mut(&window_id).unwrap().value -= 1;
87 }),
88 )),
89 )
90 .with_options(|o| {
91 o.on_close(move |state: &mut State| {
92 state.counters.remove(&window_id);
93 })
94 })
95 }),
96 )
97 .collect::<Vec<_>>()
98 .into_iter()
99}Sourcepub fn with_base_color(self, color: Color) -> Self
pub fn with_base_color(self, color: Color) -> Self
Set base color of the window.
Examples found in repository?
examples/transparent_window.rs (line 44)
24fn app_logic(state: &mut AppState) -> impl Iterator<Item = WindowView<AppState>> + use<> {
25 let base_color = Color::new([0., 0., 0., state.alpha]);
26
27 let root_view = flex_col((
28 FlexSpacer::Flex(1.),
29 flex_row((
30 text_button("-", |state: &mut AppState| {
31 state.alpha = (state.alpha - 0.25).max(0.);
32 }),
33 text_button("+", |state: &mut AppState| {
34 state.alpha = (state.alpha + 0.25).min(1.);
35 }),
36 ))
37 .gap(10.px()),
38 FlexSpacer::Flex(1.),
39 ))
40 .padding(20.);
41
42 std::iter::once(
43 xilem::window(state.window_id, "Transparency Demo", root_view)
44 .with_base_color(base_color)
45 .with_options(|o| {
46 o.with_transparent(true)
47 .on_close(|state: &mut AppState| state.is_running = false)
48 }),
49 )
50}Trait Implementations§
Source§impl<State> View<State, (), ViewCtx> for WindowView<State>where
State: 'static,
impl<State> View<State, (), ViewCtx> for WindowView<State>where
State: 'static,
Source§type ViewState = AnyViewState
type ViewState = AnyViewState
State that is used over the lifetime of the retained representation of the view. Read more
Source§fn build(
&self,
ctx: &mut ViewCtx,
app_state: &mut State,
) -> (Self::Element, Self::ViewState)
fn build( &self, ctx: &mut ViewCtx, app_state: &mut State, ) -> (Self::Element, Self::ViewState)
Create the corresponding Element value.
Source§fn rebuild(
&self,
prev: &Self,
root_widget_view_state: &mut Self::ViewState,
ctx: &mut ViewCtx,
window: Mut<'_, Self::Element>,
app_state: &mut State,
)
fn rebuild( &self, prev: &Self, root_widget_view_state: &mut Self::ViewState, ctx: &mut ViewCtx, window: Mut<'_, Self::Element>, app_state: &mut State, )
Update
element based on the difference between self and prev.Source§fn teardown(
&self,
view_state: &mut Self::ViewState,
ctx: &mut ViewCtx,
window: Mut<'_, Self::Element>,
)
fn teardown( &self, view_state: &mut Self::ViewState, ctx: &mut ViewCtx, window: Mut<'_, Self::Element>, )
Handle
element being removed from the tree. Read moreSource§fn message(
&self,
view_state: &mut Self::ViewState,
message: &mut MessageContext,
window: Mut<'_, Self::Element>,
app_state: &mut State,
) -> MessageResult<()>
fn message( &self, view_state: &mut Self::ViewState, message: &mut MessageContext, window: Mut<'_, Self::Element>, app_state: &mut State, ) -> MessageResult<()>
Route
message to id_path, if that is still a valid path.impl<State> ViewMarker for WindowView<State>where
State: 'static,
Auto Trait Implementations§
impl<State> Freeze for WindowView<State>
impl<State> !RefUnwindSafe for WindowView<State>
impl<State> !Send for WindowView<State>
impl<State> !Sync for WindowView<State>
impl<State> Unpin for WindowView<State>
impl<State> !UnwindSafe for WindowView<State>
Blanket Implementations§
Source§impl<State, Action, Context, DynamicElement, V> AnyView<State, Action, Context, DynamicElement> for Vwhere
DynamicElement: AnyElement<<V as View<State, Action, Context>>::Element, Context>,
Context: ViewPathTracker,
V: View<State, Action, Context> + 'static,
<V as View<State, Action, Context>>::ViewState: 'static,
impl<State, Action, Context, DynamicElement, V> AnyView<State, Action, Context, DynamicElement> for Vwhere
DynamicElement: AnyElement<<V as View<State, Action, Context>>::Element, Context>,
Context: ViewPathTracker,
V: View<State, Action, Context> + 'static,
<V as View<State, Action, Context>>::ViewState: 'static,
Source§fn dyn_build(
&self,
ctx: &mut Context,
app_state: &mut State,
) -> (DynamicElement, AnyViewState)
fn dyn_build( &self, ctx: &mut Context, app_state: &mut State, ) -> (DynamicElement, AnyViewState)
Type erased
View::build.Source§fn dyn_rebuild(
&self,
dyn_state: &mut AnyViewState,
ctx: &mut Context,
prev: &dyn AnyView<State, Action, Context, DynamicElement>,
element: <DynamicElement as ViewElement>::Mut<'_>,
app_state: &mut State,
)
fn dyn_rebuild( &self, dyn_state: &mut AnyViewState, ctx: &mut Context, prev: &dyn AnyView<State, Action, Context, DynamicElement>, element: <DynamicElement as ViewElement>::Mut<'_>, app_state: &mut State, )
Type erased
View::rebuild.Source§fn dyn_teardown<'el>(
&self,
dyn_state: &mut AnyViewState,
ctx: &mut Context,
element: <DynamicElement as ViewElement>::Mut<'el>,
) -> <DynamicElement as ViewElement>::Mut<'el>
fn dyn_teardown<'el>( &self, dyn_state: &mut AnyViewState, ctx: &mut Context, element: <DynamicElement as ViewElement>::Mut<'el>, ) -> <DynamicElement as ViewElement>::Mut<'el>
Type erased
View::teardown. Read moreSource§fn dyn_message(
&self,
dyn_state: &mut AnyViewState,
message: &mut MessageContext,
element: <DynamicElement as ViewElement>::Mut<'_>,
app_state: &mut State,
) -> MessageResult<Action>
fn dyn_message( &self, dyn_state: &mut AnyViewState, message: &mut MessageContext, element: <DynamicElement as ViewElement>::Mut<'_>, app_state: &mut State, ) -> MessageResult<Action>
Type erased
View::message.Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Convert
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Convert
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
Convert
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Convert
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.