pub struct Ui {
pub res: Resources,
pub nodes: Vec<Node>,
pub screen: [i32; 2],
pub sounds: Vec<usize>,
/* private fields */
}Expand description
The interface: the element tree, the resources it uses, and the state of the pointer and the keyboard.
Fields§
§res: ResourcesThe sprite sheets, fonts, element descriptions and strings, loaded once.
nodes: Vec<Node>Every element. A NodeId is an index into this list.
screen: [i32; 2]The screen’s size in pixels.
sounds: Vec<usize>UserInterface::Play requests (sound slots: 4 button down, 5 button up/click, 3 drop),
drained by the application.
Implementations§
Source§impl Ui
impl Ui
Sourcepub fn has_animations(&self) -> bool
pub fn has_animations(&self) -> bool
True if the current tree contains an animated image with frames and a positive frame rate.
Sourcepub fn update(&mut self, dt: f32)
pub fn update(&mut self, dt: f32)
Select each animated image’s frame at the supplied elapsed time in seconds.
The game’s UI step: each element’s own update (AnimatedImageElement::Update, the
containers’ wheel) by dt seconds.
Sourcepub fn update_animations(&mut self, elapsed_seconds: f32)
pub fn update_animations(&mut self, elapsed_seconds: f32)
The viewer’s preview: every animation at elapsed_seconds.
Sourcepub fn animation_info(&self) -> Option<(usize, usize, i32)>
pub fn animation_info(&self) -> Option<(usize, usize, i32)>
Current frame, frame count, and frame rate for the first animated image in the tree.
Sourcepub fn set_animation_frame(&mut self, frame: usize)
pub fn set_animation_frame(&mut self, frame: usize)
Select the same frame in every animated image, wrapping each image’s own frame count.
Source§impl Ui
impl Ui
Sourcepub fn set_value(&mut self, id: NodeId, value: f32)
pub fn set_value(&mut self, id: NodeId, value: f32)
Set the value of a slider, scroll bar or progress bar.
Sourcepub fn value(&self, id: NodeId) -> Option<f32>
pub fn value(&self, id: NodeId) -> Option<f32>
The value of a slider, scroll bar or progress bar.
Sourcepub fn set_slider_range(&mut self, id: NodeId, range: [f32; 2])
pub fn set_slider_range(&mut self, id: NodeId, range: [f32; 2])
Set the smallest and the largest value of a slider.
Sourcepub fn set_table_child(&mut self, table: NodeId, index: usize, child: NodeId)
pub fn set_table_child(&mut self, table: NodeId, index: usize, child: NodeId)
UI::TableElement::SetChild(child, index): put child in cell index (row-major).
Sourcepub fn set_images(&mut self, id: NodeId, sprite: SpriteRef)
pub fn set_images(&mut self, id: NodeId, sprite: SpriteRef)
UI::ImageElement::SetSprite on every image inside id.
Sourcepub fn set_spinner_range(&mut self, id: NodeId, min: i32, max: i32)
pub fn set_spinner_range(&mut self, id: NodeId, min: i32, max: i32)
The range of the spinner’s number edit, its current value clamped to it.
Original: SpinnerElement::SetMinMax, Runtime 0x1800da5b0.
Sourcepub fn spinner_range(&self, id: NodeId) -> Option<(i32, i32)>
pub fn spinner_range(&self, id: NodeId) -> Option<(i32, i32)>
The range of a spinner’s number edit.
Sourcepub fn set_checked(&mut self, id: NodeId, value: bool)
pub fn set_checked(&mut self, id: NodeId, value: bool)
Check or clear a check box.
Sourcepub fn set_choices(&mut self, id: NodeId, choices: Vec<String>)
pub fn set_choices(&mut self, id: NodeId, choices: Vec<String>)
Set the choices of a combo box.
Sourcepub fn set_choices_with_icons(
&mut self,
id: NodeId,
choices: Vec<String>,
icons: Vec<Option<SpriteRef>>,
)
pub fn set_choices_with_icons( &mut self, id: NodeId, choices: Vec<String>, icons: Vec<Option<SpriteRef>>, )
ComboElement::AddItem for each item, its text and sprite.
Sourcepub fn set_graph(
&mut self,
id: NodeId,
y_range: f32,
x_divisions: i32,
series: Vec<(u32, Vec<i32>)>,
)
pub fn set_graph( &mut self, id: NodeId, y_range: f32, x_divisions: i32, series: Vec<(u32, Vec<i32>)>, )
GraphElement::SetYRange, SetXDivisions, RemoveGraphs then AddGraph and
AddGraphPoint for each (colour, points).
Sourcepub fn set_label_sprite_color(&mut self, id: NodeId, color: u32)
pub fn set_label_sprite_color(&mut self, id: NodeId, color: u32)
LabelElement::SetSpriteColor.
Source§impl Ui
impl Ui
Sourcepub fn instantiate_dialog(&mut self, reference: &str) -> Option<DialogInstance>
pub fn instantiate_dialog(&mut self, reference: &str) -> Option<DialogInstance>
Build a dialog from its resource, for example Dialog/MainMenu.rsc:resource.
Sourcepub fn descendant(&self, root: NodeId, node: NodeId) -> bool
pub fn descendant(&self, root: NodeId, node: NodeId) -> bool
Whether node is root or inside it.
Source§impl Ui
impl Ui
Sourcepub fn pointer_over_interactive(&self) -> bool
pub fn pointer_over_interactive(&self) -> bool
Whether the current pointer target is a control that consumes pointer input.
Sourcepub fn cursor_index(&self, id: NodeId, x: i32, y: i32) -> i32
pub fn cursor_index(&self, id: NodeId, x: i32, y: i32) -> i32
DialogInstance::GetMouseCursorIndex: the cursor index of id, unless one of its
visible children holds (x, y), then that child’s, the last such child winning.
Sourcepub fn text_edit_focused(&self) -> bool
pub fn text_edit_focused(&self) -> bool
Whether key input should be reserved for an active text edit control.
Sourcepub fn drain_events(&mut self) -> Vec<Event>
pub fn drain_events(&mut self) -> Vec<Event>
The events since the last call, in order. (A click is returned by
pointer_button instead.)
Sourcepub fn set_shortcut(&mut self, id: NodeId, key: u32)
pub fn set_shortcut(&mut self, id: NodeId, key: u32)
Set the key that clicks an element: an upper-case character code, or 13 (Enter) or 27 (Escape).
Sourcepub fn clear_input(&mut self)
pub fn clear_input(&mut self)
Forget the pointer, the focus and the pending events, for example when the window loses the focus.
Sourcepub fn pointer_move(&mut self, x: i32, y: i32, root: NodeId)
pub fn pointer_move(&mut self, x: i32, y: i32, root: NodeId)
Move the pointer to (x, y) over the tree at root.
Press or release the pointer’s button. Returns the click when a button is released over the element it was pressed on.
Sourcepub fn wheel(&mut self, delta: i32) -> bool
pub fn wheel(&mut self, delta: i32) -> bool
ContainerElement::Update: the wheel over a container queues 7 frames of scrolling
(up for a positive delta), which Ui::update_containers plays out.
Sourcepub fn update_containers(&mut self)
pub fn update_containers(&mut self)
ContainerElement::Update, each frame: one queued wheel frame moves the vertical bar a
seventh of a third of the view (0.33 / 7), within the content.
Sourcepub fn key(&mut self, root: NodeId, key: Key) -> bool
pub fn key(&mut self, root: NodeId, key: Key) -> bool
Press a key. Returns whether the interface used it.
Sourcepub fn text_input(&mut self, text: &str) -> bool
pub fn text_input(&mut self, text: &str) -> bool
Type text into the focused edit box. Returns whether it was used.
Sourcepub fn hovered_tooltip(&self) -> Option<&str>
pub fn hovered_tooltip(&self) -> Option<&str>
The tooltip text of the element under the pointer.
Sourcepub fn place_tooltip(&mut self)
pub fn place_tooltip(&mut self)
Size and place the open tooltip dialog on the pointer (again after the application filled it).
Sourcepub fn new_tooltip(&mut self) -> Option<(NodeId, NodeId, Vec<u32>)>
pub fn new_tooltip(&mut self) -> Option<(NodeId, NodeId, Vec<u32>)>
The tooltip dialog opened since the last call: source element, dialog root and the
dialog’s controller ids. Application controllers fill it, then call place_tooltip.
Sourcepub fn set_parameters(&mut self, id: NodeId, values: &[(usize, &str)])
pub fn set_parameters(&mut self, id: NodeId, values: &[(usize, &str)])
UI::TextElement::SetParameter on a text or label whose text still holds its template.
Source§impl Ui
impl Ui
Sourcepub fn instantiate(&mut self, reference: &str) -> Option<NodeId>
pub fn instantiate(&mut self, reference: &str) -> Option<NodeId>
Build a node tree from an element reference such as Dialog\MainMenu.rsc:main.
Source§impl Ui
impl Ui
Sourcepub fn layout(&mut self, root: NodeId, rect: [i32; 4])
pub fn layout(&mut self, root: NodeId, rect: [i32; 4])
Size and lay out root inside the given rectangle.
Sourcepub fn layout_dialog(&mut self, root: NodeId, rect: [i32; 4])
pub fn layout_dialog(&mut self, root: NodeId, rect: [i32; 4])
Lay out a dialog’s root element: placed at its own size by its alignment within rect
(DialogInstance::ComputeLayout), unlike ordinary groups which fill.
Original: Runtime 0x180116620.
Source§impl Ui
impl Ui
Sourcepub fn query(&self, roots: &[NodeId], query: &Query) -> Vec<NodeId> ⓘ
pub fn query(&self, roots: &[NodeId], query: &Query) -> Vec<NodeId> ⓘ
Every shown element below roots (and the roots themselves) that matches query, in
tree order with duplicates removed.
Sourcepub fn kind_name(&self, id: NodeId) -> &'static str
pub fn kind_name(&self, id: NodeId) -> &'static str
A short lower-case name for an element’s kind: group, ribbon, border, image,
animation, button, text, label, viewport, list, lines, picture,
unsupported, or for a control check, slider, scroll, edit, combo, and so on.
Sourcepub fn text_of(&self, id: NodeId) -> String
pub fn text_of(&self, id: NodeId) -> String
An element’s text: its own for text, labels and edits, its content’s for a button.
Sourcepub fn info(&self, id: NodeId) -> ElementInfo
pub fn info(&self, id: NodeId) -> ElementInfo
What a query reports about id.
Source§impl Ui
impl Ui
Sourcepub fn find(&self, root: NodeId, name: &str) -> Option<NodeId>
pub fn find(&self, root: NodeId, name: &str) -> Option<NodeId>
Depth-first search for a node by element name below root.
Sourcepub fn children(&self, id: NodeId) -> Vec<NodeId> ⓘ
pub fn children(&self, id: NodeId) -> Vec<NodeId> ⓘ
Return every node rendered or owned directly below this node, including
control and button content that is stored outside Node::children.
Sourcepub fn set_text(&mut self, id: NodeId, text: &str)
pub fn set_text(&mut self, id: NodeId, text: &str)
Replace the text of a Text/Label node, or of a Button’s content.
Sourcepub fn set_icon(&mut self, id: NodeId, sprite: SpriteRef)
pub fn set_icon(&mut self, id: NodeId, sprite: SpriteRef)
LabelElement::SetSprite on a label, or on a combo’s label (ComboElement::UpdateText
sets the chosen item’s sprite when it has one).
Sourcepub fn select_combo_item(&mut self, combo: NodeId, index: usize)
pub fn select_combo_item(&mut self, combo: NodeId, index: usize)
A combo’s item index: the list’s selection, the label’s text and the item’s sprite.
Sourcepub fn set_visible(&mut self, id: NodeId, visible: bool)
pub fn set_visible(&mut self, id: NodeId, visible: bool)
Show or hide an element.
Sourcepub fn ribbon(&mut self, vertical: bool, spacing: i32) -> NodeId
pub fn ribbon(&mut self, vertical: bool, spacing: i32) -> NodeId
Add an empty ribbon: a row, or a column when vertical.
Sourcepub fn text(&mut self, font: &str, text: &str) -> NodeId
pub fn text(&mut self, font: &str, text: &str) -> NodeId
Add a text element with a font reference and a text.
Sourcepub fn list(&mut self, font: &str) -> NodeId
pub fn list(&mut self, font: &str) -> NodeId
A scrolling list using the game font and the White dialog sprite for highlights.
Sourcepub fn slider(&mut self, range: [f32; 2]) -> NodeId
pub fn slider(&mut self, range: [f32; 2]) -> NodeId
Create a simple horizontal slider with a built-in solid track and knob.
Sourcepub fn set_list_items(&mut self, id: NodeId, items: Vec<String>)
pub fn set_list_items(&mut self, id: NodeId, items: Vec<String>)
Set the rows of a list.
Sourcepub fn set_list_icons(
&mut self,
id: NodeId,
items: Vec<String>,
icons: Vec<Option<SpriteRef>>,
)
pub fn set_list_icons( &mut self, id: NodeId, items: Vec<String>, icons: Vec<Option<SpriteRef>>, )
Self::set_list_items with each item’s sprite.
Sourcepub fn list_select(&mut self, id: NodeId, index: Option<usize>)
pub fn list_select(&mut self, id: NodeId, index: Option<usize>)
Select a row of a list, or none.