From 13e424be07a3abf13f3b6302450277a70f3596e5 Mon Sep 17 00:00:00 2001 From: "1514344669@qq.com" <1514344669@qq.com> Date: Mon, 11 Mar 2024 21:28:44 +0800 Subject: [PATCH 01/10] Unfilled circle --- vger/src/lib.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/vger/src/lib.rs b/vger/src/lib.rs index 67ddd6400..792b09ed7 100644 --- a/vger/src/lib.rs +++ b/vger/src/lib.rs @@ -329,7 +329,16 @@ impl Renderer for VgerRenderer { width, paint, ); - } else { + } else if let Some(circle) = shape.as_circle() { + self.vger.stroke_arc( + self.vger_point(circle.center), + (circle.radius * self.scale) as f32, + width, + 0.0, + std::f32::consts::PI, + paint, + ) + }else { for segment in shape.path_segments(0.0) { match segment { floem_peniko::kurbo::PathSeg::Line(_) => todo!(), From 2d08b1beca44493725cfe73620975d007268305e Mon Sep 17 00:00:00 2001 From: "1514344669@qq.com" <1514344669@qq.com> Date: Tue, 12 Mar 2024 00:01:00 +0800 Subject: [PATCH 02/10] Unfilled circle --- vger/src/lib.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/vger/src/lib.rs b/vger/src/lib.rs index 792b09ed7..374040544 100644 --- a/vger/src/lib.rs +++ b/vger/src/lib.rs @@ -337,8 +337,8 @@ impl Renderer for VgerRenderer { 0.0, std::f32::consts::PI, paint, - ) - }else { + ); + } else { for segment in shape.path_segments(0.0) { match segment { floem_peniko::kurbo::PathSeg::Line(_) => todo!(), @@ -351,6 +351,7 @@ impl Renderer for VgerRenderer { paint, ); } + floem_peniko::kurbo::PathSeg::Cubic(_) => todo!(), } } From ccf644f01699af4dcf18b0575b3fed834bfb7fe6 Mon Sep 17 00:00:00 2001 From: "1514344669@qq.com" <1514344669@qq.com> Date: Sat, 20 Apr 2024 23:18:50 +0800 Subject: [PATCH 03/10] Text rotation --- .vscode/settings.json | 6 ++ examples/rotation/Cargo.toml | 8 ++ examples/rotation/src/main.rs | 165 ++++++++++++++++++++++++++++++++++ src/style.rs | 33 +++++++ src/views/label.rs | 39 +++++++- vger/src/lib.rs | 16 +++- 6 files changed, 259 insertions(+), 8 deletions(-) create mode 100644 .vscode/settings.json create mode 100644 examples/rotation/Cargo.toml create mode 100644 examples/rotation/src/main.rs diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 000000000..366d55904 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,6 @@ +{ + "rust-analyzer.linkedProjects": [ + ".\\examples\\rotation\\Cargo.toml" + ], + "rust-analyzer.showUnlinkedFileNotification": false +} \ No newline at end of file diff --git a/examples/rotation/Cargo.toml b/examples/rotation/Cargo.toml new file mode 100644 index 000000000..ffb9cde11 --- /dev/null +++ b/examples/rotation/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "rotation" +version = "0.1.0" +edition = "2021" + +[dependencies] +im.workspace = true +floem = { path = "../.." } diff --git a/examples/rotation/src/main.rs b/examples/rotation/src/main.rs new file mode 100644 index 000000000..c602d92c5 --- /dev/null +++ b/examples/rotation/src/main.rs @@ -0,0 +1,165 @@ +use floem::{ + event::{Event, EventListener}, + keyboard::{Key, NamedKey}, + peniko::Color, + reactive::create_signal, + style::{Background, BorderColor, Outline, OutlineColor, Style, TextColor, Transition}, + style_class, + view::View, + views::{label, stack, text, Decorators}, + widgets::button, +}; + +style_class!(pub Button); +style_class!(pub Label); +style_class!(pub Frame); + +fn app_view() -> impl View { + let blue_button = Style::new() + .background(Color::rgb8(137, 145, 160)) + .color(Color::WHITE) + .border(1.0) + .border_color(Color::rgb8(109, 121, 135)) + .hover(|s| s.background(Color::rgb8(170, 175, 187))) + .transition(TextColor, Transition::linear(0.06)) + .transition(BorderColor, Transition::linear(0.06)) + .transition(Background, Transition::linear(0.06)) + .transition(Outline, Transition::linear(0.1)) + .focus_visible(|s| { + s.outline(2.0) + .outline_color(Color::WHITE.with_alpha_factor(0.7)) + }) + .disabled(|s| { + s.background(Color::DARK_GRAY.with_alpha_factor(0.1)) + .border_color(Color::BLACK.with_alpha_factor(0.2)) + }) + .active(|s| s.background(Color::BLACK.with_alpha_factor(0.4))) + .padding(5.0) + .margin(3.0) + .border_radius(5.0); + let blue_theme = Style::new() + .background(Color::rgb8(95, 102, 118)) + .transition(Background, Transition::linear(0.1)) + .transition(TextColor, Transition::linear(0.1)) + .color(Color::WHITE) + .class(Button, move |_| blue_button) + .class(Label, |s| { + s.margin(4.0).transition(TextColor, Transition::linear(0.1)) + }) + .font_size(12.0); + + let green_button = Style::new() + .background(Color::rgb8(180, 188, 175)) + .disabled(|s| { + s.background(Color::rgb8(180, 188, 175).with_alpha_factor(0.3)) + .border_color(Color::rgb8(131, 145, 123).with_alpha_factor(0.3)) + .color(Color::GRAY) + }) + .active(|s| s.background(Color::rgb8(95, 105, 88)).color(Color::WHITE)) + .color(Color::BLACK.with_alpha_factor(0.7)) + .border(2.0) + .transition(TextColor, Transition::linear(0.3)) + .transition(BorderColor, Transition::linear(0.3)) + .transition(Background, Transition::linear(0.3)) + .transition(Outline, Transition::linear(0.2)) + .transition(OutlineColor, Transition::linear(0.2)) + .outline_color(Color::rgba8(131, 145, 123, 0)) + .focus_visible(|s| { + s.outline(10.0) + .outline_color(Color::rgb8(131, 145, 123).with_alpha_factor(0.3)) + }) + .border_color(Color::rgb8(131, 145, 123)) + .hover(|s| s.background(Color::rgb8(204, 209, 201))) + .padding(8.0) + .border_radius(8.0) + .margin(6.0); + let green_theme = Style::new() + .background(Color::rgb8(227, 231, 226)) + .transition(Background, Transition::linear(0.5)) + .class(Button, move |_| green_button) + .class(Label, |s| { + s.margin(4.0).transition(TextColor, Transition::linear(0.5)) + }) + .class(Frame, |s| { + s.border(2.0) + .border_color(Color::rgb8(131, 145, 123).with_alpha_factor(0.2)) + .border_radius(8.0) + .background(Color::WHITE.with_alpha_factor(0.1)) + .padding(12.0) + }) + .color(Color::BLACK.with_alpha_factor(0.5)) + .font_size(16.0); + + let (counter, set_counter) = create_signal(0); + let (theme, set_theme) = create_signal(false); + let view = stack((stack(( + text("Toggle Theme") + .class(Button) + .on_click_stop({ + move |_| { + set_theme.update(|theme| *theme = !*theme); + } + }) + .style(|s| s.rotation_90()) + .keyboard_navigatable(), + stack(( + label(move || format!("Value: {}", counter.get())).class(Label), + text("Increment") + .class(Button) + .on_click_stop({ + move |_| { + set_counter.update(|value| *value += 1); + } + }) + .style(|s| s.rotation_90()) + .keyboard_navigatable(), + text("Decrement") + .class(Button) + .on_click_stop({ + move |_| { + set_counter.update(|value| *value -= 1); + } + }) + .style(|s| s.rotation_180()) + .keyboard_navigatable(), + text("Reset to 0") + .class(Button) + .on_click_stop(move |_| { + println!("Reset counter pressed"); // will not fire if button is disabled + set_counter.update(|value| *value = 0); + }) + .disabled(move || counter.get() == 0) + .style(|s| s.rotation_270()) + .keyboard_navigatable(), + )) + .class(Frame) + .style(|s| s.items_center()), + )) + .style(|s| s.items_center()),)) + .style(move |_| { + if theme.get() { + blue_theme.clone() + } else { + green_theme.clone() + } + .width_full() + .height_full() + .flex_col() + .items_center() + .justify_center() + }) + .window_title(|| "Themes Example".to_string()); + + let id = view.id(); + view.on_event_stop(EventListener::KeyUp, move |e| { + if let Event::KeyUp(e) = e { + if e.key.logical_key == Key::Named(NamedKey::F11) { + id.inspect(); + } + } + }) +} + +fn main() { + floem::launch(app_view); +} diff --git a/src/style.rs b/src/style.rs index 4b0de7d77..50725f1bf 100644 --- a/src/style.rs +++ b/src/style.rs @@ -72,6 +72,7 @@ impl StylePropValue for cosmic_text::Style {} impl StylePropValue for TextOverflow {} impl StylePropValue for LineHeightValue {} impl StylePropValue for Size {} +impl StylePropValue for Rotation {} impl StylePropValue for Option { fn debug_view(&self) -> Option { @@ -1020,6 +1021,14 @@ pub enum TextOverflow { Ellipsis, } +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +pub enum Rotation { + Rotation0, + Rotation90, + Rotation180, + Rotation270, +} + #[derive(Debug, Clone, Copy, PartialEq)] pub enum CursorStyle { Default, @@ -1117,6 +1126,16 @@ impl From for StyleValue { Self::Val(x) } } +impl Rotation { + pub fn Angle(self) -> f64 { + match self { + Rotation::Rotation0 => 0.0, + Rotation::Rotation90 => 90.0, + Rotation::Rotation180 => 180.0, + Rotation::Rotation270 => 270.0, + } + } +} macro_rules! define_builtin_props { ( @@ -1213,6 +1232,7 @@ define_builtin_props!( LineHeight line_height nocb: Option { inherited } = None, AspectRatio aspect_ratio: Option {} = None, Gap gap nocb: Size {} = Size::zero(), + RotationProp rotation: Rotation {} = Rotation::Rotation0, ); prop_extractor! { @@ -1716,6 +1736,19 @@ impl Style { self.set(ZIndex, Some(z_index)) } + pub fn rotation_0(self) -> Self { + self.rotation(Rotation::Rotation0) + } + pub fn rotation_90(self) -> Self { + self.rotation(Rotation::Rotation90) + } + pub fn rotation_180(self) -> Self { + self.rotation(Rotation::Rotation180) + } + pub fn rotation_270(self) -> Self { + self.rotation(Rotation::Rotation270) + } + /// Allow the application of a function if the option exists. /// This is useful for chaining together a bunch of optional style changes. /// ```rust diff --git a/src/views/label.rs b/src/views/label.rs index 84479da7d..263b469e9 100644 --- a/src/views/label.rs +++ b/src/views/label.rs @@ -5,15 +5,15 @@ use crate::{ cosmic_text::{Attrs, AttrsList, FamilyOwned, TextLayout}, id::Id, prop_extractor, - style::Style, style::{FontProps, LineHeight, TextColor, TextOverflow, TextOverflowProp}, + style::{Rotation, RotationProp, Style}, unit::PxPct, view::{View, ViewData, Widget}, }; use floem_peniko::Color; use floem_reactive::create_updater; use floem_renderer::Renderer; -use kurbo::{Point, Rect}; +use kurbo::{Affine, Point, Rect}; use taffy::tree::NodeId; prop_extractor! { @@ -21,6 +21,7 @@ prop_extractor! { color: TextColor, text_overflow: TextOverflowProp, line_height: LineHeight, + rotation: RotationProp, } } @@ -226,6 +227,13 @@ impl Widget for Label { } let text_node = self.text_node.unwrap(); + let (width, height) = match self.style.rotation() { + Rotation::Rotation0 => (width, height), + Rotation::Rotation90 => (height, width), + Rotation::Rotation180 => (width, height), + Rotation::Rotation270 => (height, width), + }; + let style = Style::new().width(width).height(height).to_taffy_style(); let _ = cx.app_state_mut().taffy.set_style(text_node, style); @@ -283,7 +291,13 @@ impl Widget for Label { if width > available_width { if self.available_width != Some(available_width) { let mut text_layout = text_layout.clone(); - text_layout.set_size(available_width, f32::MAX); + let (width, height) = match self.style.rotation() { + Rotation::Rotation0 => (available_width, f32::MAX), + Rotation::Rotation90 => (f32::MAX, available_width), + Rotation::Rotation180 => (available_width, f32::MAX), + Rotation::Rotation270 => (f32::MAX, available_width), + }; + text_layout.set_size(width, height); self.available_text_layout = Some(text_layout); self.available_width = Some(available_width); cx.app_state_mut().request_layout(self.id()); @@ -315,13 +329,30 @@ impl Widget for Label { return; } + let text_layout = self.text_layout.as_ref().unwrap(); + let higth = text_layout.size().height as f32; + let width = text_layout.size().width as f32; let text_node = self.text_node.unwrap(); let location = cx.app_state.taffy.layout(text_node).unwrap().location; - let point = Point::new(location.x as f64, location.y as f64); + + let (x, y) = match self.style.rotation() { + Rotation::Rotation0 => (location.x, location.y), + Rotation::Rotation90 => ((location.x + higth), location.y), + Rotation::Rotation180 => ((location.x + width), (location.y + higth)), + Rotation::Rotation270 => (location.x, (location.y + width)), + }; + let point = Point::new(x as f64, y as f64); + + let mut affine = cx.transform.as_coeffs(); + affine[0] = self.style.rotation().Angle(); + cx.paint_state.renderer.transform(Affine::new(affine)); + if let Some(text_layout) = self.available_text_layout.as_ref() { cx.draw_text(text_layout, point); } else { cx.draw_text(self.text_layout.as_ref().unwrap(), point); } + + cx.paint_state.renderer.transform(cx.transform); } } diff --git a/vger/src/lib.rs b/vger/src/lib.rs index 28b9d4311..4c4aca3e2 100644 --- a/vger/src/lib.rs +++ b/vger/src/lib.rs @@ -404,12 +404,19 @@ impl Renderer for VgerRenderer { fn draw_text(&mut self, layout: &TextLayout, pos: impl Into) { let mut swash_cache = SwashCache::new(); let transform = self.transform.as_coeffs(); - let offset = Vec2::new(transform[4], transform[5]); + let pos: Point = pos.into(); + let pos = Point::new(pos.x + transform[4], pos.y + transform[5]); + // transform[0] : Angle + let theta = std::f32::consts::TAU * transform[0] as f32 / 360.0; + let pos = Affine::rotate(-theta as f64) * pos; + // Absolute coordinate rotation + self.vger.rotate(theta); + let clip = self.clip; for line in layout.layout_runs() { if let Some(rect) = clip { - let y = pos.y + offset.y + line.line_y as f64; + let y = pos.y + line.line_y as f64; if y + (line.line_height as f64) < rect.y0 { continue; } @@ -418,8 +425,8 @@ impl Renderer for VgerRenderer { } } 'line_loop: for glyph_run in line.glyphs { - let x = glyph_run.x + pos.x as f32 + offset.x as f32; - let y = line.line_y + pos.y as f32 + offset.y as f32; + let x = glyph_run.x + pos.x as f32; + let y = line.line_y + pos.y as f32; if let Some(rect) = clip { if ((x + glyph_run.w) as f64) < rect.x0 { @@ -463,6 +470,7 @@ impl Renderer for VgerRenderer { } } } + self.vger.rotate(-theta); } fn draw_img(&mut self, img: Img<'_>, rect: Rect) { From 272f4c92bed852a80acdeb1ad1656c1ce3c763b9 Mon Sep 17 00:00:00 2001 From: "1514344669@qq.com" <1514344669@qq.com> Date: Sat, 20 Apr 2024 23:38:17 +0800 Subject: [PATCH 04/10] Text rotation --- examples/rotation/src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/rotation/src/main.rs b/examples/rotation/src/main.rs index c602d92c5..f57d1a79d 100644 --- a/examples/rotation/src/main.rs +++ b/examples/rotation/src/main.rs @@ -149,7 +149,7 @@ fn app_view() -> impl View { .justify_center() }) .window_title(|| "Themes Example".to_string()); - + // let id = view.id(); view.on_event_stop(EventListener::KeyUp, move |e| { if let Event::KeyUp(e) = e { From 19363b374d70d60c99cf6b40e692065ea7dd346f Mon Sep 17 00:00:00 2001 From: "1514344669@qq.com" <1514344669@qq.com> Date: Sat, 20 Apr 2024 23:49:02 +0800 Subject: [PATCH 05/10] Text rotation --- examples/rotation/src/main.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/examples/rotation/src/main.rs b/examples/rotation/src/main.rs index f57d1a79d..86c0f6f78 100644 --- a/examples/rotation/src/main.rs +++ b/examples/rotation/src/main.rs @@ -7,7 +7,6 @@ use floem::{ style_class, view::View, views::{label, stack, text, Decorators}, - widgets::button, }; style_class!(pub Button); @@ -149,7 +148,6 @@ fn app_view() -> impl View { .justify_center() }) .window_title(|| "Themes Example".to_string()); - // let id = view.id(); view.on_event_stop(EventListener::KeyUp, move |e| { if let Event::KeyUp(e) = e { From fda56d85188d2151ad4d143096c0ee2e4f314b86 Mon Sep 17 00:00:00 2001 From: "1514344669@qq.com" <1514344669@qq.com> Date: Sun, 21 Apr 2024 13:31:04 +0800 Subject: [PATCH 06/10] 1111 --- examples/rotation/src/main.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/examples/rotation/src/main.rs b/examples/rotation/src/main.rs index 86c0f6f78..7ec0b2761 100644 --- a/examples/rotation/src/main.rs +++ b/examples/rotation/src/main.rs @@ -158,6 +158,7 @@ fn app_view() -> impl View { }) } + fn main() { floem::launch(app_view); } From b194bf75c7690e80644716b19ac46cb8061833e8 Mon Sep 17 00:00:00 2001 From: "1514344669@qq.com" <1514344669@qq.com> Date: Sun, 21 Apr 2024 13:31:21 +0800 Subject: [PATCH 07/10] angle --- src/style.rs | 2 +- src/views/label.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/style.rs b/src/style.rs index 50725f1bf..3d946065c 100644 --- a/src/style.rs +++ b/src/style.rs @@ -1127,7 +1127,7 @@ impl From for StyleValue { } } impl Rotation { - pub fn Angle(self) -> f64 { + pub fn angle(self) -> f64 { match self { Rotation::Rotation0 => 0.0, Rotation::Rotation90 => 90.0, diff --git a/src/views/label.rs b/src/views/label.rs index 263b469e9..c42fd2849 100644 --- a/src/views/label.rs +++ b/src/views/label.rs @@ -344,7 +344,7 @@ impl Widget for Label { let point = Point::new(x as f64, y as f64); let mut affine = cx.transform.as_coeffs(); - affine[0] = self.style.rotation().Angle(); + affine[0] = self.style.rotation().angle(); cx.paint_state.renderer.transform(Affine::new(affine)); if let Some(text_layout) = self.available_text_layout.as_ref() { From fcc6f994bec041df05d01909f4ab8eabe7ba0e47 Mon Sep 17 00:00:00 2001 From: "1514344669@qq.com" <1514344669@qq.com> Date: Sun, 21 Apr 2024 13:34:58 +0800 Subject: [PATCH 08/10] 111 --- examples/rotation/src/main.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/examples/rotation/src/main.rs b/examples/rotation/src/main.rs index 7ec0b2761..86c0f6f78 100644 --- a/examples/rotation/src/main.rs +++ b/examples/rotation/src/main.rs @@ -158,7 +158,6 @@ fn app_view() -> impl View { }) } - fn main() { floem::launch(app_view); } From cc6e2c701c32f60173ea350afcddb7de6564e675 Mon Sep 17 00:00:00 2001 From: "1514344669@qq.com" <1514344669@qq.com> Date: Sun, 21 Apr 2024 21:07:20 +0800 Subject: [PATCH 09/10] rotate enum Rename parameters --- examples/rotation/src/main.rs | 8 +++---- src/style.rs | 41 ++++++++++++++++++++--------------- src/views/label.rs | 24 ++++++++++---------- 3 files changed, 40 insertions(+), 33 deletions(-) diff --git a/examples/rotation/src/main.rs b/examples/rotation/src/main.rs index 86c0f6f78..91d8ca8a2 100644 --- a/examples/rotation/src/main.rs +++ b/examples/rotation/src/main.rs @@ -99,7 +99,7 @@ fn app_view() -> impl View { set_theme.update(|theme| *theme = !*theme); } }) - .style(|s| s.rotation_90()) + .style(|s| s.rotate_right()) .keyboard_navigatable(), stack(( label(move || format!("Value: {}", counter.get())).class(Label), @@ -110,7 +110,7 @@ fn app_view() -> impl View { set_counter.update(|value| *value += 1); } }) - .style(|s| s.rotation_90()) + .style(|s| s.rotate_right()) .keyboard_navigatable(), text("Decrement") .class(Button) @@ -119,7 +119,7 @@ fn app_view() -> impl View { set_counter.update(|value| *value -= 1); } }) - .style(|s| s.rotation_180()) + .style(|s| s.rotate_invert()) .keyboard_navigatable(), text("Reset to 0") .class(Button) @@ -128,7 +128,7 @@ fn app_view() -> impl View { set_counter.update(|value| *value = 0); }) .disabled(move || counter.get() == 0) - .style(|s| s.rotation_270()) + .style(|s| s.rotate_left()) .keyboard_navigatable(), )) .class(Frame) diff --git a/src/style.rs b/src/style.rs index 3d946065c..d60be8fe6 100644 --- a/src/style.rs +++ b/src/style.rs @@ -1023,10 +1023,10 @@ pub enum TextOverflow { #[derive(Debug, Clone, Copy, PartialEq, Eq)] pub enum Rotation { - Rotation0, - Rotation90, - Rotation180, - Rotation270, + NoRotation, + RotateRight, + RotateUpsideDown, + RotateLeft, } #[derive(Debug, Clone, Copy, PartialEq)] @@ -1129,10 +1129,10 @@ impl From for StyleValue { impl Rotation { pub fn angle(self) -> f64 { match self { - Rotation::Rotation0 => 0.0, - Rotation::Rotation90 => 90.0, - Rotation::Rotation180 => 180.0, - Rotation::Rotation270 => 270.0, + Rotation::NoRotation => 0.0, + Rotation::RotateRight => 90.0, + Rotation::RotateUpsideDown => 180.0, + Rotation::RotateLeft => 270.0, } } } @@ -1232,7 +1232,7 @@ define_builtin_props!( LineHeight line_height nocb: Option { inherited } = None, AspectRatio aspect_ratio: Option {} = None, Gap gap nocb: Size {} = Size::zero(), - RotationProp rotation: Rotation {} = Rotation::Rotation0, + RotationProp rotation: Rotation {} = Rotation::NoRotation, ); prop_extractor! { @@ -1736,17 +1736,24 @@ impl Style { self.set(ZIndex, Some(z_index)) } - pub fn rotation_0(self) -> Self { - self.rotation(Rotation::Rotation0) + ///rotation 0 + pub fn no_rotation(self) -> Self { + self.rotation(Rotation::NoRotation) } - pub fn rotation_90(self) -> Self { - self.rotation(Rotation::Rotation90) + + ///rotation 90 + pub fn rotate_right(self) -> Self { + self.rotation(Rotation::RotateRight) } - pub fn rotation_180(self) -> Self { - self.rotation(Rotation::Rotation180) + + ///rotation 180 + pub fn rotate_invert(self) -> Self { + self.rotation(Rotation::RotateUpsideDown) } - pub fn rotation_270(self) -> Self { - self.rotation(Rotation::Rotation270) + + ///rotation 270 + pub fn rotate_left(self) -> Self { + self.rotation(Rotation::RotateLeft) } /// Allow the application of a function if the option exists. diff --git a/src/views/label.rs b/src/views/label.rs index c42fd2849..afd02fcc7 100644 --- a/src/views/label.rs +++ b/src/views/label.rs @@ -228,10 +228,10 @@ impl Widget for Label { let text_node = self.text_node.unwrap(); let (width, height) = match self.style.rotation() { - Rotation::Rotation0 => (width, height), - Rotation::Rotation90 => (height, width), - Rotation::Rotation180 => (width, height), - Rotation::Rotation270 => (height, width), + Rotation::NoRotation => (width, height), + Rotation::RotateRight => (height, width), + Rotation::RotateUpsideDown => (width, height), + Rotation::RotateLeft => (height, width), }; let style = Style::new().width(width).height(height).to_taffy_style(); @@ -292,10 +292,10 @@ impl Widget for Label { if self.available_width != Some(available_width) { let mut text_layout = text_layout.clone(); let (width, height) = match self.style.rotation() { - Rotation::Rotation0 => (available_width, f32::MAX), - Rotation::Rotation90 => (f32::MAX, available_width), - Rotation::Rotation180 => (available_width, f32::MAX), - Rotation::Rotation270 => (f32::MAX, available_width), + Rotation::NoRotation => (available_width, f32::MAX), + Rotation::RotateRight => (f32::MAX, available_width), + Rotation::RotateUpsideDown => (available_width, f32::MAX), + Rotation::RotateLeft => (f32::MAX, available_width), }; text_layout.set_size(width, height); self.available_text_layout = Some(text_layout); @@ -336,10 +336,10 @@ impl Widget for Label { let location = cx.app_state.taffy.layout(text_node).unwrap().location; let (x, y) = match self.style.rotation() { - Rotation::Rotation0 => (location.x, location.y), - Rotation::Rotation90 => ((location.x + higth), location.y), - Rotation::Rotation180 => ((location.x + width), (location.y + higth)), - Rotation::Rotation270 => (location.x, (location.y + width)), + Rotation::NoRotation => (location.x, location.y), + Rotation::RotateRight => ((location.x + higth), location.y), + Rotation::RotateUpsideDown => ((location.x + width), (location.y + higth)), + Rotation::RotateLeft => (location.x, (location.y + width)), }; let point = Point::new(x as f64, y as f64); From 96d6f1159afd8d75e163b2a06b94e0f9d5ac7ef5 Mon Sep 17 00:00:00 2001 From: "1514344669@qq.com" <1514344669@qq.com> Date: Sun, 21 Apr 2024 21:15:20 +0800 Subject: [PATCH 10/10] delete vscode settings --- .vscode/settings.json | 6 ------ 1 file changed, 6 deletions(-) delete mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json deleted file mode 100644 index 366d55904..000000000 --- a/.vscode/settings.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "rust-analyzer.linkedProjects": [ - ".\\examples\\rotation\\Cargo.toml" - ], - "rust-analyzer.showUnlinkedFileNotification": false -} \ No newline at end of file