Trait WidgetBase

pub unsafe trait WidgetBase: WidgetExt {
    // Required methods
    fn new<'a, T>(x: i32, y: i32, width: i32, height: i32, title: T) -> Self
       where T: Into<Option<&'a str>>;
    fn default_fill() -> Self;
    fn delete(wid: Self)
       where Self: Sized;
    unsafe fn from_widget_ptr(ptr: *mut Fl_Widget) -> Self;
    unsafe fn from_widget<W>(w: W) -> Self
       where W: WidgetExt;
    fn handle<F>(&mut self, cb: F)
       where F: FnMut(&mut Self, Event) -> bool + 'static;
    fn draw<F>(&mut self, cb: F)
       where F: FnMut(&mut Self) + 'static;
    fn resize_callback<F>(&mut self, cb: F)
       where F: FnMut(&mut Self, i32, i32, i32, i32) + 'static;

    // Provided methods
    unsafe fn assume_derived(&mut self) { ... }
    fn from_dyn_widget<W>(_w: &W) -> Option<Self> 
       where W: WidgetExt,
             Self: Sized { ... }
    fn from_dyn_widget_ptr(_w: *mut Fl_Widget) -> Option<Self> 
       where Self: Sized { ... }
}
Available on crate feature dep_fltk only.
Expand description

Defines the extended methods implemented by all widgets

§Safety

fltk-rs traits depend on some FLTK internal code

§Warning

fltk-rs traits are non-exhaustive, to avoid future breakage if you try to implement them manually, use the Deref and DerefMut pattern or the widget_extends! macro

Required Methods§

fn new<'a, T>(x: i32, y: i32, width: i32, height: i32, title: T) -> Self
where T: Into<Option<&'a str>>,

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 screen
  • y - The y coordinate in the screen
  • width - The width of the widget
  • heigth - The height of the widget
  • title - 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.

fn default_fill() -> Self

Constructs a widget with the size of its parent

fn delete(wid: Self)
where Self: Sized,

Deletes widgets and their children.

unsafe fn from_widget_ptr(ptr: *mut Fl_Widget) -> Self

transforms a widget pointer to a Widget, for internal use

§Safety

The pointer must be valid

unsafe fn from_widget<W>(w: W) -> Self
where W: WidgetExt,

Get a widget from base widget

§Safety

The underlying object must be valid

fn handle<F>(&mut self, cb: F)
where F: FnMut(&mut Self, Event) -> bool + 'static,

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 here

fn draw<F>(&mut self, cb: F)
where F: FnMut(&mut Self) + 'static,

Set a custom draw method. takes the widget as a closure argument. macOS requires that WidgetBase::draw actually calls drawing functions

fn resize_callback<F>(&mut self, cb: F)
where F: FnMut(&mut Self, i32, i32, i32, i32) + 'static,

Perform a callback on resize. Avoid resizing the parent or the same widget to avoid infinite recursion

Provided Methods§

unsafe fn assume_derived(&mut self)

Makes the widget derived

§Safety

Calling this on a non-derived widget can cause undefined behavior

fn from_dyn_widget<W>(_w: &W) -> Option<Self>
where W: WidgetExt, Self: Sized,

Cast a type-erased widget back to its original widget

fn from_dyn_widget_ptr(_w: *mut Fl_Widget) -> Option<Self>
where Self: Sized,

Cast a type-erased widget pointer back to its original widget

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

§

impl WidgetBase for Browser

§

impl WidgetBase for CheckBrowser

§

impl WidgetBase for FileBrowser

§

impl WidgetBase for HoldBrowser

§

impl WidgetBase for MultiBrowser

§

impl WidgetBase for SelectBrowser

§

impl WidgetBase for Button

§

impl WidgetBase for CheckButton

§

impl WidgetBase for LightButton

§

impl WidgetBase for RadioButton

§

impl WidgetBase for RadioLightButton

§

impl WidgetBase for RadioRoundButton

§

impl WidgetBase for RepeatButton

§

impl WidgetBase for ReturnButton

§

impl WidgetBase for RoundButton

§

impl WidgetBase for ShortcutButton

§

impl WidgetBase for ToggleButton

§

impl WidgetBase for Frame

§

impl WidgetBase for ColorChooser

§

impl WidgetBase for Flex

§

impl WidgetBase for Grid

§

impl WidgetBase for Group

§

impl WidgetBase for Pack

§

impl WidgetBase for Scroll

§

impl WidgetBase for Tabs

§

impl WidgetBase for Tile

§

impl WidgetBase for Wizard

§

impl WidgetBase for FileInput

§

impl WidgetBase for FloatInput

§

impl WidgetBase for Input

§

impl WidgetBase for IntInput

§

impl WidgetBase for MultilineInput

§

impl WidgetBase for SecretInput

§

impl WidgetBase for Choice

§

impl WidgetBase for MenuBar

§

impl WidgetBase for MenuButton

§

impl WidgetBase for SysMenuBar

§

impl WidgetBase for Chart

§

impl WidgetBase for Clock

§

impl WidgetBase for HelpView

§

impl WidgetBase for InputChoice

§

impl WidgetBase for Progress

§

impl WidgetBase for Spinner

§

impl WidgetBase for MultilineOutput

§

impl WidgetBase for Output

§

impl WidgetBase for Table

§

impl WidgetBase for TableRow

§

impl WidgetBase for Terminal

§

impl WidgetBase for SimpleTerminal

§

impl WidgetBase for TextDisplay

§

impl WidgetBase for TextEditor

§

impl WidgetBase for Tree

§

impl WidgetBase for Adjuster

§

impl WidgetBase for Counter

§

impl WidgetBase for Dial

§

impl WidgetBase for FillDial

§

impl WidgetBase for FillSlider

§

impl WidgetBase for HorFillSlider

§

impl WidgetBase for HorNiceSlider

§

impl WidgetBase for HorSlider

§

impl WidgetBase for HorValueSlider

§

impl WidgetBase for LineDial

§

impl WidgetBase for NiceSlider

§

impl WidgetBase for Roller

§

impl WidgetBase for Scrollbar

§

impl WidgetBase for Slider

§

impl WidgetBase for ValueInput

§

impl WidgetBase for ValueOutput

§

impl WidgetBase for ValueSlider

§

impl WidgetBase for Widget

§

impl WidgetBase for DoubleWindow

§

impl WidgetBase for MenuWindow

§

impl WidgetBase for OverlayWindow

§

impl WidgetBase for SingleWindow