Partial implementation of the WindowDom system

This commit is contained in:
Keavon Chambers
2021-03-27 01:20:51 -07:00
parent 9a5185b5e6
commit 54425bfb9e
4 changed files with 128 additions and 19 deletions
+11 -10
View File
@@ -7,15 +7,15 @@ use std::collections::HashSet;
use std::fs;
use std::io;
pub struct LayoutSystem {
windows: Vec<WindowDom>,
pub struct LayoutSystem<'a> {
windows: Vec<WindowDom<'a>>,
loaded_components: ResourceCache<FlatComponent>,
attribute_parser: AttributeParser,
}
impl LayoutSystem {
impl<'a> LayoutSystem<'a> {
/// Construct the `LayoutSystem` with zero windows, an empty cache of component XML layouts, and an `AttributeParser` with its regex parsers
pub fn new() -> LayoutSystem {
pub fn new() -> Self {
Self {
windows: vec![],
loaded_components: ResourceCache::new(),
@@ -24,17 +24,18 @@ impl LayoutSystem {
}
/// Load and construct a new window from a layout component
pub fn add_window(&mut self, name: (&str, &str)) {
pub fn add_window(&'a mut self, name: (&str, &str)) {
// Preload the component and its dependencies
self.preload_component(name)
.expect(&format!("Failure loading layout component '{}'", Self::component_name(name))[..]);
// Get the now-loaded component
let window_root_component_name = Self::component_name(name);
let window_root_component = self.loaded_components.get(&window_root_component_name[..]).unwrap();
// let window_root_component = self.loaded_components.get(&window_root_component_name[..]).unwrap();
// println!("FC: {:#?}", window_root_component);
// Construct the window and save it
let new_window = WindowDom::new(window_root_component);
let new_window = WindowDom::new(&window_root_component_name[..], (1920, 1080), &self.loaded_components);
self.windows.push(new_window);
}
@@ -67,7 +68,7 @@ impl LayoutSystem {
}
// Go through each parameter attribute and preload any default values of layouts
for definition in &component.own_info.user_attributes {
for definition in &component.own_info.parameters {
for default in definition.type_sequence_default.iter() {
if let TypeValue::Layout(layouts) = default {
for layout in layouts {
@@ -175,7 +176,7 @@ impl LayoutSystem {
}).collect::<Vec<_>>();
cloned_tag.set_content(children);
// Return this LayoutComponentTag within the component's root definition tag
// Return this `LayoutComponentTag` within the component's root definition tag
Some(cloned_tag)
})
.collect::<Vec<_>>();
@@ -338,7 +339,7 @@ impl LayoutSystem {
}
/// Get a string in `namespace:name` format (or just `name` for primitives) given a namespace and component name
fn component_name(name: (&str, &str)) -> String {
pub fn component_name(name: (&str, &str)) -> String {
let (namespace, file) = name;
if namespace.len() > 0 {
format!("{}:{}", namespace, file)