WindowView

Struct WindowView 

Source
pub struct WindowView<State> { /* private fields */ }
Expand description

A view representing a window.

Implementations§

Source§

impl<State> WindowView<State>

Source

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
Hide additional 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}
Source

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,

Source§

type Element = PodWindow

The element type which this view operates on.
Source§

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)

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, )

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>, )

Handle element being removed from the tree. Read more
Source§

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.
Source§

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<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<State, Action, Context, DynamicElement, V> AnyView<State, Action, Context, DynamicElement> for V
where 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 as_any(&self) -> &(dyn Any + 'static)

Get an Any reference to self.
Source§

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, )

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>

Source§

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> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> Downcast<T> for T

Source§

fn downcast(&self) -> &T

Source§

impl<T> Downcast for T
where T: Any,

Source§

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>

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)

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)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> Upcast<T> for T

Source§

fn upcast(&self) -> Option<&T>

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,