feat(ui): add mouse events for card interactions
This commit is contained in:
50
src/ui.rs
50
src/ui.rs
@@ -5,8 +5,8 @@ mod series;
|
|||||||
use std::collections::BTreeMap;
|
use std::collections::BTreeMap;
|
||||||
|
|
||||||
use gpui::{
|
use gpui::{
|
||||||
App, Application, Bounds, Context, SharedString, Window, WindowBounds, WindowOptions, actions,
|
App, Application, Bounds, ClickEvent, Context, SharedString, Window, WindowBounds,
|
||||||
div, prelude::*, px, rgb, size,
|
WindowOptions, actions, div, prelude::*, px, rgb, size,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
@@ -40,7 +40,7 @@ impl Render for AppState {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
actions!(jello_actions, [OpenItem, OnLoadItem,]);
|
actions!(jello_actions, [OpenItem, OnLoadItem, MouseDownEvent]);
|
||||||
|
|
||||||
impl AppState {
|
impl AppState {
|
||||||
fn new(title: impl AsRef<str>, jellyfin_client: api::JellyfinClient) -> Self {
|
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>) {
|
// fn on_mouse_down(
|
||||||
// self.current_item = Some(item.0.clone());
|
// &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 {
|
fn header() -> impl IntoElement {
|
||||||
div()
|
div()
|
||||||
.flex()
|
.flex()
|
||||||
@@ -116,15 +133,15 @@ impl AppState {
|
|||||||
.gap_x_10()
|
.gap_x_10()
|
||||||
.border_t_10()
|
.border_t_10()
|
||||||
.p_5()
|
.p_5()
|
||||||
.child(Self::card())
|
.child(Self::card(cx, 1))
|
||||||
.child(Self::card())
|
.child(Self::card(cx, 2))
|
||||||
.child(Self::card())
|
.child(Self::card(cx, 3))
|
||||||
.child(Self::card())
|
.child(Self::card(cx, 4))
|
||||||
.child(Self::card())
|
.child(Self::card(cx, 5))
|
||||||
.child(Self::card())
|
.child(Self::card(cx, 6))
|
||||||
.child(Self::card())
|
.child(Self::card(cx, 7))
|
||||||
.child(Self::card())
|
.child(Self::card(cx, 8))
|
||||||
.child(Self::card()),
|
.child(Self::card(cx, 9)),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -138,8 +155,11 @@ impl AppState {
|
|||||||
.child(div().size_full().bg(gpui::yellow()))
|
.child(div().size_full().bg(gpui::yellow()))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn card() -> impl IntoElement {
|
fn card(cx: &mut Context<AppState>, number: usize) -> impl IntoElement {
|
||||||
div()
|
div()
|
||||||
|
.id(number)
|
||||||
|
.on_click(cx.listener(Self::load_item(number)))
|
||||||
|
.on_hover(cx.listener(Self::hover_item(number)))
|
||||||
.flex()
|
.flex()
|
||||||
.flex_col()
|
.flex_col()
|
||||||
.w_48()
|
.w_48()
|
||||||
|
|||||||
Reference in New Issue
Block a user