making the button selectable?
This commit is contained in:
parent
e7d06b5b6c
commit
2ea2a390a4
|
@ -7,6 +7,7 @@ use cosmic::{
|
||||||
},
|
},
|
||||||
Element, Task,
|
Element, Task,
|
||||||
};
|
};
|
||||||
|
use tracing::debug;
|
||||||
|
|
||||||
use crate::core::{
|
use crate::core::{
|
||||||
content::Content,
|
content::Content,
|
||||||
|
@ -79,6 +80,7 @@ impl Library {
|
||||||
}
|
}
|
||||||
Message::SelectItem(item) => {
|
Message::SelectItem(item) => {
|
||||||
self.hovered_item = item;
|
self.hovered_item = item;
|
||||||
|
debug!(?self.hovered_item);
|
||||||
Task::none()
|
Task::none()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -170,25 +172,21 @@ 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 =
|
let lib_container = if self.library_open == Some(model.kind) {
|
||||||
if self.library_open == Some(model.kind) {
|
|
||||||
let items = scrollable(
|
let items = scrollable(
|
||||||
column({
|
column({
|
||||||
model.items.iter().enumerate().map(
|
model.items.iter().enumerate().map(
|
||||||
|(index, item)| {
|
|(index, item)| {
|
||||||
let text = Container::new(
|
let text =
|
||||||
responsive(|size| {
|
Container::new(responsive(|size| {
|
||||||
text::heading(elide_text(
|
text::heading(elide_text(
|
||||||
item.title(),
|
item.title(),
|
||||||
size.width,
|
size.width,
|
||||||
))
|
))
|
||||||
.center()
|
.center()
|
||||||
.wrapping(
|
.wrapping(textm::Wrapping::None)
|
||||||
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({
|
||||||
|
@ -210,8 +208,7 @@ impl Library {
|
||||||
mouse_area(
|
mouse_area(
|
||||||
Container::new(
|
Container::new(
|
||||||
rowm![
|
rowm![
|
||||||
horizontal_space()
|
horizontal_space().width(0),
|
||||||
.width(0),
|
|
||||||
icon,
|
icon,
|
||||||
text
|
text
|
||||||
]
|
]
|
||||||
|
@ -222,15 +219,43 @@ impl Library {
|
||||||
.width(Length::Fill)
|
.width(Length::Fill)
|
||||||
.style(move |t| {
|
.style(move |t| {
|
||||||
container::Style::default()
|
container::Style::default()
|
||||||
.background(Background::Color(
|
.background(
|
||||||
|
Background::Color(
|
||||||
if let Some((
|
if let Some((
|
||||||
library,
|
library,
|
||||||
hovered,
|
selected,
|
||||||
)) = self.hovered_item
|
)) =
|
||||||
|
self.selected_item
|
||||||
{
|
{
|
||||||
if model.kind == library
|
if model.kind
|
||||||
|
== library
|
||||||
|
&& selected
|
||||||
|
== index
|
||||||
|
as i32
|
||||||
|
{
|
||||||
|
t.cosmic()
|
||||||
|
.accent
|
||||||
|
.selected
|
||||||
|
.into()
|
||||||
|
} else {
|
||||||
|
t.cosmic()
|
||||||
|
.button
|
||||||
|
.base
|
||||||
|
.into()
|
||||||
|
}
|
||||||
|
} else if let Some(
|
||||||
|
(
|
||||||
|
library,
|
||||||
|
hovered,
|
||||||
|
),
|
||||||
|
) =
|
||||||
|
self.hovered_item
|
||||||
|
{
|
||||||
|
if model.kind
|
||||||
|
== library
|
||||||
&& hovered
|
&& hovered
|
||||||
== index as i32
|
== index
|
||||||
|
as i32
|
||||||
{
|
{
|
||||||
t.cosmic()
|
t.cosmic()
|
||||||
.button
|
.button
|
||||||
|
@ -248,9 +273,11 @@ impl Library {
|
||||||
.base
|
.base
|
||||||
.into()
|
.into()
|
||||||
},
|
},
|
||||||
))
|
),
|
||||||
|
)
|
||||||
.border(
|
.border(
|
||||||
Border::default().rounded(
|
Border::default()
|
||||||
|
.rounded(
|
||||||
t.cosmic()
|
t.cosmic()
|
||||||
.corner_radii
|
.corner_radii
|
||||||
.radius_l,
|
.radius_l,
|
||||||
|
@ -263,9 +290,10 @@ impl Library {
|
||||||
index as i32,
|
index as i32,
|
||||||
))))
|
))))
|
||||||
.on_exit(Message::HoverItem(None))
|
.on_exit(Message::HoverItem(None))
|
||||||
.on_press(Message::SelectItem(Some(
|
.on_press(Message::SelectItem(Some((
|
||||||
(model.kind, index as i32),
|
model.kind,
|
||||||
)))
|
index as i32,
|
||||||
|
))))
|
||||||
.into()
|
.into()
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
@ -278,9 +306,11 @@ impl Library {
|
||||||
.background(Background::Color(
|
.background(Background::Color(
|
||||||
t.cosmic().primary.base.into(),
|
t.cosmic().primary.base.into(),
|
||||||
))
|
))
|
||||||
.border(Border::default().rounded(
|
.border(
|
||||||
|
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