Struct fltk::app::Receiver

source ·
pub struct Receiver<T: Send + Sync> { /* private fields */ }
Expand description

Creates a receiver struct

Implementations§

source§

impl<T: 'static + Send + Sync> Receiver<T>

source

pub fn recv(&self) -> Option<T>

Receives a message

Examples found in repository?
examples/messages.rs (line 31)
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
fn main() {
    let app = app::App::default();
    let mut wind = Window::default().with_size(400, 300);
    let mut frame = Frame::default().size_of(&wind).with_label("0");

    let mut val = 0;

    wind.show();

    let (s, r) = app::channel::<Message>();

    std::thread::spawn(move || loop {
        app::sleep(1.);
        s.send(Message::Increment(2));
    });

    while app.wait() {
        if let Some(Message::Increment(step)) = r.recv() {
            inc_frame(&mut frame, &mut val, step)
        }
    }
}
More examples
Hide additional examples
examples/temp_converter2.rs (line 85)
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
    pub fn run(&mut self) {
        while self.a.wait() {
            if let Some(msg) = self.r.recv() {
                match msg {
                    Message::CelciusChanged => {
                        self.inp2.set_value(&format!(
                            "{:.4}",
                            c_to_f(self.inp1.value().parse().unwrap_or(0.0))
                        ));
                    }
                    Message::FahrenheitChanged => {
                        self.inp1.set_value(&format!(
                            "{:.4}",
                            f_to_c(self.inp2.value().parse().unwrap_or(0.0))
                        ));
                    }
                }
            }
        }
    }
