Draft Editor API and TextEditor widget

This commit is contained in:
Héctor Ramón Jiménez 2023-09-12 14:51:00 +02:00
parent 346af3f8b0
commit 6448429103
No known key found for this signature in database
GPG key ID: 7CC46565708259A7
25 changed files with 1384 additions and 92 deletions

View file

@ -2,7 +2,7 @@ use crate::core::alignment;
use crate::core::{Rectangle, Size};
use crate::graphics::color;
use crate::graphics::text::cache::{self, Cache};
use crate::graphics::text::{font_system, Paragraph};
use crate::graphics::text::{font_system, Editor, Paragraph};
use crate::layer::Text;
use std::borrow::Cow;
@ -74,15 +74,19 @@ impl Pipeline {
enum Allocation {
Paragraph(Paragraph),
Editor(Editor),
Cache(cache::KeyHash),
}
let allocations: Vec<_> = sections
.iter()
.map(|section| match section {
Text::Managed { paragraph, .. } => {
Text::Paragraph { paragraph, .. } => {
paragraph.upgrade().map(Allocation::Paragraph)
}
Text::Editor { editor, .. } => {
editor.upgrade().map(Allocation::Editor)
}
Text::Cached(text) => {
let (key, _) = cache.allocate(
font_system,
@ -117,7 +121,7 @@ impl Pipeline {
vertical_alignment,
color,
) = match section {
Text::Managed {
Text::Paragraph {
position, color, ..
} => {
use crate::core::text::Paragraph as _;
@ -135,6 +139,24 @@ impl Pipeline {
*color,
)
}
Text::Editor {
position, color, ..
} => {
use crate::core::text::Editor as _;
let Some(Allocation::Editor(editor)) = allocation
else {
return None;
};
(
editor.buffer(),
Rectangle::new(*position, editor.min_bounds()),
alignment::Horizontal::Left,
alignment::Vertical::Top,
*color,
)
}
Text::Cached(text) => {
let Some(Allocation::Cache(key)) = allocation else {
return None;