Struct BaseListener

Source
pub struct BaseListener<T: WidgetBase + WidgetExt, TRIG> { /* private fields */ }
Expand description

The base listener widget, wraps a fltk WidgetBase.

Implementations§

Source§

impl<T: WidgetBase + WidgetExt + Into<BaseListener<T, TRIG>>, TRIG> BaseListener<T, TRIG>

Constructors, depends on impl From<T> for BaseListener<T, TRIG>, see crate::blocking::Listener::from

Source

pub fn from_widget(wid: T) -> Self

Not recommanded, use Into<BaseListener> like let btn: Listener<_> = btn.into();

Source

pub fn new<S: Into<Option<&'static str>>>( x: i32, y: i32, w: i32, h: i32, label: S, ) -> Self

Creates a new widget, takes an x, y coordinates, as well as a width and height, plus a title. Same as WidgetBase::new

Source

pub fn default_fill() -> Self

Construct a widget filling the parent. Same as WidgetBase::default_fill

Source§

impl<T: WidgetBase + WidgetExt, TRIG> BaseListener<T, TRIG>

Builder functions, delegated to WidgetBase

Source

pub fn with_pos(self, x: i32, y: i32) -> Self

Initialize to position x, y

Source

pub fn with_size(self, width: i32, height: i32) -> Self

Initialize to size width, height

Source

pub fn with_label(self, title: &str) -> Self

Initialize with a label

Source

pub fn with_align(self, align: Align) -> Self

Initialize with alignment

Source

pub fn with_type<W: WidgetType>(self, typ: W) -> Self

Initialize with type

Source

pub fn below_of<W: WidgetExt>(self, wid: &W, padding: i32) -> Self

Initialize at bottom of another widget

Source

pub fn above_of<W: WidgetExt>(self, wid: &W, padding: i32) -> Self

Initialize above of another widget

Source

pub fn right_of<W: WidgetExt>(self, wid: &W, padding: i32) -> Self

Initialize right of another widget

Source

pub fn left_of<W: WidgetExt>(self, wid: &W, padding: i32) -> Self

Initialize left of another widget

Source

pub fn center_of<W: WidgetExt>(self, w: &W) -> Self

Initialize center of another widget

Source

pub fn center_of_parent(self) -> Self

Initialize center of parent

Source

pub fn center_x<W: WidgetExt>(self, w: &W) -> Self

Initialize center of another widget on the x axis

Source

pub fn center_y<W: WidgetExt>(self, w: &W) -> Self

Initialize center of another widget on the y axis

Source

pub fn size_of<W: WidgetExt>(self, w: &W) -> Self

Initialize to the size of another widget

Source

pub fn size_of_parent(self) -> Self

Initialize to the size of the parent

Source§

impl<T: WidgetBase + WidgetExt> BaseListener<T, Trig<T>>

core implementation

Source

pub fn triggered(&self) -> bool

Check whether a widget was triggered

Examples found in repository?
examples/triggered.rs (line 26)
4fn main() {
5    let a = app::App::default().with_scheme(app::Scheme::Gtk);
6    app::set_font_size(20);
7
8    let mut count = 0;
9
10    let mut wind = Window::default()
11        .with_size(160, 200)
12        .with_label("Counter");
13    let flex = Flex::default()
14        .with_size(120, 160)
15        .center_of_parent()
16        .column();
17    let but_inc: Listener<_> = Button::default().with_label("+").into();
18    let mut frame = Frame::default().with_label(&count.to_string());
19    let but_dec: Listener<_> = Button::default().with_label("-").into();
20    flex.end();
21    wind.end();
22    wind.show();
23
24    while a.wait() {
25        if fltk_evented::event() {
26            if but_inc.triggered() {
27                count += 1;
28            }
29            if but_dec.triggered() {
30                count -= 1;
31            }
32            frame.set_label(&count.to_string());
33        }
34    }
35}
More examples
Hide additional examples
examples/evented.rs (line 39)
12fn main() {
13    let a = app::App::default().with_scheme(app::Scheme::Gtk);
14    app::set_font_size(20);
15
16    let mut count = 0;
17
18    let mut wind = Window::default()
19        .with_size(160, 200)
20        .with_label("Counter");
21    let flex = Flex::default()
22        .with_size(120, 160)
23        .center_of_parent()
24        .column();
25    let mut but_inc: Listener<_> = Button::default().with_label("+").into();
26    let mut frame = Frame::default().with_label(&count.to_string());
27    let mut but_dec: Listener<_> = Button::default().with_label("-").into();
28    flex.end();
29    wind.end();
30    wind.show();
31
32    fn button_color(btn: &mut Button, c: Color) {
33        btn.set_color(c);
34        btn.redraw();
35    }
36
37    while a.wait() {
38        if fltk_evented::event() {
39            if but_inc.triggered() {
40                count += 1;
41            }
42    
43            if but_dec.triggered() {
44                count -= 1;
45            }
46    
47            match but_inc.event() {
48                Event::Enter | Event::Move => button_color(&mut but_inc, Color::White),
49                Event::Leave => button_color(&mut but_inc, Color::BackGround),
50                _ => (),
51            }
52    
53            match but_dec.event() {
54                Event::Enter | Event::Move => button_color(&mut but_dec, Color::White),
55                Event::Leave => button_color(&mut but_dec, Color::BackGround),
56                _ => (),
57            }
58
59            frame.set_label(&count.to_string());
60        }
61    }
62}
Source

