Struct conrod::Ui
[−]
[src]
pub struct Ui<C> { pub theme: Theme, pub glyph_cache: GlyphCache<C>, 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 WidgetId.
- 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.
win_w: f64
Window width.
win_h: f64
Window height.
Methods
impl<C> Ui<C>
[src]
fn new(character_cache: C, theme: Theme) -> Ui<C>
Constructor for a UiContext.
fn widget_size(&self, id: WidgetId) -> Dimensions
Return the dimensions of a widget.
fn handle_event<E: GenericEvent>(&mut self, event: &E)
Handle game events and update the state.
fn get_xy(&self, maybe_idx: Option<Index>, position: Position, dim: Dimensions, h_align: HorizontalAlign, v_align: VerticalAlign) -> Point
Get the centred xy coords for some given Dimension
s, Position
and alignment.
If getting the xy for a widget, its ID should be specified so that we can also consider the
scroll offset of the scrollable parent widgets.
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 a SAFE_REDRAW_COUNT
. See the docs for SAFE_REDRAW_COUNT or draw_if_changed
for
more info on how/why the redraw count is used.
fn element(&mut self) -> &Element
Compiles the Ui
's entire widget Graph
in its current state into a single
elmesque::Element
and returns a reference to it.
This allows a user to take all information necessary for drawing within a single type,
which can be sent across threads or used to draw later on rather than drawing the whole
graph immediately (as does the Ui::draw
method).
Producing an Element
also allows for simpler interoperation with elmesque
(a purely
functional graphics layout crate which conrod uses internally).
fn element_if_changed(&mut self) -> Option<&Element>
Same as Ui::element
, but only returns an &Element
if the stored &Element
has changed
since the last time Ui::element
or Ui::element_if_changed
was called.
fn draw<G>(&mut self, context: Context, graphics: &mut G) where C: CharacterCache, G: Graphics<Texture=C::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.
See the Graph::draw
method for more details on how Widgets are drawn.
See the graph::update_visit_order
function for details on how the render order is
determined.
fn draw_if_changed<G>(&mut self, context: Context, graphics: &mut G) where C: CharacterCache, G: Graphics<Texture=C::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
produces a new
Element
because its state has changed.
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.