Focus shared screen item when clicking on it

This commit is contained in:
Antonio Scandurra 2022-10-24 11:02:10 +02:00
parent a8bd234aa4
commit e135b982c1

View file

@ -6,7 +6,7 @@ use futures::StreamExt;
use gpui::{ use gpui::{
elements::*, elements::*,
geometry::{rect::RectF, vector::vec2f}, geometry::{rect::RectF, vector::vec2f},
Entity, ModelHandle, RenderContext, Task, View, ViewContext, Entity, ModelHandle, MouseButton, RenderContext, Task, View, ViewContext,
}; };
use smallvec::SmallVec; use smallvec::SmallVec;
use std::{ use std::{
@ -63,21 +63,27 @@ impl View for SharedScreen {
"SharedScreen" "SharedScreen"
} }
fn render(&mut self, _: &mut RenderContext<Self>) -> ElementBox { fn render(&mut self, cx: &mut RenderContext<Self>) -> ElementBox {
enum Focus {}
let frame = self.frame.clone(); let frame = self.frame.clone();
Canvas::new(move |bounds, _, cx| { MouseEventHandler::<Focus>::new(0, cx, |_, _| {
if let Some(frame) = frame.clone() { Canvas::new(move |bounds, _, cx| {
let size = constrain_size_preserving_aspect_ratio( if let Some(frame) = frame.clone() {
bounds.size(), let size = constrain_size_preserving_aspect_ratio(
vec2f(frame.width() as f32, frame.height() as f32), bounds.size(),
); vec2f(frame.width() as f32, frame.height() as f32),
let origin = bounds.origin() + (bounds.size() / 2.) - size / 2.; );
cx.scene.push_surface(gpui::mac::Surface { let origin = bounds.origin() + (bounds.size() / 2.) - size / 2.;
bounds: RectF::new(origin, size), cx.scene.push_surface(gpui::mac::Surface {
image_buffer: frame.image(), bounds: RectF::new(origin, size),
}); image_buffer: frame.image(),
} });
}
})
.boxed()
}) })
.on_down(MouseButton::Left, |_, cx| cx.focus_parent_view())
.boxed() .boxed()
} }
} }