Skip to content

Commit 7950021

Browse files
committed
[remove] Redundant functions
1 parent 2288cbe commit 7950021

1 file changed

Lines changed: 9 additions & 63 deletions

File tree

  • crates/lambda-platform/src/winit

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

Lines changed: 9 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,6 @@ pub struct Loop<E: 'static> {
5050
event_loop: EventLoop<E>,
5151
}
5252

53-
/// TODO(ahlawat) = Remove this and refactor the code depending directly on it.
54-
pub fn create_event_loop<Events: 'static>() -> Loop<Events> {
55-
let event_loop = EventLoop::<Events>::with_user_event();
56-
return Loop { event_loop };
57-
}
58-
5953
/// Structure that contains properties needed for building a window.
6054
pub struct WindowProperties {
6155
pub name: String,
@@ -107,10 +101,10 @@ impl WindowHandleBuilder {
107101

108102
/// Set the window size for the WindowHandle
109103
fn with_window_size(
110-
&mut self,
104+
mut self,
111105
window_size: [u32; 2],
112106
scale_factor: f64,
113-
) -> self {
107+
) -> Self {
114108
let logical: LogicalSize<u32> = window_size.into();
115109
let physical: PhysicalSize<u32> = logical_size.to_physical(scale_factor);
116110

@@ -121,27 +115,28 @@ impl WindowHandleBuilder {
121115
physical,
122116
};
123117

124-
self.size = Some(window_size);
118+
self.size = window_size;
125119
return self;
126120
}
127121

128122
/// Probably the function that'll be used the most
129123
pub fn with_window_properties<E: 'static>(
130-
&mut self,
124+
mut self,
131125
window_properties: WindowProperties,
132126
lambda_loop: &Loop<E>,
133-
) -> self {
127+
) -> Self {
134128
let WindowProperties {
135129
name,
136130
dimensions,
137131
monitor_handle,
138132
} = window_properties;
139133

140-
self.with_window_size(dimensions, monitor_handle.scale_factor());
134+
// TODO(ahlawat) = Find out if there's a better way to do this. Looks kinda ugly.
135+
self = self.with_window_size(dimensions, monitor_handle.scale_factor());
141136

142137
let window_handle = WindowBuilder::new()
143138
.with_title(name)
144-
.with_inner_size(self.size.expect("No window size found.").logical)
139+
.with_inner_size(self.size.logical)
145140
.build(&lambda_loop.event_loop)
146141
.expect("Failed creation of window handle");
147142

@@ -156,31 +151,12 @@ impl WindowHandleBuilder {
156151
monitor_handle: self
157152
.monitor_handle
158153
.expect("Unable to find a MonitorHandle."),
159-
size: self.size.expect("Unable to find WindowSize."),
154+
size: self.size,
160155
window_handle: self.window_handle.expect("Unable to find WindowHandle."),
161156
};
162157
}
163158
}
164159

165-
// TODO(ahlawat) = Remove this as well?
166-
/// Construct WindowSize metdata from the window dimensions and scale factor of
167-
/// the monitor being rendered to.
168-
#[inline]
169-
fn construct_window_size(
170-
window_size: [u32; 2],
171-
scale_factor: f64,
172-
) -> WindowSize {
173-
let logical: LogicalSize<u32> = window_size.into();
174-
let physical: PhysicalSize<u32> = logical.to_physical(scale_factor);
175-
176-
return WindowSize {
177-
width: window_size[0],
178-
height: window_size[1],
179-
logical,
180-
physical,
181-
};
182-
}
183-
184160
pub struct LoopPublisher<E: 'static> {
185161
winit_proxy: EventLoopProxy<E>,
186162
}
@@ -206,12 +182,6 @@ impl<E: 'static> LoopPublisher<E> {
206182
}
207183

208184
impl<E: 'static> Loop<E> {
209-
// TODO(ahlawat) = Possibly remove this?
210-
pub fn create_publisher(&mut self) -> LoopPublisher<E> {
211-
let proxy = self.event_loop.create_proxy();
212-
return LoopPublisher::new(proxy);
213-
}
214-
215185
/// Returns the primary monitor for the current OS if detectable.
216186
pub fn get_primary_monitor(&self) -> Option<MonitorHandle> {
217187
return self.event_loop.primary_monitor();
@@ -237,28 +207,4 @@ impl<E: 'static> Loop<E> {
237207
{
238208
self.event_loop.run(callback);
239209
}
240-
241-
// TODO(ahlawat) = Should this be here?
242-
pub fn create_window_handle(
243-
&mut self,
244-
window_properties: WindowProperties,
245-
) -> WindowHandle {
246-
let name = window_properties.name;
247-
let dimensions = window_properties.dimensions;
248-
let monitor_handle = window_properties.monitor_handle;
249-
250-
let size = construct_window_size(dimensions, monitor_handle.scale_factor());
251-
252-
let window_handle = WindowBuilder::new()
253-
.with_title(name)
254-
.with_inner_size(size.logical)
255-
.build(&self.event_loop)
256-
.expect("Failed to create a winit handle.");
257-
258-
return WindowHandle {
259-
window_handle,
260-
size,
261-
monitor_handle,
262-
};
263-
}
264210
}

0 commit comments

Comments
 (0)