From 80fe0bc2e1a9790a6f30a066a942ce44ecf2faf7 Mon Sep 17 00:00:00 2001 From: cel 🌸 Date: Sat, 24 May 2025 10:12:15 +0100 Subject: WIP: right-click menu --- src/lib.rs | 64 +++++++++++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 51 insertions(+), 13 deletions(-) (limited to 'src') diff --git a/src/lib.rs b/src/lib.rs index 570d2f6..a3e153b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,14 +1,5 @@ use std::{ - borrow::Borrow, - cell::RefCell, - collections::{HashMap, HashSet}, - marker::PhantomData, - ops::{Deref, DerefMut}, - rc::Rc, - str::FromStr, - sync::{atomic::AtomicUsize, Arc, RwLock}, - thread::sleep, - time::{self, Duration}, + borrow::Borrow, cell::RefCell, cmp::{max, min}, collections::{HashMap, HashSet}, marker::PhantomData, ops::{Deref, DerefMut}, rc::Rc, str::FromStr, sync::{atomic::AtomicUsize, Arc, RwLock}, thread::sleep, time::{self, Duration} }; use base64::{Engine, prelude::BASE64_STANDARD}; @@ -20,10 +11,10 @@ use futures::stream::StreamExt; use indexmap::IndexMap; use jid::JID; use leptos::{ - ev::{Event, KeyboardEvent, SubmitEvent}, + ev::{Event, KeyboardEvent, MouseEvent, SubmitEvent}, html::{self, Div, Input, Pre, Textarea}, - prelude::*, - tachys::{dom::document, reactive_graph::bind::GetValue}, + prelude::{document, *}, + tachys::{dom::{document, window}, reactive_graph::bind::GetValue}, task::{spawn, spawn_local}, }; use reactive_stores::{ArcStore, Store, StoreField}; @@ -2581,3 +2572,50 @@ fn ChatsListItem(chat: MacawChat, message: MacawMessage) -> impl IntoView { } } + +#[component] +fn ContextMenu(menu: Children, children: Children) -> impl IntoView { + let (open, set_open) = signal(false); + + let on_click = |e: MouseEvent| { + e.prevent_default(); + let window = window(); + let menu = document().get_element_by_id("context-menu").expect(""); + let menu_content = document().get_element_by_id("context-menu-content"); + let x = e.client_x(); + let y = e.client_y(); + let x = max(0, min(x, window.outer_width() - menu.outer_width())); + let y = max(0, min(y, window.outer_height() - menu.outer_height())); + // set as visible + }; + + view! { + {children()} + {move || if *open.read() { + view! { +
+
+ +
+ }.into_any() + } else { + view! {}.into_any() + }} + } +} + +#[component] +fn ContextMenuWrap(children: Children) -> impl IntoView { + let (context_menu context_menu) = signal(None::>); + + view! { +
+ {children()} +
+ {move || context_menu.get()} +
+
+
+ } +} + -- cgit