pub trait ActionContainer {
// Required methods
fn find_element_by_id(&self, id: usize) -> Option<&Self>;
fn find_element_by_str_id(&self, str_id: &str) -> Option<&Self>;
fn find_element_by_class(&self, class: &str) -> Option<&Self>;
fn get_id(&self) -> usize;
fn get_str_id(&self) -> Option<&str>;
fn get_children(&self) -> &[Self]
where Self: Sized;
fn get_data_attrs(&self) -> Option<&BTreeMap<String, String>>;
fn get_calculated_dimensions(&self) -> Option<(f32, f32)>;
fn get_calculated_position(&self) -> Option<(f32, f32)>;
}Expand description
Trait for container types that can be used with the action system
§Implementation Example
To integrate with an existing Container type from hyperchad_transformer:
ⓘ
use hyperchad_actions::handler::ActionContainer;
use hyperchad_transformer::Container;
impl ActionContainer for Container {
fn find_element_by_id(&self, id: usize) -> Option<&Self> {
self.find_element_by_id(id)
}
fn find_element_by_str_id(&self, str_id: &str) -> Option<&Self> {
self.find_element_by_str_id(str_id)
}
fn find_element_by_class(&self, class: &str) -> Option<&Self> {
self.find_element_by_class(class)
}
fn get_id(&self) -> usize {
self.id
}
fn get_str_id(&self) -> Option<&str> {
self.str_id.as_deref()
}
fn get_children(&self) -> &[Self] {
&self.children
}
fn get_data_attrs(&self) -> Option<&std::collections::BTreeMap<String, String>> {
Some(&self.data)
}
fn get_calculated_dimensions(&self) -> Option<(f32, f32)> {
Some((self.calculated_width?, self.calculated_height?))
}
fn get_calculated_position(&self) -> Option<(f32, f32)> {
Some((
self.calculated_x.unwrap_or(0.0),
self.calculated_y.unwrap_or(0.0),
))
}
}Required Methods§
Sourcefn find_element_by_id(&self, id: usize) -> Option<&Self>
fn find_element_by_id(&self, id: usize) -> Option<&Self>
Find element by ID
Sourcefn find_element_by_str_id(&self, str_id: &str) -> Option<&Self>
fn find_element_by_str_id(&self, str_id: &str) -> Option<&Self>
Find element by string ID
Sourcefn find_element_by_class(&self, class: &str) -> Option<&Self>
fn find_element_by_class(&self, class: &str) -> Option<&Self>
Find element by class name
Sourcefn get_str_id(&self) -> Option<&str>
fn get_str_id(&self) -> Option<&str>
Get string ID
Sourcefn get_children(&self) -> &[Self]where
Self: Sized,
fn get_children(&self) -> &[Self]where
Self: Sized,
Get children
Sourcefn get_calculated_dimensions(&self) -> Option<(f32, f32)>
fn get_calculated_dimensions(&self) -> Option<(f32, f32)>
Get calculated dimensions if available
Sourcefn get_calculated_position(&self) -> Option<(f32, f32)>
fn get_calculated_position(&self) -> Option<(f32, f32)>
Get calculated position if available
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".