[−][src]Struct iced_native::Element
A generic Widget
.
It is useful to build composable user interfaces that do not leak implementation details in their view logic.
If you have a built-in widget, you should be able to use Into<Element>
to turn it into an Element
.
Implementations
impl<'a, Message, Renderer> Element<'a, Message, Renderer> where
Renderer: Renderer,
[src]
Renderer: Renderer,
pub fn new(
widget: impl Widget<Message, Renderer> + 'a
) -> Element<'a, Message, Renderer>
[src]
widget: impl Widget<Message, Renderer> + 'a
) -> Element<'a, Message, Renderer>
pub fn map<F, B>(self, f: F) -> Element<'a, B, Renderer> where
Message: 'static,
Renderer: 'a,
B: 'static,
F: 'static + Fn(Message) -> B,
[src]
Message: 'static,
Renderer: 'a,
B: 'static,
F: 'static + Fn(Message) -> B,
Applies a transformation to the produced message of the Element
.
This method is useful when you want to decouple different parts of your UI and make them composable.
Example
Imagine we want to use our counter. But instead of
showing a single counter, we want to display many of them. We can reuse
the Counter
type as it is!
We use composition to model the state of our new application:
use counter::Counter; struct ManyCounters { counters: Vec<Counter>, }
We can store the state of multiple counters now. However, the messages we implemented before describe the user interactions of a single counter. Right now, we need to also identify which counter is receiving user interactions. Can we use composition again? Yes.
#[derive(Debug, Clone, Copy)] pub enum Message { Counter(usize, counter::Message) }
We compose the previous messages with the index of the counter producing them. Let's implement our view logic now:
use iced_native::{Element, Row}; use iced_wgpu::Renderer; impl ManyCounters { pub fn view(&mut self) -> Row<Message, Renderer> { // We can quickly populate a `Row` by folding over our counters self.counters.iter_mut().enumerate().fold( Row::new().spacing(20), |row, (index, counter)| { // We display the counter let element: Element<counter::Message, Renderer> = counter.view().into(); row.push( // Here we turn our `Element<counter::Message>` into // an `Element<Message>` by combining the `index` and the // message of the `element`. element.map(move |message| Message::Counter(index, message)) ) } ) } }
Finally, our update logic is pretty straightforward: simple delegation.
impl ManyCounters { pub fn update(&mut self, message: Message) { match message { Message::Counter(index, counter_msg) => { if let Some(counter) = self.counters.get_mut(index) { counter.update(counter_msg); } } } } }
pub fn explain<C: Into<Color>>(self, color: C) -> Element<'a, Message, Renderer> where
Message: 'static,
Renderer: 'a + Debugger,
[src]
Message: 'static,
Renderer: 'a + Debugger,
Marks the Element
as to-be-explained.
The Renderer
will explain the layout of the Element
graphically.
This can be very useful for debugging your layout!
pub fn width(&self) -> Length
[src]
Returns the width of the Element
.
pub fn height(&self) -> Length
[src]
Returns the height of the Element
.
pub fn layout(&self, renderer: &Renderer, limits: &Limits) -> Node
[src]
pub fn on_event(
&mut self,
event: Event,
layout: Layout<'_>,
cursor_position: Point,
messages: &mut Vec<Message>,
renderer: &Renderer,
clipboard: Option<&dyn Clipboard>
)
[src]
&mut self,
event: Event,
layout: Layout<'_>,
cursor_position: Point,
messages: &mut Vec<Message>,
renderer: &Renderer,
clipboard: Option<&dyn Clipboard>
)
Processes a runtime Event
.
pub fn draw(
&self,
renderer: &mut Renderer,
defaults: &Renderer::Defaults,
layout: Layout<'_>,
cursor_position: Point
) -> Renderer::Output
[src]
&self,
renderer: &mut Renderer,
defaults: &Renderer::Defaults,
layout: Layout<'_>,
cursor_position: Point
) -> Renderer::Output
pub fn hash_layout(&self, state: &mut Hasher)
[src]
Computes the layout hash of the Element
.
pub fn overlay<'b>(
&'b mut self,
layout: Layout<'_>
) -> Option<Element<'b, Message, Renderer>>
[src]
&'b mut self,
layout: Layout<'_>
) -> Option<Element<'b, Message, Renderer>>
Returns the overlay of the Element
, if there is any.
Trait Implementations
impl<'a, Message, Renderer> From<Button<'a, Message, Renderer>> for Element<'a, Message, Renderer> where
Renderer: 'a + Renderer,
Message: 'a + Clone,
[src]
Renderer: 'a + Renderer,
Message: 'a + Clone,
impl<'a, Message, Renderer> From<Checkbox<Message, Renderer>> for Element<'a, Message, Renderer> where
Renderer: 'a + Renderer + Renderer + Renderer,
Message: 'a,
[src]
Renderer: 'a + Renderer + Renderer + Renderer,
Message: 'a,
impl<'a, Message, Renderer> From<Column<'a, Message, Renderer>> for Element<'a, Message, Renderer> where
Renderer: 'a + Renderer,
Message: 'a,
[src]
Renderer: 'a + Renderer,
Message: 'a,
impl<'a, Message, Renderer> From<Container<'a, Message, Renderer>> for Element<'a, Message, Renderer> where
Renderer: 'a + Renderer,
Message: 'a,
[src]
Renderer: 'a + Renderer,
Message: 'a,
impl<'a, Message, Renderer> From<Image> for Element<'a, Message, Renderer> where
Renderer: Renderer,
[src]
Renderer: Renderer,
impl<'a, Message, Renderer> From<PaneGrid<'a, Message, Renderer>> for Element<'a, Message, Renderer> where
Renderer: 'a + Renderer + Renderer,
Message: 'a,
[src]
Renderer: 'a + Renderer + Renderer,
Message: 'a,
impl<'a, Message, Renderer> From<ProgressBar<Renderer>> for Element<'a, Message, Renderer> where
Renderer: 'a + Renderer,
Message: 'a,
[src]
Renderer: 'a + Renderer,
Message: 'a,
fn from(progress_bar: ProgressBar<Renderer>) -> Element<'a, Message, Renderer>
[src]
impl<'a, Message, Renderer> From<Radio<Message, Renderer>> for Element<'a, Message, Renderer> where
Renderer: 'a + Renderer + Renderer + Renderer,
Message: 'a + Clone,
[src]
Renderer: 'a + Renderer + Renderer + Renderer,
Message: 'a + Clone,
impl<'a, Message, Renderer> From<Row<'a, Message, Renderer>> for Element<'a, Message, Renderer> where
Renderer: 'a + Renderer,
Message: 'a,
[src]
Renderer: 'a + Renderer,
Message: 'a,
impl<'a, Message, Renderer> From<Rule<Renderer>> for Element<'a, Message, Renderer> where
Renderer: 'a + Renderer,
Message: 'a,
[src]
Renderer: 'a + Renderer,
Message: 'a,
impl<'a, Message, Renderer> From<Scrollable<'a, Message, Renderer>> for Element<'a, Message, Renderer> where
Renderer: 'a + Renderer,
Message: 'a,
[src]
Renderer: 'a + Renderer,
Message: 'a,
fn from(
scrollable: Scrollable<'a, Message, Renderer>
) -> Element<'a, Message, Renderer>
[src]
scrollable: Scrollable<'a, Message, Renderer>
) -> Element<'a, Message, Renderer>
impl<'a, T, Message, Renderer> From<Slider<'a, T, Message, Renderer>> for Element<'a, Message, Renderer> where
T: 'a + Copy + Into<f64> + FromPrimitive,
Renderer: 'a + Renderer,
Message: 'a + Clone,
[src]
T: 'a + Copy + Into<f64> + FromPrimitive,
Renderer: 'a + Renderer,
Message: 'a + Clone,
impl<'a, Message, Renderer> From<Space> for Element<'a, Message, Renderer> where
Renderer: Renderer,
Message: 'a,
[src]
Renderer: Renderer,
Message: 'a,
impl<'a, Message, Renderer> From<Svg> for Element<'a, Message, Renderer> where
Renderer: Renderer,
[src]
Renderer: Renderer,
impl<'a, Message, Renderer> From<Text<Renderer>> for Element<'a, Message, Renderer> where
Renderer: Renderer + 'a,
[src]
Renderer: Renderer + 'a,
impl<'a, Message, Renderer> From<TextInput<'a, Message, Renderer>> for Element<'a, Message, Renderer> where
Renderer: 'a + Renderer,
Message: 'a + Clone,
[src]
Renderer: 'a + Renderer,
Message: 'a + Clone,
impl<'a, T: 'a, Message, Renderer> Into<Element<'a, Message, Renderer>> for PickList<'a, T, Message, Renderer> where
T: Clone + ToString + Eq,
[T]: ToOwned<Owned = Vec<T>>,
Renderer: Renderer + 'a,
Message: 'static,
[src]
T: Clone + ToString + Eq,
[T]: ToOwned<Owned = Vec<T>>,
Renderer: Renderer + 'a,
Message: 'static,
Auto Trait Implementations
impl<'a, Message, Renderer> !RefUnwindSafe for Element<'a, Message, Renderer>
impl<'a, Message, Renderer> !Send for Element<'a, Message, Renderer>
impl<'a, Message, Renderer> !Sync for Element<'a, Message, Renderer>
impl<'a, Message, Renderer> Unpin for Element<'a, Message, Renderer>
impl<'a, Message, Renderer> !UnwindSafe for Element<'a, Message, Renderer>
Blanket Implementations
impl<S, D, Swp, Dwp, T> AdaptInto<D, Swp, Dwp, T> for S where
D: AdaptFrom<S, Swp, Dwp, T>,
Dwp: WhitePoint,
Swp: WhitePoint,
T: Component + Float,
[src]
D: AdaptFrom<S, Swp, Dwp, T>,
Dwp: WhitePoint,
Swp: WhitePoint,
T: Component + Float,
fn adapt_into_using<M>(self, method: M) -> D where
M: TransformMatrix<Swp, Dwp, T>,
[src]
M: TransformMatrix<Swp, Dwp, T>,
fn adapt_into(self) -> D
[src]
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T, U> ConvertInto<U> for T where
U: ConvertFrom<T>,
[src]
U: ConvertFrom<T>,
fn convert_into(self) -> U
[src]
fn convert_unclamped_into(self) -> U
[src]
fn try_convert_into(self) -> Result<U, OutOfBounds<U>>
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,