StratoSDK is a framework with a declarative approach similar to Flutter/React, written and designed entirely for Rust.
| 1 | use crate::platform::mac::rendering::Device; |
| 2 | use crate::platform::mac::window::WindowState; |
| 3 | use crate::rendering::wgpu::{Renderer, Resources}; |
| 4 | use crate::{fonts, Scene}; |
| 5 | |
| 6 | impl super::super::Renderer for Renderer { |
| 7 | fn render(&mut self, scene: &Scene, window: &WindowState, font_cache: &fonts::Cache) { |
| 8 | let _ = Renderer::render( |
| 9 | self, |
| 10 | scene, |
| 11 | window.unwrap_wgpu_resources(), |
| 12 | &|glyph_key, scale, subpixel_alignment, glyph_config, format| { |
| 13 | font_cache.rasterized_glyph( |
| 14 | glyph_key, |
| 15 | scale, |
| 16 | subpixel_alignment, |
| 17 | glyph_config, |
| 18 | format, |
| 19 | ) |
| 20 | }, |
| 21 | &|glyph_key, scale, alignment| { |
| 22 | font_cache.glyph_raster_bounds(glyph_key, scale, alignment) |
| 23 | }, |
| 24 | window.physical_size(), |
| 25 | None, |
| 26 | window.capture_callback.borrow_mut().take(), |
| 27 | ); |
| 28 | } |
| 29 | |
| 30 | fn resize(&mut self, window: &WindowState) { |
| 31 | let _ = window |
| 32 | .unwrap_wgpu_resources() |
| 33 | .update_surface_size(window.physical_size()); |
| 34 | } |
| 35 | } |
| 36 | |
| 37 | impl WindowState { |
| 38 | fn unwrap_wgpu_resources(&self) -> &Resources { |
| 39 | match self.device().unwrap() { |
| 40 | Device::Metal(_) => { |
| 41 | panic!("called the WGPU renderer with a metal device"); |
| 42 | } |
| 43 | Device::WGPU(resources) => resources, |
| 44 | } |
| 45 | } |
| 46 | } |
| 47 |