-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Feat(Text Vertical Align): Added a new feature to enable the vertical… #3908
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -366,6 +366,31 @@ | |
| textInput.style.color = data.color; | ||
| textInput.style.textAlign = data.align; | ||
|
|
||
| // Apply vertical alignment using padding-top to offset text within the container | ||
| if (data.maxHeight !== undefined) { | ||
| if (data.verticalAlign === "Center" || data.verticalAlign === "Bottom") { | ||
| // Reset any existing padding first | ||
| textInput.style.paddingTop = "0px"; | ||
|
|
||
| // Wait for layout to settle so we can measure the content height | ||
| await tick(); | ||
|
|
||
| const contentHeight = textInput.scrollHeight; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P2: Vertical alignment padding is measured once and not recomputed after text edits or font updates, causing center/bottom-aligned text overlay drift. Prompt for AI agents |
||
| const containerHeight = data.maxHeight; | ||
| const freeSpace = Math.max(containerHeight - contentHeight, 0); | ||
|
|
||
| if (data.verticalAlign === "Center") { | ||
| textInput.style.paddingTop = `${freeSpace / 2}px`; | ||
| } else { | ||
| textInput.style.paddingTop = `${freeSpace}px`; | ||
| } | ||
| } else { | ||
| textInput.style.paddingTop = "0px"; | ||
| } | ||
| } else { | ||
| textInput.style.paddingTop = "0px"; | ||
| } | ||
|
|
||
| textInput.oninput = () => { | ||
| if (!textInput) return; | ||
| editor.handle.updateBounds(textInputCleanup(textInput.innerText)); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -38,6 +38,18 @@ impl From<TextAlign> for parley::Alignment { | |
| } | ||
| } | ||
|
|
||
| /// Vertical alignment of text within its bounding box. | ||
| #[repr(C)] | ||
| #[cfg_attr(feature = "wasm", derive(tsify::Tsify))] | ||
| #[derive(Debug, Clone, Copy, Default, PartialEq, Eq, serde::Serialize, serde::Deserialize, Hash, DynAny, node_macro::ChoiceType)] | ||
| #[widget(Radio)] | ||
| pub enum VerticalAlign { | ||
| #[default] | ||
| Top, | ||
| Center, | ||
| Bottom, | ||
| } | ||
|
Comment on lines
+41
to
+51
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This file appears to be a duplicate of |
||
|
|
||
| #[derive(PartialEq, Clone, Copy, Debug, serde::Serialize, serde::Deserialize)] | ||
| pub struct TypesettingConfig { | ||
| pub font_size: f64, | ||
|
|
@@ -47,6 +59,8 @@ pub struct TypesettingConfig { | |
| pub max_height: Option<f64>, | ||
| pub tilt: f64, | ||
| pub align: TextAlign, | ||
| #[serde(default)] | ||
| pub vertical_align: VerticalAlign, | ||
| } | ||
|
|
||
| impl Default for TypesettingConfig { | ||
|
|
@@ -59,6 +73,7 @@ impl Default for TypesettingConfig { | |
| max_height: None, | ||
| tilt: 0., | ||
| align: TextAlign::default(), | ||
| vertical_align: VerticalAlign::default(), | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -64,7 +64,7 @@ impl<Upstream: Default + 'static> PathBuilder<Upstream> { | |
| } | ||
| } | ||
|
|
||
| pub fn render_glyph_run(&mut self, glyph_run: &GlyphRun<'_, ()>, tilt: f64, per_glyph_instances: bool) { | ||
| pub fn render_glyph_run(&mut self, glyph_run: &GlyphRun<'_, ()>, tilt: f64, per_glyph_instances: bool, vertical_offset: f64) { | ||
| let mut run_x = glyph_run.offset(); | ||
| let run_y = glyph_run.baseline(); | ||
|
|
||
|
|
@@ -105,7 +105,7 @@ impl<Upstream: Default + 'static> PathBuilder<Upstream> { | |
| let outlines = font_ref.outline_glyphs(); | ||
|
|
||
| for glyph in glyph_run.glyphs() { | ||
| let glyph_offset = DVec2::new((run_x + glyph.x) as f64, (run_y - glyph.y) as f64); | ||
| let glyph_offset = DVec2::new((run_x + glyph.x) as f64, (run_y - glyph.y) as f64 + vertical_offset); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P2: Vertical offset is applied before skew in merged-path mode, but skew pivot remains at Prompt for AI agents |
||
| run_x += glyph.advance; | ||
|
|
||
| let glyph_id = GlyphId::from(glyph.id); | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.