1
0
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:
Emil Ernerfeldt
2026-06-22 05:45:48 +02:00
committed by GitHub
parent 467c5b84f0
commit 428e027ec7
4 changed files with 8 additions and 6 deletions

View File

@@ -454,8 +454,8 @@ pub use epaint::{
pub mod text {
pub use crate::text_selection::CCursorRange;
pub use epaint::text::{
ByteIndex, CharIndex, FontData, FontDefinitions, FontFamily, Fonts, Galley, LayoutJob,
LayoutSection, TextFormat, TextWrapping, cursor::CCursor,
ByteIndex, ByteRange, CharIndex, CharRange, FontData, FontDefinitions, FontFamily, Fonts,
Galley, LayoutJob, LayoutSection, TextFormat, TextWrapping, cursor::CCursor,
};
}

View File

@@ -604,7 +604,7 @@ impl Highlighter {
}
#[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;
let whole_start = whole.as_ptr() as usize;
let range_start = range.as_ptr() as usize;

View File

@@ -9,6 +9,7 @@ use crate::{
Color32, Mesh, Stroke, Vertex,
stroke::PathStroke,
text::{
ByteIndex, ByteRange,
font::{StyledMetrics, UvRect, is_cjk, is_cjk_break_allowed},
fonts::FontFaceKey,
},
@@ -217,7 +218,7 @@ struct TextRun {
font_key: FontFaceKey,
/// 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`].
@@ -484,7 +485,7 @@ fn layout_section(
let num_runs = runs.len();
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 {
continue;
};
@@ -1373,6 +1374,7 @@ fn segment_into_runs(font: &mut Font<'_>, text: &str, out: &mut Vec<TextRun>) {
out.clear();
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 base_char = grapheme_str.chars().next().unwrap_or(' ');

View File

@@ -342,7 +342,7 @@ pub struct LayoutSection {
pub leading_space: f32,
/// Range into [`LayoutJob::text`].
pub byte_range: Range<ByteIndex>,
pub byte_range: ByteRange,
/// How to format the text in this section (font, color, etc).
pub format: TextFormat,