From 6551e026f2c1f887c83b102131c20a6bd7059d85 Mon Sep 17 00:00:00 2001 From: Dietmar Maurer Date: Tue, 17 Dec 2024 12:05:57 +0100 Subject: [PATCH] align: move code to dom module Signed-off-by: Dietmar Maurer --- src/{widget => dom}/align.rs | 0 src/dom/mod.rs | 2 ++ src/widget/dialog.rs | 2 +- src/widget/dropdown.rs | 2 +- src/widget/menu/menu_popper.rs | 4 ++-- src/widget/mod.rs | 2 -- src/widget/tooltip.rs | 23 ++++++----------------- 7 files changed, 12 insertions(+), 23 deletions(-) rename src/{widget => dom}/align.rs (100%) diff --git a/src/widget/align.rs b/src/dom/align.rs similarity index 100% rename from src/widget/align.rs rename to src/dom/align.rs diff --git a/src/dom/mod.rs b/src/dom/mod.rs index 87be96b..6a4ad8d 100644 --- a/src/dom/mod.rs +++ b/src/dom/mod.rs @@ -1,5 +1,7 @@ //! DOM helpers. +pub mod align; + mod number_format; pub use number_format::{format_float, parse_float, LocaleInfo}; diff --git a/src/widget/dialog.rs b/src/widget/dialog.rs index 4503ec2..a3d0b46 100644 --- a/src/widget/dialog.rs +++ b/src/widget/dialog.rs @@ -11,10 +11,10 @@ use yew::html::{IntoEventCallback, IntoPropValue}; use yew::prelude::*; use yew::virtual_dom::{Key, VComp, VNode}; +use crate::dom::align::{align_to_viewport, align_to_xy, Point}; use crate::dom::IntoHtmlElement; use crate::prelude::*; use crate::props::{AsCssStylesMut, CssStyles}; -use crate::widget::align::{align_to_viewport, align_to_xy, Point}; use crate::widget::{ActionIcon, Panel}; use pwt_macros::builder; diff --git a/src/widget/dropdown.rs b/src/widget/dropdown.rs index 83a356b..92d47f0 100644 --- a/src/widget/dropdown.rs +++ b/src/widget/dropdown.rs @@ -11,7 +11,7 @@ use crate::widget::{focus::FocusTracker, Container, Input, Tooltip, Trigger}; use pwt_macros::{builder, widget}; -use crate::widget::align::{AlignOptions, AutoFloatingPlacement, GrowDirection, Point}; +use crate::dom::align::{AlignOptions, AutoFloatingPlacement, GrowDirection, Point}; use super::focus::{element_is_focusable, get_first_focusable}; diff --git a/src/widget/menu/menu_popper.rs b/src/widget/menu/menu_popper.rs index 934b233..6ce7058 100644 --- a/src/widget/menu/menu_popper.rs +++ b/src/widget/menu/menu_popper.rs @@ -1,6 +1,6 @@ use yew::prelude::*; -use crate::widget::align::{AlignOptions, GrowDirection, Point}; +use crate::dom::align::{align_to, AlignOptions, GrowDirection, Point}; pub struct MenuPopper { content_ref: NodeRef, @@ -54,7 +54,7 @@ impl MenuPopper { }); } - if let Err(err) = crate::widget::align::align_to( + if let Err(err) = align_to( &self.content_ref, &self.submenu_ref, self.align_options.clone(), diff --git a/src/widget/mod.rs b/src/widget/mod.rs index 6b5805f..e64a21b 100644 --- a/src/widget/mod.rs +++ b/src/widget/mod.rs @@ -15,8 +15,6 @@ mod message_box; pub use message_box::PwtMessageBox; pub use message_box::{MessageBox, MessageBoxButtons}; -pub mod align; - mod button; #[doc(hidden)] pub use button::PwtButton; diff --git a/src/widget/tooltip.rs b/src/widget/tooltip.rs index b08dbdc..2bcf2d6 100644 --- a/src/widget/tooltip.rs +++ b/src/widget/tooltip.rs @@ -3,8 +3,8 @@ use gloo_timers::callback::Timeout; use yew::html::IntoPropValue; use yew::virtual_dom::VNode; +use crate::dom::align::{align_to, AlignOptions, GrowDirection, Point}; use crate::prelude::*; -use crate::widget::align::{align_to, AlignOptions, GrowDirection, Point}; use crate::widget::Container; use pwt_macros::widget; @@ -77,12 +77,9 @@ impl Component for PwtTooltip { type Properties = Tooltip; fn create(_ctx: &Context) -> Self { - let align_options = AlignOptions::new(Point::BottomStart, Point::TopStart, GrowDirection::None) - .with_fallback_placement( - Point::TopStart, - Point::BottomStart, - GrowDirection::None, - ) + let align_options = + AlignOptions::new(Point::BottomStart, Point::TopStart, GrowDirection::None) + .with_fallback_placement(Point::TopStart, Point::BottomStart, GrowDirection::None) .with_fallback_placement(Point::TopEnd, Point::TopStart, GrowDirection::None) .with_fallback_placement(Point::TopStart, Point::TopEnd, GrowDirection::None) .with_fallback_placement( @@ -95,16 +92,8 @@ impl Component for PwtTooltip { Point::BottomStart, GrowDirection::StartEnd, ) - .with_fallback_placement( - Point::TopEnd, - Point::TopStart, - GrowDirection::TopBottom, - ) - .with_fallback_placement( - Point::TopStart, - Point::TopEnd, - GrowDirection::TopBottom, - ) + .with_fallback_placement(Point::TopEnd, Point::TopStart, GrowDirection::TopBottom) + .with_fallback_placement(Point::TopStart, Point::TopEnd, GrowDirection::TopBottom) .offset(4.0, 4.0); Self { -- 2.39.5