Struct conrod::UiCell
[−]
[src]
pub struct UiCell<'a, B: 'a> where B: Backend {
// some fields omitted
}
A wrapper around the Ui
that restricts the user from mutating the Ui
in certain ways while
in the scope of the Ui::set_widgets
function and within Widget
s' update
methods. Using
the UiCell
, users may access the Ui
immutably (via Deref
) however they wish, however they
may only mutate the Ui
via the &mut self
methods provided by the UiCell
.
The name came from its likening to a "jail cell for the Ui
", as it restricts a user's access
to it. However, we realise that the name may also cause ambiguity with the std Cell
and
RefCell
types (which UiCell
has nothing to do with). Thus, if you have a better name for
this type in mind, please let us know at the github repo via an issue or PR sometime before we
hit 1.0.0!
Methods
impl<'a, B> UiCell<'a, B> where B: Backend
[src]
fn theme(&self) -> &Theme
A reference to the Theme
that is currently active within the Ui
.
fn glyph_cache(&self) -> &GlyphCache<B::CharacterCache>
A reference to the Ui
's GlyphCache
.
fn window_dim(&self) -> Dimensions
Returns the dimensions of the window
fn global_input(&self) -> &Global
Returns an immutable reference to the input::Global
of the Ui
.
All coordinates here will be relative to the center of the window.
fn widget_input<I: Into<Index>>(&self, idx: I) -> Widget
Returns a input::Widget
with input events for the widget.
All coordinates in the input::Widget
will be relative to the widget at the given index.
fn new_unique_node_index(&mut self) -> NodeIndex
Generate a new, unique NodeIndex into a Placeholder node within the Ui
's widget graph.
This should only be called once for each unique widget needed to avoid unnecessary bloat
within the Ui
's widget graph.
When using this method in your Widget
's update
method, be sure to store the returned
NodeIndex somewhere within your Widget::State
so that it can be re-used on next update.
Panics if adding another node would exceed the maximum capacity for node indices.
fn kids_bounding_box<I: Into<Index>>(&self, idx: I) -> Option<Rect>
The Rect that bounds the kids of the widget with the given index.
Returns None
if the widget has no children or if there's is no widget for the given index.
fn scroll_widget<I>(&mut self, widget_idx: I, offset: [Scalar; 2]) where I: Into<Index>
Scroll the widget at the given index by the given offset amount.
The produced Scroll
event will be pushed to the pending_scroll_events
and will be
applied to the widget during the next call to Ui::set_widgets
.
Methods from Deref<Target=Ui<B>>
fn widget_input<I: Into<Index>>(&self, widget: I) -> Widget
Returns a input::Widget
for the given widget
fn rect_of<I: Into<Index>>(&self, idx: I) -> Option<Rect>
The Rect for the widget at the given index.
Returns None
if there is no widget for the given index.
fn w_of<I: Into<Index>>(&self, idx: I) -> Option<Scalar>
The absolute width of the widget at the given index.
Returns None
if there is no widget for the given index.
fn h_of<I: Into<Index>>(&self, idx: I) -> Option<Scalar>
The absolute height of the widget at the given index.
Returns None
if there is no widget for the given index.
fn wh_of<I: Into<Index>>(&self, idx: I) -> Option<Dimensions>
The absolute dimensions for the widget at the given index.
Returns None
if there is no widget for the given index.
fn xy_of<I: Into<Index>>(&self, idx: I) -> Option<Point>
The coordinates for the widget at the given index.
Returns None
if there is no widget for the given index.
fn kid_area_of<I: Into<Index>>(&self, idx: I) -> Option<Rect>
The kid_area
of the widget at the given index.
Returns None
if there is no widget for the given index.
fn maybe_prev_widget(&self) -> Option<Index>
An index to the previously updated widget if there is one.
fn widget_graph(&self) -> &Graph
Borrow the Ui's widget_graph
.
fn updated_widgets(&self) -> &HashSet<NodeIndex>
Borrow the Ui's set of updated widgets.
This set indicates which widgets have been instantiated since the beginning of the most
recent Ui::set_widgets
call.
fn prev_updated_widgets(&self) -> &HashSet<NodeIndex>
Borrow the Ui's set of updated widgets.
This set indicates which widgets have were instantiated during the previous call to
Ui::set_widgets
.
fn scroll_widget<I>(&mut self, widget_idx: I, offset: [Scalar; 2]) where I: Into<Index>
Scroll the widget at the given index by the given offset amount.
The produced Scroll
event will be applied upon the next call to Ui::set_widgets
.
fn handle_event<E>(&mut self, event: E) where E: ToRawEvent
Handle raw window events and update the Ui
state accordingly.
This occurs within several stages:
- Convert the user's given
event
to aRawEvent
so that theUi
may use it. - Interpret the
RawEvent
for higher-levelEvent
s such asDoubleClick
,WidgetCapturesKeyboard
, etc. - Update the
Ui
'sglobal_input
State
accordingly, depending on theRawEvent
. - Store newly produced
event::Ui
s within theglobal_input
so that they may be filtered and fed toWidget
s next timeUi::set_widget
is called.
This method drives the Ui
forward, and is what allows for using conrod's Ui
with any
window event stream.
The given event
must implement the ToRawEvent trait so that it can be converted to a
RawEvent
that can be used by the Ui
.
fn calc_xy(&self, maybe_idx: Option<Index>, x_position: Position, y_position: Position, dim: Dimensions, place_on_kid_area: bool) -> Point
Get the centred xy coords for some given Dimension
s, Position
and alignment.
If getting the xy for a specific widget, its widget::Index
should be specified so that we
can also consider the scroll offset of the scrollable parent widgets.
The place_on_kid_area
argument specifies whether or not Place Position variants
should target a Widget's kid_area
, or simply the Widget's total area.
fn set_widgets<F>(&mut self, user_widgets_fn: F) where F: FnOnce(UiCell<B>)
A function within which all widgets are instantiated by the user, normally situated within the "update" stage of an event loop.
fn set_num_redraw_frames(&mut self, num_frames: u8)
Set the number of frames that the Ui
should draw in the case that needs_redraw
is
called. The default is 3
(see the SAFE_REDRAW_COUNT docs for details).
fn needs_redraw(&mut self)
Tells the Ui
that it needs to be re-draw everything. It does this by setting the redraw
count to num_redraw_frames
. See the docs for set_num_redraw_frames
, SAFE_REDRAW_COUNT
or draw_if_changed
for more info on how/why the redraw count is used.
fn draw<G>(&mut self, context: Context, graphics: &mut G) where G: Graphics<Texture=B::Texture>
Draw the Ui
in it's current state.
NOTE: If you don't need to redraw your conrod GUI every frame, it is recommended to use the
Ui::draw_if_changed
method instead.
fn draw_if_changed<G>(&mut self, context: Context, graphics: &mut G) where G: Graphics<Texture=B::Texture>
Same as the Ui::draw
method, but only draws if the redraw_count
is greater than 0.
The redraw_count
is set to SAFE_REDRAW_COUNT
whenever a Widget
indicates that it
needs to be re-drawn.
It can also be triggered manually by the user using the Ui::needs_redraw
method.
This method is generally preferred over Ui::draw
as it requires far less CPU usage, only
redrawing to the screen if necessary.
Note that when Ui::needs_redraw
is triggered, it sets the redraw_count
to 3 by default.
This ensures that conrod is drawn to each buffer in the case that there is buffer swapping
happening. Let us know if you need finer control over this and we'll expose a way for you
to set the redraw count manually.
fn kids_bounding_box<I: Into<Index>>(&self, idx: I) -> Option<Rect>
The Rect that bounds the kids of the widget with the given index.
fn visible_area<I: Into<Index>>(&self, idx: I) -> Option<Rect>
The Rect that represents the maximum fully visible area for the widget with the given index, including consideration of cropped scroll area.
Otherwise, return None if the widget is not visible.
Trait Implementations
impl<'a, B> Deref for UiCell<'a, B> where B: Backend
[src]
type Target = Ui<B>
The resulting type after dereferencing
fn deref(&self) -> &Ui<B>
The method called to dereference a value