feat(ui): add mouse events for card interactions

This commit is contained in:
uttarayan21
2025-11-17 02:18:26 +05:30
parent df06190c14
commit 6ac7aa8ad8

View File

@@ -5,8 +5,8 @@ mod series;
use std::collections::BTreeMap;
use gpui::{
App, Application, Bounds, Context, SharedString, Window, WindowBounds, WindowOptions, actions,
div, prelude::*, px, rgb, size,
App, Application, Bounds, ClickEvent, Context, SharedString, Window, WindowBounds,
WindowOptions, actions, div, prelude::*, px, rgb, size,
};
#[derive(Clone, Debug)]
@@ -40,7 +40,7 @@ impl Render for AppState {
}
}
actions!(jello_actions, [OpenItem, OnLoadItem,]);
actions!(jello_actions, [OpenItem, OnLoadItem, MouseDownEvent]);
impl AppState {
fn new(title: impl AsRef<str>, jellyfin_client: api::JellyfinClient) -> Self {
@@ -53,10 +53,27 @@ impl AppState {
}
}
// fn on_open_item(&mut self, _: &OpenItem, _: &mut Window, cx: &mut Context<Self>) {
// self.current_item = Some(item.0.clone());
// fn on_mouse_down(
// &mut self,
// event: &MouseDownEvent,
// window: &mut Window,
// cx: &mut Context<Self>,
// ) {
// // Handle mouse down event
// }
fn load_item(id: usize) -> impl Fn(&mut Self, &ClickEvent, &mut Window, &mut Context<Self>) {
move |state: &mut Self, event: &ClickEvent, window: &mut Window, cx: &mut Context<Self>| {
dbg!("Loading item with ID: {}", id);
}
}
fn hover_item(id: usize) -> impl Fn(&mut Self, &bool, &mut Window, &mut Context<Self>) {
move |state: &mut Self, item: &bool, window: &mut Window, cx: &mut Context<Self>| {
dbg!("Hovering over item: {:?}", id);
}
}
fn header() -> impl IntoElement {
div()
.flex()
@@ -116,15 +133,15 @@ impl AppState {
.gap_x_10()
.border_t_10()
.p_5()
.child(Self::card())
.child(Self::card())
.child(Self::card())
.child(Self::card())
.child(Self::card())
.child(Self::card())
.child(Self::card())
.child(Self::card())
.child(Self::card()),
.child(Self::card(cx, 1))
.child(Self::card(cx, 2))
.child(Self::card(cx, 3))
.child(Self::card(cx, 4))
.child(Self::card(cx, 5))
.child(Self::card(cx, 6))
.child(Self::card(cx, 7))
.child(Self::card(cx, 8))
.child(Self::card(cx, 9)),
)
}
@@ -138,8 +155,11 @@ impl AppState {
.child(div().size_full().bg(gpui::yellow()))
}
fn card() -> impl IntoElement {
fn card(cx: &mut Context<AppState>, number: usize) -> impl IntoElement {
div()
.id(number)
.on_click(cx.listener(Self::load_item(number)))
.on_hover(cx.listener(Self::hover_item(number)))
.flex()
.flex_col()
.w_48()