Checkpoint

This commit is contained in:
Nathan Sobo 2023-09-27 21:25:06 -06:00
parent 9fefb1d898
commit 7524f7fbe8
5 changed files with 20 additions and 21 deletions

View file

@ -93,11 +93,11 @@ impl<S: 'static> Element for Text<S> {
line_height = paint_state.line_height; line_height = paint_state.line_height;
} }
let text_style = cx.text_style(); let _text_style = cx.text_style();
// todo!("We haven't added visible bounds to the new element system yet, so this is a placeholder."); // todo!("We haven't added visible bounds to the new element system yet, so this is a placeholder.");
let visible_bounds = bounds; let visible_bounds = bounds;
line.paint(bounds.origin, visible_bounds, line_height, cx); line.paint(bounds.origin, visible_bounds, line_height, cx)?;
Ok(()) Ok(())
} }

View file

@ -134,6 +134,8 @@ impl NSRectExt for NSRect {
} }
} }
// todo!
#[allow(unused)]
unsafe fn ns_url_to_path(url: id) -> crate::Result<PathBuf> { unsafe fn ns_url_to_path(url: id) -> crate::Result<PathBuf> {
let path: *mut c_char = msg_send![url, fileSystemRepresentation]; let path: *mut c_char = msg_send![url, fileSystemRepresentation];
if path.is_null() { if path.is_null() {

View file

@ -34,6 +34,8 @@ unsafe fn build_event_source() {
mem::forget(source); mem::forget(source);
} }
// todo!
#[allow(unused)]
pub fn key_to_native(key: &str) -> Cow<str> { pub fn key_to_native(key: &str) -> Cow<str> {
use cocoa::appkit::*; use cocoa::appkit::*;
let code = match key { let code = match key {

View file

@ -40,14 +40,13 @@ use super::open_type;
#[allow(non_upper_case_globals)] #[allow(non_upper_case_globals)]
const kCGImageAlphaOnly: u32 = 7; const kCGImageAlphaOnly: u32 = 7;
pub struct MacTextSystem(RwLock<TextSystemState>); pub struct MacTextSystem(RwLock<MacTextSystemState>);
struct TextSystemState { struct MacTextSystemState {
memory_source: MemSource, memory_source: MemSource,
system_source: SystemSource, system_source: SystemSource,
fonts: Vec<FontKitFont>, fonts: Vec<FontKitFont>,
font_selections: HashMap<Font, FontId>, font_selections: HashMap<Font, FontId>,
font_metrics: HashMap<FontId, FontMetrics>,
font_ids_by_postscript_name: HashMap<String, FontId>, font_ids_by_postscript_name: HashMap<String, FontId>,
font_ids_by_family_name: HashMap<SharedString, SmallVec<[FontId; 4]>>, font_ids_by_family_name: HashMap<SharedString, SmallVec<[FontId; 4]>>,
postscript_names_by_font_id: HashMap<FontId, String>, postscript_names_by_font_id: HashMap<FontId, String>,
@ -55,12 +54,11 @@ struct TextSystemState {
impl MacTextSystem { impl MacTextSystem {
pub fn new() -> Self { pub fn new() -> Self {
Self(RwLock::new(TextSystemState { Self(RwLock::new(MacTextSystemState {
memory_source: MemSource::empty(), memory_source: MemSource::empty(),
system_source: SystemSource::new(), system_source: SystemSource::new(),
fonts: Vec::new(), fonts: Vec::new(),
font_selections: HashMap::default(), font_selections: HashMap::default(),
font_metrics: HashMap::default(),
font_ids_by_postscript_name: HashMap::default(), font_ids_by_postscript_name: HashMap::default(),
font_ids_by_family_name: HashMap::default(), font_ids_by_family_name: HashMap::default(),
postscript_names_by_font_id: HashMap::default(), postscript_names_by_font_id: HashMap::default(),
@ -173,7 +171,7 @@ impl PlatformTextSystem for MacTextSystem {
} }
} }
impl TextSystemState { impl MacTextSystemState {
fn add_fonts(&mut self, fonts: &[Arc<Vec<u8>>]) -> Result<()> { fn add_fonts(&mut self, fonts: &[Arc<Vec<u8>>]) -> Result<()> {
self.memory_source.add_fonts( self.memory_source.add_fonts(
fonts fonts

View file

@ -247,13 +247,14 @@ impl Line {
} }
} }
// todo!
pub fn paint( pub fn paint(
&self, &self,
origin: Point<Pixels>, origin: Point<Pixels>,
visible_bounds: Bounds<Pixels>, visible_bounds: Bounds<Pixels>,
line_height: Pixels, line_height: Pixels,
cx: &mut WindowContext, cx: &mut WindowContext,
) { ) -> Result<()> {
let padding_top = (line_height - self.layout.ascent - self.layout.descent) / 2.; let padding_top = (line_height - self.layout.ascent - self.layout.descent) / 2.;
let baseline_offset = point(px(0.), padding_top + self.layout.ascent); let baseline_offset = point(px(0.), padding_top + self.layout.ascent);
@ -264,11 +265,7 @@ impl Line {
for run in &self.layout.runs { for run in &self.layout.runs {
cx.text_system().with_font(run.font_id, |system, font| { cx.text_system().with_font(run.font_id, |system, font| {
let max_glyph_width = cx let max_glyph_width = system.bounding_box(font, self.layout.font_size)?.size.width;
.text_system()
.bounding_box(font, self.layout.font_size)?
.size
.width;
for glyph in &run.glyphs { for glyph in &run.glyphs {
let glyph_origin = origin + baseline_offset + glyph.position; let glyph_origin = origin + baseline_offset + glyph.position;
@ -322,7 +319,6 @@ impl Line {
// }); // });
} }
// todo!()
// if glyph.is_emoji { // if glyph.is_emoji {
// cx.scene().push_image_glyph(scene::ImageGlyph { // cx.scene().push_image_glyph(scene::ImageGlyph {
// font_id: run.font_id, // font_id: run.font_id,
@ -342,7 +338,7 @@ impl Line {
} }
anyhow::Ok(()) anyhow::Ok(())
}); })??;
} }
if let Some((_underline_start, _underline_style)) = underline.take() { if let Some((_underline_start, _underline_style)) = underline.take() {
@ -355,6 +351,8 @@ impl Line {
// squiggly: underline_style.squiggly, // squiggly: underline_style.squiggly,
// }); // });
} }
Ok(())
} }
pub fn paint_wrapped( pub fn paint_wrapped(
@ -371,7 +369,7 @@ impl Line {
let mut boundaries = boundaries.into_iter().peekable(); let mut boundaries = boundaries.into_iter().peekable();
let mut color_runs = self.style_runs.iter(); let mut color_runs = self.style_runs.iter();
let mut style_run_end = 0; let mut style_run_end = 0;
let mut color = black(); let mut _color = black(); // todo!
let mut underline: Option<(Point<Pixels>, UnderlineStyle)> = None; let mut underline: Option<(Point<Pixels>, UnderlineStyle)> = None;
let mut glyph_origin = origin; let mut glyph_origin = origin;
@ -403,7 +401,7 @@ impl Line {
if glyph.index >= style_run_end { if glyph.index >= style_run_end {
if let Some(style_run) = color_runs.next() { if let Some(style_run) = color_runs.next() {
style_run_end += style_run.len as usize; style_run_end += style_run.len as usize;
color = style_run.color; _color = style_run.color;
if let Some((_, underline_style)) = &mut underline { if let Some((_, underline_style)) = &mut underline {
if style_run.underline != *underline_style { if style_run.underline != *underline_style {
finished_underline = underline.take(); finished_underline = underline.take();
@ -427,7 +425,7 @@ impl Line {
} }
} else { } else {
style_run_end = self.layout.len; style_run_end = self.layout.len;
color = black(); _color = black();
finished_underline = underline.take(); finished_underline = underline.take();
} }
} }
@ -447,7 +445,6 @@ impl Line {
origin: glyph_origin, origin: glyph_origin,
size: system.bounding_box(font, self.layout.font_size)?.size, size: system.bounding_box(font, self.layout.font_size)?.size,
}; };
// todo!()
// if glyph_bounds.intersects(visible_bounds) { // if glyph_bounds.intersects(visible_bounds) {
// if glyph.is_emoji { // if glyph.is_emoji {
// cx.scene().push_image_glyph(scene::ImageGlyph { // cx.scene().push_image_glyph(scene::ImageGlyph {
@ -467,7 +464,7 @@ impl Line {
// } // }
// } // }
anyhow::Ok(()) anyhow::Ok(())
})?; })??;
} }
} }