From c901f40fd6c5aa39f4dc056b2b59bc7133b287e6 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Tue, 14 Apr 2020 12:11:10 +0200 Subject: Introduce `Widget::overlay` :tada: --- graphics/src/widget/canvas.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'graphics/src/widget') diff --git a/graphics/src/widget/canvas.rs b/graphics/src/widget/canvas.rs index b8466239..0257f819 100644 --- a/graphics/src/widget/canvas.rs +++ b/graphics/src/widget/canvas.rs @@ -134,7 +134,7 @@ impl> Canvas { } } -impl Widget> for Canvas +impl<'a, Message, P, B> Widget<'a, Message, Renderer> for Canvas where P: Program, B: Backend, -- cgit From afd9274de26ccf65285df02007b4ddb697bea9a3 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Sat, 18 Apr 2020 14:42:48 +0200 Subject: Draft `ComboBox` and `Menu` layer --- graphics/src/widget/combo_box.rs | 67 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 graphics/src/widget/combo_box.rs (limited to 'graphics/src/widget') diff --git a/graphics/src/widget/combo_box.rs b/graphics/src/widget/combo_box.rs new file mode 100644 index 00000000..27ea762a --- /dev/null +++ b/graphics/src/widget/combo_box.rs @@ -0,0 +1,67 @@ +use crate::backend::{self, Backend}; +use crate::{Primitive, Renderer}; +use iced_native::{ + mouse, Background, Color, Font, HorizontalAlignment, Point, Rectangle, + VerticalAlignment, +}; + +pub use iced_native::ComboBox; + +impl iced_native::combo_box::Renderer for Renderer +where + B: Backend + backend::Text, +{ + const DEFAULT_PADDING: u16 = 5; + + fn draw( + &mut self, + bounds: Rectangle, + cursor_position: Point, + selected: Option, + text_size: u16, + padding: u16, + ) -> Self::Output { + let is_mouse_over = bounds.contains(cursor_position); + + let background = Primitive::Quad { + bounds, + background: Background::Color([0.87, 0.87, 0.87].into()), + border_color: if is_mouse_over { + Color::BLACK + } else { + [0.7, 0.7, 0.7].into() + }, + border_width: 1, + border_radius: 0, + }; + + ( + if let Some(label) = selected { + let label = Primitive::Text { + content: label, + size: f32::from(text_size), + font: Font::Default, + color: Color::BLACK, + bounds: Rectangle { + x: bounds.x + f32::from(padding), + y: bounds.center_y(), + ..bounds + }, + horizontal_alignment: HorizontalAlignment::Left, + vertical_alignment: VerticalAlignment::Center, + }; + + Primitive::Group { + primitives: vec![background, label], + } + } else { + background + }, + if is_mouse_over { + mouse::Interaction::Pointer + } else { + mouse::Interaction::default() + }, + ) + } +} -- cgit From e29feef8ba4f95f286039fcc1ca2e53bfe5019c5 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Sat, 18 Apr 2020 19:53:27 +0200 Subject: Render arrow icon in `ComboBox` --- graphics/src/widget/combo_box.rs | 52 +++++++++++++++++++++++++--------------- 1 file changed, 33 insertions(+), 19 deletions(-) (limited to 'graphics/src/widget') diff --git a/graphics/src/widget/combo_box.rs b/graphics/src/widget/combo_box.rs index 27ea762a..92024c6c 100644 --- a/graphics/src/widget/combo_box.rs +++ b/graphics/src/widget/combo_box.rs @@ -35,27 +35,41 @@ where border_radius: 0, }; + let arrow_down = Primitive::Text { + content: B::ARROW_DOWN_ICON.to_string(), + font: B::ICON_FONT, + size: bounds.height * 0.7, + bounds: Rectangle { + x: bounds.x + bounds.width - f32::from(padding) * 2.0, + y: bounds.center_y(), + ..bounds + }, + color: Color::BLACK, + horizontal_alignment: HorizontalAlignment::Right, + vertical_alignment: VerticalAlignment::Center, + }; + ( - if let Some(label) = selected { - let label = Primitive::Text { - content: label, - size: f32::from(text_size), - font: Font::Default, - color: Color::BLACK, - bounds: Rectangle { - x: bounds.x + f32::from(padding), - y: bounds.center_y(), - ..bounds - }, - horizontal_alignment: HorizontalAlignment::Left, - vertical_alignment: VerticalAlignment::Center, - }; + Primitive::Group { + primitives: if let Some(label) = selected { + let label = Primitive::Text { + content: label, + size: f32::from(text_size), + font: Font::Default, + color: Color::BLACK, + bounds: Rectangle { + x: bounds.x + f32::from(padding), + y: bounds.center_y(), + ..bounds + }, + horizontal_alignment: HorizontalAlignment::Left, + vertical_alignment: VerticalAlignment::Center, + }; - Primitive::Group { - primitives: vec![background, label], - } - } else { - background + vec![background, label, arrow_down] + } else { + vec![background, arrow_down] + }, }, if is_mouse_over { mouse::Interaction::Pointer -- cgit From 61f22b1db23f3495145a9a4f7255311fe8381998 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Thu, 11 Jun 2020 20:41:11 +0200 Subject: Add styling support for `ComboBox` and `Menu` --- graphics/src/widget/combo_box.rs | 42 ++++++++++++++++++++++++++-------------- 1 file changed, 28 insertions(+), 14 deletions(-) (limited to 'graphics/src/widget') diff --git a/graphics/src/widget/combo_box.rs b/graphics/src/widget/combo_box.rs index 92024c6c..078b5def 100644 --- a/graphics/src/widget/combo_box.rs +++ b/graphics/src/widget/combo_box.rs @@ -1,18 +1,29 @@ use crate::backend::{self, Backend}; use crate::{Primitive, Renderer}; use iced_native::{ - mouse, Background, Color, Font, HorizontalAlignment, Point, Rectangle, - VerticalAlignment, + mouse, Font, HorizontalAlignment, Point, Rectangle, VerticalAlignment, }; +use iced_style::menu; -pub use iced_native::ComboBox; +pub use iced_native::combo_box::State; +pub use iced_style::combo_box::{Style, StyleSheet}; + +/// A widget allowing the selection of a single value from a list of options. +pub type ComboBox<'a, T, Message, Backend> = + iced_native::ComboBox<'a, T, Message, Renderer>; impl iced_native::combo_box::Renderer for Renderer where B: Backend + backend::Text, { + type Style = Box; + const DEFAULT_PADDING: u16 = 5; + fn menu_style(style: &Box) -> menu::Style { + style.menu() + } + fn draw( &mut self, bounds: Rectangle, @@ -20,31 +31,34 @@ where selected: Option, text_size: u16, padding: u16, + style: &Box, ) -> Self::Output { let is_mouse_over = bounds.contains(cursor_position); + let style = if is_mouse_over { + style.hovered() + } else { + style.active() + }; + let background = Primitive::Quad { bounds, - background: Background::Color([0.87, 0.87, 0.87].into()), - border_color: if is_mouse_over { - Color::BLACK - } else { - [0.7, 0.7, 0.7].into() - }, - border_width: 1, - border_radius: 0, + background: style.background, + border_color: style.border_color, + border_width: style.border_width, + border_radius: style.border_radius, }; let arrow_down = Primitive::Text { content: B::ARROW_DOWN_ICON.to_string(), font: B::ICON_FONT, - size: bounds.height * 0.7, + size: bounds.height * style.icon_size, bounds: Rectangle { x: bounds.x + bounds.width - f32::from(padding) * 2.0, y: bounds.center_y(), ..bounds }, - color: Color::BLACK, + color: style.text_color, horizontal_alignment: HorizontalAlignment::Right, vertical_alignment: VerticalAlignment::Center, }; @@ -56,7 +70,7 @@ where content: label, size: f32::from(text_size), font: Font::Default, - color: Color::BLACK, + color: style.text_color, bounds: Rectangle { x: bounds.x + f32::from(padding), y: bounds.center_y(), -- cgit From 69ac47f463fd5c392f1f8e788fcf89b1a76abcae Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Wed, 8 Jul 2020 07:04:20 +0200 Subject: Implement `font` method for `ComboBox` --- graphics/src/widget/combo_box.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'graphics/src/widget') diff --git a/graphics/src/widget/combo_box.rs b/graphics/src/widget/combo_box.rs index 078b5def..e7ed4e04 100644 --- a/graphics/src/widget/combo_box.rs +++ b/graphics/src/widget/combo_box.rs @@ -29,8 +29,9 @@ where bounds: Rectangle, cursor_position: Point, selected: Option, - text_size: u16, padding: u16, + text_size: u16, + font: Font, style: &Box, ) -> Self::Output { let is_mouse_over = bounds.contains(cursor_position); @@ -69,7 +70,7 @@ where let label = Primitive::Text { content: label, size: f32::from(text_size), - font: Font::Default, + font, color: style.text_color, bounds: Rectangle { x: bounds.x + f32::from(padding), -- cgit From dc0e423142f053c59c326d92920e7829b6852cca Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Fri, 10 Jul 2020 02:01:30 +0200 Subject: Remove unnecessary lifetime in `Widget` trait --- graphics/src/widget/canvas.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'graphics/src/widget') diff --git a/graphics/src/widget/canvas.rs b/graphics/src/widget/canvas.rs index 0257f819..b8466239 100644 --- a/graphics/src/widget/canvas.rs +++ b/graphics/src/widget/canvas.rs @@ -134,7 +134,7 @@ impl> Canvas { } } -impl<'a, Message, P, B> Widget<'a, Message, Renderer> for Canvas +impl Widget> for Canvas where P: Program, B: Backend, -- cgit From 2118a726f8b6134820e1ca5b7b802fa1344e453a Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Fri, 10 Jul 2020 02:39:12 +0200 Subject: Write documentation for the new `overlay` API --- graphics/src/widget/combo_box.rs | 1 + 1 file changed, 1 insertion(+) (limited to 'graphics/src/widget') diff --git a/graphics/src/widget/combo_box.rs b/graphics/src/widget/combo_box.rs index e7ed4e04..f200c2b7 100644 --- a/graphics/src/widget/combo_box.rs +++ b/graphics/src/widget/combo_box.rs @@ -1,3 +1,4 @@ +//! Display a dropdown list of selectable values. use crate::backend::{self, Backend}; use crate::{Primitive, Renderer}; use iced_native::{ -- cgit From 73b8ae8e5e7f57c608c775272a2980995ab22bb3 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Fri, 10 Jul 2020 02:50:47 +0200 Subject: Rename `ComboBox` to `PickList` --- graphics/src/widget/combo_box.rs | 97 ---------------------------------------- graphics/src/widget/pick_list.rs | 97 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 97 insertions(+), 97 deletions(-) delete mode 100644 graphics/src/widget/combo_box.rs create mode 100644 graphics/src/widget/pick_list.rs (limited to 'graphics/src/widget') diff --git a/graphics/src/widget/combo_box.rs b/graphics/src/widget/combo_box.rs deleted file mode 100644 index f200c2b7..00000000 --- a/graphics/src/widget/combo_box.rs +++ /dev/null @@ -1,97 +0,0 @@ -//! Display a dropdown list of selectable values. -use crate::backend::{self, Backend}; -use crate::{Primitive, Renderer}; -use iced_native::{ - mouse, Font, HorizontalAlignment, Point, Rectangle, VerticalAlignment, -}; -use iced_style::menu; - -pub use iced_native::combo_box::State; -pub use iced_style::combo_box::{Style, StyleSheet}; - -/// A widget allowing the selection of a single value from a list of options. -pub type ComboBox<'a, T, Message, Backend> = - iced_native::ComboBox<'a, T, Message, Renderer>; - -impl iced_native::combo_box::Renderer for Renderer -where - B: Backend + backend::Text, -{ - type Style = Box; - - const DEFAULT_PADDING: u16 = 5; - - fn menu_style(style: &Box) -> menu::Style { - style.menu() - } - - fn draw( - &mut self, - bounds: Rectangle, - cursor_position: Point, - selected: Option, - padding: u16, - text_size: u16, - font: Font, - style: &Box, - ) -> Self::Output { - let is_mouse_over = bounds.contains(cursor_position); - - let style = if is_mouse_over { - style.hovered() - } else { - style.active() - }; - - let background = Primitive::Quad { - bounds, - background: style.background, - border_color: style.border_color, - border_width: style.border_width, - border_radius: style.border_radius, - }; - - let arrow_down = Primitive::Text { - content: B::ARROW_DOWN_ICON.to_string(), - font: B::ICON_FONT, - size: bounds.height * style.icon_size, - bounds: Rectangle { - x: bounds.x + bounds.width - f32::from(padding) * 2.0, - y: bounds.center_y(), - ..bounds - }, - color: style.text_color, - horizontal_alignment: HorizontalAlignment::Right, - vertical_alignment: VerticalAlignment::Center, - }; - - ( - Primitive::Group { - primitives: if let Some(label) = selected { - let label = Primitive::Text { - content: label, - size: f32::from(text_size), - font, - color: style.text_color, - bounds: Rectangle { - x: bounds.x + f32::from(padding), - y: bounds.center_y(), - ..bounds - }, - horizontal_alignment: HorizontalAlignment::Left, - vertical_alignment: VerticalAlignment::Center, - }; - - vec![background, label, arrow_down] - } else { - vec![background, arrow_down] - }, - }, - if is_mouse_over { - mouse::Interaction::Pointer - } else { - mouse::Interaction::default() - }, - ) - } -} diff --git a/graphics/src/widget/pick_list.rs b/graphics/src/widget/pick_list.rs new file mode 100644 index 00000000..f42a8707 --- /dev/null +++ b/graphics/src/widget/pick_list.rs @@ -0,0 +1,97 @@ +//! Display a dropdown list of selectable values. +use crate::backend::{self, Backend}; +use crate::{Primitive, Renderer}; +use iced_native::{ + mouse, Font, HorizontalAlignment, Point, Rectangle, VerticalAlignment, +}; +use iced_style::menu; + +pub use iced_native::pick_list::State; +pub use iced_style::pick_list::{Style, StyleSheet}; + +/// A widget allowing the selection of a single value from a list of options. +pub type PickList<'a, T, Message, Backend> = + iced_native::PickList<'a, T, Message, Renderer>; + +impl iced_native::pick_list::Renderer for Renderer +where + B: Backend + backend::Text, +{ + type Style = Box; + + const DEFAULT_PADDING: u16 = 5; + + fn menu_style(style: &Box) -> menu::Style { + style.menu() + } + + fn draw( + &mut self, + bounds: Rectangle, + cursor_position: Point, + selected: Option, + padding: u16, + text_size: u16, + font: Font, + style: &Box, + ) -> Self::Output { + let is_mouse_over = bounds.contains(cursor_position); + + let style = if is_mouse_over { + style.hovered() + } else { + style.active() + }; + + let background = Primitive::Quad { + bounds, + background: style.background, + border_color: style.border_color, + border_width: style.border_width, + border_radius: style.border_radius, + }; + + let arrow_down = Primitive::Text { + content: B::ARROW_DOWN_ICON.to_string(), + font: B::ICON_FONT, + size: bounds.height * style.icon_size, + bounds: Rectangle { + x: bounds.x + bounds.width - f32::from(padding) * 2.0, + y: bounds.center_y(), + ..bounds + }, + color: style.text_color, + horizontal_alignment: HorizontalAlignment::Right, + vertical_alignment: VerticalAlignment::Center, + }; + + ( + Primitive::Group { + primitives: if let Some(label) = selected { + let label = Primitive::Text { + content: label, + size: f32::from(text_size), + font, + color: style.text_color, + bounds: Rectangle { + x: bounds.x + f32::from(padding), + y: bounds.center_y(), + ..bounds + }, + horizontal_alignment: HorizontalAlignment::Left, + vertical_alignment: VerticalAlignment::Center, + }; + + vec![background, label, arrow_down] + } else { + vec![background, arrow_down] + }, + }, + if is_mouse_over { + mouse::Interaction::Pointer + } else { + mouse::Interaction::default() + }, + ) + } +} -- cgit