examples/counter2.rs (line 30)
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
fn main() -> Result<(), Box<dyn std::error::Error>> {
    let app = app::App::default();
    let mut wind = Window::default().with_size(160, 200).with_label("Counter");
    let mut flex = Flex::default_fill().column();
    flex.set_margins(30, 40, 30, 40);
    flex.set_pad(10);
    let mut but_inc = Button::default().with_label("+");
    let mut frame = Frame::default().with_label("0");
    let mut but_dec = Button::default().with_label("-");
    flex.end();
    wind.end();
    wind.show();

    let (s, r) = app::channel::<Message>();

    but_inc.emit(s, Message::Increment);
    but_dec.emit(s, Message::Decrement);

    while app.wait() {
        let label: i32 = frame.label().parse()?;

        if let Some(msg) = r.recv() {
            match msg {
                Message::Increment => frame.set_label(&(label + 1).to_string()),
                Message::Decrement => frame.set_label(&(label - 1).to_string()),
            }
        }
    }
    Ok(())
}
examples/closable_tabs2.rs (line 184)
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
fn main() {
    use fltk::{prelude::*, *};
    // Create groups to be used as content for tabs
    pub fn create_tab(from: i32, to: i32) -> group::Group {
        let grp = group::Group::new(0, 0, 800, 600, None);
        for idx in from..to {
            button::Button::new(
                idx * 10 + (idx - from) * 42,
                idx * 10 + (idx - from) * 42,
                80,
                40,
                None,
            )
            .with_label(&format!("button {idx}"));
        }
        grp.end();
        grp
    }
    let app = app::App::default();
    let mut win = window::Window::default().with_size(800, 600);
    let (s, r) = app::channel::<closable_tab::Message>();
    let mut tabs = closable_tab::ClosableTab::new(0, 0, 800, 600, &s);
    win.end();
    win.show();
    tabs.add(&mut create_tab(1, 3), "tab 1");
    tabs.add(&mut create_tab(4, 7), "tab 2");
    tabs.add(&mut create_tab(8, 11), "tab 3");
    tabs.add(&mut create_tab(12, 15), "tab 4");
    tabs.add(&mut create_tab(16, 22), "tab 5");
    tabs.set_foreground(2);
    while app.wait() {
        use closable_tab::Message::*;
        if let Some(msg) = r.recv() {
            match msg {
                Foreground(idx) => {
                    tabs.set_foreground(idx);
                }
                Delete(idx) => {
                    tabs.remove(idx);
                }
                InsertNew(_) => {}
            }
        }
    }
}
examples/threads_windows.rs (line 63)
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
fn main() -> Result<(), Box<dyn std::error::Error>> {
    let app = app::App::default();
    let mut wind = Window::default().with_size(160, 200).with_label("Counter");
    let mut col = Flex::default()
        .with_size(120, 140)
        .center_of(&wind)
        .column();
    col.set_spacing(10);
    let mut but_inc = Button::default().with_label("+");
    let mut frame = Frame::default().with_label("0");
    let mut but_dec = Button::default().with_label("-");
    col.end();
    wind.end();
    wind.show();

    let mut msg_wind = Window::default().with_size(120, 100).with_label("Message");
    let mut msgview = HelpView::default().with_size(120, 100);
    msgview.set_align(Align::Center);
    msg_wind.end();

    let (s, r) = app::channel::<Message>();

    but_inc.set_callback({
        move |_| {
            s.send(Message::Deactivate);
            thread::spawn(move || {
                thread::sleep(Duration::from_secs(1));
                s.send(Message::Increment);
                s.send(Message::Message("Incremented"));
                s.send(Message::Activate);
            });
        }
    });
    but_dec.set_callback({
        move |_| {
            s.send(Message::Deactivate);
            thread::spawn(move || {
                thread::sleep(Duration::from_secs(1));
                s.send(Message::Decrement);
                s.send(Message::Message("Decremented"));
                s.send(Message::Activate);
            });
        }
    });

    while app.wait() {
        if let Some(msg) = r.recv() {
            let label: i32 = frame.label().parse()?;
            match msg {
                Message::Increment => frame.set_label(&(label + 1).to_string()),
                Message::Decrement => frame.set_label(&(label - 1).to_string()),
                Message::Activate => {
                    but_inc.activate();
                    but_dec.activate();
                }
                Message::Deactivate => {
                    but_inc.deactivate();
                    but_dec.deactivate();
                }
                Message::Message(s) => {
                    msgview.set_value(s);
                    msg_wind.show();
                }
            }
        }
    }
    Ok(())
}
examples/editor2.rs (line 353)
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
    pub fn launch(&mut self) {
        while self.app.wait() {
            use Message::*;
            if let Some(msg) = self.r.recv() {
                match msg {
                    Changed => {
                        if !self.modified {
                            self.modified = true;
                            self.menu.menu.find_item("&File/Save\t").unwrap().activate();
                            self.menu.menu.find_item("&File/Quit\t").unwrap().set_label_color(Color::Red);
                            let name = match &self.filename {
                                Some(f) => f.to_string_lossy().to_string(),
                                None => "(Untitled)".to_string(),
                            };
                            self.main_win.set_label(&format!("* {name} - RustyEd"));
                        }
                    }
                    New => {
                        if self.buf.text() != "" {
                            let clear = if let Some(x) = dialog::choice2(center().0 - 200, center().1 - 100, "File unsaved, Do you wish to continue?", "Yes", "No!", "") {
                                x == 0
                            } else {
                                false
                            };
                            if clear {
                                self.buf.set_text("");
                            }
                        }
                    },
                    Open => {
                        let mut dlg = dialog::FileDialog::new(dialog::FileDialogType::BrowseFile);
                        dlg.set_option(dialog::FileDialogOptions::NoOptions);
                        dlg.set_filter("*.{txt,rs,toml}");
                        dlg.show();
                        let filename = dlg.filename();
                        if !filename.to_string_lossy().to_string().is_empty() {
                            if filename.exists() {
                                match self.buf.load_file(&filename) {
                                    Ok(_) => self.filename = Some(filename),
                                    Err(e) => dialog::alert(center().0 - 200, center().1 - 100, &format!("An issue occured while loading the file: {e}")),
                                }
                            } else {
                                dialog::alert(center().0 - 200, center().1 - 100, "File does not exist!")
                            }
                        }
                    },
                    Save => { self.save_file().unwrap(); },
                    SaveAs => { self.save_file_as().unwrap(); },
                    Print => {
                        let mut printer = printer::Printer::default();
                        if printer.begin_job(0).is_ok() {
                            let (w, h) = printer.printable_rect();
                            self.printable.set_size(w - 40, h - 40);
                            // Needs cleanup
                            let line_count = self.printable.count_lines(0, self.printable.buffer().unwrap().length(), true) / 45;
                            for i in 0..=line_count {
                                self.printable.scroll(45 * i, 0);
                                printer.begin_page().ok();
                                printer.print_widget(&self.printable, 20, 20);
                                printer.end_page().ok();
                            }
                            printer.end_job();
                        }
                    },
                    Quit => {
                        if self.modified {
                            match dialog::choice2(center().0 - 200, center().1 - 100,
                                "Would you like to save your work?", "Yes", "No", "") {
                                Some(0) => {
                                    if self.save_file().unwrap() {
                                        self.app.quit();
                                    }
                                },
                                Some(1) => { self.app.quit() },
                                Some(_) | None  => (),
                            }
                        } else {
                            self.app.quit();
                        }
                    },
                    Cut => self.editor.cut(),
                    Copy => self.editor.copy(),
                    Paste => self.editor.paste(),
                    About => dialog::message(center().0 - 300, center().1 - 100, "This is an example application written in Rust and using the FLTK Gui library."),
                }
            }
        }
    }
source

pub fn get() -> Self

Get the global receiver

Trait Implementations§

source§

impl<T: Send + Sync> Clone for Receiver<T>

source§

fn clone(&self) -> Self

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<T: Debug + Send + Sync> Debug for Receiver<T>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<T: Copy + Send + Sync> Copy for Receiver<T>

source§

impl<T: Send + Sync> Send for Receiver<T>

source§

impl<T: Send + Sync> Sync for Receiver<T>

Auto Trait Implementations§

§

impl<T> RefUnwindSafe for Receiver<T>where T: RefUnwindSafe,

§

impl<T> Unpin for Receiver<T>where T: Unpin,

§

impl<T> UnwindSafe for Receiver<T>where T: UnwindSafe,

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere 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> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

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

§

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 Twhere U: TryFrom<T>,

§

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.