pub fn event(&self) -> Event

Get an event the widget received, returns Event::NoEvent if no events received

Examples found in repository?
examples/evented.rs (line 47)
12fn main() {
13    let a = app::App::default().with_scheme(app::Scheme::Gtk);
14    app::set_font_size(20);
15
16    let mut count = 0;
17
18    let mut wind = Window::default()
19        .with_size(160, 200)
20        .with_label("Counter");
21    let flex = Flex::default()
22        .with_size(120, 160)
23        .center_of_parent()
24        .column();
25    let mut but_inc: Listener<_> = Button::default().with_label("+").into();
26    let mut frame = Frame::default().with_label(&count.to_string());
27    let mut but_dec: Listener<_> = Button::default().with_label("-").into();
28    flex.end();
29    wind.end();
30    wind.show();
31
32    fn button_color(btn: &mut Button, c: Color) {
33        btn.set_color(c);
34        btn.redraw();
35    }
36
37    while a.wait() {
38        if fltk_evented::event() {
39            if but_inc.triggered() {
40                count += 1;
41            }
42    
43            if but_dec.triggered() {
44                count -= 1;
45            }
46    
47            match but_inc.event() {
48                Event::Enter | Event::Move => button_color(&mut but_inc, Color::White),
49                Event::Leave => button_color(&mut but_inc, Color::BackGround),
50                _ => (),
51            }
52    
53            match but_dec.event() {
54                Event::Enter | Event::Move => button_color(&mut but_dec, Color::White),
55                Event::Leave => button_color(&mut but_dec, Color::BackGround),
56                _ => (),
57            }
58
59            frame.set_label(&count.to_string());
60        }
61    }
62}
Source

