pub struct CallbackInfo<'a> {Show 18 fields
pub state: &'a RefAny,
pub current_window_state: &'a FullWindowState,
pub modifiable_window_state: &'a mut WindowState,
pub layout_result: &'a BTreeMap<DomId, LayoutResult>,
pub scrolled_nodes: &'a BTreeMap<DomId, ScrolledNodes>,
pub cached_display_list: &'a CachedDisplayList,
pub gl_context: Rc<dyn Gl>,
pub resources: &'a mut AppResources,
pub timers: &'a mut FastHashMap<TimerId, Timer>,
pub tasks: &'a mut Vec<Task>,
pub ui_state: &'a BTreeMap<DomId, UiState>,
pub stop_propagation: &'a mut bool,
pub focus_target: &'a mut Option<FocusTarget>,
pub current_scroll_states: &'a BTreeMap<DomId, BTreeMap<NodeId, ScrollPosition>>,
pub nodes_scrolled_in_callback: &'a mut BTreeMap<DomId, BTreeMap<NodeId, LayoutPoint>>,
pub hit_dom_node: (DomId, NodeId),
pub cursor_relative_to_item: Option<(f32, f32)>,
pub cursor_in_viewport: Option<(f32, f32)>,
}
Expand description
Information about the callback that is passed to the callback whenever a callback is invoked
Fields§
§state: &'a RefAny
Your data (the global struct which all callbacks will have access to)
current_window_state: &'a FullWindowState
State of the current window that the callback was called on (read only!)
modifiable_window_state: &'a mut WindowState
User-modifiable state of the window that the callback was called on
layout_result: &'a BTreeMap<DomId, LayoutResult>
Currently active, layouted rectangles
scrolled_nodes: &'a BTreeMap<DomId, ScrolledNodes>
Nodes that overflow their parents and are able to scroll
cached_display_list: &'a CachedDisplayList
Current display list active in this window (useful for debugging)
gl_context: Rc<dyn Gl>
An Rc to the OpenGL context, in order to be able to render to OpenGL textures
resources: &'a mut AppResources
§timers: &'a mut FastHashMap<TimerId, Timer>
Currently running timers (polling functions, run on the main thread)
tasks: &'a mut Vec<Task>
Currently running tasks (asynchronous functions running each on a different thread)
ui_state: &'a BTreeMap<DomId, UiState>
UiState containing the necessary data for testing what
stop_propagation: &'a mut bool
Sets whether the event should be propagated to the parent hit node or not
focus_target: &'a mut Option<FocusTarget>
The callback can change the focus_target - note that the focus_target is set before the next frames’ layout() function is invoked, but the current frames callbacks are not affected.
current_scroll_states: &'a BTreeMap<DomId, BTreeMap<NodeId, ScrollPosition>>
Immutable (!) reference to where the nodes are currently scrolled (current position)
nodes_scrolled_in_callback: &'a mut BTreeMap<DomId, BTreeMap<NodeId, LayoutPoint>>
Mutable map where a user can set where he wants the nodes to be scrolled to (for the next frame)
hit_dom_node: (DomId, NodeId)
The ID of the DOM + the node that was hit. You can use this to query
information about the node, but please don’t hard-code any if / else
statements based on the NodeId
cursor_relative_to_item: Option<(f32, f32)>
The (x, y) position of the mouse cursor, relative to top left of the element that was hit.
cursor_in_viewport: Option<(f32, f32)>
The (x, y) position of the mouse cursor, relative to top left of the window.
Implementations§
Source§impl<'a> CallbackInfo<'a>
impl<'a> CallbackInfo<'a>
Sourcepub fn stop_propagation(&mut self)
pub fn stop_propagation(&mut self)
Sets whether the event should be propagated to the parent hit node or not
Similar to e.stopPropagation()
in JavaScript
Source§impl<'a> CallbackInfo<'a>
impl<'a> CallbackInfo<'a>
pub fn window_state(&self) -> &FullWindowState
pub fn window_state_mut(&mut self) -> &mut WindowState
pub fn get_keyboard_state(&self) -> &KeyboardState
pub fn get_mouse_state(&self) -> &MouseState
Sourcepub fn get_bounds(
&self,
(dom_id, node_id): &(DomId, NodeId),
) -> Option<&PositionedRectangle>
pub fn get_bounds( &self, (dom_id, node_id): &(DomId, NodeId), ) -> Option<&PositionedRectangle>
Returns the bounds (width / height / position / margins / border) for any given NodeId, useful for calculating scroll positions / offsets
Sourcepub fn get_words(&self, (dom_id, node_id): &(DomId, NodeId)) -> Option<&Words>
pub fn get_words(&self, (dom_id, node_id): &(DomId, NodeId)) -> Option<&Words>
If the node is a text node, return the text of the node
Sourcepub fn get_scaled_words(
&self,
(dom_id, node_id): &(DomId, NodeId),
) -> Option<&ScaledWords>
pub fn get_scaled_words( &self, (dom_id, node_id): &(DomId, NodeId), ) -> Option<&ScaledWords>
If the node is a text node, return the shaped glyphs (on a per-word basis, unpositioned)
Sourcepub fn get_word_positions(
&self,
(dom_id, node_id): &(DomId, NodeId),
) -> Option<&WordPositions>
pub fn get_word_positions( &self, (dom_id, node_id): &(DomId, NodeId), ) -> Option<&WordPositions>
If the node is a text node, return the shaped glyphs (on a per-word basis, unpositioned)
pub fn get_layouted_glyphs( &self, (dom_id, node_id): &(DomId, NodeId), ) -> Option<&LayoutedGlyphs>
Sourcepub fn get_current_scroll_position(
&self,
(dom_id, node_id): &(DomId, NodeId),
) -> Option<ScrollPosition>
pub fn get_current_scroll_position( &self, (dom_id, node_id): &(DomId, NodeId), ) -> Option<ScrollPosition>
Returns information about the current scroll position of a node, such as the size of the scroll frame, the position of the scroll in the parent (how far the node has been scrolled), as well as the size of the parent node (so that things like “scroll to left edge”, etc. are easy to calculate).
Sourcepub fn get_index_in_parent(
&self,
node_id: &(DomId, NodeId),
) -> Option<(usize, (DomId, NodeId))>
pub fn get_index_in_parent( &self, node_id: &(DomId, NodeId), ) -> Option<(usize, (DomId, NodeId))>
For any node ID, returns what the position in its parent it is, plus the parent itself.
Returns None
on the root ID (because the root has no parent, therefore it’s the 1st item)
Note: Index is 0-based (first item has the index of 0)
Sourcepub fn get_node(&self, (dom_id, node_id): &(DomId, NodeId)) -> Option<&Node>
pub fn get_node(&self, (dom_id, node_id): &(DomId, NodeId)) -> Option<&Node>
Returns the hierarchy of the given node ID
Sourcepub fn get_parent_node_id(
&self,
node_id: &(DomId, NodeId),
) -> Option<(DomId, NodeId)>
pub fn get_parent_node_id( &self, node_id: &(DomId, NodeId), ) -> Option<(DomId, NodeId)>
Returns the parent of the given NodeId
or None if the target is the root node.
Sourcepub fn get_node_hierarchy(&self) -> &NodeHierarchy
pub fn get_node_hierarchy(&self) -> &NodeHierarchy
Returns the node hierarchy (DOM tree order)
Sourcepub fn get_node_content(
&self,
(dom_id, node_id): &(DomId, NodeId),
) -> Option<&NodeData>
pub fn get_node_content( &self, (dom_id, node_id): &(DomId, NodeId), ) -> Option<&NodeData>
Returns the node content of a specific node
Sourcepub fn target_index_in_parent(&self) -> Option<usize>
pub fn target_index_in_parent(&self) -> Option<usize>
Returns the index of the target NodeId (the target that received the event) in the targets parent or None if the target is the root node
Sourcepub fn target_parent_node_id(&self) -> Option<(DomId, NodeId)>
pub fn target_parent_node_id(&self) -> Option<(DomId, NodeId)>
Returns the parent of the current target or None if the target is the root node.
Sourcepub fn target_is_node_type(&self, node_type: NodeType) -> bool
pub fn target_is_node_type(&self, node_type: NodeType) -> bool
Checks whether the target of the CallbackInfo has a certain node type
Sourcepub fn target_has_id(&self, id: &str) -> bool
pub fn target_has_id(&self, id: &str) -> bool
Checks whether the target of the CallbackInfo has a certain ID
Sourcepub fn target_has_class(&self, class: &str) -> bool
pub fn target_has_class(&self, class: &str) -> bool
Checks whether the target of the CallbackInfo has a certain class
Sourcepub fn any_parent_has_id(&self, id: &str) -> Option<(DomId, NodeId)>
pub fn any_parent_has_id(&self, id: &str) -> Option<(DomId, NodeId)>
Traverses up the hierarchy, checks whether any parent has a certain ID, the returns that parent
Sourcepub fn any_parent_has_class(&self, class: &str) -> Option<(DomId, NodeId)>
pub fn any_parent_has_class(&self, class: &str) -> Option<(DomId, NodeId)>
Traverses up the hierarchy, checks whether any parent has a certain class
Sourcepub fn scroll_node(
&mut self,
(dom_id, node_id): &(DomId, NodeId),
scroll_location: LayoutPoint,
)
pub fn scroll_node( &mut self, (dom_id, node_id): &(DomId, NodeId), scroll_location: LayoutPoint, )
Scrolls a node to a certain position
Sourcepub fn scroll_target(&mut self, scroll_location: LayoutPoint)
pub fn scroll_target(&mut self, scroll_location: LayoutPoint)
Scrolls a node to a certain position
Sourcepub fn parent_nodes<'c>(&'c self) -> ParentNodesIterator<'c> ⓘ
pub fn parent_nodes<'c>(&'c self) -> ParentNodesIterator<'c> ⓘ
Creates an iterator that starts at the current DOM node and continouusly
returns the parent (DomId, NodeId)
, until the iterator gets to the root DOM node.
Sourcepub fn set_focus_from_path(&mut self, path: CssPath)
pub fn set_focus_from_path(&mut self, path: CssPath)
Sets the focus_target by using an already-parsed CssPath
.
Sourcepub fn set_focus_from_node_id(&mut self, id: (DomId, NodeId))
pub fn set_focus_from_node_id(&mut self, id: (DomId, NodeId))
Set the focus_target of the window to a specific div using a NodeId
.
Note that this ID will be dependent on the position in the DOM and therefore the next frames UI must be the exact same as the current one, otherwise the focus_target will be cleared or shifted (depending on apps setting).
Sourcepub fn clear_focus(&mut self)
pub fn clear_focus(&mut self)
Clears the focus_target for the next frame.
Sourcepub fn add_timer(&mut self, id: TimerId, timer: Timer)
pub fn add_timer(&mut self, id: TimerId, timer: Timer)
Insert a timer into the list of active timers. Replaces the existing timer if called with the same TimerId.
Sourcepub fn has_timer(&self, timer_id: &TimerId) -> bool
pub fn has_timer(&self, timer_id: &TimerId) -> bool
Returns if a timer with the given ID is currently running
Sourcepub fn get_timer(&self, timer_id: &TimerId) -> Option<&Timer>
pub fn get_timer(&self, timer_id: &TimerId) -> Option<&Timer>
Returns a reference to an existing timer (if the TimerId
is valid)
Sourcepub fn delete_timer(&mut self, timer_id: &TimerId) -> Option<Timer>
pub fn delete_timer(&mut self, timer_id: &TimerId) -> Option<Timer>
Deletes a timer and returns it (if the TimerId
is valid)
Sourcepub fn add_task(&mut self, task: Task)
pub fn add_task(&mut self, task: Task)
Adds a (thread-safe) Task
to the app that runs on a different thread
Sourcepub fn get_gl_context(&self) -> Rc<dyn Gl>
pub fn get_gl_context(&self) -> Rc<dyn Gl>
Returns a reference-counted pointer to the OpenGL context