[−][src]Struct pugl_ui::ui::UI
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
WidgetNode
s. 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]
view: PuglViewFFI,
root_widget: Box<RW>,
scale_factor: f64
) -> UI<RW>
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]
L: Layouter,
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]
&mut self,
parent: LayoutWidgetHandle<L, LayoutWidget>,
target: L::Target
) where
L: Layouter,
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]
&mut self,
widget: WidgetHandle<W>,
parent: LayoutWidgetHandle<L, PW>,
target: L::Target
) where
L: Layouter,
W: Widget,
PW: Widget,
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]
&mut self,
layouter: LayoutWidgetHandle<L, W>
) -> &mut L::Implementor where
L: Layouter,
W: Widget,
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]
fn exposed(&mut self, expose: &ExposeArea, cr: &Context)
[src]
fn event(&mut self, ev: Event) -> Status
[src]
fn focus_in(&mut self) -> Status
[src]
fn focus_out(&mut self) -> Status
[src]
fn resize(&mut self, size: Size)
[src]
fn close_request(&mut self)
[src]
fn timer_event(&mut self, id: usize) -> Status
[src]
fn view(&self) -> PuglViewFFI
[src]
fn world(&self) -> *mut PuglWorldImpl
[src]
fn post_redisplay(&self) -> Status
[src]
fn post_redisplay_rect(&self, pos: Coord, size: Size) -> Status
[src]
fn get_frame(&self) -> Rect
[src]
fn set_frame(&self, frame: Rect) -> Status
[src]
fn set_default_size(&self, width: i32, height: i32) -> Status
[src]
fn set_min_size(&self, width: i32, height: i32) -> Status
[src]
fn set_max_size(&self, width: i32, height: i32) -> Status
[src]
fn set_aspect_ratio(
&self,
min_x: i32,
min_y: i32,
max_x: i32,
max_y: i32
) -> Status
[src]
&self,
min_x: i32,
min_y: i32,
max_x: i32,
max_y: i32
) -> Status
fn make_resizable(&self) -> Status
[src]
fn set_window_title(&self, title: &str) -> Status
[src]
fn realize(&self) -> Status
[src]
fn show_window(&self) -> Status
[src]
fn hide_window(&self) -> Status
[src]
fn is_visible(&self) -> bool
[src]
fn set_cursor(&self, c: Cursor) -> Status
[src]
fn update(&self, timeout: f64) -> Status
[src]
fn start_timer(&self, id: usize, timeout: f64) -> Status
[src]
fn stop_timer(&self, id: usize) -> Status
[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,
RW: Unpin,
impl<RW> !UnwindSafe for UI<RW>
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Downcast for T where
T: Any,
[src]
T: Any,
fn into_any(self: Box<T>) -> Box<dyn Any + 'static>
[src]
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any + 'static>
[src]
fn as_any(&self) -> &(dyn Any + 'static)
[src]
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
[src]
impl<T> DowncastSync for T where
T: Send + Sync + Any,
[src]
T: Send + Sync + Any,
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,