pub fn on(&mut self, ev: Event, cb: impl FnMut(&mut T) + 'static)

What the widget should do on a custom event

Source

pub fn on_hover(&mut self, cb: impl FnMut(&mut T) + 'static)

What the widget should do on hover

Examples found in repository?
examples/on_event.rs (lines 21-23)
9fn main() {
10    let app = app::App::default();
11    let mut wind = window::Window::default().with_size(400, 300);
12    wind.set_color(Color::White);
13    let mut but: Listener<_> = button::Button::new(160, 210, 80, 35, "Click me!").into();
14    but.set_frame(FrameType::FlatBox);
15    but.set_color(Color::Cyan);
16    but.set_selection_color(Color::Cyan.darker());
17    but.clear_visible_focus();
18    wind.end();
19    wind.show();
20
21    but.on_hover(|b| {
22        b.set_color(Color::Cyan.lighter().lighter());
23    });
24
25    but.on_leave(|b| {
26        b.set_color(Color::Cyan);
27    });
28
29    but.on_click(|b| {
30        println!("Clicked");
31        b.set_label_color(Color::White);
32    });
33
34    but.on_release(move |b| {
35        wind.set_label("Button Released!");
36        b.set_label_color(Color::Black);
37    });
38
39    app.run().unwrap();
40}
Source

pub fn on_leave(&mut self, cb: impl FnMut(&mut T) + 'static)

What the widget should do on leave

Examples found in repository?
examples/on_event.rs (lines 25-27)
9fn main() {
10    let app = app::App::default();
11    let mut wind = window::Window::default().with_size(400, 300);
12    wind.set_color(Color::White);
13    let mut but: Listener<_> = button::Button::new(160, 210, 80, 35, "Click me!").into();
14    but.set_frame(FrameType::FlatBox);
15    but.set_color(Color::Cyan);
16    but.set_selection_color(Color::Cyan.darker());
17    but.clear_visible_focus();
18    wind.end();
19    wind.show();
20
21    but.on_hover(|b| {
22        b.set_color(Color::Cyan.lighter().lighter());
23    });
24
25    but.on_leave(|b| {
26        b.set_color(Color::Cyan);
27    });
28
29    but.on_click(|b| {
30        println!("Clicked");
31        b.set_label_color(Color::White);
32    });
33
34    but.on_release(move |b| {
35        wind.set_label("Button Released!");
36        b.set_label_color(Color::Black);
37    });
38
39    app.run().unwrap();
40}
Source

pub fn on_click(&mut self, cb: impl FnMut(&mut T) + 'static)

What the widget should do on click

Examples found in repository?
examples/on_event.rs (lines 29-32)
9fn main() {
10    let app = app::App::default();
11    let mut wind = window::Window::default().with_size(400, 300);
12    wind.set_color(Color::White);
13    let mut but: Listener<_> = button::Button::new(160, 210, 80, 35, "Click me!").into();
14    but.set_frame(FrameType::FlatBox);
15    but.set_color(Color::Cyan);
16    but.set_selection_color(Color::Cyan.darker());
17    but.clear_visible_focus();
18    wind.end();
19    wind.show();
20
21    but.on_hover(|b| {
22        b.set_color(Color::Cyan.lighter().lighter());
23    });
24
25    but.on_leave(|b| {
26        b.set_color(Color::Cyan);
27    });
28
29    but.on_click(|b| {
30        println!("Clicked");
31        b.set_label_color(Color::White);
32    });
33
34    but.on_release(move |b| {
35        wind.set_label("Button Released!");
36        b.set_label_color(Color::Black);
37    });
38
39    app.run().unwrap();
40}
Source

pub fn on_release(&mut self, cb: impl FnMut(&mut T) + 'static)

What the widget should do on release

Examples found in repository?
examples/on_event.rs (lines 34-37)
9fn main() {
10    let app = app::App::default();
11    let mut wind = window::Window::default().with_size(400, 300);
12    wind.set_color(Color::White);
13    let mut but: Listener<_> = button::Button::new(160, 210, 80, 35, "Click me!").into();
14    but.set_frame(FrameType::FlatBox);
15    but.set_color(Color::Cyan);
16    but.set_selection_color(Color::Cyan.darker());
17    but.clear_visible_focus();
18    wind.end();
19    wind.show();
20
21    but.on_hover(|b| {
22        b.set_color(Color::Cyan.lighter().lighter());
23    });
24
25    but.on_leave(|b| {
26        b.set_color(Color::Cyan);
27    });
28
29    but.on_click(|b| {
30        println!("Clicked");
31        b.set_label_color(Color::White);
32    });
33
34    but.on_release(move |b| {
35        wind.set_label("Button Released!");
36        b.set_label_color(Color::Black);
37    });
38
39    app.run().unwrap();
40}
Source

pub fn on_drag(&mut self, cb: impl FnMut(&mut T) + 'static)

What the widget should do on drag

Source

pub fn on_focus(&mut self, cb: impl FnMut(&mut T) + 'static)

What the widget should do on focus

Source

pub fn on_unfocus(&mut self, cb: impl FnMut(&mut T) + 'static)

What the widget should do on unfocus

Source

pub fn on_keydown(&mut self, cb: impl FnMut(&mut T) + 'static)

What the widget should do on keydown

Source

pub fn on_keyup(&mut self, cb: impl FnMut(&mut T) + 'static)

What the widget should do on keyup

Source

pub fn on_close(&mut self, cb: impl FnMut(&mut T) + 'static)

What the widget should do on close

Source

pub fn on_move(&mut self, cb: impl FnMut(&mut T) + 'static)

What the widget should do on move

Source

pub fn on_shortcut(&mut self, cb: impl FnMut(&mut T) + 'static)

What the widget should do on shortcut

Source

pub fn on_deactivate(&mut self, cb: impl FnMut(&mut T) + 'static)

What the widget should do on deactivate

Source

pub fn on_activate(&mut self, cb: impl FnMut(&mut T) + 'static)

What the widget should do on activate

Source

pub fn on_hide(&mut self, cb: impl FnMut(&mut T) + 'static)

What the widget should do on hide

Source

pub fn on_show(&mut self, cb: impl FnMut(&mut T) + 'static)

What the widget should do on show

Source

pub fn on_paste(&mut self, cb: impl FnMut(&mut T) + 'static)

What the widget should do on paste

Source

pub fn on_selection_clear(&mut self, cb: impl FnMut(&mut T) + 'static)

What the widget should do on selection_clear

Source

pub fn on_mousewheel(&mut self, cb: impl FnMut(&mut T) + 'static)

What the widget should do on mousewheel

Source

pub fn on_dnd_enter(&mut self, cb: impl FnMut(&mut T) + 'static)

What the widget should do on dnd_enter

Source

pub fn on_dnd_drag(&mut self, cb: impl FnMut(&mut T) + 'static)

What the widget should do on dnd_drag

Source

pub fn on_dnd_leave(&mut self, cb: impl FnMut(&mut T) + 'static)

What the widget should do on dnd_leave

Source

pub fn on_dnd_release(&mut self, cb: impl FnMut(&mut T) + 'static)

What the widget should do on dnd_release

Source

pub fn on_screen_config_changed(&mut self, cb: impl FnMut(&mut T) + 'static)

What the widget should do on screen_config_changed

Source

pub fn on_fullscreen(&mut self, cb: impl FnMut(&mut T) + 'static)

What the widget should do on fullscreen

Source

pub fn on_zoom_gesture(&mut self, cb: impl FnMut(&mut T) + 'static)

What the widget should do on zoom_gesture

Source

pub fn on_zoom(&mut self, cb: impl FnMut(&mut T) + 'static)

What the widget should do on zoom

Source

pub fn on_resize(&mut self, cb: impl FnMut(&mut T) + 'static)

What the widget should do on resize

Source§

impl<T: WidgetBase + WidgetExt> BaseListener<T, Trig>

core implementation

Source

pub async fn triggered(&self) -> bool

Available on crate features tokio or async-std only.

Check whether a widget was triggered

Source

pub fn event(&self) -> Event

Available on crate features tokio or async-std only.

Get an event the widget received, returns Event::NoEvent if no events received

Trait Implementations§

Source§

impl<T: Clone + WidgetBase + WidgetExt, TRIG: Clone> Clone for BaseListener<T, TRIG>

Source§

fn clone(&self) -> BaseListener<T, TRIG>

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 + WidgetBase + WidgetExt, TRIG: Debug> Debug for BaseListener<T, TRIG>

Source§

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

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

impl<T: WidgetBase + WidgetExt + Default + Into<BaseListener<T, TRIG>>, TRIG> Default for BaseListener<T, TRIG>

#[derive(Default)] won’t register callbacks, so we must impl Default manually.

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<T: WidgetBase + WidgetExt, TRIG> Deref for BaseListener<T, TRIG>

Used to call methods like WidgetExt::x.

Source§

type Target = T

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl<T: WidgetBase + WidgetExt, TRIG> DerefMut for BaseListener<T, TRIG>

Used to call methods like WidgetExt::set_pos.

Source§

fn deref_mut(&mut self) -> &mut Self::Target

Mutably dereferences the value.

Auto Trait Implementations§

§

impl<T, TRIG> Freeze for BaseListener<T, TRIG>
where T: Freeze, TRIG: Freeze,

§

impl<T, TRIG> RefUnwindSafe for BaseListener<T, TRIG>
where T: RefUnwindSafe, TRIG: RefUnwindSafe,

§

impl<T, TRIG> Send for BaseListener<T, TRIG>
where T: Send, TRIG: Send,

§

impl<T, TRIG> Sync for BaseListener<T, TRIG>
where T: Sync, TRIG: Sync,

§

impl<T, TRIG> Unpin for BaseListener<T, TRIG>
where T: Unpin, TRIG: Unpin,

§

impl<T, TRIG> UnwindSafe for BaseListener<T, TRIG>
where T: UnwindSafe, TRIG: UnwindSafe,

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<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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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 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<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

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