#[repr(C)]pub struct Color {
pub r: f32,
pub g: f32,
pub b: f32,
pub a: f32,
}Expand description
Color represented as RGBA (0.0 - 1.0).
Fields§
§r: f32§g: f32§b: f32§a: f32Implementations§
Source§impl Color
impl Color
pub const WHITE: Color
pub const BLACK: Color
pub const RED: Color
pub const GREEN: Color
pub const BLUE: Color
pub const YELLOW: Color
pub const CYAN: Color
pub const MAGENTA: Color
pub const TRANSPARENT: Color
Sourcepub const fn rgb(r: f32, g: f32, b: f32) -> Self
pub const fn rgb(r: f32, g: f32, b: f32) -> Self
Examples found in repository?
examples/textured_window.rs (line 266)
241 fn render(
242 &mut self,
243 _ctx: &mut astrelis_winit::app::AppCtx,
244 window_id: WindowId,
245 events: &mut astrelis_winit::event::EventBatch,
246 ) {
247 if window_id != self.window_id {
248 return;
249 }
250
251 // Handle window resize events
252 events.dispatch(|event| {
253 if let astrelis_winit::event::Event::WindowResized(size) = event {
254 self.window.resized(*size);
255 astrelis_winit::event::HandleStatus::consumed()
256 } else {
257 astrelis_winit::event::HandleStatus::ignored()
258 }
259 });
260
261 let mut frame = self.window.begin_drawing();
262
263 // Render with automatic scoping (no manual {} block needed)
264 frame.clear_and_render(
265 RenderTarget::Surface,
266 Color::rgb(0.1, 0.2, 0.3),
267 |pass| {
268 let pass = pass.descriptor();
269 pass.set_pipeline(&self.pipeline);
270 pass.set_bind_group(0, &self.bind_group, &[]);
271 pass.set_vertex_buffer(0, self.vertex_buffer.slice(..));
272 pass.draw(0..6, 0..1);
273 },
274 );
275
276 frame.finish();
277 }More examples
examples/sprite_sheet.rs (line 411)
386 fn render(
387 &mut self,
388 _ctx: &mut astrelis_winit::app::AppCtx,
389 window_id: WindowId,
390 events: &mut astrelis_winit::event::EventBatch,
391 ) {
392 let Some(window) = self.windows.get_mut(&window_id) else {
393 return;
394 };
395
396 // Handle resize
397 events.dispatch(|event| {
398 if let astrelis_winit::event::Event::WindowResized(size) = event {
399 window.resized(*size);
400 astrelis_winit::event::HandleStatus::consumed()
401 } else {
402 astrelis_winit::event::HandleStatus::ignored()
403 }
404 });
405
406 let mut frame = window.begin_drawing();
407
408 // Render with automatic scoping (no manual {} block needed)
409 frame.clear_and_render(
410 RenderTarget::Surface,
411 Color::rgb(0.1, 0.1, 0.15),
412 |pass| {
413 let pass = pass.descriptor();
414 pass.set_pipeline(&self.pipeline);
415 pass.set_bind_group(0, &self.bind_group, &[]);
416 pass.set_vertex_buffer(0, self.vertex_buffer.slice(..));
417 pass.draw(0..6, 0..1);
418 },
419 );
420
421 frame.finish();
422 }examples/image_blitting.rs (line 469)
444 fn render(
445 &mut self,
446 _ctx: &mut astrelis_winit::app::AppCtx,
447 window_id: WindowId,
448 events: &mut astrelis_winit::event::EventBatch,
449 ) {
450 let Some(window) = self.windows.get_mut(&window_id) else {
451 return;
452 };
453
454 // Handle resize
455 events.dispatch(|event| {
456 if let astrelis_winit::event::Event::WindowResized(size) = event {
457 window.resized(*size);
458 astrelis_winit::event::HandleStatus::consumed()
459 } else {
460 astrelis_winit::event::HandleStatus::ignored()
461 }
462 });
463
464 let mut frame = window.begin_drawing();
465
466 // Render with automatic scoping (no manual {} block needed)
467 frame.clear_and_render(
468 RenderTarget::Surface,
469 Color::rgb(0.05, 0.05, 0.08),
470 |pass| {
471 let pass = pass.descriptor();
472 pass.set_pipeline(&self.pipeline);
473 pass.set_bind_group(0, &self.bind_group, &[]);
474 pass.set_vertex_buffer(0, self.vertex_buffer.slice(..));
475 pass.draw(0..6, 0..1);
476 },
477 );
478
479 frame.finish();
480 }examples/window_manager_demo.rs (line 43)
33fn main() {
34 logging::init();
35
36 run_app(|ctx| {
37 let graphics_ctx = GraphicsContext::new_owned_sync_or_panic();
38 let mut window_manager = WindowManager::new(graphics_ctx);
39 let mut window_colors = HashMap::new();
40
41 // Create 3 windows with different colors
42 let colors = [
43 Color::rgb(0.8, 0.2, 0.2), // Red
44 Color::rgb(0.2, 0.8, 0.2), // Green
45 Color::rgb(0.2, 0.2, 0.8), // Blue
46 ];
47
48 for (i, color) in colors.iter().enumerate() {
49 let window_id = window_manager.create_window_with_descriptor(
50 ctx,
51 WindowDescriptor {
52 title: format!("Window {} - WindowManager Demo", i + 1),
53 size: Some(WinitPhysicalSize::new(400.0, 300.0)),
54 ..Default::default()
55 },
56 WindowContextDescriptor {
57 format: Some(wgpu::TextureFormat::Bgra8UnormSrgb),
58 ..Default::default()
59 },
60 ).expect("Failed to create window");
61
62 window_colors.insert(window_id, *color);
63 }
64
65 Box::new(WindowManagerApp {
66 window_manager,
67 window_colors,
68 })
69 });
70}examples/renderer_api.rs (line 297)
277 fn render(&mut self, _ctx: &mut AppCtx, window_id: WindowId, events: &mut EventBatch) {
278 if window_id != self.window_id {
279 return;
280 }
281
282 // Handle window-specific resize events
283 events.dispatch(|event| {
284 if let astrelis_winit::event::Event::WindowResized(size) = event {
285 self.window.resized(*size);
286 astrelis_winit::event::HandleStatus::consumed()
287 } else {
288 astrelis_winit::event::HandleStatus::ignored()
289 }
290 });
291
292 let mut frame = self.window.begin_drawing();
293
294 // Pass 1: Render to offscreen framebuffer with automatic scoping
295 frame.clear_and_render(
296 RenderTarget::Framebuffer(&self.offscreen_fb),
297 Color::rgb(0.2, 0.1, 0.3),
298 |pass| {
299 let pass = pass.descriptor();
300 pass.set_pipeline(&self.pipeline);
301 pass.set_bind_group(0, &self.bind_group, &[]);
302 pass.set_vertex_buffer(0, self.vertex_buffer.slice(..));
303 pass.draw(0..6, 0..1);
304 },
305 );
306
307 // Pass 2: Blit framebuffer to surface with automatic scoping
308 frame.clear_and_render(
309 RenderTarget::Surface,
310 Color::rgb(0.1, 0.2, 0.3),
311 |pass| {
312 let pass = pass.descriptor();
313 pass.set_pipeline(&self.blit_pipeline);
314 pass.set_bind_group(0, &self.blit_bind_group, &[]);
315 // Draw fullscreen triangle
316 pass.draw(0..3, 0..1);
317 },
318 );
319
320 frame.finish();
321 }Sourcepub const fn rgba(r: f32, g: f32, b: f32, a: f32) -> Self
pub const fn rgba(r: f32, g: f32, b: f32, a: f32) -> Self
Examples found in repository?
examples/multi_window.rs (line 120)
93 fn render(
94 &mut self,
95 _ctx: &mut astrelis_winit::app::AppCtx,
96 window_id: WindowId,
97 events: &mut astrelis_winit::event::EventBatch,
98 ) {
99 // Get the window and color for this specific window
100 let Some((window, color)) = self.windows.get_mut(&window_id) else {
101 return;
102 };
103
104 // Handle window-specific resize events
105 events.dispatch(|event| {
106 if let astrelis_winit::event::Event::WindowResized(size) = event {
107 window.resized(*size);
108 astrelis_winit::event::HandleStatus::consumed()
109 } else {
110 astrelis_winit::event::HandleStatus::ignored()
111 }
112 });
113
114 // Render this specific window
115 let mut frame = window.begin_drawing();
116
117 // Render with automatic scoping (no manual {} block needed)
118 frame.clear_and_render(
119 RenderTarget::Surface,
120 astrelis_render::Color::rgba(color.r as f32, color.g as f32, color.b as f32, color.a as f32),
121 |_pass| {
122 // Just clearing - no rendering commands needed
123 },
124 );
125
126 frame.finish();
127 }pub fn from_rgba_u8(r: u8, g: u8, b: u8, a: u8) -> Self
Sourcepub fn from_rgb_u8(r: u8, g: u8, b: u8) -> Self
pub fn from_rgb_u8(r: u8, g: u8, b: u8) -> Self
Examples found in repository?
examples/camera_demo.rs (line 107)
90 fn render(&mut self, _ctx: &mut AppCtx, window_id: WindowId, events: &mut EventBatch) {
91 if window_id != self.window_id {
92 return;
93 }
94
95 events.dispatch(|event| {
96 if let astrelis_winit::event::Event::WindowResized(size) = event {
97 self.window.resized(*size);
98 astrelis_winit::event::HandleStatus::consumed()
99 } else {
100 astrelis_winit::event::HandleStatus::ignored()
101 }
102 });
103
104 let mut frame = self.window.begin_drawing();
105 frame.clear_and_render(
106 RenderTarget::Surface,
107 Color::from_rgb_u8(20, 30, 40),
108 |_pass| {},
109 );
110 frame.finish();
111 }More examples
examples/mesh_primitives.rs (line 110)
93 fn render(&mut self, _ctx: &mut AppCtx, window_id: WindowId, events: &mut EventBatch) {
94 if window_id != self.window_id {
95 return;
96 }
97
98 events.dispatch(|event| {
99 if let astrelis_winit::event::Event::WindowResized(size) = event {
100 self.window.resized(*size);
101 astrelis_winit::event::HandleStatus::consumed()
102 } else {
103 astrelis_winit::event::HandleStatus::ignored()
104 }
105 });
106
107 let mut frame = self.window.begin_drawing();
108 frame.clear_and_render(
109 RenderTarget::Surface,
110 Color::from_rgb_u8(20, 30, 40),
111 |_pass| {},
112 );
113 frame.finish();
114 }examples/render_graph_demo.rs (line 107)
90 fn render(&mut self, _ctx: &mut AppCtx, window_id: WindowId, events: &mut EventBatch) {
91 if window_id != self.window_id {
92 return;
93 }
94
95 events.dispatch(|event| {
96 if let astrelis_winit::event::Event::WindowResized(size) = event {
97 self.window.resized(*size);
98 astrelis_winit::event::HandleStatus::consumed()
99 } else {
100 astrelis_winit::event::HandleStatus::ignored()
101 }
102 });
103
104 let mut frame = self.window.begin_drawing();
105 frame.clear_and_render(
106 RenderTarget::Surface,
107 Color::from_rgb_u8(20, 30, 40),
108 |_pass| {},
109 );
110 frame.finish();
111 }examples/material_system.rs (line 131)
107 fn render(&mut self, _ctx: &mut AppCtx, window_id: WindowId, events: &mut EventBatch) {
108 if window_id != self.window_id {
109 return;
110 }
111
112 // Handle resize
113 events.dispatch(|event| {
114 if let astrelis_winit::event::Event::WindowResized(size) = event {
115 self.window.resized(*size);
116 astrelis_winit::event::HandleStatus::consumed()
117 } else {
118 astrelis_winit::event::HandleStatus::ignored()
119 }
120 });
121
122 // In a real application, materials would be bound during rendering:
123 // material.bind(&mut render_pass);
124 // draw_mesh(&mesh);
125
126 // Begin frame
127 let mut frame = self.window.begin_drawing();
128
129 frame.clear_and_render(
130 RenderTarget::Surface,
131 Color::from_rgb_u8(20, 30, 40),
132 |_pass| {
133 // Materials would be applied here in actual rendering
134 // This is a conceptual demonstration
135 },
136 );
137
138 frame.finish();
139 }examples/performance_benchmark.rs (line 160)
103 fn render(&mut self, _ctx: &mut AppCtx, window_id: WindowId, events: &mut EventBatch) {
104 if window_id != self.window_id {
105 return;
106 }
107
108 let frame_start = Instant::now();
109
110 // Handle resize
111 events.dispatch(|event| {
112 if let Event::WindowResized(size) = event {
113 self.window.resized(*size);
114 HandleStatus::consumed()
115 } else {
116 HandleStatus::ignored()
117 }
118 });
119
120 // Handle keyboard input
121 events.dispatch(|event| {
122 if let Event::KeyInput(key) = event {
123 if key.state == astrelis_winit::event::ElementState::Pressed {
124 match &key.logical_key {
125 Key::Named(NamedKey::Space) => {
126 self.rendering = !self.rendering;
127 println!("Rendering: {}", self.rendering);
128 return HandleStatus::consumed();
129 }
130 Key::Character(c) if c == "+" || c == "=" => {
131 self.object_count = (self.object_count + 500).min(50000);
132 println!("Object count: {}", self.object_count);
133 return HandleStatus::consumed();
134 }
135 Key::Character(c) if c == "-" => {
136 self.object_count = self.object_count.saturating_sub(500).max(100);
137 println!("Object count: {}", self.object_count);
138 return HandleStatus::consumed();
139 }
140 _ => {}
141 }
142 }
143 }
144 HandleStatus::ignored()
145 });
146
147 // Begin frame
148 let mut frame = self.window.begin_drawing();
149
150 if self.rendering {
151 // Simulate rendering thousands of objects
152 // In a real scenario, this would involve:
153 // - Instanced draw calls
154 // - Uniform buffer updates
155 // - Texture binding
156 // - Shader state changes
157
158 frame.clear_and_render(
159 RenderTarget::Surface,
160 Color::from_rgb_u8(10, 10, 15),
161 |_pass| {
162 // Actual rendering would happen here
163 // For benchmark purposes, we're measuring the overhead
164 // of the render pass itself with clear operations
165 },
166 );
167 } else {
168 frame.clear_and_render(
169 RenderTarget::Surface,
170 Color::from_rgb_u8(10, 10, 15),
171 |_pass| {},
172 );
173 }
174
175 frame.finish();
176
177 let frame_end = Instant::now();
178 self.last_frame_time = frame_end.duration_since(frame_start).as_secs_f32() * 1000.0;
179 }pub fn from_hex(hex: u32) -> Self
pub fn from_hex_alpha(hex: u32) -> Self
pub fn to_wgpu(self) -> Color
pub fn to_array(self) -> [f32; 4]
Trait Implementations§
impl Copy for Color
impl Pod for Color
impl StructuralPartialEq for Color
Auto Trait Implementations§
impl Freeze for Color
impl RefUnwindSafe for Color
impl Send for Color
impl Sync for Color
impl Unpin for Color
impl UnwindSafe for Color
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CheckedBitPattern for Twhere
T: AnyBitPattern,
impl<T> CheckedBitPattern for Twhere
T: AnyBitPattern,
Source§type Bits = T
type Bits = T
Self must have the same layout as the specified Bits except for
the possible invalid bit patterns being checked during
is_valid_bit_pattern.Source§fn is_valid_bit_pattern(_bits: &T) -> bool
fn is_valid_bit_pattern(_bits: &T) -> bool
If this function returns true, then it must be valid to reinterpret
bits
as &Self.Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Convert
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Convert
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
Convert
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Convert
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more