Skip to content

Commit

Permalink
Start work on the prose widget
Browse files Browse the repository at this point in the history
Doesn't do selections yet
  • Loading branch information
DJMcNab committed May 2, 2024
1 parent 99dab71 commit 6722508
Show file tree
Hide file tree
Showing 7 changed files with 743 additions and 16 deletions.
11 changes: 5 additions & 6 deletions crates/masonry/src/text2/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ impl<T> TextLayout<T> {
///
/// See also [`set_text_color`][Self::set_text_color]
/// for a convenience method when using a solid color.
pub fn set_overrid_brush(&mut self, override_brush: Option<Brush>) {
pub fn set_override_brush(&mut self, override_brush: Option<Brush>) {
if override_brush != self.override_brush {
self.override_brush = override_brush;
self.invalidate();
Expand Down Expand Up @@ -312,11 +312,8 @@ impl<T: TextStorage> TextLayout<T> {
pub fn cursor_for_text_position(&self, text_pos: usize) -> Cursor {
self.assert_rebuilt("cursor_for_text_position");

Cursor::from_position(
&self.layout,
text_pos,
/* TODO handle affinity */ false,
)
// TODO: As a reminder, `is_leading``
Cursor::from_position(&self.layout, text_pos, false)
}

/// Given the utf-8 position of a character boundary in the underlying text,
Expand Down Expand Up @@ -351,6 +348,8 @@ impl<T: TextStorage> TextLayout<T> {
/// return a `Line` suitable for drawing a vertical cursor at that boundary.
///
/// This is not meaningful until [`Self::rebuild`] has been called.
// TODO: This is too simplistic. See https://raphlinus.github.io/text/2020/10/26/text-layout.html#shaping-cluster
// for example. This would break in a `fi` ligature
pub fn cursor_line_for_text_position(&self, text_pos: usize) -> Line {
let from_position = self.cursor_for_text_position(text_pos);

Expand Down
4 changes: 3 additions & 1 deletion crates/masonry/src/text2/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@
//! All of these have the same set of global styling options, and can contain rich text
mod edit;
pub mod layout;
mod layout;
// mod movement;
mod selection;
mod store;

pub use layout::{LayoutMetrics, TextLayout};
pub use selection::TextWithSelection;
pub use selection::{len_utf8_from_first_byte, EditableTextCursor, Selectable, StringCursor};
pub use store::{Link, TextStorage};
Loading

0 comments on commit 6722508

Please sign in to comment.