[][src]Struct neutrino::widgets::container::Container

pub struct Container { /* fields omitted */ }

A container for other widgets

Fields

name: String
state: ContainerState
listener: Option<Box<dyn ContainerListener>>

Default values

name: name.to_string()
state:
    children: vec![]
    direction: Direction::Vertical
    position: Position::Start
    alignment: Alignment::None
    stretched: false
    style: "".to_string()
listener: None

Style

div.container

Example

use std::cell::RefCell;
use std::rc::Rc;

use neutrino::widgets::container::{Container, ContainerListener, ContainerState};
use neutrino::widgets::label::Label;
use neutrino::widgets::widget::Widget;
use neutrino::utils::theme::Theme;
use neutrino::{App, Window};


struct Quotes {
    values: Vec<String>,
}

impl Quotes {
    fn new() -> Self {
        Self { values: vec![] }
    }

    fn values(&self) -> &Vec<String> {
        &self.values
    }
}


struct MyContainerListener {
    quotes: Rc<RefCell<Quotes>>,
}

impl MyContainerListener {
   pub fn new(quotes: Rc<RefCell<Quotes>>) -> Self {
       Self { quotes }
   }
}

impl ContainerListener for MyContainerListener {
    fn on_update(&self, state: &mut ContainerState) {
        let labels = self.quotes.borrow().values().iter().enumerate().map(|(i, q)| {
            let name = format!("quote-{}", i);
            let mut w = Label::new(&name);
            w.set_text(q);
            let b: Box<dyn Widget> = Box::new(w);
            b
        }).collect::<Vec<Box<dyn Widget>>>();
        state.set_children(labels);
    }
}


fn main() {
    let quotes = Rc::new(RefCell::new(Quotes::new()));

    let my_listener = MyContainerListener::new(Rc::clone(&quotes));

    let mut my_container = Container::new("my_container");
    my_container.set_listener(Box::new(my_listener));
}

Methods

impl Container[src]

pub fn new(name: &str) -> Self[src]

Create a Container

pub fn set_direction(&mut self, direction: Direction)[src]

Set the direction

pub fn set_position(&mut self, position: Position)[src]

Set the position

pub fn set_alignment(&mut self, alignment: Alignment)[src]

Set the alignment

pub fn set_stretched(&mut self)[src]

Set the stretched flag to true. Alignment needs to be set to Alignment::None (default) for the Container to stretch.

pub fn set_listener(&mut self, listener: Box<dyn ContainerListener>)[src]

Set the listener

pub fn set_style(&mut self, style: &str)[src]

Set the style

pub fn add(&mut self, widget: Box<dyn Widget>)[src]

Add a widget

Trait Implementations

impl Widget for Container[src]

Auto Trait Implementations

impl !Send for Container

impl Unpin for Container

impl !Sync for Container

impl !UnwindSafe for Container

impl !RefUnwindSafe for Container

Blanket Implementations

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> From<T> for T[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,