pub fn draggable_window<M>(inner: impl Childable<M>) -> impl FnOnce(Ctx) -> Ctx {
    |ctx: Ctx| {
        let main_box = ctx.current_entity();
        ctx.with(PositionType::SelfDirected)
            .with(Top(Units::Pixels(0.)))
            .with(Left(Units::Pixels(0.)))
            .child(|ctx| {
                let drag_box_entity = ctx.current_entity();
                ctx.with(UiColor(Color::BLACK))
                    .with(MinWidth(Units::Pixels(200.)))
                    .with(Width(Units::Auto))
                    .with(Height(Units::Pixels(20.)))
                    .with(OnClick::new(move |w| {
                        if let Some((cursor_pos, height)) = (|| {
                            let window = w.get_resource::<Windows>()?.get_primary()?;
                            Some((window.cursor_position()?, window.height()))
                        })() {
                            // preprocessing
                            let drag_box = w.entity(main_box);
                            let initial_pos = Vec2::Y * height + cursor_pos * Vec2::new(1., -1.);
                            let t = match drag_box.get::<Top>() {
                                Some(Top(Units::Pixels(p))) => *p,
                                _ => unreachable!(),
                            };
                            let l = match drag_box.get::<Left>() {
                                Some(Left(Units::Pixels(p))) => *p,
                                _ => unreachable!(),
                            };
                            let initial_lt = Vec2::new(l, t);
                            w.entity_mut(drag_box_entity).insert(EngagedDraggable {
                                process: Arc::new(move |w, cursor_pos| {
                                    // processing
                                    let cursor_pos =
                                        Vec2::Y * height + cursor_pos * Vec2::new(1., -1.);
                                    let delta = cursor_pos - initial_pos;
                                    let new_lt = initial_lt + delta;
                                    let mut drag_box = w.entity_mut(main_box);
                                    drag_box.insert(Left(Units::Pixels(new_lt.x)));
                                    drag_box.insert(Top(Units::Pixels(new_lt.y)));
                                }),
                            });
                        }
                    }))
                    .with(OnRelease::new(move |w| {
                        w.entity_mut(drag_box_entity).remove::<EngagedDraggable>();
                    }))
                    .with(Interaction::None)
                    .with(FuncScratch::default())
            })
            .child(|ctx| {
                ctx.with(MinWidth(Units::Pixels(200.)))
                    .with(Width(Units::Auto))
                    .with(MinHeight(Units::Pixels(180.)))
                    .with(Height(Units::Auto))
                    .with(UiColor(Color::DARK_GRAY))
                    .children(inner)
            })
    }
}
/// A window you can drag around in it's parent
///
/// Use in combination with [ManualRoot](crate::dom::ManualRoot) if you want to make a popup.
A window you can drag around in it's parent
Use in combination with [ManualRoot](crate::dom::ManualRoot) if you want to make a popup.
A window you can drag around in it ' s parent Use in combination with [ ManualRoot ] ( crate :: dom :: ManualRoot ) if you want to make a popup .
pub fn draggable_window<M>(inner: impl Childable<M>) -> impl FnOnce(Ctx) -> Ctx {
    |ctx: Ctx| {
        let main_box = ctx.current_entity();
        ctx.with(PositionType::SelfDirected)
            .with(Top(Units::Pixels(0.)))
            .with(Left(Units::Pixels(0.)))
            .child(|ctx| {
                let drag_box_entity = ctx.current_entity();
                ctx.with(UiColor(Color::BLACK))
                    .with(MinWidth(Units::Pixels(200.)))
                    .with(Width(Units::Auto))
                    .with(Height(Units::Pixels(20.)))
                    .with(OnClick::new(move |w| {
                        if let Some((cursor_pos, height)) = (|| {
                            let window = w.get_resource::<Windows>()?.get_primary()?;
                            Some((window.cursor_position()?, window.height()))
                        })() {
                            // preprocessing
                            let drag_box = w.entity(main_box);
                            let initial_pos = Vec2::Y * height + cursor_pos * Vec2::new(1., -1.);
                            let t = match drag_box.get::<Top>() {
                                Some(Top(Units::Pixels(p))) => *p,
                                _ => unreachable!(),
                            };
                            let l = match drag_box.get::<Left>() {
                                Some(Left(Units::Pixels(p))) => *p,
                                _ => unreachable!(),
                            };
                            let initial_lt = Vec2::new(l, t);
                            w.entity_mut(drag_box_entity).insert(EngagedDraggable {
                                process: Arc::new(move |w, cursor_pos| {
                                    // processing
                                    let cursor_pos =
                                        Vec2::Y * height + cursor_pos * Vec2::new(1., -1.);
                                    let delta = cursor_pos - initial_pos;
                                    let new_lt = initial_lt + delta;
                                    let mut drag_box = w.entity_mut(main_box);
                                    drag_box.insert(Left(Units::Pixels(new_lt.x)));
                                    drag_box.insert(Top(Units::Pixels(new_lt.y)));
                                }),
                            });
                        }
                    }))
                    .with(OnRelease::new(move |w| {
                        w.entity_mut(drag_box_entity).remove::<EngagedDraggable>();
                    }))
                    .with(Interaction::None)
                    .with(FuncScratch::default())
            })
            .child(|ctx| {
                ctx.with(MinWidth(Units::Pixels(200.)))
                    .with(Width(Units::Auto))
                    .with(MinHeight(Units::Pixels(180.)))
                    .with(Height(Units::Auto))
                    .with(UiColor(Color::DARK_GRAY))
                    .children(inner)
            })
    }
}
pub fn draggable_window < M > ( inner : impl Childable < M > ) -> impl FnOnce ( Ctx ) -> Ctx { | ctx : Ctx | { let main_box = ctx . current_entity ( ) ; ctx . with ( PositionType :: SelfDirected ) . with ( Top ( Units :: Pixels ( 0. ) ) ) . with ( Left ( Units :: Pixels ( 0. ) ) ) . child ( | ctx | { let drag_box_entity = ctx . current_entity ( ) ; ctx . with ( UiColor ( Color :: BLACK ) ) . with ( MinWidth ( Units :: Pixels ( 200. ) ) ) . with ( Width ( Units :: Auto ) ) . with ( Height ( Units :: Pixels ( 20. ) ) ) . with ( OnClick :: new ( move | w | { if let Some ( ( cursor_pos , height ) ) = ( | | { let window = w . get_resource :: < Windows > ( ) ? . get_primary ( ) ? ; Some ( ( window . cursor_position ( ) ? , window . height ( ) ) ) } ) ( ) { // preprocessing let drag_box = w . entity ( main_box ) ; let initial_pos = Vec2 :: Y * height + cursor_pos * Vec2 :: new ( 1. , - 1. ) ; let t = match drag_box . get :: < Top > ( ) { Some ( Top ( Units :: Pixels ( p ) ) ) => * p , _ => unreachable ! ( ) , } ; let l = match drag_box . get :: < Left > ( ) { Some ( Left ( Units :: Pixels ( p ) ) ) => * p , _ => unreachable ! ( ) , } ; let initial_lt = Vec2 :: new ( l , t ) ; w . entity_mut ( drag_box_entity ) . insert ( EngagedDraggable { process : Arc :: new ( move | w , cursor_pos | { // processing let cursor_pos = Vec2 :: Y * height + cursor_pos * Vec2 :: new ( 1. , - 1. ) ; let delta = cursor_pos - initial_pos ; let new_lt = initial_lt + delta ; let mut drag_box = w . entity_mut ( main_box ) ; drag_box . insert ( Left ( Units :: Pixels ( new_lt . x ) ) ) ; drag_box . insert ( Top ( Units :: Pixels ( new_lt . y ) ) ) ; } ) , } ) ; } } ) ) . with ( OnRelease :: new ( move | w | { w . entity_mut ( drag_box_entity ) . remove :: < EngagedDraggable > ( ) ; } ) ) . with ( Interaction :: None ) . with ( FuncScratch :: default ( ) ) } ) . child ( | ctx | { ctx . with ( MinWidth ( Units :: Pixels ( 200. ) ) ) . with ( Width ( Units :: Auto ) ) . with ( MinHeight ( Units :: Pixels ( 180. ) ) ) . with ( Height ( Units :: Auto ) ) . with ( UiColor ( Color :: DARK_GRAY ) ) . children ( inner ) } ) } }
A window you can drag around in it's parent
Use in combination with [ManualRoot](crate::dom::ManualRoot) if you want to make a popup.
A window you can drag around in it ' s parent Use in combination with [ ManualRoot ] ( crate :: dom :: ManualRoot ) if you want to make a popup .
inner
impl Childable<M>
inner
impl Childable<M>