Skip to content

Commit d1d2962

Browse files
committed
[update] event imports & update lambda-platform documentation.
1 parent ac49d73 commit d1d2962

3 files changed

Lines changed: 56 additions & 44 deletions

File tree

crates/lambda-platform/src/gfx/api.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
//! GPU API exports to set the platforms primary rendering API for rendering
2+
//! implementations to use.
3+
14
cfg_if::cfg_if! {
25
if #[cfg(feature = "with-gl")] {
36
pub use gfx_backend_gl as RenderingAPI;

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

Lines changed: 35 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,40 @@ pub mod viewport;
1515

1616
use gfx_hal::Instance as _;
1717

18+
// ----------------------- INSTANCE BUILDER AND INSTANCE -------------------------------
19+
20+
pub struct InstanceBuilder {}
21+
22+
impl InstanceBuilder {
23+
pub fn new() -> Self {
24+
return Self {};
25+
}
26+
27+
/// Builds a graphical instance for the current platform.
28+
pub fn build<RenderBackend: internal::Backend>(
29+
self,
30+
name: &str,
31+
) -> Instance<RenderBackend> {
32+
return Instance::new(name);
33+
}
34+
}
35+
36+
pub struct Instance<RenderBackend: internal::Backend> {
37+
gfx_hal_instance: RenderBackend::Instance,
38+
}
39+
40+
impl<RenderBackend: internal::Backend> Instance<RenderBackend> {
41+
/// Create a new GfxInstance connected to the current platforms primary backend.
42+
fn new(name: &str) -> Self {
43+
let instance = RenderBackend::Instance::create(name, 1)
44+
.expect("gfx backend not supported by the current platform");
45+
46+
return Self {
47+
gfx_hal_instance: instance,
48+
};
49+
}
50+
}
51+
1852
// ----------------------- INTERNAL INSTANCE OPERATIONS ------------------------
1953

2054
pub mod internal {
@@ -43,7 +77,7 @@ pub mod internal {
4377
let surface = instance
4478
.gfx_hal_instance
4579
.create_surface(&window_handle.window_handle)
46-
.unwrap();
80+
.expect("Failed to create a surface using the current instance and window handle.");
4781

4882
return surface;
4983
};
@@ -70,34 +104,3 @@ pub mod internal {
70104
.remove(adapter_num);
71105
}
72106
}
73-
74-
pub struct InstanceBuilder {}
75-
76-
impl InstanceBuilder {
77-
pub fn new() -> Self {
78-
return Self {};
79-
}
80-
81-
pub fn build<RenderBackend: internal::Backend>(
82-
self,
83-
name: &str,
84-
) -> Instance<RenderBackend> {
85-
return Instance::new(name);
86-
}
87-
}
88-
89-
pub struct Instance<RenderBackend: internal::Backend> {
90-
gfx_hal_instance: RenderBackend::Instance,
91-
}
92-
93-
impl<RenderBackend: internal::Backend> Instance<RenderBackend> {
94-
/// Create a new GfxInstance connected to the platforms primary backend.
95-
fn new(name: &str) -> Self {
96-
let instance = RenderBackend::Instance::create(name, 1)
97-
.expect("gfx backend not supported by the current platform");
98-
99-
return Self {
100-
gfx_hal_instance: instance,
101-
};
102-
}
103-
}

tools/lambda_rs_demo/src/main.rs

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,13 @@ use lambda::{
66
Component,
77
RenderableComponent,
88
},
9-
events::Events,
9+
events::{
10+
ComponentEvent,
11+
Events,
12+
KeyEvent,
13+
RuntimeEvent,
14+
WindowEvent,
15+
},
1016
render::{
1117
command::RenderCommand,
1218
pipeline::{
@@ -39,7 +45,7 @@ pub struct DemoComponent {
3945

4046
impl Component<Events> for DemoComponent {
4147
fn on_attach(&mut self) {
42-
println!("Attached the first layer to lambda");
48+
println!("Attached the DemoComponent.");
4349
}
4450

4551
fn on_detach(self: &mut DemoComponent) {}
@@ -53,38 +59,38 @@ impl Component<Events> for DemoComponent {
5359
_ => {}
5460
},
5561
Events::Window { event, issued_at } => match event {
56-
lambda::core::events::WindowEvent::Resize { width, height } => {
62+
WindowEvent::Resize { width, height } => {
5763
println!("Window resized to {}x{}", width, height);
5864
}
59-
lambda::core::events::WindowEvent::Close => {
65+
WindowEvent::Close => {
6066
println!("Window closed");
6167
}
6268
},
6369
Events::Keyboard { event, issued_at } => match event {
64-
lambda::core::events::KeyEvent::KeyPressed {
70+
KeyEvent::KeyPressed {
6571
scan_code,
6672
virtual_key,
6773
} => {
6874
println!("Key pressed: {:?}", virtual_key);
6975
}
70-
lambda::core::events::KeyEvent::KeyReleased {
76+
KeyEvent::KeyReleased {
7177
scan_code,
7278
virtual_key,
7379
} => {
7480
println!("Key released: {:?}", virtual_key);
7581
}
76-
lambda::core::events::KeyEvent::ModifierPressed {
82+
KeyEvent::ModifierPressed {
7783
modifier,
7884
virtual_key,
7985
} => {
8086
println!("Modifier pressed: {:?}", virtual_key);
8187
}
8288
},
8389
Events::Component { event, issued_at } => match event {
84-
lambda::core::events::ComponentEvent::Attached { name } => {
90+
ComponentEvent::Attached { name } => {
8591
println!("Component attached: {:?}", name);
8692
}
87-
lambda::core::events::ComponentEvent::Detached { name } => {
93+
ComponentEvent::Detached { name } => {
8894
println!("Component detached: {:?}", name);
8995
}
9096
},
@@ -207,10 +213,10 @@ impl Default for DemoComponent {
207213
fn main() {
208214
let runtime = GenericRuntimeBuilder::new("2D Triangle Demo")
209215
.with_renderer(move |render_context_builder| {
210-
return render_context_builder;
216+
return render_context_builder.with_render_timeout(1_000_000_000);
211217
})
212-
.with_component(move |kernel, demo: DemoComponent| {
213-
return (kernel, demo);
218+
.with_component(move |runtime, demo: DemoComponent| {
219+
return (runtime, demo);
214220
})
215221
.build();
216222

0 commit comments

Comments
 (0)