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;
}
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.");
let visible_bounds = bounds;
line.paint(bounds.origin, visible_bounds, line_height, cx);
line.paint(bounds.origin, visible_bounds, line_height, cx)?;
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> {
let path: *mut c_char = msg_send![url, fileSystemRepresentation];
if path.is_null() {

View file

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

View file

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

View file

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