mirror of
https://github.com/emilk/egui.git
synced 2026-06-26 14:49:06 -04:00
Export ByteRange and CharRange (#8247)
This commit is contained in:
@@ -454,8 +454,8 @@ pub use epaint::{
|
|||||||
pub mod text {
|
pub mod text {
|
||||||
pub use crate::text_selection::CCursorRange;
|
pub use crate::text_selection::CCursorRange;
|
||||||
pub use epaint::text::{
|
pub use epaint::text::{
|
||||||
ByteIndex, CharIndex, FontData, FontDefinitions, FontFamily, Fonts, Galley, LayoutJob,
|
ByteIndex, ByteRange, CharIndex, CharRange, FontData, FontDefinitions, FontFamily, Fonts,
|
||||||
LayoutSection, TextFormat, TextWrapping, cursor::CCursor,
|
Galley, LayoutJob, LayoutSection, TextFormat, TextWrapping, cursor::CCursor,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -604,7 +604,7 @@ impl Highlighter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "syntect")]
|
#[cfg(feature = "syntect")]
|
||||||
fn as_byte_range(whole: &str, range: &str) -> std::ops::Range<egui::text::ByteIndex> {
|
fn as_byte_range(whole: &str, range: &str) -> egui::text::ByteRange {
|
||||||
use egui::text::ByteIndex;
|
use egui::text::ByteIndex;
|
||||||
let whole_start = whole.as_ptr() as usize;
|
let whole_start = whole.as_ptr() as usize;
|
||||||
let range_start = range.as_ptr() as usize;
|
let range_start = range.as_ptr() as usize;
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ use crate::{
|
|||||||
Color32, Mesh, Stroke, Vertex,
|
Color32, Mesh, Stroke, Vertex,
|
||||||
stroke::PathStroke,
|
stroke::PathStroke,
|
||||||
text::{
|
text::{
|
||||||
|
ByteIndex, ByteRange,
|
||||||
font::{StyledMetrics, UvRect, is_cjk, is_cjk_break_allowed},
|
font::{StyledMetrics, UvRect, is_cjk, is_cjk_break_allowed},
|
||||||
fonts::FontFaceKey,
|
fonts::FontFaceKey,
|
||||||
},
|
},
|
||||||
@@ -217,7 +218,7 @@ struct TextRun {
|
|||||||
font_key: FontFaceKey,
|
font_key: FontFaceKey,
|
||||||
|
|
||||||
/// Byte range within the section text.
|
/// Byte range within the section text.
|
||||||
byte_range: std::ops::Range<usize>,
|
byte_range: ByteRange,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Emit shaped glyphs from a [`harfrust::GlyphBuffer`] into a [`Paragraph`].
|
/// Emit shaped glyphs from a [`harfrust::GlyphBuffer`] into a [`Paragraph`].
|
||||||
@@ -484,7 +485,7 @@ fn layout_section(
|
|||||||
|
|
||||||
let num_runs = runs.len();
|
let num_runs = runs.len();
|
||||||
for (run_idx, run) in runs.iter().enumerate() {
|
for (run_idx, run) in runs.iter().enumerate() {
|
||||||
let run_text = &segment[run.byte_range.clone()];
|
let run_text = &segment[run.byte_range.as_usize()];
|
||||||
let Some(font_face) = font.fonts_by_id.get(&run.font_key) else {
|
let Some(font_face) = font.fonts_by_id.get(&run.font_key) else {
|
||||||
continue;
|
continue;
|
||||||
};
|
};
|
||||||
@@ -1373,6 +1374,7 @@ fn segment_into_runs(font: &mut Font<'_>, text: &str, out: &mut Vec<TextRun>) {
|
|||||||
out.clear();
|
out.clear();
|
||||||
|
|
||||||
for (byte_offset, grapheme_str) in text.grapheme_indices(true) {
|
for (byte_offset, grapheme_str) in text.grapheme_indices(true) {
|
||||||
|
let byte_offset = ByteIndex(byte_offset);
|
||||||
let byte_end = byte_offset + grapheme_str.len();
|
let byte_end = byte_offset + grapheme_str.len();
|
||||||
|
|
||||||
let base_char = grapheme_str.chars().next().unwrap_or(' ');
|
let base_char = grapheme_str.chars().next().unwrap_or(' ');
|
||||||
|
|||||||
@@ -342,7 +342,7 @@ pub struct LayoutSection {
|
|||||||
pub leading_space: f32,
|
pub leading_space: f32,
|
||||||
|
|
||||||
/// Range into [`LayoutJob::text`].
|
/// Range into [`LayoutJob::text`].
|
||||||
pub byte_range: Range<ByteIndex>,
|
pub byte_range: ByteRange,
|
||||||
|
|
||||||
/// How to format the text in this section (font, color, etc).
|
/// How to format the text in this section (font, color, etc).
|
||||||
pub format: TextFormat,
|
pub format: TextFormat,
|
||||||
|
|||||||
Reference in New Issue
Block a user