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
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
Sourcepub fn from_widget(wid: T) -> Self
pub fn from_widget(wid: T) -> Self
Not recommanded, use Into<BaseListener>
like let btn: Listener<_> = btn.into();
Sourcepub fn new<S: Into<Option<&'static str>>>(
x: i32,
y: i32,
w: i32,
h: i32,
label: S,
) -> Self
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
Sourcepub fn default_fill() -> Self
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
impl<T: WidgetBase + WidgetExt, TRIG> BaseListener<T, TRIG>
Builder functions, delegated to WidgetBase
Sourcepub fn with_label(self, title: &str) -> Self
pub fn with_label(self, title: &str) -> Self
Initialize with a label
Sourcepub fn with_align(self, align: Align) -> Self
pub fn with_align(self, align: Align) -> Self
Initialize with alignment
Sourcepub fn with_type<W: WidgetType>(self, typ: W) -> Self
pub fn with_type<W: WidgetType>(self, typ: W) -> Self
Initialize with type
Sourcepub fn below_of<W: WidgetExt>(self, wid: &W, padding: i32) -> Self
pub fn below_of<W: WidgetExt>(self, wid: &W, padding: i32) -> Self
Initialize at bottom of another widget
Sourcepub fn above_of<W: WidgetExt>(self, wid: &W, padding: i32) -> Self
pub fn above_of<W: WidgetExt>(self, wid: &W, padding: i32) -> Self
Initialize above of another widget
Sourcepub fn right_of<W: WidgetExt>(self, wid: &W, padding: i32) -> Self
pub fn right_of<W: WidgetExt>(self, wid: &W, padding: i32) -> Self
Initialize right of another widget
Sourcepub fn left_of<W: WidgetExt>(self, wid: &W, padding: i32) -> Self
pub fn left_of<W: WidgetExt>(self, wid: &W, padding: i32) -> Self
Initialize left of another widget
Sourcepub fn center_of_parent(self) -> Self
pub fn center_of_parent(self) -> Self
Initialize center of parent
Sourcepub fn center_x<W: WidgetExt>(self, w: &W) -> Self
pub fn center_x<W: WidgetExt>(self, w: &W) -> Self
Initialize center of another widget on the x axis
Sourcepub fn center_y<W: WidgetExt>(self, w: &W) -> Self
pub fn center_y<W: WidgetExt>(self, w: &W) -> Self
Initialize center of another widget on the y axis
Sourcepub fn size_of_parent(self) -> Self
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
impl<T: WidgetBase + WidgetExt> BaseListener<T, Trig<T>>
core implementation
Sourcepub fn triggered(&self) -> bool
pub fn triggered(&self) -> bool
Check whether a widget was triggered
Examples found in repository?
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
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}
Sourcepub fn event(&self) -> Event
pub fn event(&self) -> Event
Get an event the widget received,
returns Event::NoEvent
if no events received
Examples found in repository?
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}
Sourcepub fn on(&mut self, ev: Event, cb: impl FnMut(&mut T) + 'static)
pub fn on(&mut self, ev: Event, cb: impl FnMut(&mut T) + 'static)
What the widget should do on a custom event
Sourcepub fn on_hover(&mut self, cb: impl FnMut(&mut T) + 'static)
pub fn on_hover(&mut self, cb: impl FnMut(&mut T) + 'static)
What the widget should do on hover
Examples found in repository?
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}
Sourcepub fn on_leave(&mut self, cb: impl FnMut(&mut T) + 'static)
pub fn on_leave(&mut self, cb: impl FnMut(&mut T) + 'static)
What the widget should do on leave
Examples found in repository?
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}
Sourcepub fn on_click(&mut self, cb: impl FnMut(&mut T) + 'static)
pub fn on_click(&mut self, cb: impl FnMut(&mut T) + 'static)
What the widget should do on click
Examples found in repository?
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}
Sourcepub fn on_release(&mut self, cb: impl FnMut(&mut T) + 'static)
pub fn on_release(&mut self, cb: impl FnMut(&mut T) + 'static)
What the widget should do on release
Examples found in repository?
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}
Sourcepub fn on_focus(&mut self, cb: impl FnMut(&mut T) + 'static)
pub fn on_focus(&mut self, cb: impl FnMut(&mut T) + 'static)
What the widget should do on focus
Sourcepub fn on_unfocus(&mut self, cb: impl FnMut(&mut T) + 'static)
pub fn on_unfocus(&mut self, cb: impl FnMut(&mut T) + 'static)
What the widget should do on unfocus
Sourcepub fn on_keydown(&mut self, cb: impl FnMut(&mut T) + 'static)
pub fn on_keydown(&mut self, cb: impl FnMut(&mut T) + 'static)
What the widget should do on keydown
Sourcepub fn on_keyup(&mut self, cb: impl FnMut(&mut T) + 'static)
pub fn on_keyup(&mut self, cb: impl FnMut(&mut T) + 'static)
What the widget should do on keyup
Sourcepub fn on_close(&mut self, cb: impl FnMut(&mut T) + 'static)
pub fn on_close(&mut self, cb: impl FnMut(&mut T) + 'static)
What the widget should do on close
Sourcepub fn on_shortcut(&mut self, cb: impl FnMut(&mut T) + 'static)
pub fn on_shortcut(&mut self, cb: impl FnMut(&mut T) + 'static)
What the widget should do on shortcut
Sourcepub fn on_deactivate(&mut self, cb: impl FnMut(&mut T) + 'static)
pub fn on_deactivate(&mut self, cb: impl FnMut(&mut T) + 'static)
What the widget should do on deactivate
Sourcepub fn on_activate(&mut self, cb: impl FnMut(&mut T) + 'static)
pub fn on_activate(&mut self, cb: impl FnMut(&mut T) + 'static)
What the widget should do on activate
Sourcepub fn on_paste(&mut self, cb: impl FnMut(&mut T) + 'static)
pub fn on_paste(&mut self, cb: impl FnMut(&mut T) + 'static)
What the widget should do on paste
Sourcepub fn on_selection_clear(&mut self, cb: impl FnMut(&mut T) + 'static)
pub fn on_selection_clear(&mut self, cb: impl FnMut(&mut T) + 'static)
What the widget should do on selection_clear
Sourcepub fn on_mousewheel(&mut self, cb: impl FnMut(&mut T) + 'static)
pub fn on_mousewheel(&mut self, cb: impl FnMut(&mut T) + 'static)
What the widget should do on mousewheel
Sourcepub fn on_dnd_enter(&mut self, cb: impl FnMut(&mut T) + 'static)
pub fn on_dnd_enter(&mut self, cb: impl FnMut(&mut T) + 'static)
What the widget should do on dnd_enter
Sourcepub fn on_dnd_drag(&mut self, cb: impl FnMut(&mut T) + 'static)
pub fn on_dnd_drag(&mut self, cb: impl FnMut(&mut T) + 'static)
What the widget should do on dnd_drag
Sourcepub fn on_dnd_leave(&mut self, cb: impl FnMut(&mut T) + 'static)
pub fn on_dnd_leave(&mut self, cb: impl FnMut(&mut T) + 'static)
What the widget should do on dnd_leave
Sourcepub fn on_dnd_release(&mut self, cb: impl FnMut(&mut T) + 'static)
pub fn on_dnd_release(&mut self, cb: impl FnMut(&mut T) + 'static)
What the widget should do on dnd_release
Sourcepub fn on_screen_config_changed(&mut self, cb: impl FnMut(&mut T) + 'static)
pub fn on_screen_config_changed(&mut self, cb: impl FnMut(&mut T) + 'static)
What the widget should do on screen_config_changed
Sourcepub fn on_fullscreen(&mut self, cb: impl FnMut(&mut T) + 'static)
pub fn on_fullscreen(&mut self, cb: impl FnMut(&mut T) + 'static)
What the widget should do on fullscreen
Sourcepub fn on_zoom_gesture(&mut self, cb: impl FnMut(&mut T) + 'static)
pub fn on_zoom_gesture(&mut self, cb: impl FnMut(&mut T) + 'static)
What the widget should do on zoom_gesture
Source§impl<T: WidgetBase + WidgetExt> BaseListener<T, Trig>
core implementation
impl<T: WidgetBase + WidgetExt> BaseListener<T, Trig>
core implementation
Trait Implementations§
Source§impl<T: Clone + WidgetBase + WidgetExt, TRIG: Clone> Clone for BaseListener<T, TRIG>
impl<T: Clone + WidgetBase + WidgetExt, TRIG: Clone> Clone for BaseListener<T, TRIG>
Source§fn clone(&self) -> BaseListener<T, TRIG>
fn clone(&self) -> BaseListener<T, TRIG>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl<T: Debug + WidgetBase + WidgetExt, TRIG: Debug> Debug for BaseListener<T, TRIG>
impl<T: Debug + WidgetBase + WidgetExt, TRIG: Debug> Debug for BaseListener<T, TRIG>
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.
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§impl<T: WidgetBase + WidgetExt, TRIG> Deref for BaseListener<T, TRIG>
Used to call methods like WidgetExt::x
.
impl<T: WidgetBase + WidgetExt, TRIG> Deref for BaseListener<T, TRIG>
Used to call methods like WidgetExt::x
.
Source§impl<T: WidgetBase + WidgetExt, TRIG> DerefMut for BaseListener<T, TRIG>
Used to call methods like WidgetExt::set_pos
.
impl<T: WidgetBase + WidgetExt, TRIG> DerefMut for BaseListener<T, TRIG>
Used to call methods like WidgetExt::set_pos
.