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,29 +172,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 =
|
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 =
|
||||||
let text = Container::new(
|
Container::new(responsive(|size| {
|
||||||
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(
|
.into()
|
||||||
textm::Wrapping::None,
|
}))
|
||||||
)
|
|
||||||
.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({
|
||||||
match model.kind {
|
match model.kind {
|
||||||
LibraryKind::Song => {
|
LibraryKind::Song => {
|
||||||
"folder-music-symbolic"
|
"folder-music-symbolic"
|
||||||
}
|
}
|
||||||
|
@ -206,85 +204,117 @@ impl Library {
|
||||||
"x-office-presentation-symbolic"
|
"x-office-presentation-symbolic"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
mouse_area(
|
mouse_area(
|
||||||
Container::new(
|
Container::new(
|
||||||
rowm![
|
rowm![
|
||||||
horizontal_space()
|
horizontal_space().width(0),
|
||||||
.width(0),
|
icon,
|
||||||
icon,
|
text
|
||||||
text
|
]
|
||||||
]
|
.spacing(10)
|
||||||
.spacing(10)
|
.align_y(Vertical::Center),
|
||||||
.align_y(Vertical::Center),
|
|
||||||
)
|
|
||||||
.padding(5)
|
|
||||||
.width(Length::Fill)
|
|
||||||
.style(move |t| {
|
|
||||||
container::Style::default()
|
|
||||||
.background(Background::Color(
|
|
||||||
if let Some((
|
|
||||||
library,
|
|
||||||
hovered,
|
|
||||||
)) = self.hovered_item
|
|
||||||
{
|
|
||||||
if model.kind == library
|
|
||||||
&& hovered
|
|
||||||
== index as i32
|
|
||||||
{
|
|
||||||
t.cosmic()
|
|
||||||
.button
|
|
||||||
.hover
|
|
||||||
.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((
|
.padding(5)
|
||||||
model.kind,
|
.width(Length::Fill)
|
||||||
index as i32,
|
.style(move |t| {
|
||||||
))))
|
container::Style::default()
|
||||||
.on_exit(Message::HoverItem(None))
|
.background(
|
||||||
.on_press(Message::SelectItem(Some(
|
Background::Color(
|
||||||
(model.kind, index as i32),
|
if let Some((
|
||||||
)))
|
library,
|
||||||
.into()
|
selected,
|
||||||
},
|
)) =
|
||||||
)
|
self.selected_item
|
||||||
})
|
{
|
||||||
.spacing(2)
|
if model.kind
|
||||||
.width(Length::Fill),
|
== library
|
||||||
);
|
&& selected
|
||||||
Container::new(items).padding(5).style(|t| {
|
== index
|
||||||
container::Style::default()
|
as i32
|
||||||
.background(Background::Color(
|
{
|
||||||
t.cosmic().primary.base.into(),
|
t.cosmic()
|
||||||
))
|
.accent
|
||||||
.border(Border::default().rounded(
|
.selected
|
||||||
t.cosmic().corner_radii.radius_m,
|
.into()
|
||||||
))
|
} else {
|
||||||
|
t.cosmic()
|
||||||
|
.button
|
||||||
|
.base
|
||||||
|
.into()
|
||||||
|
}
|
||||||
|
} else if let Some(
|
||||||
|
(
|
||||||
|
library,
|
||||||
|
hovered,
|
||||||
|
),
|
||||||
|
) =
|
||||||
|
self.hovered_item
|
||||||
|
{
|
||||||
|
if model.kind
|
||||||
|
== library
|
||||||
|
&& hovered
|
||||||
|
== index
|
||||||
|
as i32
|
||||||
|
{
|
||||||
|
t.cosmic()
|
||||||
|
.button
|
||||||
|
.hover
|
||||||
|
.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()
|
||||||
|
},
|
||||||
|
)
|
||||||
})
|
})
|
||||||
} else {
|
.spacing(2)
|
||||||
Container::new(Space::new(0, 0))
|
.width(Length::Fill),
|
||||||
};
|
);
|
||||||
|
Container::new(items).padding(5).style(|t| {
|
||||||
|
container::Style::default()
|
||||||
|
.background(Background::Color(
|
||||||
|
t.cosmic().primary.base.into(),
|
||||||
|
))
|
||||||
|
.border(
|
||||||
|
Border::default().rounded(
|
||||||
|
t.cosmic().corner_radii.radius_m,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
Container::new(Space::new(0, 0))
|
||||||
|
};
|
||||||
column![button, lib_container].into()
|
column![button, lib_container].into()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue