fltk/prelude.rs
1use crate::enums::{
2 Align, Color, ColorDepth, Cursor, Damage, Event, Font, FrameType, LabelType, Shortcut, When,
3};
4use std::convert::From;
5use std::string::FromUtf8Error;
6use std::{fmt, io};
7
8/// Error types returned by fltk-rs + wrappers of std errors
9#[derive(Debug)]
10#[non_exhaustive]
11pub enum FltkError {
12 /// i/o error
13 IoError(io::Error),
14 /// Utf-8 conversion error
15 Utf8Error(FromUtf8Error),
16 /// Null string conversion error
17 NullError(std::ffi::NulError),
18 /// Internal fltk error
19 Internal(FltkErrorKind),
20 /// Error using an erroneous env variable
21 EnvVarError(std::env::VarError),
22 /// Parsing error
23 ParseIntError(std::num::ParseIntError),
24 /// Unknown error
25 Unknown(String),
26}
27
28unsafe impl Send for FltkError {}
29unsafe impl Sync for FltkError {}
30
31/// Error kinds enum for `FltkError`
32#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
33#[non_exhaustive]
34pub enum FltkErrorKind {
35 /// Failed to run the application
36 FailedToRun,
37 /// Failed to initialize the multithreading
38 FailedToLock,
39 /// Failed to set the general scheme of the application
40 FailedToSetScheme,
41 /// Failed operation, mostly unknown reason!
42 FailedOperation,
43 /// System resource (file, image) not found
44 ResourceNotFound,
45 /// Image format error when opening an image of an unsupported format
46 ImageFormatError,
47 /// Error filling table
48 TableError,
49 /// Error due to printing
50 PrintError,
51 /// Invalid color
52 InvalidColor,
53 /// Failed to set grid widget
54 FailedGridSetWidget,
55}
56
57impl std::error::Error for FltkError {
58 fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
59 match self {
60 FltkError::IoError(err) => Some(err),
61 FltkError::NullError(err) => Some(err),
62 _ => None,
63 }
64 }
65}
66
67impl fmt::Display for FltkError {
68 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
69 match *self {
70 FltkError::IoError(ref err) => err.fmt(f),
71 FltkError::NullError(ref err) => err.fmt(f),
72 FltkError::Internal(ref err) => write!(f, "An internal error occurred {err:?}"),
73 FltkError::EnvVarError(ref err) => write!(f, "An env var error occurred {err:?}"),
74 FltkError::Utf8Error(ref err) => {
75 write!(f, "A UTF8 conversion error occurred {err:?}")
76 }
77 FltkError::ParseIntError(ref err) => {
78 write!(f, "An int parsing error occurred {err:?}")
79 }
80 FltkError::Unknown(ref err) => write!(f, "An unknown error occurred {err:?}"),
81 }
82 }
83}
84
85impl From<io::Error> for FltkError {
86 fn from(err: io::Error) -> FltkError {
87 FltkError::IoError(err)
88 }
89}
90
91impl From<std::ffi::NulError> for FltkError {
92 fn from(err: std::ffi::NulError) -> FltkError {
93 FltkError::NullError(err)
94 }
95}
96
97impl From<std::env::VarError> for FltkError {
98 fn from(err: std::env::VarError) -> FltkError {
99 FltkError::EnvVarError(err)
100 }
101}
102
103impl From<std::string::FromUtf8Error> for FltkError {
104 fn from(err: std::string::FromUtf8Error) -> FltkError {
105 FltkError::Utf8Error(err)
106 }
107}
108
109impl From<std::num::ParseIntError> for FltkError {
110 fn from(err: std::num::ParseIntError) -> FltkError {
111 FltkError::ParseIntError(err)
112 }
113}
114
115/// A trait defined for all enums passable to the [`WidgetExt::set_type()`](`crate::prelude::WidgetExt::set_type`) method
116pub trait WidgetType {
117 /// Get the integral representation of the widget type
118 fn to_i32(self) -> i32;
119 /// Get the widget type from its integral representation
120 fn from_i32(val: i32) -> Self;
121}
122
123/// Defines the methods implemented by all widgets
124///
125/// For multithreaded usage, see the [`widget` module documentation's note](crate::widget)
126/// # Safety
127/// fltk-rs traits depend on some FLTK internal code
128/// # Warning
129/// fltk-rs traits are non-exhaustive,
130/// to avoid future breakage if you try to implement them manually,
131/// use the Deref and `DerefMut` pattern or the `widget_extends!` macro
132pub unsafe trait WidgetExt {
133 /// Sets the widget's label.
134 /// labels support special symbols preceded by an `@` [sign](https://www.fltk.org/doc-1.3/symbols.png).
135 /// and for the [associated formatting](https://www.fltk.org/doc-1.3/common.html).
136 fn set_label(&mut self, title: &str);
137 /// Unset a widget's label
138 fn unset_label(&mut self);
139 /// Redraws a widget, necessary for resizing and changing positions
140 fn redraw(&mut self);
141 /// Shows the widget
142 fn show(&mut self);
143 /// Hides the widget
144 fn hide(&mut self);
145 /// Returns the x coordinate of the widget
146 fn x(&self) -> i32;
147 /// Returns the y coordinate of the widget
148 fn y(&self) -> i32;
149 /// Returns the width of the widget
150 fn w(&self) -> i32;
151 /// Returns the height of the widget
152 fn h(&self) -> i32;
153 /// Returns the label of the widget
154 fn label(&self) -> Option<String>;
155 /// Measures the label's width and height
156 fn measure_label(&self) -> (i32, i32);
157 /// transforms a widget to a base `Fl_Widget`, for internal use
158 fn as_widget_ptr(&self) -> *mut fltk_sys::widget::Fl_Widget;
159 /// Checks whether the self widget is inside another widget
160 fn inside<W: WidgetExt>(&self, wid: &W) -> bool
161 where
162 Self: Sized;
163 /// Returns the widget type when applicable
164 fn get_type<T: WidgetType>(&self) -> T
165 where
166 Self: Sized;
167 /// Sets the widget type
168 fn set_type<T: WidgetType>(&mut self, typ: T)
169 where
170 Self: Sized;
171 /// Sets the image of the widget
172 fn set_image<I: ImageExt>(&mut self, image: Option<I>)
173 where
174 Self: Sized;
175 /// Sets the image of the widget scaled to the widget's size
176 fn set_image_scaled<I: ImageExt>(&mut self, image: Option<I>)
177 where
178 Self: Sized;
179 /// Gets the image associated with the widget
180 fn image(&self) -> Option<Box<dyn ImageExt>>
181 where
182 Self: Sized;
183 /// Sets the deactivated image of the widget
184 fn set_deimage<I: ImageExt>(&mut self, image: Option<I>)
185 where
186 Self: Sized;
187 /// Sets the deactivated image of the widget scaled to the widget's size
188 fn set_deimage_scaled<I: ImageExt>(&mut self, image: Option<I>)
189 where
190 Self: Sized;
191 /// Gets the deactivated image associated with the widget
192 fn deimage(&self) -> Option<Box<dyn ImageExt>>
193 where
194 Self: Sized;
195 /// Sets the callback when the widget is triggered (clicks for example)
196 /// takes the widget as a closure argument
197 fn set_callback<F: FnMut(&mut Self) + 'static>(&mut self, cb: F)
198 where
199 Self: Sized;
200 /// Emits a message on callback using a sender
201 fn emit<T: 'static + Clone + Send + Sync>(&mut self, sender: crate::app::Sender<T>, msg: T)
202 where
203 Self: Sized;
204 /// Activates the widget
205 fn activate(&mut self);
206 /// Deactivates the widget
207 fn deactivate(&mut self);
208 /// Redraws the label of the widget
209 fn redraw_label(&mut self);
210 /// Resizes and/or moves the widget, takes x, y, width and height
211 fn resize(&mut self, x: i32, y: i32, width: i32, height: i32);
212 /// Returns the tooltip text
213 fn tooltip(&self) -> Option<String>;
214 /// Sets the tooltip text
215 fn set_tooltip(&mut self, txt: &str);
216 /// Returns the widget color
217 fn color(&self) -> Color;
218 /// Sets the widget's color
219 fn set_color(&mut self, color: Color);
220 /// Returns the widget label's color
221 fn label_color(&self) -> Color;
222 /// Sets the widget label's color
223 fn set_label_color(&mut self, color: Color);
224 /// Returns the widget label's font
225 fn label_font(&self) -> Font;
226 /// Sets the widget label's font
227 fn set_label_font(&mut self, font: Font);
228 /// Returns the widget label's size
229 fn label_size(&self) -> i32;
230 /// Sets the widget label's size
231 fn set_label_size(&mut self, sz: i32);
232 /// Returns the widget label's type
233 fn label_type(&self) -> LabelType;
234 /// Sets the widget label's type
235 fn set_label_type(&mut self, typ: LabelType);
236 /// Returns the widget's frame type
237 fn frame(&self) -> FrameType;
238 /// Sets the widget's frame type
239 fn set_frame(&mut self, typ: FrameType);
240 /// Returns whether the widget was changed
241 fn changed(&self) -> bool;
242 /// Mark the widget as changed
243 fn set_changed(&mut self);
244 /// Clears the changed status of the widget
245 fn clear_changed(&mut self);
246 /// Returns the alignment of the widget
247 fn align(&self) -> Align;
248 /// Sets the alignment of the widget
249 fn set_align(&mut self, align: Align);
250 /// Returns the parent of the widget
251 fn parent(&self) -> Option<crate::group::Group>;
252 /// Gets the selection color of the widget
253 fn selection_color(&self) -> Color;
254 /// Sets the selection color of the widget
255 fn set_selection_color(&mut self, color: Color);
256 /// Runs the already registered callback
257 fn do_callback(&mut self);
258 /// Returns the direct window holding the widget
259 fn window(&self) -> Option<Box<dyn WindowExt>>;
260 /// Returns the topmost window holding the widget
261 fn top_window(&self) -> Option<Box<dyn WindowExt>>;
262 /// Checks whether a widget is capable of taking events
263 fn takes_events(&self) -> bool;
264 /// Make the widget take focus
265 /// # Errors
266 /// Errors on failure to take focus
267 fn take_focus(&mut self) -> Result<(), FltkError>;
268 /// Set the widget to have visible focus
269 fn set_visible_focus(&mut self);
270 /// Clear visible focus
271 fn clear_visible_focus(&mut self);
272 /// Set the visible focus using a flag
273 fn visible_focus(&mut self, v: bool);
274 /// Return whether the widget has visible focus
275 fn has_visible_focus(&self) -> bool;
276 /// Return whether the widget has focus
277 fn has_focus(&self) -> bool;
278 /// Check if a widget was deleted
279 fn was_deleted(&self) -> bool;
280 /// Return whether the widget was damaged
281 fn damage(&self) -> bool;
282 /// Signal the widget as damaged and it should be redrawn in the next event loop cycle
283 fn set_damage(&mut self, flag: bool);
284 /// Return the damage mask
285 fn damage_type(&self) -> Damage;
286 /// Signal the type of damage a widget received
287 fn set_damage_type(&mut self, mask: Damage);
288 /// Signal damage for an area inside the widget
289 fn set_damage_area(&mut self, mask: Damage, x: i32, y: i32, w: i32, h: i32);
290 /// Clear the damaged flag
291 fn clear_damage(&mut self);
292 /// Sets the default callback trigger for a widget, equivalent to `when()`
293 fn set_when(&mut self, trigger: When);
294 /// Return the callback trigger, equivalent to `when()`
295 fn when(&self) -> When;
296 /// Return the widget as a window if it's a window
297 fn as_window(&self) -> Option<Box<dyn WindowExt>>;
298 /// Return the widget as a group widget if it's a group widget
299 fn as_group(&self) -> Option<crate::group::Group>;
300 #[doc(hidden)]
301 /// INTERNAL: Retakes ownership of the user callback data
302 /// # Safety
303 /// Can return multiple mutable references to the `user_data`
304 unsafe fn user_data(&self) -> Option<Box<dyn FnMut()>>;
305 #[doc(hidden)]
306 /// INTERNAL: Get the raw user data of the widget
307 /// # Safety
308 /// Can return multiple mutable references to the `user_data`
309 unsafe fn raw_user_data(&self) -> *mut std::os::raw::c_void;
310 #[doc(hidden)]
311 /// INTERNAL: Set the raw user data of the widget
312 /// # Safety
313 /// Can return multiple mutable references to the `user_data`
314 unsafe fn set_raw_user_data(&mut self, data: *mut std::os::raw::c_void);
315 /// Upcast a `WidgetExt` to some widget type
316 /// # Safety
317 /// Allows for potentially unsafe casts between incompatible widget types
318 unsafe fn as_widget<W: WidgetBase>(&self) -> W
319 where
320 Self: Sized;
321 /// Upcast a `WidgetExt` to a Widget
322 fn as_base_widget(&self) -> crate::widget::Widget
323 where
324 Self: Sized,
325 {
326 unsafe { self.as_widget() }
327 }
328 /// Returns whether a widget is visible
329 fn visible(&self) -> bool;
330 /// Returns whether a widget or any of its parents are visible (recursively)
331 fn visible_r(&self) -> bool;
332 /// Return whether two widgets object point to the same widget
333 fn is_same<W: WidgetExt>(&self, other: &W) -> bool
334 where
335 Self: Sized;
336 /// Returns whether a widget is active
337 fn active(&self) -> bool;
338 /// Returns whether a widget or any of its parents are active (recursively)
339 fn active_r(&self) -> bool;
340 #[doc(hidden)]
341 /**
342 Return the default callback function, this allows storing then running within the overridden callback.
343 Works only for FLTK types (with no callback defined in the Rust side)
344 ```rust,no_run
345 use fltk::{prelude::*, *};
346 fn main() {
347 let a = app::App::default();
348 let mut win = window::Window::default().with_size(400, 300);
349 let scroll = group::Scroll::default().size_of_parent();
350 let _btn = button::Button::new(160, 500, 80, 40, "click");
351 let mut scrollbar = scroll.scrollbar();
352 scrollbar.set_callback({
353 let mut cb = scrollbar.callback();
354 move |_| {
355 println!("print something, and also run the default callback");
356 if let Some(cb) = cb.as_mut() {
357 (*cb)();
358 }
359 }
360 });
361 win.end();
362 win.show();
363 a.run().unwrap();
364 }
365 ```
366 */
367 fn callback(&self) -> Option<Box<dyn FnMut()>>;
368 /// Does a simple resize ignoring class-specific resize functionality
369 fn widget_resize(&mut self, x: i32, y: i32, w: i32, h: i32);
370 /// Handle a specific event
371 fn handle_event(&mut self, event: Event) -> bool;
372 /// Check whether a widget is derived
373 fn is_derived(&self) -> bool {
374 unimplemented!();
375 }
376}
377
378/// Defines the extended methods implemented by all widgets
379/// # Safety
380/// fltk-rs traits depend on some FLTK internal code
381/// # Warning
382/// fltk-rs traits are non-exhaustive,
383/// to avoid future breakage if you try to implement them manually,
384/// use the Deref and `DerefMut` pattern or the `widget_extends!` macro
385pub unsafe trait WidgetBase: WidgetExt {
386 /// Deletes widgets and their children.
387 fn delete(wid: Self)
388 where
389 Self: Sized;
390 /// transforms a widget pointer to a Widget, for internal use
391 /// # Safety
392 /// The pointer must be valid
393 unsafe fn from_widget_ptr(ptr: *mut fltk_sys::widget::Fl_Widget) -> Self;
394 /// Get a widget from base widget
395 /// # Safety
396 /// The underlying object must be valid
397 unsafe fn from_widget<W: WidgetExt>(w: W) -> Self;
398 /// Set a custom handler, where events are managed manually, akin to `Fl_Widget::handle(int)`.
399 /// Handled or ignored events should return true, unhandled events should return false.
400 /// takes the widget as a closure argument.
401 /// The ability to handle an event might depend on handling other events, as explained [here](https://www.fltk.org/doc-1.4/events.html)
402 fn handle<F: FnMut(&mut Self, Event) -> bool + 'static>(&mut self, cb: F);
403 /// Set a custom draw method.
404 /// takes the widget as a closure argument.
405 /// macOS requires that `WidgetBase::draw` actually calls drawing functions
406 fn draw<F: FnMut(&mut Self) + 'static>(&mut self, cb: F);
407 #[doc(hidden)]
408 /// INTERNAL: Retrieve the draw data
409 /// # Safety
410 /// Can return multiple mutable references to the `draw_data`
411 unsafe fn draw_data(&self) -> Option<Box<dyn FnMut()>>;
412 #[doc(hidden)]
413 /// INTERNAL: Retrieve the handle data
414 /// # Safety
415 /// Can return multiple mutable references to the `handle_data`
416 unsafe fn handle_data(&self) -> Option<Box<dyn FnMut(Event) -> bool>>;
417 /// Perform a callback on resize.
418 /// Avoid resizing the parent or the same widget to avoid infinite recursion
419 fn resize_callback<F: FnMut(&mut Self, i32, i32, i32, i32) + 'static>(&mut self, cb: F);
420 /// Makes the widget derived
421 /// # Safety
422 /// Calling this on a non-derived widget can cause undefined behavior
423 unsafe fn assume_derived(&mut self) {
424 unimplemented!();
425 }
426 /// Cast a type-erased widget back to its original widget
427 fn from_dyn_widget<W: WidgetExt>(_w: &W) -> Option<Self>
428 where
429 Self: Sized,
430 {
431 None
432 }
433 /// Cast a type-erased widget pointer back to its original widget
434 fn from_dyn_widget_ptr(_w: *mut fltk_sys::widget::Fl_Widget) -> Option<Self>
435 where
436 Self: Sized,
437 {
438 None
439 }
440 #[doc(hidden)]
441 /// Determine whether the base class's draw method is called, default is true
442 fn super_draw(&mut self, flag: bool) {
443 let _ = flag;
444 }
445 #[doc(hidden)]
446 /// Determine whether the base class's draw method is called last, default is true
447 fn super_draw_first(&mut self, flag: bool) {
448 let _ = flag;
449 }
450 #[doc(hidden)]
451 /// Determine whether the base class's handle method should have an event propagated even
452 /// if handled by the instantiated widget
453 fn super_handle_first(&mut self, flag: bool) {
454 let _ = flag;
455 }
456}
457
458/// Defines the methods implemented by all button widgets.
459/// More details can be found in the [wiki](https://github.com/fltk-rs/fltk-rs/wiki/buttons).
460/// # Safety
461/// fltk-rs traits depend on some FLTK internal code
462/// # Warning
463/// fltk-rs traits are non-exhaustive,
464/// to avoid future breakage if you try to implement them manually,
465/// use the Deref and `DerefMut` pattern or the `widget_extends!` macro
466pub unsafe trait ButtonExt: WidgetExt {
467 /// Gets the shortcut associated with a button
468 fn shortcut(&self) -> Shortcut;
469 /// Sets the shortcut associated with a button
470 fn set_shortcut(&mut self, shortcut: Shortcut);
471 /// Clears the value of the button.
472 /// Useful for round, radio, light, toggle and check buttons
473 fn clear(&mut self);
474 /// Returns whether a button is set or not.
475 /// Useful for round, radio, light, toggle and check buttons
476 fn is_set(&self) -> bool;
477 /// Sets whether a button is set or not.
478 /// Useful for round, radio, light, toggle and check buttons
479 fn set(&mut self, flag: bool);
480 /// Returns whether a button is set or not.
481 /// Useful for round, radio, light, toggle and check buttons
482 fn value(&self) -> bool;
483 /// Sets whether a button is set or not.
484 /// Useful for round, radio, light, toggle and check buttons
485 fn set_value(&mut self, flag: bool);
486 /// Set the `down_box` of the widget
487 fn set_down_frame(&mut self, f: FrameType);
488 /// Get the down frame type of the widget
489 fn down_frame(&self) -> FrameType;
490}
491
492/// Defines the methods implemented by all group widgets.
493/// These widgets include Window types and others found in the group module: Group, Scroll, Pack, Tile, Flex ...etc.
494/// Widgets implementing the `GroupExt` trait, are characterized by having to call `::end()` method to basically close them.
495/// More details can be found in the [wiki](https://github.com/fltk-rs/fltk-rs/wiki/group_widgets).
496/// ```rust
497/// use fltk::{app, button::Button, window::Window, prelude::GroupExt};
498/// let a = app::App::default();
499/// let win = Window::default();
500/// let btn = Button::default();
501/// // Instantiate other widgets
502/// win.end();
503/// ```
504/// In the above example, the button `btn` will be parented by the window.
505/// After `end`ing such `GroupExt` widgets, any other widgets instantiated after the `end` call, will be instantiated outside.
506/// These can still be added using the `::add(&other_widget)` method (or using `::insert`):
507/// ```rust
508/// use fltk::{app, button::Button, window::Window, prelude::GroupExt};
509/// let a = app::App::default();
510/// let mut win = Window::default();
511/// win.end();
512/// let btn = Button::default();
513/// win.add(&btn);
514/// ```
515/// Another option is to reopen the widget:
516/// ```rust
517/// use fltk::{app, button::Button, window::Window, prelude::GroupExt};
518/// let a = app::App::default();
519/// let win = Window::default();
520/// win.end();
521/// win.begin();
522/// let btn = Button::default();
523/// // other widgets
524/// win.end();
525/// ```
526/// # Safety
527/// fltk-rs traits depend on some FLTK internal code
528/// # Warning
529/// fltk-rs traits are non-exhaustive,
530/// to avoid future breakage if you try to implement them manually,
531/// use the Deref and `DerefMut` pattern or the `widget_extends!` macro
532pub unsafe trait GroupExt: WidgetExt {
533 /// Begins a group, used for widgets implementing the group trait
534 fn begin(&self);
535 /// Ends a group, used for widgets implementing the group trait
536 fn end(&self);
537 /// Clear a group from all widgets
538 fn clear(&mut self);
539 #[doc(hidden)]
540 /// Clear a group from all widgets using FLTK's clear call.
541 /// # Safety
542 /// Ignores widget tracking
543 unsafe fn unsafe_clear(&mut self);
544 /// Return the number of children in a group
545 fn children(&self) -> i32;
546 /// Return child widget by index
547 fn child(&self, idx: i32) -> Option<crate::widget::Widget>;
548 /// Find a widget within a group and return its index
549 fn find<W: WidgetExt>(&self, widget: &W) -> i32
550 where
551 Self: Sized;
552 /// Add a widget to a group
553 fn add<W: WidgetExt>(&mut self, widget: &W)
554 where
555 Self: Sized;
556 /// Insert a widget to a group at a certain index
557 fn insert<W: WidgetExt>(&mut self, widget: &W, index: i32)
558 where
559 Self: Sized;
560 /// Remove a widget from a group, but does not delete it
561 fn remove<W: WidgetExt>(&mut self, widget: &W)
562 where
563 Self: Sized;
564 /// Remove a child widget by its index
565 fn remove_by_index(&mut self, idx: i32);
566 /// The resizable widget defines both the resizing frame and the resizing behavior of the group and its children.
567 fn resizable<W: WidgetExt>(&self, widget: &W)
568 where
569 Self: Sized;
570 /// Make the group itself resizable, should be called before the widget is shown
571 fn make_resizable(&mut self, val: bool);
572 /// Adds a widget to the group and makes it the resizable widget
573 fn add_resizable<W: WidgetExt>(&mut self, widget: &W)
574 where
575 Self: Sized;
576 /// Clips children outside the group boundaries
577 fn set_clip_children(&mut self, flag: bool);
578 /// Get whether `clip_children` is set
579 fn clip_children(&self) -> bool;
580 /// Draw a child widget, the call should be in a [`WidgetBase::draw`](`crate::prelude::WidgetBase::draw`) method
581 fn draw_child<W: WidgetExt>(&self, w: &mut W)
582 where
583 Self: Sized;
584 /// Update a child widget, the call should be in a [`WidgetBase::draw`](`crate::prelude::WidgetBase::draw`) method
585 fn update_child<W: WidgetExt>(&self, w: &mut W)
586 where
587 Self: Sized;
588 /// Draw the outside label, the call should be in a [`WidgetBase::draw`](`crate::prelude::WidgetBase::draw`) method
589 fn draw_outside_label<W: WidgetExt>(&self, w: &mut W)
590 where
591 Self: Sized;
592 /// Draw children, the call should be in a [`WidgetBase::draw`](`crate::prelude::WidgetBase::draw`) method
593 fn draw_children(&mut self);
594 /// Resets the internal array of widget sizes and positions
595 fn init_sizes(&mut self);
596 /// Get the bounds of all children widgets (left, upper, right, bottom)
597 fn bounds(&self) -> Vec<(i32, i32, i32, i32)>;
598 /// Converts a widget implementing `GroupExt` into a Group widget
599 /// # Safety
600 /// If the widget wasn't created by fltk-rs,
601 /// vtable differences mean certain methods can't be overridden (e.g. handle & draw)
602 unsafe fn as_group(&self) -> crate::group::Group;
603}
604
605/// Defines the methods implemented by all window widgets.
606/// More details can be found in the [wiki](https://github.com/fltk-rs/fltk-rs/wiki/windows).
607/// Windows (which can be found in the window module) implement `GroupExt` as well.
608/// # Safety
609/// fltk-rs traits depend on some FLTK internal code
610/// # Warning
611/// fltk-rs traits are non-exhaustive,
612/// to avoid future breakage if you try to implement them manually,
613/// use the Deref and `DerefMut` pattern or the `widget_extends!` macro
614pub unsafe trait WindowExt: GroupExt {
615 /// Positions the window to the center of the screen
616 fn set_center_screen(&mut self);
617 /// Makes a window modal, should be called before `show`
618 fn make_modal(&mut self, val: bool);
619 /// Makes a window fullscreen.
620 /// Requires that the window is resizable.
621 fn fullscreen(&mut self, val: bool);
622 /// Makes the window current
623 fn make_current(&mut self);
624 /// Returns the icon of the window
625 fn icon(&self) -> Option<Box<dyn ImageExt>>;
626 /// Sets the windows icon.
627 /// Supported formats are bmp, jpeg, png and rgb.
628 fn set_icon(&mut self, image: Option<crate::image::RgbImage>);
629 /// Sets the cursor style within the window.
630 /// Needs to be called after the window is shown
631 fn set_cursor(&mut self, cursor: Cursor);
632 /// Returns whether a window is shown
633 fn shown(&self) -> bool;
634 /// Sets whether the window has a border
635 fn set_border(&mut self, flag: bool);
636 /// Returns whether a window has a border
637 fn border(&self) -> bool;
638 /// Frees the position of the window
639 fn free_position(&mut self);
640 /// Get the raw system handle of the window
641 fn raw_handle(&self) -> crate::window::RawHandle;
642 /// Get the graphical draw region of the window
643 fn region(&self) -> crate::draw::Region;
644 /// Set the graphical draw region of the window
645 /// # Safety
646 /// The data must be valid.
647 unsafe fn set_region(&mut self, region: crate::draw::Region);
648 /// Iconifies the window.
649 /// You can tell that the window is iconized by checking that it's shown and not visible
650 fn iconize(&mut self);
651 /// Returns whether the window is fullscreen or not
652 fn fullscreen_active(&self) -> bool;
653 /// Returns the decorated width
654 fn decorated_w(&self) -> i32;
655 /// Returns the decorated height
656 fn decorated_h(&self) -> i32;
657 /// Set the window's minimum width, minimum height, max width and max height.
658 /// You can pass 0 as `max_w` and `max_h` to allow unlimited upward resize of the window.
659 fn size_range(&mut self, min_w: i32, min_h: i32, max_w: i32, max_h: i32);
660 /// Set the hotspot widget of the window
661 fn hotspot<W: WidgetExt>(&mut self, w: &W)
662 where
663 Self: Sized;
664 /// Set the shape of the window.
665 /// Supported image formats are BMP, RGB and Pixmap.
666 /// The window covers non-transparent/non-black shape of the image.
667 /// The image must not be scaled(resized) beforehand.
668 /// The size will be adapted to the window's size
669 fn set_shape(&mut self, image: Option<crate::image::RgbImage>);
670 /// Get the shape of the window
671 fn shape(&self) -> Option<Box<dyn ImageExt>>;
672 /// Get the window's x coord from the screen
673 fn x_root(&self) -> i32;
674 /// Get the window's y coord from the screen
675 fn y_root(&self) -> i32;
676 /// Set the cursor image
677 fn set_cursor_image(&mut self, image: crate::image::RgbImage, hot_x: i32, hot_y: i32);
678 /// Set the window's default cursor
679 fn default_cursor(&mut self, cursor: Cursor);
680 /// Get the screen number
681 fn screen_num(&self) -> i32;
682 /// Set the screen number
683 fn set_screen_num(&mut self, n: i32);
684 /// wait for the window to be displayed after calling `show()`.
685 /// More info [here](https://www.fltk.org/doc-1.4/classFl__Window.html#aafbec14ca8ff8abdaff77a35ebb23dd8)
686 fn wait_for_expose(&self);
687 /// Get the window's opacity
688 fn opacity(&self) -> f64;
689 /// Set the window's opacity,
690 /// Ranges from 0.0 to 1.0, where 1.0 is fully opaque and 0.0 is fully transparent.
691 /// This should be called on a shown window.
692 /// On X11, opacity support depends on the window manager and can be queried:
693 /// ```ignore
694 /// $ xprop -root _NET_SUPPORTED | grep -o _NET_WM_WINDOW_OPACITY
695 /// ```
696 fn set_opacity(&mut self, val: f64);
697 /// Get the window's `XA_WM_CLASS` property
698 fn xclass(&self) -> Option<String>;
699 /// Set the window's `XA_WM_CLASS` property.
700 /// This should be called before showing the window
701 fn set_xclass(&mut self, s: &str);
702 /// Clear the modal state of the window
703 fn clear_modal_states(&mut self);
704 /// removes the window border and sets the window on top, by settings the NOBORDER and OVERRIDE flags
705 fn set_override(&mut self);
706 /// Checks whether the OVERRIDE flag was set
707 fn is_override(&self) -> bool;
708 /// Forces the position of the window
709 fn force_position(&mut self, flag: bool);
710 /// Set the icon label
711 fn set_icon_label(&mut self, label: &str);
712 /// Get the icon label
713 fn icon_label(&self) -> Option<String>;
714 /// Allow the window to expand outside its parent (if supported by the platform/driver)
715 fn allow_expand_outside_parent(&mut self);
716 /// Return the OS-specific window id/handle as an integer (useful for interop)
717 fn os_id(&self) -> usize;
718}
719
720/// Defines the methods implemented by all input and output widgets.
721/// More details can be found in the [wiki](https://github.com/fltk-rs/fltk-rs/wiki/inout_widgets).
722/// # Safety
723/// fltk-rs traits depend on some FLTK internal code
724/// # Warning
725/// fltk-rs traits are non-exhaustive,
726/// to avoid future breakage if you try to implement them manually,
727/// use the Deref and `DerefMut` pattern or the `widget_extends!` macro
728pub unsafe trait InputExt: WidgetExt {
729 /// Returns the value inside the input/output widget
730 fn value(&self) -> String;
731 /// Sets the value inside an input/output widget
732 fn set_value(&mut self, val: &str);
733 /// Returns the maximum size (in bytes) accepted by an input/output widget
734 fn maximum_size(&self) -> i32;
735 /// Sets the maximum size (in bytes) accepted by an input/output widget
736 fn set_maximum_size(&mut self, val: i32);
737 /// Returns the index position inside an input/output widget
738 fn insert_position(&self) -> i32;
739 /// Sets the index position inside an input/output widget
740 /// # Errors
741 /// Errors on failure to set the cursor position in the text
742 fn set_position(&mut self, val: i32) -> Result<(), FltkError>;
743 /// Returns the index mark inside an input/output widget
744 fn mark(&self) -> i32;
745 /// Sets the index mark inside an input/output widget
746 /// # Errors
747 /// Errors on failure to set the mark
748 fn set_mark(&mut self, val: i32) -> Result<(), FltkError>;
749 /// Replace content with a &str
750 /// # Errors
751 /// Errors on failure to replace text
752 fn replace(&mut self, beg: i32, end: i32, val: &str) -> Result<(), FltkError>;
753 /// Insert a &str
754 /// # Errors
755 /// Errors on failure to insert text
756 fn insert(&mut self, txt: &str) -> Result<(), FltkError>;
757 /// Append a &str
758 /// # Errors
759 /// Errors on failure to append text
760 fn append(&mut self, txt: &str) -> Result<(), FltkError>;
761 /// Copy the value within the widget
762 /// # Errors
763 /// Errors on failure to copy selection
764 fn copy(&mut self) -> Result<(), FltkError>;
765 /// Undo changes
766 /// # Errors
767 /// Errors on failure to undo
768 fn undo(&mut self) -> Result<(), FltkError>;
769 /// Cut the value within the widget
770 /// # Errors
771 /// Errors on failure to cut selection
772 fn cut(&mut self) -> Result<(), FltkError>;
773 /// Return the cursor color
774 fn cursor_color(&self) -> Color;
775 /// Sets the cursor color
776 fn set_cursor_color(&mut self, color: Color);
777 /// Return the text font
778 fn text_font(&self) -> Font;
779 /// Sets the text font
780 fn set_text_font(&mut self, font: Font);
781 /// Return the text color
782 fn text_color(&self) -> Color;
783 /// Sets the text color
784 fn set_text_color(&mut self, color: Color);
785 /// Return the text size
786 fn text_size(&self) -> i32;
787 /// Sets the text size
788 fn set_text_size(&mut self, sz: i32);
789 /// Returns whether the input/output widget is readonly
790 fn readonly(&self) -> bool;
791 /// Set readonly status of the input/output widget
792 fn set_readonly(&mut self, val: bool);
793 /// Return whether text is wrapped inside an input/output widget
794 fn wrap(&self) -> bool;
795 /// Set whether text is wrapped inside an input/output widget
796 fn set_wrap(&mut self, val: bool);
797 /// Sets whether tab navigation is enabled, true by default
798 fn set_tab_nav(&mut self, val: bool);
799 /// Returns whether tab navigation is enabled
800 fn tab_nav(&self) -> bool;
801}
802
803/// Defines the methods implemented by all menu widgets
804/// These are found in the menu module: `MenuBar`, `SysMenuBar`, Choice, `MenuButton` ...etc.
805/// Menus function in 2 main ways which are discussed in the [wiki](https://github.com/fltk-rs/fltk-rs/wiki/menus)
806/// # Safety
807/// fltk-rs traits depend on some FLTK internal code
808/// # Warning
809/// fltk-rs traits are non-exhaustive,
810/// to avoid future breakage if you try to implement them manually,
811/// use the Deref and `DerefMut` pattern or the `widget_extends!` macro
812pub unsafe trait MenuExt: WidgetExt {
813 /// Get a menu item by name
814 fn find_item(&self, name: &str) -> Option<crate::menu::MenuItem>;
815 /// Set selected item
816 fn set_item(&mut self, item: &crate::menu::MenuItem) -> bool;
817 /// Find an item's index by its label
818 fn find_index(&self, label: &str) -> i32;
819 /// Return the text font
820 fn text_font(&self) -> Font;
821 /// Sets the text font
822 fn set_text_font(&mut self, c: Font);
823 /// Return the text size
824 fn text_size(&self) -> i32;
825 /// Sets the text size
826 fn set_text_size(&mut self, c: i32);
827 /// Return the text color
828 fn text_color(&self) -> Color;
829 /// Sets the text color
830 fn set_text_color(&mut self, c: Color);
831 /// Add a menu item along with its callback.
832 /// The characters "&", "/", "\\", and "\_" (underscore) are treated as special characters in the label string. The "&" character specifies that the following character is an accelerator and will be underlined.
833 /// The "\\" character is used to escape the next character in the string. Labels starting with the "\_" (underscore) character cause a divider to be placed after that menu item.
834 /// Takes the menu item as a closure argument
835 fn add<F: FnMut(&mut Self) + 'static>(
836 &mut self,
837 name: &str,
838 shortcut: Shortcut,
839 flag: crate::menu::MenuFlag,
840 cb: F,
841 ) -> i32
842 where
843 Self: Sized;
844 /// Inserts a menu item at an index along with its callback.
845 /// The characters "&", "/", "\\", and "\_" (underscore) are treated as special characters in the label string. The "&" character specifies that the following character is an accelerator and will be underlined.
846 /// The "\\" character is used to escape the next character in the string. Labels starting with the "\_" (underscore) character cause a divider to be placed after that menu item.
847 /// Takes the menu item as a closure argument
848 fn insert<F: FnMut(&mut Self) + 'static>(
849 &mut self,
850 idx: i32,
851 name: &str,
852 shortcut: Shortcut,
853 flag: crate::menu::MenuFlag,
854 cb: F,
855 ) -> i32
856 where
857 Self: Sized;
858 /// Add a menu item along with an emit (sender and message).
859 /// The characters "&", "/", "\\", and "\_" (underscore) are treated as special characters in the label string. The "&" character specifies that the following character is an accelerator and will be underlined.
860 /// The "\\" character is used to escape the next character in the string. Labels starting with the "\_" (underscore) character cause a divider to be placed after that menu item.
861 fn add_emit<T: 'static + Clone + Send + Sync>(
862 &mut self,
863 label: &str,
864 shortcut: Shortcut,
865 flag: crate::menu::MenuFlag,
866 sender: crate::app::Sender<T>,
867 msg: T,
868 ) -> i32
869 where
870 Self: Sized;
871 /// Inserts a menu item along with an emit (sender and message).
872 /// The characters "&", "/", "\\", and "\_" (underscore) are treated as special characters in the label string. The "&" character specifies that the following character is an accelerator and will be underlined.
873 /// The "\\" character is used to escape the next character in the string. Labels starting with the "\_" (underscore) character cause a divider to be placed after that menu item.
874 fn insert_emit<T: 'static + Clone + Send + Sync>(
875 &mut self,
876 idx: i32,
877 label: &str,
878 shortcut: Shortcut,
879 flag: crate::menu::MenuFlag,
880 sender: crate::app::Sender<T>,
881 msg: T,
882 ) -> i32
883 where
884 Self: Sized;
885 /// Remove a menu item by index
886 fn remove(&mut self, idx: i32);
887 /// Adds a simple text option to the Choice and `MenuButton` widgets.
888 /// The characters "&", "/", "\\", "|", and "\_" (underscore) are treated as special characters in the label string. The "&" character specifies that the following character is an accelerator and will be underlined.
889 /// The "\\" character is used to escape the next character in the string. Labels starting with the "\_" (underscore) character cause a divider to be placed after that menu item.
890 fn add_choice(&mut self, text: &str) -> i32;
891 /// Gets the user choice from the Choice and `MenuButton` widgets
892 fn choice(&self) -> Option<String>;
893 /// Get index into menu of the last item chosen, returns -1 if no item was chosen
894 fn value(&self) -> i32;
895 /// Set index into menu of the last item chosen,return true if the new value is different than the old one
896 fn set_value(&mut self, v: i32) -> bool;
897 /// Clears the items in a menu, effectively deleting them.
898 fn clear(&mut self);
899 /// Clears a submenu by index
900 /// # Errors
901 /// Errors on failure to clear the submenu, failure returns an [`FltkErrorKind::FailedOperation`](`crate::prelude::FltkErrorKind::FailedOperation`)
902 fn clear_submenu(&mut self, idx: i32) -> Result<(), FltkError>;
903 /// Clears the items in a menu, effectively deleting them, and recursively force-cleans capturing callbacks
904 /// # Safety
905 /// Deletes `user_data` and any captured objects in the callback
906 unsafe fn unsafe_clear(&mut self);
907 #[doc(hidden)]
908 /// Clears a submenu by index. Also recursively force-cleans capturing callbacks
909 /// # Safety
910 /// Deletes `user_data` and any captured objects in the callback, , failure returns an [`FltkErrorKind::FailedOperation`](`crate::prelude::FltkErrorKind::FailedOperation`)
911 /// # Errors
912 /// Errors on failure to clear the submenu
913 unsafe fn unsafe_clear_submenu(&mut self, idx: i32) -> Result<(), FltkError>;
914 /// Get the size of the menu widget
915 fn size(&self) -> i32;
916 /// Get the text label of the menu item at index idx
917 fn text(&self, idx: i32) -> Option<String>;
918 /// Get the menu item at an index
919 fn at(&self, idx: i32) -> Option<crate::menu::MenuItem>;
920 /// Get the mode of a menu item by index and flag
921 fn mode(&self, idx: i32) -> crate::menu::MenuFlag;
922 /// Set the mode of a menu item
923 fn set_mode(&mut self, idx: i32, flag: crate::menu::MenuFlag);
924 /// End the menu
925 fn end(&mut self);
926 /// Set the `down_box` of the widget
927 fn set_down_frame(&mut self, f: FrameType);
928 /// Get the down frame type of the widget
929 fn down_frame(&self) -> FrameType;
930 /// Make a menu globally accessible from any window
931 fn global(&mut self);
932 /// Get the menu element
933 fn menu(&self) -> Option<crate::menu::MenuItem>;
934 /// Set the menu element
935 /// # Safety
936 /// The `MenuItem` must be in a format recognized by FLTK (Empty `CMenuItem` after submenus and at the end of the menu)
937 unsafe fn set_menu(&mut self, item: crate::menu::MenuItem);
938 /// Get an item's pathname
939 fn item_pathname(&self, item: Option<&crate::menu::MenuItem>) -> Result<String, FltkError>;
940 /// Set the menu's popup frame type
941 fn set_menu_frame(&mut self, f: FrameType);
942 /// Get the menu's popup frame type
943 fn menu_frame(&self) -> FrameType;
944 /// Get the selected menu item
945 fn mvalue(&self) -> Option<crate::menu::MenuItem>;
946 /// Get the previously selected menu item
947 fn prev_mvalue(&self) -> Option<crate::menu::MenuItem>;
948}
949
950/// Defines the methods implemented by all valuator widgets
951/// More details can be found in the [wiki](https://github.com/fltk-rs/fltk-rs/wiki/valuators).
952/// # Safety
953/// fltk-rs traits depend on some FLTK internal code
954/// # Warning
955/// fltk-rs traits are non-exhaustive,
956/// to avoid future breakage if you try to implement them manually,
957/// use the Deref and `DerefMut` pattern or the `widget_extends!` macro
958pub unsafe trait ValuatorExt: WidgetExt {
959 /// Set bounds of a valuator
960 fn set_bounds(&mut self, a: f64, b: f64);
961 /// Get the minimum bound of a valuator
962 fn minimum(&self) -> f64;
963 /// Set the minimum bound of a valuator
964 fn set_minimum(&mut self, a: f64);
965 /// Get the maximum bound of a valuator
966 fn maximum(&self) -> f64;
967 /// Set the maximum bound of a valuator
968 fn set_maximum(&mut self, a: f64);
969 /// Set the range of a valuator
970 fn set_range(&mut self, a: f64, b: f64);
971 /// Set change step of a valuator.
972 /// Rounds to multiples of a/b, or no rounding if a is zero
973 fn set_step(&mut self, a: f64, b: i32);
974 /// Get change step of a valuator
975 fn step(&self) -> f64;
976 /// Set the precision of a valuator
977 fn set_precision(&mut self, digits: i32);
978 /// Get the value of a valuator
979 fn value(&self) -> f64;
980 /// Set the value of a valuator
981 fn set_value(&mut self, arg2: f64);
982 /// Set the format of a valuator
983 /// # Errors
984 /// Errors on failure to set the format of the widget
985 fn format(&mut self, arg2: &str) -> Result<(), FltkError>;
986 /// Round the valuator
987 fn round(&self, arg2: f64) -> f64;
988 /// Clamp the valuator
989 fn clamp(&self, arg2: f64) -> f64;
990 /// Increment the valuator
991 fn increment(&mut self, arg2: f64, arg3: i32) -> f64;
992}
993
994/// Defines the methods implemented by `TextDisplay` and `TextEditor`
995/// More details can be found in the [wiki](https://github.com/fltk-rs/fltk-rs/wiki/text).
996/// # Safety
997/// fltk-rs traits depend on some FLTK internal code
998/// # Warning
999/// fltk-rs traits are non-exhaustive,
1000/// to avoid future breakage if you try to implement them manually,
1001/// use the Deref and `DerefMut` pattern or the `widget_extends!` macro
1002pub unsafe trait DisplayExt: WidgetExt {
1003 /// Check if the Display widget has an associated buffer
1004 #[doc(hidden)]
1005 fn has_buffer(&self) -> bool;
1006 /// Get the associated `TextBuffer`
1007 fn buffer(&self) -> Option<crate::text::TextBuffer>;
1008 /// Sets the associated `TextBuffer`.
1009 /// Since the widget is long-lived, the lifetime of the buffer is prolonged to the lifetime of the program
1010 fn set_buffer<B: Into<Option<crate::text::TextBuffer>>>(&mut self, buffer: B);
1011 /// Get the associated style `TextBuffer`
1012 fn style_buffer(&self) -> Option<crate::text::TextBuffer>;
1013 /// Return the text font
1014 fn text_font(&self) -> Font;
1015 /// Sets the text font
1016 fn set_text_font(&mut self, font: Font);
1017 /// Return the text color
1018 fn text_color(&self) -> Color;
1019 /// Sets the text color
1020 fn set_text_color(&mut self, color: Color);
1021 /// Return the text size
1022 fn text_size(&self) -> i32;
1023 /// Sets the text size
1024 fn set_text_size(&mut self, sz: i32);
1025 /// Scroll down the Display widget
1026 fn scroll(&mut self, top_line_num: i32, horiz_offset: i32);
1027 /// Insert into Display widget
1028 fn insert(&self, text: &str);
1029 /// Set the insert position
1030 fn set_insert_position(&mut self, new_pos: i32);
1031 /// Return the insert position
1032 fn insert_position(&self) -> i32;
1033 /// Gets the x and y positions of the cursor
1034 fn position_to_xy(&self, pos: i32) -> (i32, i32);
1035 /// Counts the lines from start to end
1036 fn count_lines(&self, start: i32, end: i32, is_line_start: bool) -> i32;
1037 /// Moves the cursor right
1038 /// # Errors
1039 /// Errors on failure to move the cursor
1040 fn move_right(&mut self) -> Result<(), FltkError>;
1041 /// Moves the cursor left
1042 /// # Errors
1043 /// Errors on failure to move the cursor
1044 fn move_left(&mut self) -> Result<(), FltkError>;
1045 /// Moves the cursor up
1046 /// # Errors
1047 /// Errors on failure to move the cursor
1048 fn move_up(&mut self) -> Result<(), FltkError>;
1049 /// Moves the cursor down
1050 /// # Errors
1051 /// Errors on failure to move the cursor
1052 fn move_down(&mut self) -> Result<(), FltkError>;
1053 /// Shows/hides the cursor
1054 fn show_cursor(&mut self, val: bool);
1055 /// Sets the style of the text widget
1056 fn set_highlight_data<
1057 B: Into<Option<crate::text::TextBuffer>>,
1058 E: Into<Vec<crate::text::StyleTableEntry>>,
1059 >(
1060 &mut self,
1061 style_buffer: B,
1062 entries: E,
1063 );
1064 /// Unset the style of the text widget
1065 fn unset_highlight_data<B: Into<Option<crate::text::TextBuffer>>>(&mut self, style_buffer: B);
1066 /// Sets the cursor style
1067 fn set_cursor_style(&mut self, style: crate::text::Cursor);
1068 /// Sets the cursor color
1069 fn set_cursor_color(&mut self, color: Color);
1070 /// Sets the scrollbar size in pixels
1071 fn set_scrollbar_size(&mut self, size: i32);
1072 /// Sets the scrollbar alignment
1073 fn set_scrollbar_align(&mut self, align: Align);
1074 /// Returns the cursor style
1075 fn cursor_style(&self) -> crate::text::Cursor;
1076 /// Returns the cursor color
1077 fn cursor_color(&self) -> Color;
1078 /// Returns the scrollbar size in pixels
1079 fn scrollbar_size(&self) -> i32;
1080 /// Returns the scrollbar alignment
1081 fn scrollbar_align(&self) -> Align;
1082 /// Returns the beginning of the line from the current position.
1083 /// Returns new position as index
1084 fn line_start(&self, pos: i32) -> i32;
1085 /// Returns the ending of the line from the current position.
1086 /// Returns new position as index
1087 fn line_end(&self, start_pos: i32, is_line_start: bool) -> i32;
1088 /// Skips lines from `start_pos`
1089 fn skip_lines(&mut self, start_pos: i32, lines: i32, is_line_start: bool) -> i32;
1090 /// Rewinds the lines
1091 fn rewind_lines(&mut self, start_pos: i32, lines: i32) -> i32;
1092 /// Goes to the next word
1093 fn next_word(&mut self);
1094 /// Goes to the previous word
1095 fn previous_word(&mut self);
1096 /// Returns the position of the start of the word, relative to the current position
1097 fn word_start(&self, pos: i32) -> i32;
1098 /// Returns the position of the end of the word, relative to the current position
1099 fn word_end(&self, pos: i32) -> i32;
1100 /// Convert an x pixel position into a column number.
1101 fn x_to_col(&self, x: f64) -> f64;
1102 /// Convert a column number into an x pixel position
1103 fn col_to_x(&self, col: f64) -> f64;
1104 /// Sets the linenumber width
1105 fn set_linenumber_width(&mut self, w: i32);
1106 /// Gets the linenumber width
1107 fn linenumber_width(&self) -> i32;
1108 /// Sets the linenumber font
1109 fn set_linenumber_font(&mut self, font: Font);
1110 /// Gets the linenumber font
1111 fn linenumber_font(&self) -> Font;
1112 /// Sets the linenumber size
1113 fn set_linenumber_size(&mut self, size: i32);
1114 /// Gets the linenumber size
1115 fn linenumber_size(&self) -> i32;
1116 /// Sets the linenumber foreground color
1117 fn set_linenumber_fgcolor(&mut self, color: Color);
1118 /// Gets the linenumber foreground color
1119 fn linenumber_fgcolor(&self) -> Color;
1120 /// Sets the linenumber background color
1121 fn set_linenumber_bgcolor(&mut self, color: Color);
1122 /// Gets the linenumber background color
1123 fn linenumber_bgcolor(&self) -> Color;
1124 /// Sets the linenumber alignment
1125 fn set_linenumber_align(&mut self, align: Align);
1126 /// Gets the linenumber alignment
1127 fn linenumber_align(&self) -> Align;
1128 /// Sets the line number format string
1129 fn set_linenumber_format(&mut self, fmt: &str);
1130 /// Gets the current line number format string
1131 fn linenumber_format(&self) -> Option<String>;
1132 /// Query style position in line
1133 fn position_style(&self, line_start_pos: i32, line_len: i32, line_index: i32) -> i32;
1134 /// Maintain absolute top line number state
1135 fn maintain_absolute_top_line_number(&mut self, state: bool);
1136 /// Get absolute top line number
1137 fn get_absolute_top_line_number(&self) -> i32;
1138 /// Update absolute top line number with old first char
1139 fn absolute_top_line_number(&mut self, old_first_char: i32);
1140 /// Return whether maintaining absolute top line number is enabled
1141 fn maintaining_absolute_top_line_number(&self) -> bool;
1142 /// Reset absolute top line number tracking
1143 fn reset_absolute_top_line_number(&mut self);
1144 /// Checks whether a pixel is within a text selection
1145 fn in_selection(&self, x: i32, y: i32) -> bool;
1146 /// Sets the wrap mode of the Display widget.
1147 /// If the wrap mode is `AtColumn`, wrap margin is the column.
1148 /// If the wrap mode is `AtPixel`, wrap margin is the pixel.
1149 /// For more [info](https://www.fltk.org/doc-1.4/classFl__Text__Display.html#ab9378d48b949f8fc7da04c6be4142c54)
1150 fn wrap_mode(&mut self, wrap: crate::text::WrapMode, wrap_margin: i32);
1151 /// Correct a column number based on an unconstrained position
1152 fn wrapped_column(&self, row: i32, column: i32) -> i32;
1153 /// Correct a row number from an unconstrained position
1154 fn wrapped_row(&self, row: i32) -> i32;
1155 /// Set the grammar underline color
1156 fn set_grammar_underline_color(&mut self, color: Color);
1157 /// Get the grammar underline color
1158 fn grammar_underline_color(&self) -> Color;
1159 /// Set the spelling underline color
1160 fn set_spelling_underline_color(&mut self, color: Color);
1161 /// Get the spelling underline color
1162 fn spelling_underline_color(&self) -> Color;
1163 /// Set the secondary selection color
1164 fn set_secondary_selection_color(&mut self, color: Color);
1165 /// Get the secondary selection color
1166 fn secondary_selection_color(&self) -> Color;
1167 /// Scrolls the text buffer to show the current insert position
1168 fn show_insert_position(&mut self);
1169 /// Overstrikes the current selection or inserts text at cursor
1170 fn overstrike(&mut self, text: &str);
1171 /// Redisplay a range of text
1172 fn redisplay_range(&mut self, start: i32, end: i32);
1173 /// Converts x and y pixel positions into a position in the text buffer
1174 fn xy_to_position(&self, x: i32, y: i32, pos_type: crate::text::PositionType) -> i32;
1175 /// Converts x and y pixel positions into a column and row number
1176 fn xy_to_rowcol(&self, x: i32, y: i32, pos_type: crate::text::PositionType) -> (i32, i32);
1177 /// Returns the number of rows
1178 fn scroll_row(&self) -> i32;
1179 /// Returns the number of columns
1180 fn scroll_col(&self) -> i32;
1181}
1182
1183/// Defines the methods implemented by all browser types
1184/// More info can be found in the [wiki](https://github.com/fltk-rs/fltk-rs/wiki/browsers)
1185/// # Safety
1186/// fltk-rs traits depend on some FLTK internal code
1187/// # Warning
1188/// fltk-rs traits are non-exhaustive,
1189/// to avoid future breakage if you try to implement them manually,
1190/// use the Deref and `DerefMut` pattern or the `widget_extends!` macro
1191pub unsafe trait BrowserExt: WidgetExt {
1192 /// Removes the specified line.
1193 /// Lines start at 1
1194 fn remove(&mut self, line: i32);
1195 /// Adds an item
1196 fn add(&mut self, item: &str);
1197 /// Adds an item with associated data
1198 fn add_with_data<T: Clone + 'static>(&mut self, item: &str, data: T);
1199 /// Inserts an item at an index.
1200 /// Lines start at 1
1201 fn insert(&mut self, line: i32, item: &str);
1202 /// Inserts an item at an index with associated data.
1203 /// Lines start at 1
1204 fn insert_with_data<T: Clone + 'static>(&mut self, line: i32, item: &str, data: T);
1205 /// Moves an item.
1206 /// Lines start at 1
1207 fn move_item(&mut self, to: i32, from: i32);
1208 /// Swaps 2 items.
1209 /// Lines start at 1
1210 fn swap(&mut self, a: i32, b: i32);
1211 /// Clears the browser widget
1212 fn clear(&mut self);
1213 /// Returns the number of items
1214 fn size(&self) -> i32;
1215 /// Select an item at the specified line.
1216 /// Lines start at 1
1217 fn select(&mut self, line: i32);
1218 /// Select an item at the specified line.
1219 /// Lines start at 1
1220 fn deselect(&mut self, line: i32);
1221 /// Returns whether the item is selected
1222 /// Lines start at 1
1223 fn selected(&self, line: i32) -> bool;
1224 /// Returns the text of the item at `line`.
1225 /// Lines start at 1
1226 fn text(&self, line: i32) -> Option<String>;
1227 /// Returns the text of the selected item.
1228 /// Lines start at 1
1229 fn selected_text(&self) -> Option<String>;
1230 /// Sets the text of the selected item.
1231 /// Lines start at 1
1232 fn set_text(&mut self, line: i32, txt: &str);
1233 /// Load a file
1234 /// # Errors
1235 /// Errors on non-existent paths
1236 fn load<P: AsRef<std::path::Path>>(&mut self, path: P) -> Result<(), FltkError>;
1237 /// Return the text size
1238 fn text_size(&self) -> i32;
1239 /// Sets the text size.
1240 /// Lines start at 1
1241 fn set_text_size(&mut self, sz: i32);
1242 /// Sets the icon for browser elements.
1243 /// Lines start at 1
1244 fn set_icon<Img: ImageExt>(&mut self, line: i32, image: Option<Img>);
1245 /// Returns the icon of a browser element.
1246 /// Lines start at 1
1247 fn icon(&self, line: i32) -> Option<Box<dyn ImageExt>>;
1248 /// Removes the icon of a browser element.
1249 /// Lines start at 1
1250 fn remove_icon(&mut self, line: i32);
1251 /// Scrolls the browser so the top item in the browser is showing the specified line.
1252 /// Lines start at 1
1253 fn top_line(&mut self, line: i32);
1254 /// Scrolls the browser so the bottom item in the browser is showing the specified line.
1255 /// Lines start at 1
1256 fn bottom_line(&mut self, line: i32);
1257 /// Scrolls the browser so the middle item in the browser is showing the specified line.
1258 /// Lines start at 1
1259 fn middle_line(&mut self, line: i32);
1260 /// Gets the current format code prefix character, which by default is '\@'.
1261 /// More info [here](https://www.fltk.org/doc-1.3/classFl__Browser.html#a129dca59d64baf166503ba59341add69)
1262 fn format_char(&self) -> char;
1263 /// Sets the current format code prefix character to \p c. The default prefix is '\@'.
1264 /// c should be ascii
1265 fn set_format_char(&mut self, c: char);
1266 /// Gets the current column separator character. The default is '\t'
1267 fn column_char(&self) -> char;
1268 /// Sets the column separator to c. This will only have an effect if you also use `set_column_widths()`.
1269 /// c should be ascii
1270 fn set_column_char(&mut self, c: char);
1271 /// Gets the current column width array
1272 fn column_widths(&self) -> Vec<i32>;
1273 /// Sets the current column width array
1274 fn set_column_widths(&mut self, arr: &[i32]);
1275 /// Returns whether a certain line is displayed
1276 fn displayed(&self, line: i32) -> bool;
1277 /// Makes a specified line visible
1278 fn make_visible(&mut self, line: i32);
1279 /// Gets the vertical scroll position of the list as a pixel position
1280 fn vposition(&self) -> i32;
1281 /// Sets the vertical scroll position of the list as a pixel position
1282 fn set_vposition(&mut self, pos: i32);
1283 /// Gets the horizontal scroll position of the list as a pixel position
1284 fn hposition(&self) -> i32;
1285 /// Sets the horizontal scroll position of the list as a pixel position
1286 fn set_hposition(&mut self, pos: i32);
1287 /// Returns the type of scrollbar associated with the browser
1288 fn has_scrollbar(&self) -> crate::browser::BrowserScrollbar;
1289 /// Sets the type of scrollbar associated with the browser
1290 fn set_has_scrollbar(&mut self, mode: crate::browser::BrowserScrollbar);
1291 /// Gets the scrollbar size
1292 fn scrollbar_size(&self) -> i32;
1293 /// Sets the scrollbar size
1294 fn set_scrollbar_size(&mut self, new_size: i32);
1295 /// Sorts the items of the browser
1296 fn sort(&mut self);
1297 /// Returns the vertical scrollbar
1298 fn scrollbar(&self) -> crate::valuator::Scrollbar;
1299 /// Returns the horizontal scrollbar
1300 fn hscrollbar(&self) -> crate::valuator::Scrollbar;
1301 /// Returns the selected line, returns 0 if no line is selected
1302 fn value(&self) -> i32;
1303 /// Set the data associated with the line
1304 fn set_data<T: Clone + 'static>(&mut self, line: i32, data: T);
1305 /// Get the data associated with the line
1306 /// # Safety
1307 /// Type correctness is insured by the developer
1308 unsafe fn data<T: Clone + 'static>(&self, line: i32) -> Option<T>;
1309 /// Hides a the specified line
1310 fn hide_line(&mut self, line: i32);
1311 /// Gets the selected items
1312 fn selected_items(&self) -> Vec<i32>;
1313}
1314
1315/// Defines the methods implemented by table types.
1316/// More details can be found in the [wiki](https://github.com/fltk-rs/fltk-rs/wiki/tables).
1317/// # Safety
1318/// fltk-rs traits depend on some FLTK internal code
1319/// # Warning
1320/// fltk-rs traits are non-exhaustive,
1321/// to avoid future breakage if you try to implement them manually,
1322/// use the Deref and `DerefMut` pattern or the `widget_extends!` macro
1323pub unsafe trait TableExt: GroupExt {
1324 /// Clears the table
1325 fn clear(&mut self);
1326 /// Sets the table frame
1327 fn set_table_frame(&mut self, frame: FrameType);
1328 /// Gets the table frame
1329 fn table_frame(&self) -> FrameType;
1330 /// Sets the number of rows
1331 fn set_rows(&mut self, val: i32);
1332 /// Gets the number of rows
1333 fn rows(&self) -> i32;
1334 /// Sets the number of columns
1335 fn set_cols(&mut self, val: i32);
1336 /// Gets the number of columns
1337 fn cols(&self) -> i32;
1338 /// The range of row and column numbers for all visible and partially visible cells in the table.
1339 /// Returns (`row_top`, `col_left`, `row_bot`, `col_right`)
1340 fn visible_cells(&self) -> Option<(i32, i32, i32, i32)>;
1341 /// Returns whether the resize is interactive
1342 fn is_interactive_resize(&self) -> bool;
1343 /// Returns whether a row is resizable
1344 fn row_resize(&self) -> bool;
1345 /// Sets a row to be resizable
1346 fn set_row_resize(&mut self, flag: bool);
1347 /// Returns whether a column is resizable
1348 fn col_resize(&self) -> bool;
1349 /// Sets a column to be resizable
1350 fn set_col_resize(&mut self, flag: bool);
1351 /// Returns the current column minimum resize value.
1352 fn col_resize_min(&self) -> i32;
1353 /// Sets the current column minimum resize value.
1354 fn set_col_resize_min(&mut self, val: i32);
1355 /// Returns the current row minimum resize value.
1356 fn row_resize_min(&self) -> i32;
1357 /// Sets the current row minimum resize value.
1358 fn set_row_resize_min(&mut self, val: i32);
1359 /// Returns if row headers are enabled or not
1360 fn row_header(&self) -> bool;
1361 /// Sets whether a row headers are enabled or not
1362 fn set_row_header(&mut self, flag: bool);
1363 /// Returns if column headers are enabled or not
1364 fn col_header(&self) -> bool;
1365 /// Sets whether a column headers are enabled or not
1366 fn set_col_header(&mut self, flag: bool);
1367 /// Sets the column header height
1368 fn set_col_header_height(&mut self, height: i32);
1369 /// Gets the column header height
1370 fn col_header_height(&self) -> i32;
1371 /// Sets the row header width
1372 fn set_row_header_width(&mut self, width: i32);
1373 /// Gets the row header width
1374 fn row_header_width(&self) -> i32;
1375 /// Sets the row header color
1376 fn set_row_header_color(&mut self, val: Color);
1377 /// Gets the row header color
1378 fn row_header_color(&self) -> Color;
1379 /// Sets the column header color
1380 fn set_col_header_color(&mut self, val: Color);
1381 /// Gets the row header color
1382 fn col_header_color(&self) -> Color;
1383 /// Sets the row's height
1384 fn set_row_height(&mut self, row: i32, height: i32);
1385 /// Gets the row's height
1386 fn row_height(&self, row: i32) -> i32;
1387 /// Sets the column's width
1388 fn set_col_width(&mut self, col: i32, width: i32);
1389 /// Gets the column's width
1390 fn col_width(&self, col: i32) -> i32;
1391 /// Sets all rows height
1392 fn set_row_height_all(&mut self, height: i32);
1393 /// Sets all column's width
1394 fn set_col_width_all(&mut self, width: i32);
1395 /// Sets the row's position
1396 fn set_row_position(&mut self, row: i32);
1397 /// Sets the column's position
1398 fn set_col_position(&mut self, col: i32);
1399 /// Gets the row's position
1400 fn row_position(&self) -> i32;
1401 /// Gets the column's position
1402 fn col_position(&self) -> i32;
1403 /// Sets the top row
1404 fn set_top_row(&mut self, row: i32);
1405 /// Gets the top row
1406 fn top_row(&self) -> i32;
1407 /// Returns whether a cell is selected
1408 fn is_selected(&self, r: i32, c: i32) -> bool;
1409 /// Tries to get the selection.
1410 /// Returns an Option((`row_top`, `col_left`, `row_bot`, `col_right`))
1411 fn get_selection(&self) -> Option<(i32, i32, i32, i32)>;
1412 /// Sets the selection
1413 fn set_selection(&mut self, row_top: i32, col_left: i32, row_bot: i32, col_right: i32);
1414 /// Unset selection
1415 fn unset_selection(&mut self);
1416 /// Moves the cursor with shift select
1417 /// # Errors
1418 /// Errors on failure to move the cursor
1419 fn move_cursor_with_shift_select(
1420 &mut self,
1421 r: i32,
1422 c: i32,
1423 shiftselect: bool,
1424 ) -> Result<(), FltkError>;
1425 /// Moves the cursor
1426 /// # Errors
1427 /// Errors on failure to move the cursor
1428 fn move_cursor(&mut self, r: i32, c: i32) -> Result<(), FltkError>;
1429 /// Returns the scrollbar size
1430 fn scrollbar_size(&self) -> i32;
1431 /// Sets the scrollbar size
1432 fn set_scrollbar_size(&mut self, new_size: i32);
1433 /// Sets whether tab key cell navigation is enabled
1434 fn set_tab_cell_nav(&mut self, val: bool);
1435 /// Returns whether tab key cell navigation is enabled
1436 fn tab_cell_nav(&self) -> bool;
1437 /// Override `draw_cell`.
1438 /// callback args: &mut self, `TableContext`, Row: i32, Column: i32, X: i32, Y: i32, Width: i32 and Height: i32.
1439 /// takes the widget as a closure argument
1440 fn draw_cell<
1441 F: FnMut(&mut Self, crate::table::TableContext, i32, i32, i32, i32, i32, i32) + 'static,
1442 >(
1443 &mut self,
1444 cb: F,
1445 );
1446 #[doc(hidden)]
1447 /// INTERNAL: Retrieve the draw cell data
1448 /// # Safety
1449 /// Can return multiple mutable references to the `draw_cell_data`
1450 unsafe fn draw_cell_data(&self) -> Option<Box<dyn FnMut()>>;
1451 /// Get the callback column, should be called from within a callback
1452 fn callback_col(&self) -> i32;
1453 /// Get the callback row, should be called from within a callback
1454 fn callback_row(&self) -> i32;
1455 /// Get the callback context, should be called from within a callback
1456 fn callback_context(&self) -> crate::table::TableContext;
1457 /// Returns the table's vertical scrollbar
1458 fn scrollbar(&self) -> crate::valuator::Scrollbar;
1459 /// Returns the table's horizontal scrollbar
1460 fn hscrollbar(&self) -> crate::valuator::Scrollbar;
1461 /// Returns the Scroll child of the Table
1462 fn scroll(&self) -> Option<crate::group::Scroll>;
1463 /// Find a cell's coords and size by row and column
1464 fn find_cell(
1465 &self,
1466 ctx: crate::table::TableContext,
1467 row: i32,
1468 col: i32,
1469 ) -> Option<(i32, i32, i32, i32)>;
1470 /// Get the cursor to row/col
1471 fn cursor2rowcol(
1472 &self,
1473 ) -> Option<(
1474 crate::table::TableContext,
1475 i32,
1476 i32,
1477 crate::table::TableResizeFlag,
1478 )>;
1479}
1480
1481/// Defines the methods implemented by all image types
1482/// # Safety
1483/// fltk-rs traits depend on some FLTK internal code
1484/// # Warning
1485/// fltk-rs traits are non-exhaustive,
1486/// to avoid future breakage if you try to implement them manually,
1487/// use the Deref and `DerefMut` pattern
1488pub unsafe trait ImageExt {
1489 /// Performs a deep copy of the image
1490 #[must_use]
1491 fn copy(&self) -> Self
1492 where
1493 Self: Sized;
1494 /// Performs a deep copy of the image but to a new size. This will make use of the scaling algorithm when resizing.
1495 #[must_use]
1496 fn copy_sized(&self, w: i32, h: i32) -> Self
1497 where
1498 Self: Sized;
1499 /// Draws the image at the presupplied coordinates and size
1500 fn draw(&mut self, x: i32, y: i32, width: i32, height: i32);
1501 /// Draws the image at the presupplied coordinates and size and offset cx, cy
1502 fn draw_ext(&mut self, x: i32, y: i32, width: i32, height: i32, cx: i32, cy: i32);
1503 /// Return the width of the image
1504 fn w(&self) -> i32;
1505 /// Return the height of the image
1506 fn h(&self) -> i32;
1507 /// Returns a pointer of the image
1508 fn as_image_ptr(&self) -> *mut fltk_sys::image::Fl_Image;
1509 /// Transforms a raw image pointer to an image
1510 /// # Safety
1511 /// The pointer must be valid
1512 unsafe fn from_image_ptr(ptr: *mut fltk_sys::image::Fl_Image) -> Self
1513 where
1514 Self: Sized;
1515 /// Returns the underlying raw rgb image data
1516 fn as_rgb_data(&self) -> Vec<u8>;
1517 /// Transforms the image into an `RgbImage`
1518 /// # Errors
1519 /// Errors on failure to transform to `RgbImage`
1520 fn as_rgb_image(&self) -> Result<crate::image::RgbImage, FltkError>;
1521 /// Scales the image
1522 fn scale(&mut self, width: i32, height: i32, proportional: bool, can_expand: bool);
1523 /// Return the count of pointers in an image (Pixmaps have more than 1, bitmaps have 0, Rgb based images have 1)
1524 fn count(&self) -> i32;
1525 /// Gets the image's data width
1526 fn data_w(&self) -> i32;
1527 /// Gets the image's data height
1528 fn data_h(&self) -> i32;
1529 /// Gets the image's depth
1530 fn depth(&self) -> ColorDepth;
1531 /// Gets the image's line data size
1532 fn ld(&self) -> i32;
1533 /// Greys the image
1534 fn inactive(&mut self);
1535 /// Deletes the image
1536 /// # Safety
1537 /// An image shouldn't be deleted while it's being used by a widget
1538 unsafe fn delete(img: Self)
1539 where
1540 Self: Sized;
1541 /// Checks if the image was deleted
1542 fn was_deleted(&self) -> bool;
1543 /// Transforms an Image base into another Image
1544 /// # Safety
1545 /// Can be unsafe if used to downcast to an image of different format
1546 unsafe fn into_image<I: ImageExt>(self) -> I
1547 where
1548 Self: Sized;
1549 /// Blend the image with color c with weight i in range [0,1]
1550 fn color_average(&mut self, c: crate::enums::Color, i: f32);
1551 /// Desaturate (grayscale) the image
1552 fn desaturate(&mut self);
1553 /// Clear internal caches
1554 fn uncache(&mut self);
1555 /// Set this image as the label image for a menu item
1556 fn label_for_menu_item(&self, item: &mut crate::menu::MenuItem);
1557}
1558
1559#[allow(clippy::return_self_not_must_use)]
1560/// Builder pattern helper
1561pub trait WidgetProps {
1562 /// Initialize to a position x, y
1563 fn with_pos(self, x: i32, y: i32) -> Self
1564 where
1565 Self: Sized;
1566 /// Initialize to size width, height
1567 fn with_size(self, width: i32, height: i32) -> Self
1568 where
1569 Self: Sized;
1570 /// Initialize with a label
1571 fn with_label(self, title: &str) -> Self
1572 where
1573 Self: Sized;
1574 /// Initialize with alignment
1575 fn with_align(self, align: crate::enums::Align) -> Self
1576 where
1577 Self: Sized;
1578 /// Initialize with type
1579 fn with_type<T: WidgetType>(self, typ: T) -> Self
1580 where
1581 Self: Sized;
1582 /// Initialize at bottom of another widget
1583 fn below_of<W: WidgetExt>(self, wid: &W, padding: i32) -> Self
1584 where
1585 Self: Sized;
1586 /// Initialize above of another widget
1587 fn above_of<W: WidgetExt>(self, wid: &W, padding: i32) -> Self
1588 where
1589 Self: Sized;
1590 /// Initialize right of another widget
1591 fn right_of<W: WidgetExt>(self, wid: &W, padding: i32) -> Self
1592 where
1593 Self: Sized;
1594 /// Initialize left of another widget
1595 fn left_of<W: WidgetExt>(self, wid: &W, padding: i32) -> Self
1596 where
1597 Self: Sized;
1598 /// Initialize center of another widget
1599 fn center_of<W: WidgetExt>(self, w: &W) -> Self
1600 where
1601 Self: Sized;
1602 /// Initialize center of another widget on the x axis
1603 fn center_x<W: WidgetExt>(self, w: &W) -> Self
1604 where
1605 Self: Sized;
1606 /// Initialize center of another widget on the y axis
1607 fn center_y<W: WidgetExt>(self, w: &W) -> Self
1608 where
1609 Self: Sized;
1610 /// Initialize center of parent
1611 fn center_of_parent(self) -> Self
1612 where
1613 Self: Sized;
1614 /// Initialize to the size of another widget
1615 fn size_of<W: WidgetExt>(self, w: &W) -> Self
1616 where
1617 Self: Sized;
1618 /// Initialize to the size of the parent
1619 fn size_of_parent(self) -> Self
1620 where
1621 Self: Sized;
1622}
1623
1624/// Defines the methods implemented by all surface types, currently `ImageSurface`
1625pub trait SurfaceDevice {
1626 /// Checks whether this surface is the current surface
1627 fn is_current(&self) -> bool;
1628 /// Get the current surface
1629 fn surface() -> Self;
1630 /// Push a surface as a current surface
1631 fn push_current(new_current: &Self);
1632 /// Pop the current surface
1633 fn pop_current();
1634}
1635
1636/// Defines a set of convenience functions for constructing and anchoring custom widgets.
1637/// Usage: `fltk::widget_extends!(CustomWidget`, `BaseWidget`, member);
1638/// It basically implements Deref and `DerefMut` on the custom widget, and adds the aforementioned methods.
1639/// This means you can call widget methods directly, for e.x. `custom_widget.set_color(enums::Color::Red)`.
1640/// For your custom widget to be treated as a widget it would need dereferencing: `group.add(&*custom_widget);`
1641#[macro_export]
1642macro_rules! widget_extends {
1643 ($widget:ty, $base:ty, $member:tt) => {
1644 $crate::macros::utils::widget_props!($widget);
1645
1646 impl std::ops::Deref for $widget {
1647 type Target = $base;
1648
1649 fn deref(&self) -> &Self::Target {
1650 &self.$member
1651 }
1652 }
1653
1654 impl std::ops::DerefMut for $widget {
1655 fn deref_mut(&mut self) -> &mut Self::Target {
1656 &mut self.$member
1657 }
1658 }
1659 };
1660}
1661
1662pub use crate::app::WidgetId;