From 8b8f7563ad33dafeadf6238e377748cdec17d67a Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Tue, 10 Sep 2019 19:41:49 +0200 Subject: Switch to workspace layout --- src/widget/row.rs | 219 ------------------------------------------------------ 1 file changed, 219 deletions(-) delete mode 100644 src/widget/row.rs (limited to 'src/widget/row.rs') diff --git a/src/widget/row.rs b/src/widget/row.rs deleted file mode 100644 index 959528dc..00000000 --- a/src/widget/row.rs +++ /dev/null @@ -1,219 +0,0 @@ -use std::hash::Hash; - -use crate::{ - Align, Element, Event, Hasher, Justify, Layout, MouseCursor, Node, Point, - Style, Widget, -}; - -/// A container that distributes its contents horizontally. -/// -/// A [`Row`] will try to fill the horizontal space of its container. -/// -/// [`Row`]: struct.Row.html -#[derive(Default)] -pub struct Row<'a, Message, Renderer> { - style: Style, - spacing: u16, - children: Vec>, -} - -impl<'a, Message, Renderer> std::fmt::Debug for Row<'a, Message, Renderer> { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - f.debug_struct("Row") - .field("style", &self.style) - .field("spacing", &self.spacing) - .field("children", &self.children) - .finish() - } -} - -impl<'a, Message, Renderer> Row<'a, Message, Renderer> { - /// Creates an empty [`Row`]. - /// - /// [`Row`]: struct.Row.html - pub fn new() -> Self { - Row { - style: Style::default().fill_width(), - spacing: 0, - children: Vec::new(), - } - } - - /// Sets the horizontal spacing _between_ elements in pixels. - /// - /// Custom margins per element do not exist in Iced. You should use this - /// method instead! While less flexible, it helps you keep spacing between - /// elements consistent. - pub fn spacing(mut self, px: u16) -> Self { - self.spacing = px; - self - } - - /// Sets the padding of the [`Row`] in pixels. - /// - /// [`Row`]: struct.Row.html - pub fn padding(mut self, px: u16) -> Self { - self.style = self.style.padding(px); - self - } - - /// Sets the width of the [`Row`] in pixels. - /// - /// [`Row`]: struct.Row.html - pub fn width(mut self, width: u16) -> Self { - self.style = self.style.width(width); - self - } - - /// Sets the height of the [`Row`] in pixels. - /// - /// [`Row`]: struct.Row.html - pub fn height(mut self, height: u16) -> Self { - self.style = self.style.height(height); - self - } - - /// Sets the maximum width of the [`Row`] in pixels. - /// - /// [`Row`]: struct.Row.html - pub fn max_width(mut self, max_width: u16) -> Self { - self.style = self.style.max_width(max_width); - self - } - - /// Sets the maximum height of the [`Row`] in pixels. - /// - /// [`Row`]: struct.Row.html - pub fn max_height(mut self, max_height: u16) -> Self { - self.style = self.style.max_height(max_height); - self - } - - /// Sets the alignment of the [`Row`] itself. - /// - /// This is useful if you want to override the default alignment given by - /// the parent container. - /// - /// [`Row`]: struct.Row.html - pub fn align_self(mut self, align: Align) -> Self { - self.style = self.style.align_self(align); - self - } - - /// Sets the vertical alignment of the contents of the [`Row`] . - /// - /// [`Row`]: struct.Row.html - pub fn align_items(mut self, align: Align) -> Self { - self.style = self.style.align_items(align); - self - } - - /// Sets the horizontal distribution strategy for the contents of the - /// [`Row`] . - /// - /// [`Row`]: struct.Row.html - pub fn justify_content(mut self, justify: Justify) -> Self { - self.style = self.style.justify_content(justify); - self - } - - /// Adds an [`Element`] to the [`Row`]. - /// - /// [`Element`]: ../struct.Element.html - /// [`Row`]: struct.Row.html - pub fn push(mut self, child: E) -> Row<'a, Message, Renderer> - where - E: Into>, - { - self.children.push(child.into()); - self - } -} - -impl<'a, Message, Renderer> Widget - for Row<'a, Message, Renderer> -{ - fn node(&self, renderer: &Renderer) -> Node { - let mut children: Vec = self - .children - .iter() - .map(|child| { - let mut node = child.widget.node(renderer); - - let mut style = node.0.style(); - style.margin.end = - stretch::style::Dimension::Points(f32::from(self.spacing)); - - node.0.set_style(style); - node - }) - .collect(); - - if let Some(node) = children.last_mut() { - let mut style = node.0.style(); - style.margin.end = stretch::style::Dimension::Undefined; - - node.0.set_style(style); - } - - Node::with_children(self.style, children) - } - - fn on_event( - &mut self, - event: Event, - layout: Layout<'_>, - cursor_position: Point, - messages: &mut Vec, - ) { - self.children.iter_mut().zip(layout.children()).for_each( - |(child, layout)| { - child - .widget - .on_event(event, layout, cursor_position, messages) - }, - ); - } - - fn draw( - &self, - renderer: &mut Renderer, - layout: Layout<'_>, - cursor_position: Point, - ) -> MouseCursor { - let mut cursor = MouseCursor::OutOfBounds; - - self.children.iter().zip(layout.children()).for_each( - |(child, layout)| { - let new_cursor = - child.widget.draw(renderer, layout, cursor_position); - - if new_cursor != MouseCursor::OutOfBounds { - cursor = new_cursor; - } - }, - ); - - cursor - } - - fn hash_layout(&self, state: &mut Hasher) { - self.style.hash(state); - self.spacing.hash(state); - - for child in &self.children { - child.widget.hash_layout(state); - } - } -} - -impl<'a, Message, Renderer> From> - for Element<'a, Message, Renderer> -where - Renderer: 'a, - Message: 'static, -{ - fn from(row: Row<'a, Message, Renderer>) -> Element<'a, Message, Renderer> { - Element::new(row) - } -} -- cgit From a97401aed2a173260a4abfdb65a77975ce6c0f01 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Sat, 14 Sep 2019 19:16:06 +0200 Subject: Rethink workspace structure --- src/widget/row.rs | 219 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 219 insertions(+) create mode 100644 src/widget/row.rs (limited to 'src/widget/row.rs') diff --git a/src/widget/row.rs b/src/widget/row.rs new file mode 100644 index 00000000..959528dc --- /dev/null +++ b/src/widget/row.rs @@ -0,0 +1,219 @@ +use std::hash::Hash; + +use crate::{ + Align, Element, Event, Hasher, Justify, Layout, MouseCursor, Node, Point, + Style, Widget, +}; + +/// A container that distributes its contents horizontally. +/// +/// A [`Row`] will try to fill the horizontal space of its container. +/// +/// [`Row`]: struct.Row.html +#[derive(Default)] +pub struct Row<'a, Message, Renderer> { + style: Style, + spacing: u16, + children: Vec>, +} + +impl<'a, Message, Renderer> std::fmt::Debug for Row<'a, Message, Renderer> { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_struct("Row") + .field("style", &self.style) + .field("spacing", &self.spacing) + .field("children", &self.children) + .finish() + } +} + +impl<'a, Message, Renderer> Row<'a, Message, Renderer> { + /// Creates an empty [`Row`]. + /// + /// [`Row`]: struct.Row.html + pub fn new() -> Self { + Row { + style: Style::default().fill_width(), + spacing: 0, + children: Vec::new(), + } + } + + /// Sets the horizontal spacing _between_ elements in pixels. + /// + /// Custom margins per element do not exist in Iced. You should use this + /// method instead! While less flexible, it helps you keep spacing between + /// elements consistent. + pub fn spacing(mut self, px: u16) -> Self { + self.spacing = px; + self + } + + /// Sets the padding of the [`Row`] in pixels. + /// + /// [`Row`]: struct.Row.html + pub fn padding(mut self, px: u16) -> Self { + self.style = self.style.padding(px); + self + } + + /// Sets the width of the [`Row`] in pixels. + /// + /// [`Row`]: struct.Row.html + pub fn width(mut self, width: u16) -> Self { + self.style = self.style.width(width); + self + } + + /// Sets the height of the [`Row`] in pixels. + /// + /// [`Row`]: struct.Row.html + pub fn height(mut self, height: u16) -> Self { + self.style = self.style.height(height); + self + } + + /// Sets the maximum width of the [`Row`] in pixels. + /// + /// [`Row`]: struct.Row.html + pub fn max_width(mut self, max_width: u16) -> Self { + self.style = self.style.max_width(max_width); + self + } + + /// Sets the maximum height of the [`Row`] in pixels. + /// + /// [`Row`]: struct.Row.html + pub fn max_height(mut self, max_height: u16) -> Self { + self.style = self.style.max_height(max_height); + self + } + + /// Sets the alignment of the [`Row`] itself. + /// + /// This is useful if you want to override the default alignment given by + /// the parent container. + /// + /// [`Row`]: struct.Row.html + pub fn align_self(mut self, align: Align) -> Self { + self.style = self.style.align_self(align); + self + } + + /// Sets the vertical alignment of the contents of the [`Row`] . + /// + /// [`Row`]: struct.Row.html + pub fn align_items(mut self, align: Align) -> Self { + self.style = self.style.align_items(align); + self + } + + /// Sets the horizontal distribution strategy for the contents of the + /// [`Row`] . + /// + /// [`Row`]: struct.Row.html + pub fn justify_content(mut self, justify: Justify) -> Self { + self.style = self.style.justify_content(justify); + self + } + + /// Adds an [`Element`] to the [`Row`]. + /// + /// [`Element`]: ../struct.Element.html + /// [`Row`]: struct.Row.html + pub fn push(mut self, child: E) -> Row<'a, Message, Renderer> + where + E: Into>, + { + self.children.push(child.into()); + self + } +} + +impl<'a, Message, Renderer> Widget + for Row<'a, Message, Renderer> +{ + fn node(&self, renderer: &Renderer) -> Node { + let mut children: Vec = self + .children + .iter() + .map(|child| { + let mut node = child.widget.node(renderer); + + let mut style = node.0.style(); + style.margin.end = + stretch::style::Dimension::Points(f32::from(self.spacing)); + + node.0.set_style(style); + node + }) + .collect(); + + if let Some(node) = children.last_mut() { + let mut style = node.0.style(); + style.margin.end = stretch::style::Dimension::Undefined; + + node.0.set_style(style); + } + + Node::with_children(self.style, children) + } + + fn on_event( + &mut self, + event: Event, + layout: Layout<'_>, + cursor_position: Point, + messages: &mut Vec, + ) { + self.children.iter_mut().zip(layout.children()).for_each( + |(child, layout)| { + child + .widget + .on_event(event, layout, cursor_position, messages) + }, + ); + } + + fn draw( + &self, + renderer: &mut Renderer, + layout: Layout<'_>, + cursor_position: Point, + ) -> MouseCursor { + let mut cursor = MouseCursor::OutOfBounds; + + self.children.iter().zip(layout.children()).for_each( + |(child, layout)| { + let new_cursor = + child.widget.draw(renderer, layout, cursor_position); + + if new_cursor != MouseCursor::OutOfBounds { + cursor = new_cursor; + } + }, + ); + + cursor + } + + fn hash_layout(&self, state: &mut Hasher) { + self.style.hash(state); + self.spacing.hash(state); + + for child in &self.children { + child.widget.hash_layout(state); + } + } +} + +impl<'a, Message, Renderer> From> + for Element<'a, Message, Renderer> +where + Renderer: 'a, + Message: 'static, +{ + fn from(row: Row<'a, Message, Renderer>) -> Element<'a, Message, Renderer> { + Element::new(row) + } +} -- cgit From f9de39ddaa3020a9585b1648afb0ead45dfd7aa9 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Thu, 19 Sep 2019 15:01:12 +0200 Subject: Unify `web` and `ggez` tour examples :tada: --- src/widget/row.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/widget/row.rs') diff --git a/src/widget/row.rs b/src/widget/row.rs index 959528dc..181020e3 100644 --- a/src/widget/row.rs +++ b/src/widget/row.rs @@ -133,7 +133,7 @@ impl<'a, Message, Renderer> Row<'a, Message, Renderer> { impl<'a, Message, Renderer> Widget for Row<'a, Message, Renderer> { - fn node(&self, renderer: &Renderer) -> Node { + fn node(&self, renderer: &mut Renderer) -> Node { let mut children: Vec = self .children .iter() -- cgit From b9e0f7494881ad7cdfbcbc16878ecc6ef717753f Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Fri, 20 Sep 2019 19:15:31 +0200 Subject: Create `iced_core` and `iced_native` --- src/widget/row.rs | 219 ------------------------------------------------------ 1 file changed, 219 deletions(-) delete mode 100644 src/widget/row.rs (limited to 'src/widget/row.rs') diff --git a/src/widget/row.rs b/src/widget/row.rs deleted file mode 100644 index 181020e3..00000000 --- a/src/widget/row.rs +++ /dev/null @@ -1,219 +0,0 @@ -use std::hash::Hash; - -use crate::{ - Align, Element, Event, Hasher, Justify, Layout, MouseCursor, Node, Point, - Style, Widget, -}; - -/// A container that distributes its contents horizontally. -/// -/// A [`Row`] will try to fill the horizontal space of its container. -/// -/// [`Row`]: struct.Row.html -#[derive(Default)] -pub struct Row<'a, Message, Renderer> { - style: Style, - spacing: u16, - children: Vec>, -} - -impl<'a, Message, Renderer> std::fmt::Debug for Row<'a, Message, Renderer> { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - f.debug_struct("Row") - .field("style", &self.style) - .field("spacing", &self.spacing) - .field("children", &self.children) - .finish() - } -} - -impl<'a, Message, Renderer> Row<'a, Message, Renderer> { - /// Creates an empty [`Row`]. - /// - /// [`Row`]: struct.Row.html - pub fn new() -> Self { - Row { - style: Style::default().fill_width(), - spacing: 0, - children: Vec::new(), - } - } - - /// Sets the horizontal spacing _between_ elements in pixels. - /// - /// Custom margins per element do not exist in Iced. You should use this - /// method instead! While less flexible, it helps you keep spacing between - /// elements consistent. - pub fn spacing(mut self, px: u16) -> Self { - self.spacing = px; - self - } - - /// Sets the padding of the [`Row`] in pixels. - /// - /// [`Row`]: struct.Row.html - pub fn padding(mut self, px: u16) -> Self { - self.style = self.style.padding(px); - self - } - - /// Sets the width of the [`Row`] in pixels. - /// - /// [`Row`]: struct.Row.html - pub fn width(mut self, width: u16) -> Self { - self.style = self.style.width(width); - self - } - - /// Sets the height of the [`Row`] in pixels. - /// - /// [`Row`]: struct.Row.html - pub fn height(mut self, height: u16) -> Self { - self.style = self.style.height(height); - self - } - - /// Sets the maximum width of the [`Row`] in pixels. - /// - /// [`Row`]: struct.Row.html - pub fn max_width(mut self, max_width: u16) -> Self { - self.style = self.style.max_width(max_width); - self - } - - /// Sets the maximum height of the [`Row`] in pixels. - /// - /// [`Row`]: struct.Row.html - pub fn max_height(mut self, max_height: u16) -> Self { - self.style = self.style.max_height(max_height); - self - } - - /// Sets the alignment of the [`Row`] itself. - /// - /// This is useful if you want to override the default alignment given by - /// the parent container. - /// - /// [`Row`]: struct.Row.html - pub fn align_self(mut self, align: Align) -> Self { - self.style = self.style.align_self(align); - self - } - - /// Sets the vertical alignment of the contents of the [`Row`] . - /// - /// [`Row`]: struct.Row.html - pub fn align_items(mut self, align: Align) -> Self { - self.style = self.style.align_items(align); - self - } - - /// Sets the horizontal distribution strategy for the contents of the - /// [`Row`] . - /// - /// [`Row`]: struct.Row.html - pub fn justify_content(mut self, justify: Justify) -> Self { - self.style = self.style.justify_content(justify); - self - } - - /// Adds an [`Element`] to the [`Row`]. - /// - /// [`Element`]: ../struct.Element.html - /// [`Row`]: struct.Row.html - pub fn push(mut self, child: E) -> Row<'a, Message, Renderer> - where - E: Into>, - { - self.children.push(child.into()); - self - } -} - -impl<'a, Message, Renderer> Widget - for Row<'a, Message, Renderer> -{ - fn node(&self, renderer: &mut Renderer) -> Node { - let mut children: Vec = self - .children - .iter() - .map(|child| { - let mut node = child.widget.node(renderer); - - let mut style = node.0.style(); - style.margin.end = - stretch::style::Dimension::Points(f32::from(self.spacing)); - - node.0.set_style(style); - node - }) - .collect(); - - if let Some(node) = children.last_mut() { - let mut style = node.0.style(); - style.margin.end = stretch::style::Dimension::Undefined; - - node.0.set_style(style); - } - - Node::with_children(self.style, children) - } - - fn on_event( - &mut self, - event: Event, - layout: Layout<'_>, - cursor_position: Point, - messages: &mut Vec, - ) { - self.children.iter_mut().zip(layout.children()).for_each( - |(child, layout)| { - child - .widget - .on_event(event, layout, cursor_position, messages) - }, - ); - } - - fn draw( - &self, - renderer: &mut Renderer, - layout: Layout<'_>, - cursor_position: Point, - ) -> MouseCursor { - let mut cursor = MouseCursor::OutOfBounds; - - self.children.iter().zip(layout.children()).for_each( - |(child, layout)| { - let new_cursor = - child.widget.draw(renderer, layout, cursor_position); - - if new_cursor != MouseCursor::OutOfBounds { - cursor = new_cursor; - } - }, - ); - - cursor - } - - fn hash_layout(&self, state: &mut Hasher) { - self.style.hash(state); - self.spacing.hash(state); - - for child in &self.children { - child.widget.hash_layout(state); - } - } -} - -impl<'a, Message, Renderer> From> - for Element<'a, Message, Renderer> -where - Renderer: 'a, - Message: 'static, -{ - fn from(row: Row<'a, Message, Renderer>) -> Element<'a, Message, Renderer> { - Element::new(row) - } -} -- cgit