Use default font color and remove Color
		
	This commit is contained in:
		
					parent
					
						
							
								7eb4d41c25
							
						
					
				
			
			
				commit
				
					
						4c1a83548e
					
				
			
		
					 3 changed files with 11 additions and 19 deletions
				
			
		|  | @ -1,4 +1,4 @@ | ||||||
| use cosmic_text::{Attrs, FontSystem, SwashCache, TextBuffer, TextMetrics}; | use cosmic_text::{Attrs, Color, FontSystem, SwashCache, TextBuffer, TextMetrics}; | ||||||
| use glyphon::{Resolution, TextAtlas, TextRenderer}; | use glyphon::{Resolution, TextAtlas, TextRenderer}; | ||||||
| use wgpu::{ | use wgpu::{ | ||||||
|     Backends, CommandEncoderDescriptor, CompositeAlphaMode, DeviceDescriptor, Features, Instance, |     Backends, CommandEncoderDescriptor, CompositeAlphaMode, DeviceDescriptor, Features, Instance, | ||||||
|  | @ -101,6 +101,7 @@ async fn run() { | ||||||
|                             height: config.height, |                             height: config.height, | ||||||
|                         }, |                         }, | ||||||
|                         &mut buffer, |                         &mut buffer, | ||||||
|  |                         Color::rgb(255, 255, 255), | ||||||
|                         &mut cache, |                         &mut cache, | ||||||
|                     ) |                     ) | ||||||
|                     .unwrap(); |                     .unwrap(); | ||||||
|  |  | ||||||
							
								
								
									
										16
									
								
								src/lib.rs
									
										
									
									
									
								
							
							
						
						
									
										16
									
								
								src/lib.rs
									
										
									
									
									
								
							|  | @ -12,20 +12,6 @@ pub use text_render::TextRenderer; | ||||||
| 
 | 
 | ||||||
| pub use cosmic_text; | pub use cosmic_text; | ||||||
| 
 | 
 | ||||||
| /// The color to use when rendering text.
 |  | ||||||
| #[repr(C)] |  | ||||||
| #[derive(Clone, Copy, Debug, Eq, PartialEq)] |  | ||||||
| pub struct Color { |  | ||||||
|     /// The red component of the color.
 |  | ||||||
|     pub r: u8, |  | ||||||
|     /// The green component of the color.
 |  | ||||||
|     pub g: u8, |  | ||||||
|     /// The blue component of the color.
 |  | ||||||
|     pub b: u8, |  | ||||||
|     /// The alpha component of the color.
 |  | ||||||
|     pub a: u8, |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| pub(crate) enum GpuCache { | pub(crate) enum GpuCache { | ||||||
|     InAtlas { x: u16, y: u16 }, |     InAtlas { x: u16, y: u16 }, | ||||||
|     SkipRasterization, |     SkipRasterization, | ||||||
|  | @ -46,7 +32,7 @@ pub(crate) struct GlyphToRender { | ||||||
|     pos: [i32; 2], |     pos: [i32; 2], | ||||||
|     dim: [u16; 2], |     dim: [u16; 2], | ||||||
|     uv: [u16; 2], |     uv: [u16; 2], | ||||||
|     color: [u8; 4], |     color: u32, | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| /// The screen resolution to use when rendering text.
 | /// The screen resolution to use when rendering text.
 | ||||||
|  |  | ||||||
|  | @ -1,4 +1,4 @@ | ||||||
| use cosmic_text::{CacheKey, SwashCache, SwashContent, TextBuffer}; | use cosmic_text::{CacheKey, Color, SwashCache, SwashContent, TextBuffer}; | ||||||
| use etagere::{size2, Allocation}; | use etagere::{size2, Allocation}; | ||||||
| 
 | 
 | ||||||
| use std::{collections::HashSet, iter, mem::size_of, num::NonZeroU32, slice}; | use std::{collections::HashSet, iter, mem::size_of, num::NonZeroU32, slice}; | ||||||
|  | @ -64,6 +64,7 @@ impl TextRenderer { | ||||||
|         atlas: &mut TextAtlas, |         atlas: &mut TextAtlas, | ||||||
|         screen_resolution: Resolution, |         screen_resolution: Resolution, | ||||||
|         buffer: &mut TextBuffer<'a>, |         buffer: &mut TextBuffer<'a>, | ||||||
|  |         default_color: Color, | ||||||
|         cache: &mut SwashCache, |         cache: &mut SwashCache, | ||||||
|     ) -> Result<(), PrepareError> { |     ) -> Result<(), PrepareError> { | ||||||
|         self.screen_resolution = screen_resolution; |         self.screen_resolution = screen_resolution; | ||||||
|  | @ -233,6 +234,11 @@ impl TextRenderer { | ||||||
|                 let line_y = run.line_y; |                 let line_y = run.line_y; | ||||||
| 
 | 
 | ||||||
|                 for glyph in run.glyphs.iter() { |                 for glyph in run.glyphs.iter() { | ||||||
|  |                     let color = match glyph.color_opt { | ||||||
|  |                         Some(some) => some, | ||||||
|  |                         None => default_color, | ||||||
|  |                     }; | ||||||
|  | 
 | ||||||
|                     let details = atlas.glyph_cache.get(&glyph.cache_key).unwrap(); |                     let details = atlas.glyph_cache.get(&glyph.cache_key).unwrap(); | ||||||
| 
 | 
 | ||||||
|                     let mut x = glyph.x_int + details.left as i32; |                     let mut x = glyph.x_int + details.left as i32; | ||||||
|  | @ -296,8 +302,7 @@ impl TextRenderer { | ||||||
|                             pos: [x as i32, y as i32], |                             pos: [x as i32, y as i32], | ||||||
|                             dim: [width as u16, height as u16], |                             dim: [width as u16, height as u16], | ||||||
|                             uv: [atlas_x, atlas_y], |                             uv: [atlas_x, atlas_y], | ||||||
|                             // TODO
 |                             color: color.0, | ||||||
|                             color: [255, 255, 255, 255], |  | ||||||
|                         }) |                         }) | ||||||
|                         .take(4), |                         .take(4), | ||||||
|                     ); |                     ); | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue