items are hoverable
This commit is contained in:
parent
a792bc459f
commit
9753c6f366
|
@ -25,6 +25,8 @@ pub(crate) struct Library {
|
||||||
presentation_library: Model<Presentation>,
|
presentation_library: Model<Presentation>,
|
||||||
library_open: Option<LibraryKind>,
|
library_open: Option<LibraryKind>,
|
||||||
library_hovered: Option<LibraryKind>,
|
library_hovered: Option<LibraryKind>,
|
||||||
|
selected_item: Option<(LibraryKind, i32)>,
|
||||||
|
hovered_item: Option<(LibraryKind, i32)>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
|
@ -34,6 +36,8 @@ pub(crate) enum Message {
|
||||||
OpenItem,
|
OpenItem,
|
||||||
HoverLibrary(Option<LibraryKind>),
|
HoverLibrary(Option<LibraryKind>),
|
||||||
OpenLibrary(Option<LibraryKind>),
|
OpenLibrary(Option<LibraryKind>),
|
||||||
|
HoverItem(Option<(LibraryKind, i32)>),
|
||||||
|
SelectItem(Option<(LibraryKind, i32)>),
|
||||||
None,
|
None,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -50,6 +54,8 @@ impl Library {
|
||||||
.await,
|
.await,
|
||||||
library_open: None,
|
library_open: None,
|
||||||
library_hovered: None,
|
library_hovered: None,
|
||||||
|
selected_item: None,
|
||||||
|
hovered_item: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -67,6 +73,14 @@ impl Library {
|
||||||
self.library_open = library_kind;
|
self.library_open = library_kind;
|
||||||
Task::none()
|
Task::none()
|
||||||
}
|
}
|
||||||
|
Message::HoverItem(item) => {
|
||||||
|
self.hovered_item = item;
|
||||||
|
Task::none()
|
||||||
|
}
|
||||||
|
Message::SelectItem(item) => {
|
||||||
|
self.hovered_item = item;
|
||||||
|
Task::none()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -156,20 +170,25 @@ impl Library {
|
||||||
})
|
})
|
||||||
.on_enter(Message::HoverLibrary(Some(model.kind)))
|
.on_enter(Message::HoverLibrary(Some(model.kind)))
|
||||||
.on_exit(Message::HoverLibrary(None));
|
.on_exit(Message::HoverLibrary(None));
|
||||||
let lib_container = if self.library_open == Some(model.kind) {
|
let lib_container =
|
||||||
|
if self.library_open == Some(model.kind) {
|
||||||
let items = scrollable(
|
let items = scrollable(
|
||||||
column({
|
column({
|
||||||
model.items.iter().map(|item| {
|
model.items.iter().enumerate().map(
|
||||||
let text =
|
|(index, item)| {
|
||||||
Container::new(responsive(|size| {
|
let text = Container::new(
|
||||||
|
responsive(|size| {
|
||||||
text::heading(elide_text(
|
text::heading(elide_text(
|
||||||
item.title(),
|
item.title(),
|
||||||
size.width,
|
size.width,
|
||||||
))
|
))
|
||||||
.center()
|
.center()
|
||||||
.wrapping(textm::Wrapping::None)
|
.wrapping(
|
||||||
|
textm::Wrapping::None,
|
||||||
|
)
|
||||||
.into()
|
.into()
|
||||||
}))
|
}),
|
||||||
|
)
|
||||||
.center_y(25)
|
.center_y(25)
|
||||||
.center_x(Length::Fill);
|
.center_x(Length::Fill);
|
||||||
let icon = icon::from_name({
|
let icon = icon::from_name({
|
||||||
|
@ -188,9 +207,11 @@ impl Library {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
mouse_area(
|
||||||
Container::new(
|
Container::new(
|
||||||
rowm![
|
rowm![
|
||||||
horizontal_space().width(0),
|
horizontal_space()
|
||||||
|
.width(0),
|
||||||
icon,
|
icon,
|
||||||
text
|
text
|
||||||
]
|
]
|
||||||
|
@ -199,17 +220,55 @@ impl Library {
|
||||||
)
|
)
|
||||||
.padding(5)
|
.padding(5)
|
||||||
.width(Length::Fill)
|
.width(Length::Fill)
|
||||||
.style(|t| {
|
.style(move |t| {
|
||||||
container::Style::default()
|
container::Style::default()
|
||||||
.background(Background::Color(
|
.background(Background::Color(
|
||||||
t.cosmic().button.base.into(),
|
if let Some((
|
||||||
))
|
library,
|
||||||
.border(Border::default().rounded(
|
hovered,
|
||||||
t.cosmic().corner_radii.radius_l,
|
)) = self.hovered_item
|
||||||
))
|
{
|
||||||
})
|
if model.kind == library
|
||||||
|
&& hovered
|
||||||
|
== index as i32
|
||||||
|
{
|
||||||
|
t.cosmic()
|
||||||
|
.button
|
||||||
|
.hover
|
||||||
.into()
|
.into()
|
||||||
})
|
} else {
|
||||||
|
t.cosmic()
|
||||||
|
.button
|
||||||
|
.base
|
||||||
|
.into()
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
t.cosmic()
|
||||||
|
.button
|
||||||
|
.base
|
||||||
|
.into()
|
||||||
|
},
|
||||||
|
))
|
||||||
|
.border(
|
||||||
|
Border::default().rounded(
|
||||||
|
t.cosmic()
|
||||||
|
.corner_radii
|
||||||
|
.radius_l,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
.on_enter(Message::HoverItem(Some((
|
||||||
|
model.kind,
|
||||||
|
index as i32,
|
||||||
|
))))
|
||||||
|
.on_exit(Message::HoverItem(None))
|
||||||
|
.on_press(Message::SelectItem(Some(
|
||||||
|
(model.kind, index as i32),
|
||||||
|
)))
|
||||||
|
.into()
|
||||||
|
},
|
||||||
|
)
|
||||||
})
|
})
|
||||||
.spacing(2)
|
.spacing(2)
|
||||||
.width(Length::Fill),
|
.width(Length::Fill),
|
||||||
|
@ -219,11 +278,9 @@ impl Library {
|
||||||
.background(Background::Color(
|
.background(Background::Color(
|
||||||
t.cosmic().primary.base.into(),
|
t.cosmic().primary.base.into(),
|
||||||
))
|
))
|
||||||
.border(
|
.border(Border::default().rounded(
|
||||||
Border::default().rounded(
|
|
||||||
t.cosmic().corner_radii.radius_m,
|
t.cosmic().corner_radii.radius_m,
|
||||||
),
|
))
|
||||||
)
|
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
Container::new(Space::new(0, 0))
|
Container::new(Space::new(0, 0))
|
||||||
|
|
Loading…
Reference in a new issue