overflow: hidden/scroll scissor support, remove depth

This commit is contained in:
Aleksander
2025-09-25 23:21:11 +02:00
parent 8f75d451e4
commit eb12a6a319
28 changed files with 299 additions and 182 deletions

View File

@@ -5,9 +5,7 @@ pub mod text_renderer;
use std::{cell::RefCell, rc::Rc, sync::LazyLock};
use cosmic_text::{
Align, Attrs, Buffer, Color, FontSystem, Metrics, Style, SwashCache, Weight, Wrap,
};
use cosmic_text::{Align, Attrs, Buffer, Color, FontSystem, Metrics, Style, SwashCache, Weight, Wrap};
use custom_glyph::{ContentType, CustomGlyph};
use etagere::AllocId;
use glam::Mat4;
@@ -15,10 +13,8 @@ use parking_lot::Mutex;
use crate::drawing::{self};
pub static FONT_SYSTEM: LazyLock<Mutex<FontSystem>> =
LazyLock::new(|| Mutex::new(FontSystem::new()));
pub static SWASH_CACHE: LazyLock<Mutex<SwashCache>> =
LazyLock::new(|| Mutex::new(SwashCache::new()));
pub static FONT_SYSTEM: LazyLock<Mutex<FontSystem>> = LazyLock::new(|| Mutex::new(FontSystem::new()));
pub static SWASH_CACHE: LazyLock<Mutex<SwashCache>> = LazyLock::new(|| Mutex::new(SwashCache::new()));
/// Used in case no `font_size` is defined
const DEFAULT_FONT_SIZE: f32 = 14.;
@@ -26,10 +22,8 @@ const DEFAULT_FONT_SIZE: f32 = 14.;
/// In case no `line_height` is defined, use `font_size` * `DEFAULT_LINE_HEIGHT_RATIO`
const DEFAULT_LINE_HEIGHT_RATIO: f32 = 1.43;
pub(crate) const DEFAULT_METRICS: Metrics = Metrics::new(
DEFAULT_FONT_SIZE,
DEFAULT_FONT_SIZE * DEFAULT_LINE_HEIGHT_RATIO,
);
pub(crate) const DEFAULT_METRICS: Metrics =
Metrics::new(DEFAULT_FONT_SIZE, DEFAULT_FONT_SIZE * DEFAULT_LINE_HEIGHT_RATIO);
#[derive(Default, Clone)]
pub struct TextStyle {
@@ -66,11 +60,7 @@ impl From<&TextStyle> for Metrics {
impl From<&TextStyle> for Wrap {
fn from(value: &TextStyle) -> Self {
if value.wrap {
Self::WordOrGlyph
} else {
Self::None
}
if value.wrap { Self::WordOrGlyph } else { Self::None }
}
}
@@ -155,11 +145,7 @@ impl From<cosmic_text::Color> for drawing::Color {
// glyphon types below
pub(super) enum GpuCacheStatus {
InAtlas {
x: u16,
y: u16,
content_type: ContentType,
},
InAtlas { x: u16, y: u16, content_type: ContentType },
SkipRasterization,
}
@@ -215,8 +201,6 @@ pub struct TextArea<'a> {
pub default_color: Color,
/// Additional custom glyphs to render.
pub custom_glyphs: &'a [CustomGlyph],
/// Distance from camera, 0.0..=1.0
pub depth: f32,
/// Text transformation
pub transform: Mat4,
}

View File

@@ -42,10 +42,7 @@ impl TextPipeline {
true,
)?;
Ok(Self {
gfx,
inner: pipeline,
})
Ok(Self { gfx, inner: pipeline })
}
}
@@ -63,8 +60,6 @@ pub struct GlyphVertex {
#[format(R32_UINT)]
pub in_content_type: [u16; 2], // 2 bytes unused! TODO
#[format(R32_SFLOAT)]
pub depth: f32,
#[format(R32_SFLOAT)]
pub scale: f32,
}
@@ -86,12 +81,7 @@ impl InnerAtlas {
const INITIAL_SIZE: u32 = 256;
fn new(common: TextPipeline, kind: Kind) -> anyhow::Result<Self> {
let max_texture_dimension_2d = common
.gfx
.device
.physical_device()
.properties()
.max_image_dimension2_d;
let max_texture_dimension_2d = common.gfx.device.physical_device().properties().max_image_dimension2_d;
let size = Self::INITIAL_SIZE.min(max_texture_dimension_2d);
let packer = BucketedAtlasAllocator::new(size2(size as i32, size as i32));
@@ -180,11 +170,7 @@ impl InnerAtlas {
self.kind.num_channels()
}
pub(super) fn grow(
&mut self,
font_system: &mut FontSystem,
cache: &mut SwashCache,
) -> anyhow::Result<bool> {
pub(super) fn grow(&mut self, font_system: &mut FontSystem, cache: &mut SwashCache) -> anyhow::Result<bool> {
const GROWTH_FACTOR: u32 = 2;
if self.size >= self.max_texture_dimension_2d {
@@ -327,10 +313,7 @@ impl TextAtlas {
Ok(did_grow)
}
pub(super) const fn inner_for_content_mut(
&mut self,
content_type: ContentType,
) -> &mut InnerAtlas {
pub(super) const fn inner_for_content_mut(&mut self, content_type: ContentType) -> &mut InnerAtlas {
match content_type {
ContentType::Color => &mut self.color_atlas,
ContentType::Mask => &mut self.mask_atlas,

View File

@@ -116,7 +116,6 @@ impl TextRenderer {
bounds_min_y,
bounds_max_x,
bounds_max_y,
depth: text_area.depth,
transform: &text_area.transform,
},
|_cache, _font_system| -> Option<GetGlyphImageResult> {
@@ -192,7 +191,6 @@ impl TextRenderer {
bounds_min_y,
bounds_max_x,
bounds_max_y,
depth: text_area.depth,
transform: &text_area.transform,
},
|cache, font_system| -> Option<GetGlyphImageResult> {
@@ -319,7 +317,6 @@ struct PrepareGlyphParams<'a> {
bounds_min_y: i32,
bounds_max_x: i32,
bounds_max_y: i32,
depth: f32,
}
#[allow(clippy::too_many_lines)]
@@ -484,7 +481,6 @@ fn prepare_glyph(
content_type as u16,
0, // unused (TODO!)
],
depth: par.depth,
scale: par.glyph_scale,
}))
}