Struct conrod::Ui [] [src]

pub struct Ui<C> {
    pub theme: Theme,
    pub glyph_cache: GlyphCache<C>,
    pub window: NodeIndex,
    pub win_w: f64,
    pub win_h: f64,
    // some fields omitted
}

Ui is the most important type within Conrod and is necessary for rendering and maintaining widget state.

Ui Handles the following:

  • Contains the state of all widgets which can be indexed via their widget::Index.
  • Stores rendering state for each widget until the end of each render cycle.
  • Contains the theme used for default styling of the widgets.
  • Maintains the latest user input state (for mouse and keyboard).
  • Maintains the latest window dimensions.

Fields

theme: Theme

The theme used to set default styling for widgets.

glyph_cache: GlyphCache<C>

Cache for character textures, used for label width calculation and glyph rendering.

window: NodeIndex

An index into the root widget of the graph, representing the entire window.

win_w: f64

Window width.

win_h: f64

Window height.

Methods

impl<C> Ui<C>
[src]

fn new(character_cache: C, theme: Theme) -> Self

A new, empty Ui.

fn with_capacity(character_cache: C, theme: Theme, n_widgets: usize) -> Self

A new Ui with the capacity given as a number of widgets.

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 width_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 height_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 dim_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 handle_event<E: GenericEvent>(&mut self, event: &E)

Handle game events and update the state.

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 Dimensions, 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 C: CharacterCache, F: FnOnce(&mut Self)

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, C: CharacterCache<Texture=G::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, C: CharacterCache<Texture=G::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.