Remove comments that only restate the text code
This commit is contained in:
1 parent
1a027813f5
commit
95f28953b7
8 files changed
-25
No files matched your search
@@ -10,7 +10,6 @@ pub struct Color<T> {
|
||||
pub a: T,
|
||||
}
|
||||
|
||||
/// Defaults to visible, unstyled text for Parley's brush requirement.
|
||||
impl<T: ColorNum> Default for Color<T> {
|
||||
fn default() -> Self {
|
||||
Self::BLACK
|
||||
|
||||
@@ -9,7 +9,6 @@ use swash::{
|
||||
zeno::{Format, Vector},
|
||||
};
|
||||
|
||||
/// Shared font, layout, rasterization, and glyph-atlas state.
|
||||
pub struct TextData {
|
||||
pub font_cx: FontContext,
|
||||
pub layout_cx: LayoutContext<UiColor>,
|
||||
@@ -28,7 +27,6 @@ impl Default for TextData {
|
||||
}
|
||||
}
|
||||
|
||||
/// An owned font family that can be stored by a widget.
|
||||
#[derive(Clone, PartialEq)]
|
||||
pub enum Family {
|
||||
SansSerif,
|
||||
@@ -56,7 +54,6 @@ pub struct TextAttrs {
|
||||
pub line_height: f32,
|
||||
pub family: Family,
|
||||
pub wrap: bool,
|
||||
/// Alignment within the text's region.
|
||||
pub align: RegionAlign,
|
||||
}
|
||||
|
||||
@@ -80,7 +77,6 @@ impl Default for TextAttrs {
|
||||
pub struct TextBuffer {
|
||||
text: String,
|
||||
layout: Layout<UiColor>,
|
||||
/// The inputs used to build the cached layout.
|
||||
shaped: Option<(TextAttrs, Option<f32>)>,
|
||||
}
|
||||
|
||||
@@ -149,7 +145,6 @@ impl TextBuffer {
|
||||
}
|
||||
|
||||
impl TextData {
|
||||
/// Rasterizes uncached glyphs and places them relative to the text origin.
|
||||
pub fn place(&mut self, buffer: &TextBuffer, textures: &mut Textures) -> Vec<PlacedGlyph> {
|
||||
let mut placed = Vec::new();
|
||||
for line in buffer.layout.lines() {
|
||||
@@ -229,7 +224,6 @@ fn hash_coords(coords: &[i16]) -> u64 {
|
||||
h
|
||||
}
|
||||
|
||||
/// Cached glyph placement for a laid-out string.
|
||||
#[derive(Clone)]
|
||||
pub struct RenderedText {
|
||||
pub glyphs: std::sync::Arc<Vec<PlacedGlyph>>,
|
||||
|
||||
@@ -29,7 +29,6 @@ pub struct Textures {
|
||||
pub enum TextureUpdate<'a> {
|
||||
Push(&'a DynamicImage),
|
||||
Set(u32, &'a DynamicImage),
|
||||
/// Overwrite one rectangle without uploading the entire texture.
|
||||
Patch(u32, PatchRect, &'a DynamicImage),
|
||||
Free(u32),
|
||||
PushFree,
|
||||
@@ -92,7 +91,6 @@ impl Textures {
|
||||
}
|
||||
}
|
||||
|
||||
/// The stored image for a handle, to be written into before `patch`.
|
||||
pub fn image_mut(&mut self, handle: &TextureHandle) -> &mut DynamicImage {
|
||||
self.images[handle.inner.view_idx as usize]
|
||||
.as_mut()
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
//! Packs reusable rasterized glyphs into shared texture pages.
|
||||
|
||||
use crate::{
|
||||
PatchRect, TextureHandle, Textures,
|
||||
util::{HashMap, Vec2},
|
||||
@@ -7,14 +5,12 @@ use crate::{
|
||||
use image::RgbaImage;
|
||||
use swash::scale::image::{Content, Image};
|
||||
|
||||
/// A 1024-pixel RGBA8 page occupies 4 MiB.
|
||||
const PAGE: u32 = 1024;
|
||||
|
||||
/// Transparent margin kept around every glyph, so that sampling one cannot
|
||||
/// pick up its neighbour along a shared edge.
|
||||
const PAD: u32 = 1;
|
||||
|
||||
/// Includes every input that can change the rasterized pixels.
|
||||
#[derive(Clone, Copy, PartialEq, Eq, Hash)]
|
||||
pub struct GlyphKey {
|
||||
pub font: u64,
|
||||
@@ -45,7 +41,6 @@ pub struct GlyphEntry {
|
||||
|
||||
struct Page {
|
||||
handle: TextureHandle,
|
||||
/// Shelf packing is effective because glyphs at one size have similar heights.
|
||||
x: u32,
|
||||
y: u32,
|
||||
shelf_height: u32,
|
||||
@@ -64,7 +59,6 @@ impl GlyphAtlas {
|
||||
self.entries.get(key).copied()
|
||||
}
|
||||
|
||||
/// Returns `None` when a glyph has no pixels or cannot fit on a page.
|
||||
pub fn insert(
|
||||
&mut self,
|
||||
key: GlyphKey,
|
||||
@@ -78,7 +72,6 @@ impl GlyphAtlas {
|
||||
return None;
|
||||
}
|
||||
if w + PAD * 2 > PAGE || h + PAD * 2 > PAGE {
|
||||
// Never silently crop an oversized glyph.
|
||||
self.entries.insert(key, None);
|
||||
return None;
|
||||
}
|
||||
@@ -142,7 +135,6 @@ impl GlyphAtlas {
|
||||
(self.pages.len() - 1, PAD, PAD)
|
||||
}
|
||||
|
||||
/// Record that a glyph has no pixels, so it is not re-rasterised.
|
||||
pub fn insert_empty(&mut self, key: GlyphKey) {
|
||||
self.entries.insert(key, None);
|
||||
}
|
||||
@@ -157,7 +149,6 @@ impl GlyphAtlas {
|
||||
}
|
||||
|
||||
fn fits(page: &Page, need_w: u32, need_h: u32) -> bool {
|
||||
// On the current shelf, or on a new one above it.
|
||||
(page.x + need_w <= PAGE && page.y + need_h <= PAGE)
|
||||
|| (need_w + PAD <= PAGE && page.y + page.shelf_height + need_h <= PAGE)
|
||||
}
|
||||
@@ -202,7 +193,6 @@ fn write_glyph(page: &mut RgbaImage, image: &Image, x: u32, y: u32) {
|
||||
}
|
||||
}
|
||||
|
||||
/// Where a glyph goes on screen, in pixels relative to the text's origin.
|
||||
#[derive(Clone, Copy)]
|
||||
pub struct PlacedGlyph {
|
||||
pub entry: GlyphEntry,
|
||||
|
||||
@@ -231,7 +231,6 @@ pub struct TexturePrimitive {
|
||||
pub sampler_idx: u32,
|
||||
}
|
||||
|
||||
/// An atlas subrectangle, tinted for masks or unchanged for color glyphs.
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
pub struct GlyphPrimitive {
|
||||
|
||||
@@ -100,7 +100,6 @@ impl<'a> Painter<'a> {
|
||||
ui.text.render(buffer, attrs, width, &mut ui.textures)
|
||||
}
|
||||
|
||||
/// Draws one atlas-sampling quad per glyph.
|
||||
pub fn glyphs(&mut self, text: &RenderedText, origin: UiRegion) {
|
||||
let flags_for = |is_color| {
|
||||
if is_color {
|
||||
|
||||
@@ -104,7 +104,6 @@ pub struct TextEditCtx<'a> {
|
||||
}
|
||||
|
||||
impl<'a> TextEditCtx<'a> {
|
||||
/// Returns a layout synchronized with the current text.
|
||||
fn layout(&mut self) -> &Layout<UiColor> {
|
||||
let attrs = self.text.view.attrs.clone();
|
||||
let width = self.text.view.wrap_width();
|
||||
@@ -112,7 +111,6 @@ impl<'a> TextEditCtx<'a> {
|
||||
self.text.view.buf.layout()
|
||||
}
|
||||
|
||||
/// Keep the selection valid after the text underneath it changed.
|
||||
fn refresh(&mut self) {
|
||||
if let Some(sel) = self.text.selection {
|
||||
let layout = self.layout();
|
||||
@@ -180,7 +178,6 @@ impl<'a> TextEditCtx<'a> {
|
||||
self.set_caret(at + text.len());
|
||||
}
|
||||
|
||||
/// True when there was a span to remove.
|
||||
pub fn clear_span(&mut self) -> bool {
|
||||
let Some(sel) = self.text.selection else {
|
||||
return false;
|
||||
|
||||
@@ -27,7 +27,6 @@ impl TextView {
|
||||
self.buf.is_empty()
|
||||
}
|
||||
|
||||
/// The width used by the cached layout.
|
||||
pub fn wrap_width(&self) -> Option<f32> {
|
||||
self.width
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user