Checkpoint

This commit is contained in:
Nathan Sobo 2023-08-21 16:14:59 -06:00
parent f4d8763d2b
commit ff7b25c538
6 changed files with 146 additions and 133 deletions

View file

@ -2,12 +2,10 @@ use crate::{
element::{Element, IntoElement, Layout},
layout_context::LayoutContext,
paint_context::PaintContext,
style::Style,
};
use anyhow::Result;
use gpui::{geometry::Size, text_layout::LineLayout, RenderContext};
use gpui::text_layout::LineLayout;
use parking_lot::Mutex;
use refineable::Refineable;
use std::sync::Arc;
impl<V: 'static, S: Into<ArcCow<'static, str>>> IntoElement<V> for S {
@ -30,39 +28,40 @@ impl<V: 'static> Element<V> for Text {
view: &mut V,
cx: &mut LayoutContext<V>,
) -> Result<Layout<V, Self::Layout>> {
let rem_size = cx.rem_pixels();
let fonts = cx.platform().fonts();
let text_style = cx.text_style();
let line_height = cx.font_cache().line_height(text_style.font_size);
let layout_engine = cx.layout_engine().expect("no layout engine present");
let text = self.text.clone();
let layout = Arc::new(Mutex::new(None));
// let rem_size = cx.rem_pixels();
// let fonts = cx.platform().fonts();
// let text_style = cx.text_style();
// let line_height = cx.font_cache().line_height(text_style.font_size);
// let layout_engine = cx.layout_engine().expect("no layout engine present");
// let text = self.text.clone();
// let layout = Arc::new(Mutex::new(None));
let style: Style = Style::default().refined(&self.metadata.style);
let node_id = layout_engine.add_measured_node(style.to_taffy(rem_size), {
let layout = layout.clone();
move |params| {
let line_layout = fonts.layout_line(
text.as_ref(),
text_style.font_size,
&[(text.len(), text_style.to_run())],
);
// let style: Style = Style::default().refined(&self.metadata.style);
// let node_id = layout_engine.add_measured_node(style.to_taffy(rem_size), {
// let layout = layout.clone();
// move |params| {
// let line_layout = fonts.layout_line(
// text.as_ref(),
// text_style.font_size,
// &[(text.len(), text_style.to_run())],
// );
let size = Size {
width: line_layout.width,
height: line_height,
};
// let size = Size {
// width: line_layout.width,
// height: line_height,
// };
layout.lock().replace(TextLayout {
line_layout: Arc::new(line_layout),
line_height,
});
// layout.lock().replace(TextLayout {
// line_layout: Arc::new(line_layout),
// line_height,
// });
size
}
})?;
// size
// }
// })?;
Ok((node_id, layout))
// Ok((node_id, layout))
todo!()
}
fn paint<'a>(
@ -71,24 +70,26 @@ impl<V: 'static> Element<V> for Text {
layout: &mut Layout<V, Self::Layout>,
cx: &mut PaintContext<V>,
) {
let element_layout_lock = layout.from_element.lock();
let element_layout = element_layout_lock
.as_ref()
.expect("layout has not been performed");
let line_layout = element_layout.line_layout.clone();
let line_height = element_layout.line_height;
drop(element_layout_lock);
// ) {
// let element_layout_lock = layout.from_element.lock();
// let element_layout = element_layout_lock
// .as_ref()
// .expect("layout has not been performed");
// let line_layout = element_layout.line_layout.clone();
// let line_height = element_layout.line_height;
// drop(element_layout_lock);
let text_style = cx.text_style();
let line =
gpui::text_layout::Line::new(line_layout, &[(self.text.len(), text_style.to_run())]);
line.paint(
cx.scene,
layout.from_engine.bounds.origin(),
layout.from_engine.bounds,
line_height,
cx.legacy_cx,
);
// let text_style = cx.text_style();
// let line =
// gpui::text_layout::Line::new(line_layout, &[(self.text.len(), text_style.to_run())]);
// line.paint(
// cx.scene,
// layout.from_engine.bounds.origin(),
// layout.from_engine.bounds,
// line_height,
// cx.legacy_cx,
// );
todo!()
}
}