Skip to content

Commit

Permalink
sctk_subsurface: Use two surfaces, handle button presses
Browse files Browse the repository at this point in the history
Useful for testing pointer input to subsurfaces.
  • Loading branch information
ids1024 committed Feb 27, 2024
1 parent 971ff40 commit 749ee84
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions examples/sctk_subsurface/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ struct SubsurfaceApp {
pub enum Message {
WaylandEvent(WaylandEvent),
Wayland(wayland::Event),
Pressed(&'static str),
}

impl Application for SubsurfaceApp {
Expand Down Expand Up @@ -65,16 +66,32 @@ impl Application for SubsurfaceApp {
self.red_buffer = Some(buffer);
}
},
Message::Pressed(side) => println!("{side} surface pressed"),
}
Command::none()
}

fn view(&self, _id: window::Id) -> Element<Self::Message> {
if let Some(buffer) = &self.red_buffer {
iced_sctk::subsurface_widget::Subsurface::new(1, 1, buffer)
iced::widget::row![
iced::widget::button(
iced_sctk::subsurface_widget::Subsurface::new(1, 1, buffer)
.width(Length::Fill)
.height(Length::Fill)
)
.width(Length::Fill)
.height(Length::Fill)
.into()
.on_press(Message::Pressed("left")),
iced::widget::button(
iced_sctk::subsurface_widget::Subsurface::new(1, 1, buffer)
.width(Length::Fill)
.height(Length::Fill)
)
.width(Length::Fill)
.height(Length::Fill)
.on_press(Message::Pressed("right"))
]
.into()
} else {
text("No subsurface").into()
}
Expand Down

0 comments on commit 749ee84

Please sign in to comment.