[][src]Struct woab::Factory

pub struct Factory<A, W, S> { /* fields omitted */ }

Holds instructions for generating GTK widgets and connecing them to Actix actors.

  1. The first generic parameter, A, is the actor type.
  2. The second generic parameter, W, is the widgets type. Typically created with #[derive(woab::WidgetsFromBuilder)] on a struct that specifies the widgets of the Glade XML file that the code needs to access.
  3. The third generic parameter, S, is the signal type. Typically created with #[derive(woab::BuilderSignal)] on an enum that lists the signals from the Glade XML file that the code wants to handle.

A can be () if the widgets are to be handled by an existing actor - usually the one that handles their parent widget. S can also be () if it is desired to just generate widgets without connecting a signal.

Refer to #[derive(woab::Factories)] for how to create instances of this struct.

#[derive(woab::Factories)]
struct Factories {
    window: woab::Factory<WindowActor, WindowWidgets, WindowSignal>,
    row: woab::Factory<(), RowWidgets, RowSignal>,
}

struct WindowActor {
    widgets: WindowWidgets,
}

impl actix::StreamHandler<WindowSignal> for WindowActor {
    fn handle(&mut self, signal: WindowSignal, _ctx: &mut <Self as actix::Actor>::Context) {
        match signal {
            // Handle the signals of the main window
        }
    }
}

#[derive(woab::WidgetsFromBuilder)]
struct WindowWidgets {
    window: gtk::ApplicationWindow,
    list_box: gtk::ListBox,
}

#[derive(woab::WidgetsFromBuilder)]
struct RowWidgets {
    row: gtk::ListBoxRow,
    label: gtk::Label,
}

impl actix::StreamHandler<(usize, RowSignal)> for WindowActor {
    fn handle(&mut self, (row_number, signal): (usize, RowSignal), _ctx: &mut <Self as actix::Actor>::Context) {
        match signal {
            // Handle the signals of row #row_number
        }
    }

    // ******************************************************
    // * VERY IMPORTANT! Otherwise once one row is deleted, *
    // * its signal stream will be closed and the default   *
    // * implementation will close the WindowActor.         *
    // ******************************************************
    fn finished(&mut self, _ctx: &mut Self::Context) {}
}

fn create_window_with_rows(factory: &Factories) {
    factory.window.build().actor(|ctx, widgets| {
        for row_number in 0..10 {
            let row_widgets = factory.row.build()
                .connect_tagged_builder_signals(ctx, row_number)
                .widgets().unwrap();
            row_widgets.label.set_text(&format!("Roe number {}", row_number));
            widgets.list_box.add(&row_widgets.row);
        }
        WindowActor { widgets }
    }).unwrap();
}

Implementations

impl<A, W, S> Factory<A, W, S>[src]

pub fn build(&self) -> BuilderUtilizer<A, W, S>[src]

Create the gtk::Builder (inside a woab::BuilderUtilizer)

Note that this causes the GTK widgets to be created (but not to be shown or be connected to anything)

Trait Implementations

impl<A, W, S> From<String> for Factory<A, W, S>[src]

Auto Trait Implementations

impl<A, W, S> RefUnwindSafe for Factory<A, W, S> where
    A: RefUnwindSafe,
    S: RefUnwindSafe,
    W: RefUnwindSafe

impl<A, W, S> Send for Factory<A, W, S> where
    A: Send,
    S: Send,
    W: Send

impl<A, W, S> Sync for Factory<A, W, S> where
    A: Sync,
    S: Sync,
    W: Sync

impl<A, W, S> Unpin for Factory<A, W, S> where
    A: Unpin,
    S: Unpin,
    W: Unpin

impl<A, W, S> UnwindSafe for Factory<A, W, S> where
    A: UnwindSafe,
    S: UnwindSafe,
    W: UnwindSafe

Blanket Implementations

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

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

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

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

impl<T, U> Into<U> for T where
    U: From<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<V, T> VZip<V> for T where
    V: MultiLane<T>,