Skip to content

Commit 7e86b40

Browse files
committed
[update] monitor retrieval.
1 parent 811e15b commit 7e86b40

3 files changed

Lines changed: 25 additions & 26 deletions

File tree

crates/lambda-platform/src/winit/mod.rs

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -187,19 +187,14 @@ pub struct LoopPublisher<E: 'static> {
187187
}
188188

189189
impl<E: 'static + std::fmt::Debug> LoopPublisher<E> {
190-
/// Instantiate a new EventLoopPublisher from an event loop proxy.
190+
/// New LoopPublishers are created from a lambda_loop directly and don't need
191191
#[inline]
192-
pub fn new(winit_proxy: EventLoopProxy<E>) -> Self {
193-
return LoopPublisher { winit_proxy };
194-
}
195-
196-
/// Instantiate a new LoopPublisher from a loop
197-
pub fn from(lambda_loop: &Loop<E>) -> Self {
192+
pub fn new(lambda_loop: &Loop<E>) -> Self {
198193
let winit_proxy = lambda_loop.event_loop.create_proxy();
199194
return LoopPublisher { winit_proxy };
200195
}
201196

202-
/// Send an event
197+
/// Publishes an event into the event loop that created this publisher.
203198
#[inline]
204199
pub fn publish_event(&self, event: E) {
205200
self
@@ -210,9 +205,9 @@ impl<E: 'static + std::fmt::Debug> LoopPublisher<E> {
210205
}
211206

212207
impl<E: 'static + std::fmt::Debug> Loop<E> {
213-
pub fn create_publisher(&mut self) -> LoopPublisher<E> {
214-
let proxy = self.event_loop.create_proxy();
215-
return LoopPublisher::new(proxy);
208+
/// Create an event publisher for this Loop.
209+
pub fn create_event_publisher(&mut self) -> LoopPublisher<E> {
210+
return LoopPublisher::new(&self);
216211
}
217212

218213
/// Returns the primary monitor for the current OS if detectable.
@@ -225,12 +220,9 @@ impl<E: 'static + std::fmt::Debug> Loop<E> {
225220
return self.event_loop.available_monitors();
226221
}
227222

228-
pub fn get_any_available_monitors(&self) -> MonitorHandle {
229-
// TODO(vmarcella): Remove the panic from this in favor of returning a result or an error.
230-
match self.event_loop.available_monitors().next() {
231-
Some(monitor) => monitor,
232-
None => panic!("No available monitors found."),
233-
}
223+
/// Gets the first available monitor or panics.
224+
pub fn get_any_available_monitors(&self) -> Option<MonitorHandle> {
225+
return self.event_loop.available_monitors().next();
234226
}
235227

236228
/// Uses the winit event loop to run forever

lambda/src/core/render/window.rs

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,24 @@ pub struct WindowBuilder {
1313
}
1414

1515
impl WindowBuilder {
16-
/// Construct a new window window builder.
16+
/// A new window builder will be 480x360 by default and have the name
17+
/// "Window". After customizing the window with whatever properties your
18+
/// application needs, you can supply it an event loop to process the
19+
/// events that will be generated by the window.
1720
pub fn new() -> Self {
1821
return Self {
19-
name: "Window".to_string(),
22+
name: String::from("Window"),
2023
dimensions: (480, 360),
2124
};
2225
}
2326

24-
/// The name of the window (Will also appear as the title of the window/application)
27+
/// The name to be displayed in the title bar of the window.
2528
pub fn with_name(mut self, name: &str) -> Self {
2629
self.name = name.to_string();
2730
return self;
2831
}
2932

30-
/// Specify the dimensions for the window (Defaults to 480 x 360)
33+
/// Specify the dimensions for the window (Defaults to 480 x 360).
3134
pub fn with_dimensions(mut self, width: u32, height: u32) -> Self {
3235
self.dimensions = (width, height);
3336
return self;
@@ -50,9 +53,13 @@ impl Window {
5053
dimensions: (u32, u32),
5154
event_loop: &mut Loop<Events>,
5255
) -> Self {
53-
let monitor_handle = event_loop
54-
.get_primary_monitor()
55-
.unwrap_or(event_loop.get_any_available_monitors());
56+
// Attempt to get the primary monitor first and then falls back to the first
57+
// available monitor if that isn't found.
58+
let monitor_handle = event_loop.get_primary_monitor().unwrap_or(
59+
event_loop
60+
.get_any_available_monitors()
61+
.expect("No monitors available"),
62+
);
5663

5764
let window_properties = WindowProperties {
5865
name: name.to_string(),
@@ -77,7 +84,7 @@ impl Window {
7784
return &self.window_handle;
7885
}
7986

80-
/// Returns the dimensions of the current window.
87+
/// Returns the dimensions of the current window. (width, height)
8188
pub fn dimensions(&self) -> (u32, u32) {
8289
return (
8390
self.window_handle.size.width,

lambda/src/runtimes/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ impl Runtime for GenericRuntime {
132132

133133
let mut active_render_api = Some(render_api);
134134

135-
let publisher = event_loop.create_publisher();
135+
let publisher = event_loop.create_event_publisher();
136136
publisher.publish_event(Events::Runtime {
137137
event: RuntimeEvent::Initialized,
138138
issued_at: Instant::now(),

0 commit comments

Comments
 (0)