diff --git a/gui/README.md b/gui/README.md index d59fb9dca..bbef92510 100644 --- a/gui/README.md +++ b/gui/README.md @@ -17,13 +17,13 @@ Layout is controlled using predefined attributes, such as `width`, `height`, `x- ## Component lifetime -The children of a component are passed to it as a `content` attribute. For example, looking at the row component: +The children of a component are passed to it as a `children` attribute. For example, looking at the row component: ```xml - + {{INNER_XML}} ``` -The `content` attribute defines a new variable `INNER_XML` of type `Layout` which can contain more XML layout structure. It has a default value of `[[]]` which refers to an empty layout— XML syntax (for the `Layout` data type) written in a tag's attribute is wrapped in ``[[`` (opening) and `]]` (closing) symbols. In this case the `INNER_XML` variable defaults to empty XML, however it is not stricly useful here because the `content` attribute will always have its value replaced by whatever exists between opening and closing tags when this component is called from elsewhere. +The `children` attribute defines a new variable `INNER_XML` of type `Layout` which can contain more XML layout structure. It has a default value of `[[]]` which refers to an empty layout— XML syntax (for the `Layout` data type) written in a tag's attribute is wrapped in ``[[`` (opening) and `]]` (closing) symbols. In this case the `INNER_XML` variable defaults to empty XML, however it is not strictly useful here because the `children` attribute will always have its value replaced by whatever exists between opening and closing tags when this component is called from elsewhere. This is then expanded in the body of the row: `{{INNER_XML}}`. diff --git a/gui/box.xml b/gui/box.xml index 29034b60b..d42c70173 100644 --- a/gui/box.xml +++ b/gui/box.xml @@ -1,3 +1,3 @@ - + {{INNER_XML}} diff --git a/gui/col.xml b/gui/col.xml index 015a1f8cd..6e35a920d 100644 --- a/gui/col.xml +++ b/gui/col.xml @@ -1,3 +1,3 @@ - + {{INNER_XML}} diff --git a/gui/icon.xml b/gui/icon.xml index bce3573cd..7cee7db69 100644 --- a/gui/icon.xml +++ b/gui/icon.xml @@ -1,3 +1,3 @@ - + {{INNER_XML}} diff --git a/gui/if.xml b/gui/if.xml index 8d05e0c20..2b381dc56 100644 --- a/gui/if.xml +++ b/gui/if.xml @@ -1,3 +1,3 @@ - + {{RESULT}} diff --git a/gui/input/checkbox-with-dropdown.xml b/gui/input/checkbox-with-dropdown.xml index 0c3e1e137..838c5d803 100644 --- a/gui/input/checkbox-with-dropdown.xml +++ b/gui/input/checkbox-with-dropdown.xml @@ -1,4 +1,4 @@ - + diff --git a/gui/input/dropdown.xml b/gui/input/dropdown.xml index add69cdfd..44d261b81 100644 --- a/gui/input/dropdown.xml +++ b/gui/input/dropdown.xml @@ -1,4 +1,4 @@ - + diff --git a/gui/row.xml b/gui/row.xml index 001905682..664d2d490 100644 --- a/gui/row.xml +++ b/gui/row.xml @@ -1,3 +1,3 @@ - + {{INNER_XML}} diff --git a/gui/text.xml b/gui/text.xml index 341d1aa28..a4a1564b1 100644 --- a/gui/text.xml +++ b/gui/text.xml @@ -1 +1 @@ - + diff --git a/src/application.rs b/src/application.rs index fad4a597d..cd6f6f4c1 100644 --- a/src/application.rs +++ b/src/application.rs @@ -85,7 +85,7 @@ impl Application { // Main window in the XML layout language let mut main_window_layout = LayoutSystem::new(); - main_window_layout.add_window(("window", "main")); + main_window_layout.add_window(("window", "main"), (1920, 1080)); Self { surface, diff --git a/src/layout_abstract_syntax.rs b/src/layout_abstract_syntax.rs index 24b09932d..8d60a713e 100644 --- a/src/layout_abstract_syntax.rs +++ b/src/layout_abstract_syntax.rs @@ -9,9 +9,9 @@ pub struct FlatComponent { pub child_components: Vec, } -/// A component in its final processed form (after parsing its XML file), with information on its definition with a list of child components with their own children in their `content` attributes +/// A component in its final processed form (after parsing its XML file), with information on its definition with a list of child components with their own children in their `children` attributes impl FlatComponent { - // Construct a layout component which stores its own root-level component definition (with prop definitions, etc.) and a flat list of its direct child tags, each with an AST in their `content` attribute + // Construct a layout component which stores its own root-level component definition (with prop definitions, etc.) and a flat list of its direct child tags, each with an AST in their `children` attribute pub fn new(own_info: LayoutComponentDefinition, child_components: Vec) -> FlatComponent { Self { own_info, child_components } } @@ -99,7 +99,7 @@ impl LayoutComponentDefinition { // ==================================================================================================== -/// Abstract representation of a tag inside an abstract component with attributes and descendant content +/// Abstract representation of a tag inside an abstract component with attributes and children #[derive(Debug, Clone, PartialEq)] pub struct LayoutComponentTag { /// Namespace and name of the tag's referenced component @@ -108,8 +108,8 @@ pub struct LayoutComponentTag { pub layout: LayoutAttributes, /// Props on this tag, which are prefixed with ':' pub props: Vec, - /// The special content attribute, containing the inner elements of this tag - pub content: Option>, + /// The special `children` attribute, containing the inner elements of this tag + pub children: Option>, } impl LayoutComponentTag { @@ -118,14 +118,14 @@ impl LayoutComponentTag { Self { name, layout: Default::default(), - content: None, + children: None, props: Vec::new(), } } - /// Provide a sequence of ASTs for this component's content attribute - pub fn set_content(&mut self, content: Vec) { - self.content = Some(content); + /// Provide a sequence of ASTs for this component's special `children` attribute + pub fn set_children(&mut self, children: Vec) { + self.children = Some(children); } /// Add an XML tag attribute to this component (either a layout engine setting, a prop, or an event handler binding) @@ -170,8 +170,8 @@ impl LayoutComponentTag { /// Print the layout tag (for debugging) pub fn debug_print(&self) { println!("Tag Node: {:#?}", self); - if let Some(ref content) = self.content { - for child in content { + if let Some(ref children) = self.children { + for child in children { for node in child.descendants() { println!("> Descendant Node: {:#?}", node); } diff --git a/src/layout_system.rs b/src/layout_system.rs index 3c28da869..5e270f2bf 100644 --- a/src/layout_system.rs +++ b/src/layout_system.rs @@ -24,7 +24,7 @@ impl<'a> LayoutSystem<'a> { } /// Load and construct a new window from a layout component - pub fn add_window(&'a mut self, name: (&str, &str)) { + pub fn add_window(&'a mut self, name: (&str, &str), window_size: (u32, u32)) { // Preload the component and its dependencies self.preload_component(name) .expect(&format!("Failure loading layout component '{}'", Self::component_name(name))[..]); @@ -33,7 +33,7 @@ impl<'a> LayoutSystem<'a> { let window_root_component_name = Self::component_name(name); // Construct the window and save it - let new_window = WindowDom::new(&window_root_component_name[..], (1920, 1080), &self.loaded_components); + let new_window = WindowDom::new(&window_root_component_name[..], window_size, &self.loaded_components); self.windows.push(new_window); } @@ -117,9 +117,9 @@ impl<'a> LayoutSystem<'a> { } } - // Explore the tree of `content` children - if let Some(ref content) = tag.content { - for child_node in content.iter() { + // Explore the tree of the `children` elements stored in this component + if let Some(ref children) = tag.children { + for child_node in children.iter() { for descendant in child_node.descendants() { match &*descendant.borrow() { LayoutComponentNode::Tag(component_tag) => self.explore_component_tag(component_tag, already_loaded_layouts), @@ -144,7 +144,7 @@ impl<'a> LayoutSystem<'a> { Ok(Self::node_tree_from_node_or_def_tree(&parsed_tree)) } - /// Flatten a full XML component AST into a vector of the immediate children and put the descendants of those nodes into `content` attributes + /// Flatten a full XML component AST into a vector of the immediate children and put the descendants of those nodes into `children` attributes fn flatten_component_tree(tree: &mut NodeOrDefTree) -> FlatComponent { let own_info = match &*tree.borrow() { LayoutComponentNodeOrDefinition::LayoutComponentDefinition(definition) => definition.clone(), @@ -152,11 +152,11 @@ impl<'a> LayoutSystem<'a> { LayoutComponentNodeOrDefinition::LayoutComponentNode(LayoutComponentNode::Text(_)) => panic!("Text node found in place of component definition"), }; - // Turn all the tag nodes (but not text nodes) into a list of flat child components (with their descendant trees in their `content` attributes) + // Turn all the tag nodes (but not text nodes) into a list of flat child components (with their descendant trees in their `children` attributes) let child_components = tree // Get the direct children from this tree node .children() - // Clone each child abstract tag node (ignoring text nodes) with each of their descendants added to their `content` attribute variable + // Clone each child abstract tag node (ignoring text nodes) with each of their descendants added to their `children` attribute variable .filter_map(|child_node| { // Filter out text nodes because they make no sense as child components let mut cloned_tag = match &*child_node.borrow() { @@ -165,14 +165,14 @@ impl<'a> LayoutSystem<'a> { LayoutComponentNodeOrDefinition::LayoutComponentDefinition(_) => panic!("Component definition found in place of tag node"), }; - // Clone the tree for this child as `LayoutComponentNode`s and turn its children into a vector, then set that vector as the content attribute + // Clone the tree for this child as `LayoutComponentNode`s and turn its children into a vector, then set that vector as the `children` attribute let node_within_root = Self::node_tree_from_node_or_def_tree(&child_node); let children = node_within_root.children().map(|mut child| { // Child must be detached in order to live on its own in the vector, otherwise it will be cleaned up when its (former) parent is dropped child.detach(); child }).collect::>(); - cloned_tag.set_content(children); + cloned_tag.set_children(children); // Return this `LayoutComponentTag` within the component's root definition tag Some(cloned_tag)