Skip to content

Commit 8034f07

Browse files
committed
[update] the kernel builder.
1 parent 51244d7 commit 8034f07

2 files changed

Lines changed: 23 additions & 20 deletions

File tree

lambda/src/kernels/mod.rs

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -30,23 +30,25 @@ use crate::core::{
3030
};
3131

3232
pub struct LambdaKernelBuilder {
33-
name: String,
33+
app_name: String,
3434
render_api: RenderContextBuilder,
3535
window_size: (u32, u32),
36+
components: Vec<Box<dyn RenderableComponent<Events>>>,
3637
}
3738

3839
impl LambdaKernelBuilder {
39-
pub fn new(name: &str) -> Self {
40+
pub fn new(app_name: &str) -> Self {
4041
return Self {
41-
name: name.to_string(),
42-
render_api: RenderContextBuilder::new(name),
42+
app_name: app_name.to_string(),
43+
render_api: RenderContextBuilder::new(app_name),
4344
window_size: (800, 600),
45+
components: Vec::new(),
4446
};
4547
}
4648

4749
/// Update the name of the LambdaKernel.
48-
pub fn with_name(mut self, name: &str) -> Self {
49-
self.name = name.to_string();
50+
pub fn with_app_name(mut self, name: &str) -> Self {
51+
self.app_name = name.to_string();
5052
return self;
5153
}
5254

@@ -64,12 +66,23 @@ impl LambdaKernelBuilder {
6466
self.render_api = configure(self.render_api);
6567
return self;
6668
}
69+
/// Jjk
70+
/// Attach a component to the current runnable.
71+
pub fn with_component<T: Default + RenderableComponent<Events> + 'static>(
72+
self,
73+
configure_component: impl FnOnce(Self, T) -> (Self, T),
74+
) -> Self {
75+
let (mut kernel_builder, component) =
76+
configure_component(self, T::default());
77+
kernel_builder.components.push(Box::new(component));
78+
return kernel_builder;
79+
}
6780

6881
/// Builds a LambdaKernel equipped with Windowing, an event loop, and a
6982
/// component stack that allows components to be dynamically pushed into the
7083
/// Kernel to receive events & render access.
7184
pub fn build(self) -> LambdaKernel {
72-
let name = self.name;
85+
let name = self.app_name;
7386
let mut event_loop = create_event_loop::<Events>();
7487
let (width, height) = self.window_size;
7588

@@ -101,17 +114,7 @@ pub struct LambdaKernel {
101114
render_api: RenderContext,
102115
}
103116

104-
impl LambdaKernel {
105-
/// Attach a component to the current runnable.
106-
pub fn with_component<T: Default + RenderableComponent<Events> + 'static>(
107-
self,
108-
configure_component: impl FnOnce(Self, T) -> (Self, T),
109-
) -> Self {
110-
let (mut kernel, component) = configure_component(self, T::default());
111-
kernel.component_stack.push(Box::new(component));
112-
return kernel;
113-
}
114-
}
117+
impl LambdaKernel {}
115118

116119
impl Kernel for LambdaKernel {
117120
/// Initiates an event loop that captures the context of the LambdaKernel

tools/lambda_rs_demo/src/main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,10 +170,10 @@ fn configure_renderer(builder: RenderContextBuilder) -> RenderContextBuilder {
170170
fn main() {
171171
let kernel = LambdaKernelBuilder::new("Lambda 2D Demo")
172172
.configure_renderer(configure_renderer)
173-
.build()
174173
.with_component(move |kernel, demo: DemoComponent| {
175174
return (kernel, demo);
176-
});
175+
})
176+
.build();
177177

178178
start_kernel(kernel);
179179
}

0 commit comments

Comments
 (0)