pub struct Frame { /* private fields */ }
Expand description
Creates a new frame, an equivalent of Fl_Box
Implementations§
Source§impl Frame
impl Frame
Sourcepub fn new<'a, T: Into<Option<&'a str>>>(
x: i32,
y: i32,
width: i32,
height: i32,
title: T,
) -> Frame
pub fn new<'a, T: Into<Option<&'a str>>>( x: i32, y: i32, width: i32, height: i32, title: T, ) -> Frame
Creates a new widget, takes an x, y coordinates, as well as a width and height, plus a title
§Arguments
x
- The x coordinate in the screeny
- The y coordinate in the screenwidth
- The width of the widgetheigth
- The height of the widgettitle
- The title or label of the widget
To use dynamic strings use with_label(self, &str)
or set_label(&mut self, &str)
.
labels support special symbols preceded by an @
sign
and for the associated formatting.
Examples found in repository?
More examples
examples/animations.rs (line 60)
56fn main() {
57 let app = app::App::default();
58 let mut wind = Window::default().with_label("timeout").with_size(720, 486);
59 wind.set_center_screen();
60 let mut frame = Frame::new(-200, 150, 200, 200, "");
61 let mut pxm = Pixmap::new(PXM).unwrap();
62 pxm.scale(200, 200, true, true);
63 frame.set_image_scaled(Some(pxm));
64 wind.set_color(enums::Color::White);
65 wind.end();
66 wind.show_with_env_args();
67
68 app::add_timeout(0.016, move |handle| {
69 let frame = frame.clone();
70 move_image(frame, handle);
71 });
72 app.run().unwrap();
73}
examples/gradients.rs (line 13)
5fn create_vertical_gradient_frame(
6 x: i32,
7 y: i32,
8 w: i32,
9 h: i32,
10 col1: Color,
11 col2: Color,
12) -> frame::Frame {
13 let mut frame = frame::Frame::new(x, y, w, h, "Vertical");
14 frame.draw(move |f| {
15 let imax = f.h();
16 let d = if imax > 0 { imax } else { 1 };
17 for i in 0..=imax {
18 let w = 1.0 - i as f32 / d as f32;
19 set_draw_color(Color::inactive(&Color::color_average(col1, col2, w)));
20 draw_hline(f.x(), f.y() + i, f.x() + f.w());
21 }
22 set_draw_color(Color::Black);
23 set_font(Font::Helvetica, app::font_size());
24 draw_text_boxed(&f.label().unwrap(), f.x(), f.y(), f.w(), f.h(), f.align());
25 });
26 frame
27}
28
29fn create_horizontal_gradient_frame(
30 x: i32,
31 y: i32,
32 w: i32,
33 h: i32,
34 col1: Color,
35 col2: Color,
36) -> frame::Frame {
37 let mut frame = frame::Frame::new(x, y, w, h, "Horizontal");
38 frame.draw(move |f| {
39 let imax = f.w();
40 let d = if imax > 0 { imax } else { 1 };
41 for i in 0..=imax {
42 let w = 1.0 - i as f32 / d as f32;
43 set_draw_color(Color::inactive(&Color::color_average(col1, col2, w)));
44 draw_vline(f.x() + i, f.y(), f.y() + f.h());
45 }
46 set_draw_color(Color::Black);
47 set_font(Font::Helvetica, app::font_size());
48 draw_text_boxed(&f.label().unwrap(), f.x(), f.y(), f.w(), f.h(), f.align());
49 });
50 frame
51}
52
53fn create_horizontal_svg_gradient_frame(
54 x: i32,
55 y: i32,
56 w: i32,
57 h: i32,
58 col1: Color,
59 col2: Color,
60) -> frame::Frame {
61 let mut frame = frame::Frame::new(x, y, w, h, "Svg");
62 frame.draw(move |f| {
63 let (r1, g1, b1) = Color::inactive(&col1).to_rgb();
64 let (r2, g2, b2) = Color::inactive(&col2).to_rgb();
65 let svg = format!(
66 "<svg viewBox='0 0 {} {}'>
67 <defs>
68 <linearGradient id='grad1' x1='0%' y1='0%' x2='0%' y2='100%'>
69 <stop offset='0%' style='stop-color:rgb({},{},{});stop-opacity:1' />
70 <stop offset='100%' style='stop-color:rgb({},{},{});stop-opacity:1' />
71 </linearGradient>
72 </defs>
73 <rect width='100%' height='100%' fill='url(#grad1)' />
74 </svg>",
75 f.w(),
76 f.h() + 1,
77 r1,
78 g1,
79 b1,
80 r2,
81 g2,
82 b2
83 );
84 let mut image = image::SvgImage::from_data(&svg).unwrap();
85 image.draw(f.x(), f.y(), f.w(), f.h());
86 set_draw_color(Color::Black);
87 set_font(Font::Helvetica, app::font_size());
88 draw_text_boxed(&f.label().unwrap(), f.x(), f.y(), f.w(), f.h(), f.align());
89 });
90 frame
91}
examples/custom_choice.rs (line 110)
108 pub fn new<S: Into<Option<&'static str>>>(x: i32, y: i32, w: i32, h: i32, label: S) -> Self {
109 let grp = group::Group::new(x, y, w, h, label).with_align(Align::Left);
110 let mut frame = frame::Frame::new(x, y, w - w / 4, h, None);
111 frame.set_frame(FrameType::DownBox);
112 frame.set_color(Color::Background2);
113 let mut btn = button::Button::new(x + w - w / 4, y, w / 4, h, "@2>");
114 btn.clear_visible_focus();
115 grp.end();
116 let choices = Rc::from(RefCell::from(vec![]));
117 btn.set_callback({
118 let c = choices.clone();
119 let mut f = frame.clone();
120 let btn_win = btn.window().unwrap();
121 move |b| {
122 let mut menu = MyPopup::new(&c.borrow());
123 let s = menu.popup(b.x() + btn_win.x() - f.w(), b.y() + btn_win.y() + b.h());
124 f.set_label(&s.0);
125 }
126 });
127 Self {
128 grp,
129 frame,
130 btn,
131 choices,
132 }
133 }
examples/custom_dial.rs (line 19)
13 pub fn new(x: i32, y: i32, w: i32, h: i32, label: &str) -> Self {
14 let value = Rc::from(RefCell::from(0));
15 let mut main_wid = group::Group::new(x, y, w, h, None)
16 .with_label(label)
17 .with_align(Align::Top);
18 let mut value_frame =
19 frame::Frame::new(main_wid.x(), main_wid.y() + 80, main_wid.w(), 40, "0");
20 value_frame.set_label_size(26);
21 main_wid.end();
22 let value_c = value.clone();
23 main_wid.draw(move |w| {
24 draw::set_draw_rgb_color(230, 230, 230);
25 draw::draw_pie(w.x(), w.y(), w.w(), w.h(), 0., 180.);
26 draw::set_draw_hex_color(0xb0bf1a);
27 draw::draw_pie(
28 w.x(),
29 w.y(),
30 w.w(),
31 w.h(),
32 (100 - *value_c.borrow()) as f64 * 1.8,
33 180.,
34 );
35 draw::set_draw_color(Color::White);
36 draw::draw_pie(
37 w.x() - 50 + w.w() / 2,
38 w.y() - 50 + w.h() / 2,
39 100,
40 100,
41 0.,
42 360.,
43 );
44 w.draw_children();
45 });
46 Self {
47 main_wid,
48 value,
49 value_frame,
50 }
51 }
examples/rounded_images.rs (line 7)
6 pub fn new(radius: i32, mut image: image::RgbImage) -> Self {
7 let mut frame = frame::Frame::new(0, 0, radius * 2, radius * 2, None);
8 frame.set_frame(enums::FrameType::FlatBox);
9 frame.draw(move |f| {
10 image.scale(f.w(), f.h(), false, true);
11 image.draw(f.x(), f.y(), f.w(), f.h());
12 let color = f.color().to_rgb();
13 let s = format!(
14 "<?xml version='1.0' encoding='UTF-8' standalone='no'?>\n
15 <svg width='{}' height='{}'>\n
16 <rect x='{}'
17 y='{}'
18 rx='{}'
19 ry='{}'
20 width='{}'
21 height='{}'
22 fill='none'
23 stroke='rgb({}, {}, {})'
24 stroke-width='{}' />\n
25 </svg>\n",
26 f.w(),
27 f.h(),
28 -f.w() / 2,
29 -f.w() / 2,
30 f.w(),
31 f.w(),
32 f.w() + f.w(),
33 f.h() + f.w(),
34 color.0,
35 color.1,
36 color.2,
37 f.w()
38 );
39 let mut s = image::SvgImage::from_data(&s).unwrap();
40 s.draw(f.x(), f.y(), f.w(), f.h());
41 });
42 Self
43 }
Additional examples can be found in:
Sourcepub fn default_fill() -> Self
pub fn default_fill() -> Self
Constructs a widget with the size of its parent
Examples found in repository?
examples/image.rs (line 7)
4fn main() -> Result<(), Box<dyn Error>> {
5 let app = app::App::default().with_scheme(app::Scheme::Gleam);
6 let mut wind = Window::default().with_size(400, 300);
7 let mut frame = Frame::default_fill();
8
9 {
10 let mut image = JpegImage::load("screenshots/calc.jpg")?;
11 frame.set_image(Some(image.clone()));
12 image.scale(200, 200, true, true);
13 }
14
15 // // To remove an image
16 // frame.set_image(None::<SharedImage>);
17
18 wind.end();
19 wind.make_resizable(true);
20 wind.show();
21
22 app.run()?;
23 Ok(())
24}
More examples
examples/fb.rs (line 19)
14fn main() -> Result<(), Box<dyn std::error::Error>> {
15 let app = app::App::default();
16 let mut win = Window::default()
17 .with_size(WIDTH, HEIGHT)
18 .with_label("Framebuffer");
19 let mut frame = frame::Frame::default_fill();
20 win.end();
21 win.make_resizable(true);
22 win.show();
23
24 let mut framebuf: Vec<u8> = vec![0; (WIDTH * HEIGHT * 4) as usize];
25 let mut world = World::new();
26
27 unsafe {
28 utils::blit_rgba_nocopy(&mut frame, &framebuf);
29 }
30
31 app::add_idle(move |_| {
32 world.update();
33 world.draw(&mut framebuf);
34 // utils::blit_rgba(&mut frame, &framebuf).unwrap(); // A safe variant of draw_rgba_nocopy
35 win.redraw();
36 // sleeps are necessary when calling redraw in the event loop
37 app::sleep(0.016);
38 });
39
40 app.run()?;
41 Ok(())
42}
examples/rgb.rs (line 6)
3fn main() {
4 let app = app::App::default();
5 let mut wind = window::Window::default().with_size(400, 400);
6 let mut frame = frame::Frame::default_fill();
7 wind.make_resizable(true);
8 wind.end();
9 wind.show();
10 frame.draw(move |f| {
11 let mut fb: Vec<u8> = vec![0u8; (f.w() * f.h() * 4) as usize];
12 for (iter, pixel) in fb.chunks_exact_mut(4).enumerate() {
13 let x = iter % f.w() as usize;
14 let y = iter / f.w() as usize;
15 let (red, green, blue) = utils::hex2rgb((x ^ y) as u32);
16 pixel.copy_from_slice(&[red, green, blue, 255]);
17 }
18 let mut image = image::RgbImage::new(&fb, f.w(), f.h(), ColorDepth::Rgba8)
19 .unwrap()
20 .to_srgb_image()
21 .unwrap()
22 .blur(50)
23 .unwrap()
24 .convert(ColorDepth::Rgb8)
25 .unwrap();
26 image.draw(f.x(), f.y(), f.w(), f.h());
27 });
28
29 app.run().unwrap();
30}
Trait Implementations§
Source§impl WidgetBase for Frame
impl WidgetBase for Frame
Source§unsafe fn from_widget_ptr(ptr: *mut Fl_Widget) -> Self
unsafe fn from_widget_ptr(ptr: *mut Fl_Widget) -> Self
transforms a widget pointer to a Widget, for internal use Read more
Source§unsafe fn from_widget<W: WidgetExt>(w: W) -> Self
unsafe fn from_widget<W: WidgetExt>(w: W) -> Self
Get a widget from base widget Read more
Source§fn handle<F: FnMut(&mut Self, Event) -> bool + 'static>(&mut self, cb: F)
fn handle<F: FnMut(&mut Self, Event) -> bool + 'static>(&mut self, cb: F)
Set a custom handler, where events are managed manually, akin to
Fl_Widget::handle(int)
.
Handled or ignored events should return true, unhandled events should return false.
takes the widget as a closure argument.
The ability to handle an event might depend on handling other events, as explained hereSource§fn draw<F: FnMut(&mut Self) + 'static>(&mut self, cb: F)
fn draw<F: FnMut(&mut Self) + 'static>(&mut self, cb: F)
Set a custom draw method.
takes the widget as a closure argument.
macOS requires that
WidgetBase::draw
actually calls drawing functionsSource§fn resize_callback<F: FnMut(&mut Self, i32, i32, i32, i32) + 'static>(
&mut self,
cb: F,
)
fn resize_callback<F: FnMut(&mut Self, i32, i32, i32, i32) + 'static>( &mut self, cb: F, )
Perform a callback on resize.
Avoid resizing the parent or the same widget to avoid infinite recursion
Source§unsafe fn assume_derived(&mut self)
unsafe fn assume_derived(&mut self)
Makes the widget derived Read more
Source§impl WidgetExt for Frame
impl WidgetExt for Frame
Source§fn set_label(&mut self, title: &str)
fn set_label(&mut self, title: &str)
Sets the widget’s label.
labels support special symbols preceded by an
@
sign.
and for the associated formatting.Source§fn unset_label(&mut self)
fn unset_label(&mut self)
Unset a widget’s label
Source§fn measure_label(&self) -> (i32, i32)
fn measure_label(&self) -> (i32, i32)
Measures the label’s width and height
Source§fn as_widget_ptr(&self) -> *mut Fl_Widget
fn as_widget_ptr(&self) -> *mut Fl_Widget
transforms a widget to a base
Fl_Widget
, for internal useSource§fn deactivate(&mut self)
fn deactivate(&mut self)
Deactivates the widget
Source§fn redraw_label(&mut self)
fn redraw_label(&mut self)
Redraws the label of the widget
Source§fn resize(&mut self, x: i32, y: i32, width: i32, height: i32)
fn resize(&mut self, x: i32, y: i32, width: i32, height: i32)
Resizes and/or moves the widget, takes x, y, width and height
Source§fn widget_resize(&mut self, x: i32, y: i32, width: i32, height: i32)
fn widget_resize(&mut self, x: i32, y: i32, width: i32, height: i32)
Does a simple resize ignoring class-specific resize functionality
Source§fn set_tooltip(&mut self, txt: &str)
fn set_tooltip(&mut self, txt: &str)
Sets the tooltip text
Source§fn label_color(&self) -> Color
fn label_color(&self) -> Color
Returns the widget label’s color
Source§fn set_label_color(&mut self, color: Color)
fn set_label_color(&mut self, color: Color)
Sets the widget label’s color
Source§fn label_font(&self) -> Font
fn label_font(&self) -> Font
Returns the widget label’s font
Source§fn set_label_font(&mut self, font: Font)
fn set_label_font(&mut self, font: Font)
Sets the widget label’s font
Source§fn label_size(&self) -> i32
fn label_size(&self) -> i32
Returns the widget label’s size
Source§fn set_label_size(&mut self, sz: i32)
fn set_label_size(&mut self, sz: i32)
Sets the widget label’s size
Source§fn label_type(&self) -> LabelType
fn label_type(&self) -> LabelType
Returns the widget label’s type
Source§fn set_label_type(&mut self, typ: LabelType)
fn set_label_type(&mut self, typ: LabelType)
Sets the widget label’s type
Source§fn set_changed(&mut self)
fn set_changed(&mut self)
Mark the widget as changed
Source§fn clear_changed(&mut self)
fn clear_changed(&mut self)
Clears the changed status of the widget
Source§fn set_when(&mut self, trigger: When)
fn set_when(&mut self, trigger: When)
Sets the default callback trigger for a widget, equivalent to
when()
Source§fn selection_color(&self) -> Color
fn selection_color(&self) -> Color
Gets the selection color of the widget
Source§fn set_selection_color(&mut self, color: Color)
fn set_selection_color(&mut self, color: Color)
Sets the selection color of the widget
Source§fn do_callback(&mut self)
fn do_callback(&mut self)
Runs the already registered callback
Source§fn top_window(&self) -> Option<Box<dyn WindowExt>>
fn top_window(&self) -> Option<Box<dyn WindowExt>>
Returns the topmost window holding the widget
Source§fn takes_events(&self) -> bool
fn takes_events(&self) -> bool
Checks whether a widget is capable of taking events
Source§fn set_visible_focus(&mut self)
fn set_visible_focus(&mut self)
Set the widget to have visible focus
Source§fn clear_visible_focus(&mut self)
fn clear_visible_focus(&mut self)
Clear visible focus
Source§fn visible_focus(&mut self, v: bool)
fn visible_focus(&mut self, v: bool)
Set the visible focus using a flag
Source§fn has_visible_focus(&self) -> bool
fn has_visible_focus(&self) -> bool
Return whether the widget has visible focus
Source§fn was_deleted(&self) -> bool
fn was_deleted(&self) -> bool
Check if a widget was deleted
Source§fn set_damage(&mut self, flag: bool)
fn set_damage(&mut self, flag: bool)
Signal the widget as damaged and it should be redrawn in the next event loop cycle
Source§fn damage_type(&self) -> Damage
fn damage_type(&self) -> Damage
Return the damage mask
Source§fn set_damage_type(&mut self, mask: Damage)
fn set_damage_type(&mut self, mask: Damage)
Signal the type of damage a widget received
Source§fn set_damage_area(&mut self, mask: Damage, x: i32, y: i32, w: i32, h: i32)
fn set_damage_area(&mut self, mask: Damage, x: i32, y: i32, w: i32, h: i32)
Signal damage for an area inside the widget
Source§fn clear_damage(&mut self)
fn clear_damage(&mut self)
Clear the damaged flag
Source§fn as_window(&self) -> Option<Box<dyn WindowExt>>
fn as_window(&self) -> Option<Box<dyn WindowExt>>
Return the widget as a window if it’s a window
Source§fn as_group(&self) -> Option<Group>
fn as_group(&self) -> Option<Group>
Return the widget as a group widget if it’s a group widget
Source§fn inside<W: WidgetExt>(&self, wid: &W) -> bool
fn inside<W: WidgetExt>(&self, wid: &W) -> bool
Checks whether the self widget is inside another widget
Source§fn get_type<T: WidgetType>(&self) -> T
fn get_type<T: WidgetType>(&self) -> T
Returns the widget type when applicable
Source§fn set_type<T: WidgetType>(&mut self, typ: T)
fn set_type<T: WidgetType>(&mut self, typ: T)
Sets the widget type
Source§fn set_image_scaled<I: ImageExt>(&mut self, image: Option<I>)
fn set_image_scaled<I: ImageExt>(&mut self, image: Option<I>)
Sets the image of the widget scaled to the widget’s size
Source§fn set_deimage<I: ImageExt>(&mut self, image: Option<I>)
fn set_deimage<I: ImageExt>(&mut self, image: Option<I>)
Sets the deactivated image of the widget
Source§fn set_deimage_scaled<I: ImageExt>(&mut self, image: Option<I>)
fn set_deimage_scaled<I: ImageExt>(&mut self, image: Option<I>)
Sets the deactivated image of the widget scaled to the widget’s size
Source§fn deimage(&self) -> Option<Box<dyn ImageExt>>
fn deimage(&self) -> Option<Box<dyn ImageExt>>
Gets the deactivated image associated with the widget
Source§fn set_callback<F: FnMut(&mut Self) + 'static>(&mut self, cb: F)
fn set_callback<F: FnMut(&mut Self) + 'static>(&mut self, cb: F)
Sets the callback when the widget is triggered (clicks for example)
takes the widget as a closure argument
Source§fn emit<T: 'static + Clone + Send + Sync>(&mut self, sender: Sender<T>, msg: T)
fn emit<T: 'static + Clone + Send + Sync>(&mut self, sender: Sender<T>, msg: T)
Emits a message on callback using a sender
Source§unsafe fn as_widget<W: WidgetBase>(&self) -> W
unsafe fn as_widget<W: WidgetBase>(&self) -> W
Upcast a
WidgetExt
to some widget type Read moreSource§fn visible_r(&self) -> bool
fn visible_r(&self) -> bool
Returns whether a widget or any of its parents are visible (recursively)
Source§fn is_same<W: WidgetExt>(&self, other: &W) -> bool
fn is_same<W: WidgetExt>(&self, other: &W) -> bool
Return whether two widgets object point to the same widget
Source§fn active_r(&self) -> bool
fn active_r(&self) -> bool
Returns whether a widget or any of its parents are active (recursively)
Source§fn handle_event(&mut self, event: Event) -> bool
fn handle_event(&mut self, event: Event) -> bool
Handle a specific event
Source§fn is_derived(&self) -> bool
fn is_derived(&self) -> bool
Check whether a widget is derived
Source§fn as_base_widget(&self) -> Widgetwhere
Self: Sized,
fn as_base_widget(&self) -> Widgetwhere
Self: Sized,
Upcast a
WidgetExt
to a WidgetSource§impl WidgetProps for Frame
impl WidgetProps for Frame
Source§fn with_label(self, title: &str) -> Self
fn with_label(self, title: &str) -> Self
Initialize with a label
Source§fn with_align(self, align: Align) -> Self
fn with_align(self, align: Align) -> Self
Initialize with alignment
Source§fn with_type<T: WidgetType>(self, typ: T) -> Self
fn with_type<T: WidgetType>(self, typ: T) -> Self
Initialize with type
Source§fn below_of<W: WidgetExt>(self, wid: &W, padding: i32) -> Self
fn below_of<W: WidgetExt>(self, wid: &W, padding: i32) -> Self
Initialize at bottom of another widget
Source§fn above_of<W: WidgetExt>(self, wid: &W, padding: i32) -> Self
fn above_of<W: WidgetExt>(self, wid: &W, padding: i32) -> Self
Initialize above of another widget
Source§fn right_of<W: WidgetExt>(self, wid: &W, padding: i32) -> Self
fn right_of<W: WidgetExt>(self, wid: &W, padding: i32) -> Self
Initialize right of another widget
Source§fn left_of<W: WidgetExt>(self, wid: &W, padding: i32) -> Self
fn left_of<W: WidgetExt>(self, wid: &W, padding: i32) -> Self
Initialize left of another widget
Source§fn center_x<W: WidgetExt>(self, w: &W) -> Self
fn center_x<W: WidgetExt>(self, w: &W) -> Self
Initialize center of another widget on the x axis
Source§fn center_y<W: WidgetExt>(self, w: &W) -> Self
fn center_y<W: WidgetExt>(self, w: &W) -> Self
Initialize center of another widget on the y axis
Source§fn center_of_parent(self) -> Self
fn center_of_parent(self) -> Self
Initialize center of parent
Source§fn size_of_parent(self) -> Self
fn size_of_parent(self) -> Self
Initialize to the size of the parent
impl Eq for Frame
impl Send for Frame
Available on non-crate feature
single-threaded
only.impl Sync for Frame
Available on non-crate feature
single-threaded
only.Auto Trait Implementations§
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more