[][src]Struct pugl_ui::ui::UI

pub struct UI<RW: Widget + 'static> { /* fields omitted */ }

The central interface between application, widgets and the windowing system

The UI has the following responsibilities.

  • retain references to the widgets

  • receive events from the windowing system and pass them to the relevant widgets

  • lend widgets to the application, so the application can check the state of the widgets.

  • supervise widget layouting

Event propagation

The UI receives events from the windowing system. Depending on the context (mouse cursor position, kind of event, focused widget, ...) the UI passes the event to the widget that should receive the event. If that widget does not processes the event, the event can then be passed to another widget, usually the parent of the widget. This is done by the following rules.

Keyboard events

Keyboard events are first passed to the root widget, i.e. the widget that has been passed to the constructor of the UI.

If the root widget does not process the event, the event is passed to the focused widget. There are the methods focus_widget() and focus_next_widget() to set the focus to a specific widget.

Mouse events

A mouse events goes to the widget that is under the mouse pointer. Widgets are kept in a tree of WidgetNodes. If the widget under the pointer does not process the event, it is passed to its parent.

Exeption: mouse dragging

When a mouse dragging is ongoing, the widget in which the mouse dragging started, receives, mouse events and key events first, until the dragging stops.

Implementations

impl<RW: Widget + 'static> UI<RW>[src]

pub fn new(view: PuglViewFFI, root_widget: Box<RW>) -> UI<RW>[src]

Creates a new UI instance from a PuglViewFFI and a heap allocated root widget

The UI instance needs a PuglViewFFI instance from the pugl-sys crate as interface to the windowing system.

pub fn new_scaled(
    view: PuglViewFFI,
    root_widget: Box<RW>,
    scale_factor: f64
) -> UI<RW>
[src]

Creates a new UI which is scaled by the scale_factor

Widgets don't know about the scale factor. They can do their drawing and event processing as if the scale_factor was 1.0. The UI everything including the cairo::Context transparently.

pub fn new_widget<W: Widget>(&mut self, widget: Box<W>) -> WidgetHandle<W>[src]

Registers a new widget in the UI.

The instance of the widget must be passed heap allocated in a Box. Returns a WidgetHandle to the widget.

pub fn new_layouter<L>(&mut self) -> LayoutWidgetHandle<L, LayoutWidget> where
    L: Layouter
[src]

Creates a new LayoutingWidget for a Layouter of type L and registers it to the UI/

Returns a LayoutWidgetHandle to the Layouter` object.

pub fn add_spacer<L>(
    &mut self,
    parent: LayoutWidgetHandle<L, LayoutWidget>,
    target: L::Target
) where
    L: Layouter
[src]

Adds a spacing widget to a layouter.

This is a convenience function

pub fn pack_to_layout<L, W, PW>(
    &mut self,
    widget: WidgetHandle<W>,
    parent: LayoutWidgetHandle<L, PW>,
    target: L::Target
) where
    L: Layouter,
    W: Widget,
    PW: Widget
[src]

Adds the widget to a layout according to the layout target. The target is specific to the actual Layouter type L

pub fn do_layout(&mut self)[src]

Performs the layouting of the widgets.

This must be done before the view is realized (or window is shown). All registered widgets should have been packed to a layout before.

pub fn fit_window_size(&self)[src]

Sets the default window size, so that the widget layout fits into it.

pub fn fit_window_min_size(&self)[src]

Sets the minimal window size, so that the widget layout fits into it.

pub fn close_request_issued(&self) -> bool[src]

Returns true iff a the window has been requested to close by the windowing system

The application should check for this at every cycle of the event loop and terminate the event loop if true is returned.

pub fn layouter<L, W>(
    &mut self,
    layouter: LayoutWidgetHandle<L, W>
) -> &mut L::Implementor where
    L: Layouter,
    W: Widget
[src]

Returns a mutable reference to the Layouter of the passed LayoutWidgetHandle.

This can be used to borrow a handle to the layouter in order to change layouting parameters.

pub fn root_layout(&self) -> LayoutWidgetHandle<VerticalLayouter, RW>[src]

Returns a mutable reference to the Layouter of root Layouter.

This can be used to borrow a handle to the layouter in order to change layouting parameters.

pub fn root_widget(&mut self) -> &mut RW[src]

Returns a mutable reference to the root widget.

pub fn widget<W: Widget>(&mut self, widget: WidgetHandle<W>) -> &mut W[src]

Returns a mutable reference to the specified by widget.

It returns a reference to the actual widget instance, so type specific methods of the widget can be used.

pub fn focus_next_widget(&mut self)[src]

Performs a step in the cycle of the widget focus.

Can be called when the root widget received a TAB key press event.

pub fn focus_widget<W: Widget>(&mut self, widget: WidgetHandle<W>)[src]

Focuses the widget specified by widget

pub fn has_focus(&self) -> bool[src]

Returns true iff the window has the focus.

pub fn next_event(&mut self, timeout: f64)[src]

Initiates the next cycle of the event loop

The application should call it at the beginning of the event loop.

From pugl documentation: If timeout is zero, then this function will not block. Plugins should always use a timeout of zero to avoid blocking the host.

If a positive timeout is given, then events will be processed for that amount of time, starting from when this function was called.

If a negative timeout is given, this function will block indefinitely until an event occurs.

For continuously animating programs, a timeout that is a reasonable fraction of the ideal frame period should be used, to minimize input latency by ensuring that as many input events are consumed as possible before drawing.

Trait Implementations

impl<RW: Widget> PuglViewTrait for UI<RW>[src]

Auto Trait Implementations

impl<RW> !RefUnwindSafe for UI<RW>

impl<RW> !Send for UI<RW>

impl<RW> !Sync for UI<RW>

impl<RW> Unpin for UI<RW> where
    RW: Unpin

impl<RW> !UnwindSafe for UI<RW>

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Downcast for T where
    T: Any
[src]

impl<T> DowncastSync for T where
    T: Send + Sync + Any
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.