Fix event passthrough with image background
Diff
shalom/src/pages/room.rs | 38 ++++++++++++++++++++++++++++++--------
shalom/src/widgets/image_background.rs | 29 ++++++++++++++++++++++++-----
shalom/src/widgets/toggle_card.rs | 28 +++++++++++++++++++---------
3 files changed, 56 insertions(+), 39 deletions(-)
@@ -186,10 +186,15 @@
let mut col = Column::new().spacing(20).padding(40).push(header);
if let Some((_, speaker)) = self.speaker.clone() {
col = col.push(
container(
widgets::media_player::media_player(speaker, self.now_playing_image.clone())
match self.current_page {
Page::Climate => {}
Page::Listen => {
if let Some((_, speaker)) = self.speaker.clone() {
col = col.push(container(
widgets::media_player::media_player(
speaker,
self.now_playing_image.clone(),
)
.on_volume_change(Message::OnSpeakerVolumeChange)
.on_mute_change(Message::OnSpeakerMuteChange)
.on_repeat_change(Message::OnSpeakerRepeatChange)
@@ -198,20 +203,21 @@
.on_next_track(Message::OnSpeakerNextTrack)
.on_previous_track(Message::OnSpeakerPreviousTrack)
.on_shuffle_change(Message::OnSpeakerShuffleChange),
));
}
}
Page::Lights => {
let lights = Row::with_children(
self.lights
.iter()
.map(|(id, item)| light(*id, item))
.map(Element::from)
.collect::<Vec<_>>(),
)
.padding([12, 0, 24, 0]),
);
.spacing(10);
col = col.push(lights);
}
}
let lights = Row::with_children(
self.lights
.iter()
.map(|(id, item)| light(*id, item))
.map(Element::from)
.collect::<Vec<_>>(),
)
.spacing(10);
col = col.push(lights);
row![
RoomNavigation::new(self.current_page)
@@ -144,7 +144,9 @@
for Overlay<'a, 'b, M, R>
{
fn layout(&self, renderer: &R, _bounds: Size, position: Point) -> Node {
let limits = Limits::new(Size::ZERO, self.size).pad([0, 0, 10, 0].into());
let limits = Limits::new(Size::ZERO, self.size)
.width(Length::Fill)
.height(Length::Fill);
let mut child = self.el.as_widget().layout(renderer, &limits);
child.align(Alignment::Start, Alignment::Start, limits.max());
@@ -176,16 +178,23 @@
fn on_event(
&mut self,
_event: Event,
_layout: Layout<'_>,
_cursor: Cursor,
_renderer: &R,
_clipboard: &mut dyn Clipboard,
_shell: &mut Shell<'_, M>,
event: Event,
layout: Layout<'_>,
cursor: Cursor,
renderer: &R,
clipboard: &mut dyn Clipboard,
shell: &mut Shell<'_, M>,
) -> Status {
Status::Ignored
self.el.as_widget_mut().on_event(
self.tree,
event,
layout.children().next().unwrap(),
cursor,
renderer,
clipboard,
shell,
&layout.bounds(),
)
}
}
@@ -203,39 +203,41 @@
type Style = Theme;
fn appearance(&self, _style: &Self::Style) -> container::Appearance {
let c = |c| Color { a: 0.8, ..c };
match self {
Style::Disabled => container::Appearance {
text_color: Some(Color::BLACK),
background: Some(Background::Color(SLATE_600)),
border_radius: 5.0.into(),
text_color: Some(Color::WHITE),
background: Some(Background::Color(c(SLATE_600))),
border_radius: 10.0.into(),
border_width: 0.0,
border_color: Color::default(),
},
Style::Inactive => container::Appearance {
text_color: Some(Color::BLACK),
background: Some(Background::Color(SLATE_200)),
border_radius: 5.0.into(),
text_color: Some(Color::WHITE),
background: Some(Background::Color(c(SLATE_200))),
border_radius: 10.0.into(),
border_width: 0.0,
border_color: Color::default(),
},
Style::InactiveHover => container::Appearance {
text_color: Some(Color::BLACK),
background: Some(Background::Color(SLATE_300)),
border_radius: 5.0.into(),
text_color: Some(Color::WHITE),
background: Some(Background::Color(c(SLATE_300))),
border_radius: 10.0.into(),
border_width: 0.0,
border_color: Color::default(),
},
Style::Active(_) => container::Appearance {
text_color: Some(Color::WHITE),
background: Some(Background::Color(SKY_400)),
border_radius: 5.0.into(),
background: Some(Background::Color(c(SKY_400))),
border_radius: 10.0.into(),
border_width: 0.0,
border_color: Color::default(),
},
Style::ActiveHover(_) => container::Appearance {
text_color: Some(Color::WHITE),
background: Some(Background::Color(SKY_500)),
border_radius: 5.0.into(),
background: Some(Background::Color(c(SKY_500))),
border_radius: 10.0.into(),
border_width: 0.0,
border_color: Color::default(),
},