From 334260e9bd131c3257a9447024fc41ce33df6e03 Mon Sep 17 00:00:00 2001 From: Nail Sharipov Date: Tue, 27 Jan 2026 20:38:13 +0300 Subject: [PATCH] fix overlay_editor up iced to 0.14.0 --- examples/overlay_editor/Cargo.toml | 4 +- .../overlay_editor/src/app/boolean/content.rs | 9 ++- .../overlay_editor/src/app/boolean/control.rs | 16 +++- .../src/app/boolean/workspace.rs | 2 +- examples/overlay_editor/src/app/design.rs | 23 +++--- examples/overlay_editor/src/app/main.rs | 35 ++++----- .../overlay_editor/src/app/outline/content.rs | 10 ++- .../overlay_editor/src/app/outline/control.rs | 10 ++- .../src/app/outline/workspace.rs | 2 +- .../overlay_editor/src/app/string/content.rs | 11 ++- .../overlay_editor/src/app/string/control.rs | 16 +++- .../src/app/string/workspace.rs | 2 +- .../overlay_editor/src/app/stroke/content.rs | 10 ++- .../overlay_editor/src/app/stroke/control.rs | 22 ++++-- .../src/app/stroke/workspace.rs | 2 +- examples/overlay_editor/src/draw/path.rs | 19 +++-- examples/overlay_editor/src/draw/shape.rs | 19 +++-- .../overlay_editor/src/draw/varicolored.rs | 32 ++++---- examples/overlay_editor/src/draw/vectors.rs | 19 +++-- .../overlay_editor/src/point_editor/widget.rs | 49 ++++++------ examples/overlay_editor/src/sheet/widget.rs | 75 +++++++++++-------- 21 files changed, 226 insertions(+), 161 deletions(-) diff --git a/examples/overlay_editor/Cargo.toml b/examples/overlay_editor/Cargo.toml index 423fc5d8..7d2e313d 100644 --- a/examples/overlay_editor/Cargo.toml +++ b/examples/overlay_editor/Cargo.toml @@ -15,7 +15,7 @@ crate-type = ["cdylib"] [dependencies] #iced = { path = "../../../../iced", features = ["wgpu", "advanced"] } -iced = { git = "https://github.com/iced-rs/iced", branch = "master", features = ["wgpu", "advanced", "fira-sans"] } +iced = { version = "0.14.0", features = ["wgpu", "advanced", "fira-sans"] } serde = { version = "^1.0", features = ["derive"] } serde_json = "^1.0" @@ -32,4 +32,4 @@ i_triangle = { version = "^0.35.0", features = ["serde"] } #i_triangle = { path = "../../../../iShape/iTriangle/iTriangle", default-features = true, features = ["serde"] } #i_mesh = { path = "../../../../iShape/iMesh/iMesh" } -#ICED_BACKEND=wgpu cargo r -r \ No newline at end of file +#ICED_BACKEND=wgpu cargo r -r diff --git a/examples/overlay_editor/src/app/boolean/content.rs b/examples/overlay_editor/src/app/boolean/content.rs index f01c543d..9919c43a 100644 --- a/examples/overlay_editor/src/app/boolean/content.rs +++ b/examples/overlay_editor/src/app/boolean/content.rs @@ -41,7 +41,11 @@ pub(crate) enum BooleanMessage { impl EditorApp { fn boolean_sidebar(&self) -> Column { let count = self.app_resource.boolean.count; - let mut column = Column::new().push(Space::new(Length::Fill, Length::Fixed(2.0))); + let mut column = Column::new().push( + Space::new() + .width(Length::Fill) + .height(Length::Fixed(2.0)), + ); for index in 0..count { let is_selected = self.state.boolean.test == index; @@ -62,7 +66,7 @@ impl EditorApp { column } - pub(crate) fn boolean_content(&self) -> Row { + pub(crate) fn boolean_content(&self) -> Row<'_, AppMessage> { Row::new() .push( scrollable( @@ -223,4 +227,3 @@ impl BooleanState { self.update_solution(); } } - diff --git a/examples/overlay_editor/src/app/boolean/control.rs b/examples/overlay_editor/src/app/boolean/control.rs index 889b3e92..ba7c5109 100644 --- a/examples/overlay_editor/src/app/boolean/control.rs +++ b/examples/overlay_editor/src/app/boolean/control.rs @@ -7,7 +7,7 @@ use iced::{Alignment, Length}; use iced::widget::{Column, Container, pick_list, Row, Space, Text}; impl EditorApp { - pub(crate) fn boolean_control(&self) -> Column { + pub(crate) fn boolean_control(&self) -> Column<'_, AppMessage> { let solver_pick_list = Row::new() .push(Text::new("Solver:") @@ -64,9 +64,17 @@ impl EditorApp { Column::new() .push(solver_pick_list) - .push(Space::new(Length::Shrink, Length::Fixed(4.0))) + .push( + Space::new() + .width(Length::Shrink) + .height(Length::Fixed(4.0)), + ) .push(fill_pick_list) - .push(Space::new(Length::Shrink, Length::Fixed(4.0))) + .push( + Space::new() + .width(Length::Shrink) + .height(Length::Fixed(4.0)), + ) .push(mode_pick_list) } } @@ -142,4 +150,4 @@ impl std::fmt::Display for ModeOption { } ) } -} \ No newline at end of file +} diff --git a/examples/overlay_editor/src/app/boolean/workspace.rs b/examples/overlay_editor/src/app/boolean/workspace.rs index d14ba90e..6e72cc0d 100644 --- a/examples/overlay_editor/src/app/boolean/workspace.rs +++ b/examples/overlay_editor/src/app/boolean/workspace.rs @@ -25,7 +25,7 @@ pub(crate) struct WorkspaceState { } impl EditorApp { - pub(crate) fn boolean_workspace(&self) -> Container { + pub(crate) fn boolean_workspace(&self) -> Container<'_, AppMessage> { Container::new({ let mut stack = Stack::new(); stack = stack.push( diff --git a/examples/overlay_editor/src/app/design.rs b/examples/overlay_editor/src/app/design.rs index 85142bb9..a2b6f7ae 100644 --- a/examples/overlay_editor/src/app/design.rs +++ b/examples/overlay_editor/src/app/design.rs @@ -23,7 +23,7 @@ impl Design { } pub(crate) fn negative_color() -> Color { - if iced::Theme::default().extended_palette().is_dark { + if Theme::Dark.extended_palette().is_dark { Color::from_rgb8(224, 224, 224) } else { Color::from_rgb8(32, 32, 32) @@ -58,23 +58,22 @@ impl Design { pub(super) fn style_sidebar_button(theme: &Theme, status: button::Status) -> button::Style { let palette = theme.extended_palette(); + let text_color = theme.palette().text; let base = button::Style { - background: Some(Background::Color(palette.primary.strong.color)), - text_color: palette.primary.strong.text, + background: Some(Background::Color(Color::TRANSPARENT)), + text_color, border: border::rounded(6), ..button::Style::default() }; match status { - button::Status::Pressed => base, - button::Status::Hovered => button::Style { - background: Some(Background::Color(palette.background.weak.color.scale_alpha(0.2))), - ..base - }, - button::Status::Disabled | button::Status::Active => button::Style { - background: Some(Background::Color(Color::TRANSPARENT)), + button::Status::Pressed | button::Status::Hovered => button::Style { + background: Some(Background::Color( + palette.background.weak.color.scale_alpha(0.2), + )), ..base }, + button::Status::Disabled | button::Status::Active => base, } } @@ -127,9 +126,9 @@ pub(super) fn style_separator(theme: &Theme) -> rule::Style { rule::Style { color, - width: 1, radius: border::Radius::new(0), fill_mode: rule::FillMode::Padded(0), + snap: true, } } @@ -139,4 +138,4 @@ pub(super) fn style_sheet_background(theme: &Theme) -> container::Style { } else { container::Style::default().background(Color::WHITE.scale_alpha(0.4)) } -} \ No newline at end of file +} diff --git a/examples/overlay_editor/src/app/main.rs b/examples/overlay_editor/src/app/main.rs index 49e49f94..326b7096 100644 --- a/examples/overlay_editor/src/app/main.rs +++ b/examples/overlay_editor/src/app/main.rs @@ -9,7 +9,7 @@ use crate::app::stroke::content::StrokeState; use iced::event::Event as MainEvent; use iced::keyboard::key::Named; use iced::keyboard::Key; -use iced::widget::{vertical_rule, Space}; +use iced::widget::{rule, Space}; use iced::widget::{Button, Column, Container, Row, Text}; use iced::{keyboard, Alignment, Element, Length}; use iced::{Subscription, Task}; @@ -118,16 +118,13 @@ impl EditorApp { } pub fn subscription(&self) -> Subscription { - keyboard::on_key_press(|key, _mods| { - match key.as_ref() { - Key::Named(Named::ArrowDown) => { - Some(AppMessage::NextTest) - } - Key::Named(Named::ArrowUp) => { - Some(AppMessage::PrevTest) - } + keyboard::listen().filter_map(|event| match event { + keyboard::Event::KeyPressed { key, .. } => match key { + Key::Named(Named::ArrowDown) => Some(AppMessage::NextTest), + Key::Named(Named::ArrowUp) => Some(AppMessage::PrevTest), _ => None, - } + }, + _ => None, }) } @@ -145,7 +142,7 @@ impl EditorApp { } } - pub fn view(&self) -> Element { + pub fn view(&self) -> Element<'_, AppMessage> { let content = Row::new().push( Container::new(self.main_navigation()) .width(Length::Fixed(160.0)) @@ -155,25 +152,29 @@ impl EditorApp { let content = match self.state.selected_action { MainAction::Boolean => content - .push(vertical_rule(1).style(style_separator)) + .push(rule::vertical(1).style(style_separator)) .push(self.boolean_content()), MainAction::String => content - .push(vertical_rule(1).style(style_separator)) + .push(rule::vertical(1).style(style_separator)) .push(self.string_content()), MainAction::Stroke => content - .push(vertical_rule(1).style(style_separator)) + .push(rule::vertical(1).style(style_separator)) .push(self.stroke_content()), MainAction::Outline => content - .push(vertical_rule(1).style(style_separator)) + .push(rule::vertical(1).style(style_separator)) .push(self.outline_content()), }; content.height(Length::Fill).into() } - fn main_navigation(&self) -> Column { + fn main_navigation(&self) -> Column<'_, AppMessage> { self.main_actions.iter().fold( - Column::new().push(Space::new(Length::Fill, Length::Fixed(2.0))), + Column::new().push( + Space::new() + .width(Length::Fill) + .height(Length::Fixed(2.0)), + ), |column, item| { let is_selected = self.state.selected_action.eq(item); column.push( diff --git a/examples/overlay_editor/src/app/outline/content.rs b/examples/overlay_editor/src/app/outline/content.rs index b8e61c62..f7c068a7 100644 --- a/examples/overlay_editor/src/app/outline/content.rs +++ b/examples/overlay_editor/src/app/outline/content.rs @@ -39,9 +39,13 @@ pub(crate) enum OutlineMessage { } impl EditorApp { - fn outline_sidebar(&self) -> Column { + fn outline_sidebar(&self) -> Column<'_, AppMessage> { let count = self.app_resource.outline.count; - let mut column = Column::new().push(Space::new(Length::Fill, Length::Fixed(2.0))); + let mut column = Column::new().push( + Space::new() + .width(Length::Fill) + .height(Length::Fixed(2.0)), + ); for index in 0..count { let is_selected = self.state.outline.test == index; column = column.push( @@ -70,7 +74,7 @@ impl EditorApp { column } - pub(crate) fn outline_content(&self) -> Row { + pub(crate) fn outline_content(&self) -> Row<'_, AppMessage> { Row::new() .push( scrollable( diff --git a/examples/overlay_editor/src/app/outline/control.rs b/examples/overlay_editor/src/app/outline/control.rs index 00f62b59..367f4ca5 100644 --- a/examples/overlay_editor/src/app/outline/control.rs +++ b/examples/overlay_editor/src/app/outline/control.rs @@ -30,7 +30,7 @@ impl std::fmt::Display for JoinOption { } impl EditorApp { - pub(crate) fn outline_control(&self) -> Column { + pub(crate) fn outline_control(&self) -> Column<'_, AppMessage> { let outer_offset_list = Row::new() .push( Text::new("Outer Offset:") @@ -103,7 +103,11 @@ impl EditorApp { Column::new() .push(outer_offset_list) .push(inner_offset_list) - .push(Space::new(Length::Shrink, Length::Fixed(4.0))) + .push( + Space::new() + .width(Length::Shrink) + .height(Length::Fixed(4.0)), + ) .push(join_pick_list) } } @@ -122,4 +126,4 @@ fn on_select_join(option: JoinOption) -> AppMessage { fn on_update_join_value(value: u8) -> AppMessage { AppMessage::Outline(OutlineMessage::JoinValueUpdated(value)) -} \ No newline at end of file +} diff --git a/examples/overlay_editor/src/app/outline/workspace.rs b/examples/overlay_editor/src/app/outline/workspace.rs index c71f7c33..8cf04f0e 100644 --- a/examples/overlay_editor/src/app/outline/workspace.rs +++ b/examples/overlay_editor/src/app/outline/workspace.rs @@ -22,7 +22,7 @@ pub(crate) struct WorkspaceState { } impl EditorApp { - pub(crate) fn outline_workspace(&self) -> Container { + pub(crate) fn outline_workspace(&self) -> Container<'_, AppMessage> { Container::new({ let mut stack = Stack::new(); stack = stack.push( diff --git a/examples/overlay_editor/src/app/string/content.rs b/examples/overlay_editor/src/app/string/content.rs index 493486f6..187b1ea6 100644 --- a/examples/overlay_editor/src/app/string/content.rs +++ b/examples/overlay_editor/src/app/string/content.rs @@ -40,9 +40,13 @@ pub(crate) enum StringMessage { } impl EditorApp { - fn string_sidebar(&self) -> Column { + fn string_sidebar(&self) -> Column<'_, AppMessage> { let count = self.app_resource.string.count; - let mut column = Column::new().push(Space::new(Length::Fill, Length::Fixed(2.0))); + let mut column = Column::new().push( + Space::new() + .width(Length::Fill) + .height(Length::Fixed(2.0)), + ); for index in 0..count { let is_selected = self.state.string.test == index; column = column.push( @@ -62,7 +66,7 @@ impl EditorApp { column } - pub(crate) fn string_content(&self) -> Row { + pub(crate) fn string_content(&self) -> Row<'_, AppMessage> { Row::new() .push( scrollable( @@ -232,4 +236,3 @@ impl StringState { self.update_solution(); } } - diff --git a/examples/overlay_editor/src/app/string/control.rs b/examples/overlay_editor/src/app/string/control.rs index cfdaea15..4a5960c5 100644 --- a/examples/overlay_editor/src/app/string/control.rs +++ b/examples/overlay_editor/src/app/string/control.rs @@ -6,7 +6,7 @@ use iced::{Alignment, Length}; use iced::widget::{Column, Container, pick_list, Row, Space, Text}; impl EditorApp { - pub(crate) fn string_control(&self) -> Column { + pub(crate) fn string_control(&self) -> Column<'_, AppMessage> { let solver_pick_list = Row::new() .push(Text::new("Solver:") @@ -63,9 +63,17 @@ impl EditorApp { Column::new() .push(solver_pick_list) - .push(Space::new(Length::Shrink, Length::Fixed(4.0))) + .push( + Space::new() + .width(Length::Shrink) + .height(Length::Fixed(4.0)), + ) .push(fill_pick_list) - .push(Space::new(Length::Shrink, Length::Fixed(4.0))) + .push( + Space::new() + .width(Length::Shrink) + .height(Length::Fixed(4.0)), + ) .push(mode_pick_list) } } @@ -116,4 +124,4 @@ impl std::fmt::Display for ModeOption { } ) } -} \ No newline at end of file +} diff --git a/examples/overlay_editor/src/app/string/workspace.rs b/examples/overlay_editor/src/app/string/workspace.rs index 3fd013a2..ecadfc00 100644 --- a/examples/overlay_editor/src/app/string/workspace.rs +++ b/examples/overlay_editor/src/app/string/workspace.rs @@ -31,7 +31,7 @@ pub(crate) struct WorkspaceState { } impl EditorApp { - pub(crate) fn string_workspace(&self) -> Container { + pub(crate) fn string_workspace(&self) -> Container<'_, AppMessage> { Container::new({ let mut stack = Stack::new(); stack = stack.push( diff --git a/examples/overlay_editor/src/app/stroke/content.rs b/examples/overlay_editor/src/app/stroke/content.rs index 19cdc84f..ec71743d 100644 --- a/examples/overlay_editor/src/app/stroke/content.rs +++ b/examples/overlay_editor/src/app/stroke/content.rs @@ -47,9 +47,13 @@ pub(crate) enum StrokeMessage { } impl EditorApp { - fn stroke_sidebar(&self) -> Column { + fn stroke_sidebar(&self) -> Column<'_, AppMessage> { let count = self.app_resource.stroke.count; - let mut column = Column::new().push(Space::new(Length::Fill, Length::Fixed(2.0))); + let mut column = Column::new().push( + Space::new() + .width(Length::Fill) + .height(Length::Fixed(2.0)), + ); for index in 0..count { let is_selected = self.state.stroke.test == index; column = column.push( @@ -78,7 +82,7 @@ impl EditorApp { column } - pub(crate) fn stroke_content(&self) -> Row { + pub(crate) fn stroke_content(&self) -> Row<'_, AppMessage> { Row::new() .push( scrollable( diff --git a/examples/overlay_editor/src/app/stroke/control.rs b/examples/overlay_editor/src/app/stroke/control.rs index 8ba46a82..1fc05ba8 100644 --- a/examples/overlay_editor/src/app/stroke/control.rs +++ b/examples/overlay_editor/src/app/stroke/control.rs @@ -58,7 +58,7 @@ impl std::fmt::Display for JoinOption { } impl EditorApp { - pub(crate) fn stroke_control(&self) -> Column { + pub(crate) fn stroke_control(&self) -> Column<'_, AppMessage> { let width_list = Row::new() .push( Text::new("Stroke Width:") @@ -185,14 +185,22 @@ impl EditorApp { Column::new() .push(width_list) .push(start_cap_pick_list) - .push(Space::new(Length::Shrink, Length::Fixed(4.0))) + .push( + Space::new() + .width(Length::Shrink) + .height(Length::Fixed(4.0)), + ) .push(end_cap_pick_list) - .push(Space::new(Length::Shrink, Length::Fixed(4.0))) + .push( + Space::new() + .width(Length::Shrink) + .height(Length::Fixed(4.0)), + ) .push(join_pick_list) .push( - checkbox("Is Closed", self.state.stroke.is_closed) - .on_toggle(on_set_is_closed) - + checkbox(self.state.stroke.is_closed) + .label("Is Closed") + .on_toggle(on_set_is_closed), ) } } @@ -227,4 +235,4 @@ fn on_select_join(option: JoinOption) -> AppMessage { fn on_update_join_value(value: u8) -> AppMessage { AppMessage::Stroke(StrokeMessage::JoinValueUpdated(value)) -} \ No newline at end of file +} diff --git a/examples/overlay_editor/src/app/stroke/workspace.rs b/examples/overlay_editor/src/app/stroke/workspace.rs index e4b23f10..0364756f 100644 --- a/examples/overlay_editor/src/app/stroke/workspace.rs +++ b/examples/overlay_editor/src/app/stroke/workspace.rs @@ -23,7 +23,7 @@ pub(crate) struct WorkspaceState { } impl EditorApp { - pub(crate) fn stroke_workspace(&self) -> Container { + pub(crate) fn stroke_workspace(&self) -> Container<'_, AppMessage> { Container::new({ let mut stack = Stack::new(); stack = stack.push( diff --git a/examples/overlay_editor/src/draw/path.rs b/examples/overlay_editor/src/draw/path.rs index 05a00bdc..9dbda547 100644 --- a/examples/overlay_editor/src/draw/path.rs +++ b/examples/overlay_editor/src/draw/path.rs @@ -129,7 +129,7 @@ impl Widget for PathWidget { } fn layout( - &self, + &mut self, _tree: &mut Tree, _renderer: &Renderer, limits: &layout::Limits, @@ -150,12 +150,15 @@ impl Widget for PathWidget { use iced::advanced::graphics::mesh::Renderer as _; use iced::advanced::Renderer as _; - let offset = Vector::point(layout.position()); - if let Some(mesh) = &self.stroke { - renderer.with_translation(offset, |renderer| { - renderer.draw_mesh(mesh.clone()) - }); - } + let bounds = layout.bounds(); + renderer.with_layer(bounds, |renderer| { + let offset = Vector::point(layout.position()); + if let Some(mesh) = &self.stroke { + renderer.with_translation(offset, |renderer| { + renderer.draw_mesh(mesh.clone()) + }); + } + }); } } @@ -163,4 +166,4 @@ impl<'a, Message: 'a> From for Element<'a, Message> { fn from(editor: PathWidget) -> Self { Self::new(editor) } -} \ No newline at end of file +} diff --git a/examples/overlay_editor/src/draw/shape.rs b/examples/overlay_editor/src/draw/shape.rs index e957bb72..8447ff22 100644 --- a/examples/overlay_editor/src/draw/shape.rs +++ b/examples/overlay_editor/src/draw/shape.rs @@ -273,7 +273,7 @@ impl Widget for ShapeWidget { } fn layout( - &self, + &mut self, _tree: &mut Tree, _renderer: &Renderer, limits: &layout::Limits, @@ -294,13 +294,16 @@ impl Widget for ShapeWidget { use iced::advanced::graphics::mesh::Renderer as _; use iced::advanced::Renderer as _; - let offset = Vector::point(layout.position()); - if let Some(mesh) = &self.fill { - renderer.with_translation(offset, |renderer| renderer.draw_mesh(mesh.clone())); - } - if let Some(mesh) = &self.stroke { - renderer.with_translation(offset, |renderer| renderer.draw_mesh(mesh.clone())); - } + let bounds = layout.bounds(); + renderer.with_layer(bounds, |renderer| { + let offset = Vector::point(layout.position()); + if let Some(mesh) = &self.fill { + renderer.with_translation(offset, |renderer| renderer.draw_mesh(mesh.clone())); + } + if let Some(mesh) = &self.stroke { + renderer.with_translation(offset, |renderer| renderer.draw_mesh(mesh.clone())); + } + }); } } diff --git a/examples/overlay_editor/src/draw/varicolored.rs b/examples/overlay_editor/src/draw/varicolored.rs index b42fe1c6..aeea0a8d 100644 --- a/examples/overlay_editor/src/draw/varicolored.rs +++ b/examples/overlay_editor/src/draw/varicolored.rs @@ -162,7 +162,7 @@ impl Widget for VaricoloredWidget { } fn layout( - &self, + &mut self, _tree: &mut Tree, _renderer: &Renderer, limits: &layout::Limits, @@ -183,19 +183,21 @@ impl Widget for VaricoloredWidget { use iced::advanced::graphics::mesh::Renderer as _; use iced::advanced::Renderer as _; - let offset = Vector::point(layout.position()); - - renderer.with_translation(offset, |renderer| { - for mesh in self.fill.iter() { - renderer.draw_mesh(mesh.clone()) - } - }); - - - renderer.with_translation(offset, |renderer| { - for mesh in self.stroke.iter() { - renderer.draw_mesh(mesh.clone()) - } + let bounds = layout.bounds(); + renderer.with_layer(bounds, |renderer| { + let offset = Vector::point(layout.position()); + + renderer.with_translation(offset, |renderer| { + for mesh in self.fill.iter() { + renderer.draw_mesh(mesh.clone()) + } + }); + + renderer.with_translation(offset, |renderer| { + for mesh in self.stroke.iter() { + renderer.draw_mesh(mesh.clone()) + } + }); }); } } @@ -204,4 +206,4 @@ impl<'a, Message: 'a> From for Element<'a, Message> { fn from(editor: VaricoloredWidget) -> Self { Self::new(editor) } -} \ No newline at end of file +} diff --git a/examples/overlay_editor/src/draw/vectors.rs b/examples/overlay_editor/src/draw/vectors.rs index b6cc6dec..4cb5cd47 100644 --- a/examples/overlay_editor/src/draw/vectors.rs +++ b/examples/overlay_editor/src/draw/vectors.rs @@ -199,7 +199,7 @@ impl Widget for VectorsWidget { } fn layout( - &self, + &mut self, _tree: &mut Tree, _renderer: &Renderer, limits: &layout::Limits, @@ -220,12 +220,15 @@ impl Widget for VectorsWidget { use iced::advanced::graphics::mesh::Renderer as _; use iced::advanced::Renderer as _; - let offset = Vector::point(layout.position()); - if let Some(mesh) = &self.stroke { - renderer.with_translation(offset, |renderer| { - renderer.draw_mesh(mesh.clone()) - }); - } + let bounds = layout.bounds(); + renderer.with_layer(bounds, |renderer| { + let offset = Vector::point(layout.position()); + if let Some(mesh) = &self.stroke { + renderer.with_translation(offset, |renderer| { + renderer.draw_mesh(mesh.clone()) + }); + } + }); } } @@ -268,4 +271,4 @@ impl MeshBuilder { indices: self.indices, } } -} \ No newline at end of file +} diff --git a/examples/overlay_editor/src/point_editor/widget.rs b/examples/overlay_editor/src/point_editor/widget.rs index bca56c41..374fc64c 100644 --- a/examples/overlay_editor/src/point_editor/widget.rs +++ b/examples/overlay_editor/src/point_editor/widget.rs @@ -33,7 +33,7 @@ impl<'a, Message> PointsEditorWidget<'a, Message> { camera: Camera, on_update: impl Fn(PointEditUpdate) -> Message + 'a, ) -> Self { - let binding = Theme::default(); + let binding = Theme::Dark; let palette = binding.extended_palette(); let (main_color, hover_color, drag_color) = if palette.is_dark { @@ -90,7 +90,7 @@ impl Widget for PointsEditorWidget<'_, Messag } fn layout( - &self, + &mut self, tree: &mut Tree, _renderer: &Renderer, limits: &layout::Limits, @@ -181,30 +181,33 @@ impl Widget for PointsEditorWidget<'_, Messag use iced::advanced::graphics::mesh::Renderer as _; use iced::advanced::Renderer as _; - let offset = layout.position() - Point::new(self.mesh_radius, self.mesh_radius); - - for (index, p) in self.points.iter().enumerate() { - let position = self.camera.world_to_screen(offset, p.pos); - let mesh = match &state.select { - SelectState::Hover(hover_index) => { - if index == *hover_index { - mesh.hover.clone() - } else { - mesh.main.clone() + let bounds = layout.bounds(); + renderer.with_layer(bounds, |renderer| { + let offset = layout.position() - Point::new(self.mesh_radius, self.mesh_radius); + + for (index, p) in self.points.iter().enumerate() { + let position = self.camera.world_to_screen(offset, p.pos); + let mesh = match &state.select { + SelectState::Hover(hover_index) => { + if index == *hover_index { + mesh.hover.clone() + } else { + mesh.main.clone() + } } - } - SelectState::Drag(drag) => { - if index == drag.index { - mesh.drag.clone() - } else { - mesh.main.clone() + SelectState::Drag(drag) => { + if index == drag.index { + mesh.drag.clone() + } else { + mesh.main.clone() + } } - } - SelectState::None => mesh.main.clone(), - }; + SelectState::None => mesh.main.clone(), + }; - renderer.with_translation(position, |renderer| renderer.draw_mesh(mesh)); - } + renderer.with_translation(position, |renderer| renderer.draw_mesh(mesh)); + } + }); } } diff --git a/examples/overlay_editor/src/sheet/widget.rs b/examples/overlay_editor/src/sheet/widget.rs index 64f36980..28073e3b 100644 --- a/examples/overlay_editor/src/sheet/widget.rs +++ b/examples/overlay_editor/src/sheet/widget.rs @@ -85,7 +85,7 @@ impl Widget for SheetWidget<'_, Message> { } fn layout( - &self, + &mut self, _tree: &mut Tree, _renderer: &Renderer, limits: &layout::Limits, @@ -181,49 +181,58 @@ impl Widget for SheetWidget<'_, Message> { // stroke radius let r = 1.0; + use iced::advanced::graphics::mesh::Renderer as _; + use iced::advanced::Renderer as _; + let rect = layout.bounds(); + renderer.with_layer(rect, |renderer| { + let view_min = Vector::new(0.0, 0.0); + let view_max = Vector::new(rect.width, rect.height); - let view_min = Vector::new(0.0, 0.0); - let view_max = Vector::new(rect.width, rect.height); + let world_min = self.camera.view_to_world(view_min); + let world_max = self.camera.view_to_world(view_max); - let world_min = self.camera.view_to_world(view_min); - let world_max = self.camera.view_to_world(view_max); + let round_world_min_x = world_min.x.ceil(); + let round_world_min_y = world_min.y.ceil(); - let round_world_min_x = world_min.x.ceil(); - let round_world_min_y = world_min.y.ceil(); + let round_world_max_x = world_max.x.trunc(); + let round_world_max_y = world_max.y.trunc(); - let round_world_max_x = world_max.x.trunc(); - let round_world_max_y = world_max.y.trunc(); + let nfx = (round_world_max_x - round_world_min_x + 0.001).round().abs(); + let nfy = (round_world_max_y - round_world_min_y + 0.001).round().abs(); - let nfx = (round_world_max_x - round_world_min_x + 0.001).round().abs(); - let nfy = (round_world_max_y - round_world_min_y + 0.001).round().abs(); + let nx = nfx as usize; + let ny = nfy as usize; - let nx = nfx as usize; - let ny = nfy as usize; + let vr_mesh = self.line_mesh(-r, view_min.y, r, view_max.y, s); + let hz_mesh = self.line_mesh(view_min.x, -r, view_max.x, r, s); - let vr_mesh = self.line_mesh(-r, view_min.y, r, view_max.y, s); - let hz_mesh = self.line_mesh(view_min.x, -r, view_max.x, r, s); + let round_view_min = self + .camera + .world_to_view(Vector::new(round_world_min_x, round_world_min_y)); + let round_view_max = self + .camera + .world_to_view(Vector::new(round_world_max_x, round_world_max_y)); - use iced::advanced::graphics::mesh::Renderer as _; - use iced::advanced::Renderer as _; + let dx = (round_view_max.x - round_view_min.x) / nfx; + let dy = (round_view_max.y - round_view_min.y) / nfy; - let round_view_min = self.camera.world_to_view(Vector::new(round_world_min_x, round_world_min_y)); - let round_view_max = self.camera.world_to_view(Vector::new(round_world_max_x, round_world_max_y)); - - let dx = (round_view_max.x - round_view_min.x) / nfx; - let dy = (round_view_max.y - round_view_min.y) / nfy; - - let mut position = Vector::new(round_view_min.x + rect.x, view_min.y + rect.y); - for _ in 0..=nx { - renderer.with_translation(position, |renderer| renderer.draw_mesh(vr_mesh.clone())); - position.x += dx; - } + let mut position = Vector::new(round_view_min.x + rect.x, view_min.y + rect.y); + for _ in 0..=nx { + renderer.with_translation(position, |renderer| { + renderer.draw_mesh(vr_mesh.clone()) + }); + position.x += dx; + } - let mut position = Vector::new(view_min.x + rect.x, round_view_min.y + rect.y); - for _ in 0..=ny { - renderer.with_translation(position, |renderer| renderer.draw_mesh(hz_mesh.clone())); - position.y += dy; - } + let mut position = Vector::new(view_min.x + rect.x, round_view_min.y + rect.y); + for _ in 0..=ny { + renderer.with_translation(position, |renderer| { + renderer.draw_mesh(hz_mesh.clone()) + }); + position.y += dy; + } + }); } }