Skip to content

Update to latest Parley version. #936

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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
237 changes: 95 additions & 142 deletions Cargo.lock

Large diffs are not rendered by default.

10 changes: 6 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -92,18 +92,20 @@ tree_arena = { version = "0.1.0", path = "tree_arena" }
vello = "0.4.0"
wgpu = "23.0.1"
kurbo = "0.11.1"
parley = { version = "0.3.0", features = ["accesskit"] }
parley = { git = "https://github.com/linebender/parley", rev = "8f343fa508bf727ff5cf6d49351cda1272f3626d", features = [
"accesskit",
] }
peniko = "0.3.1"
winit = "0.30.4"
winit = "0.30.9"
tracing = { version = "0.1.40", default-features = false }
smallvec = "1.13.2"
hashbrown = "0.15.2"
dpi = "0.1.1"
image = { version = "0.25.2", default-features = false }
web-time = "1.1.0"
bitflags = "2.6.0"
accesskit = "0.17.0"
accesskit_winit = "0.23.0"
accesskit = "0.18.0"
accesskit_winit = "0.24.0"
time = "0.3.36"

[profile.ci]
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 2 additions & 1 deletion masonry/src/event_loop_runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,8 @@ impl MasonryState<'_> {

let window = event_loop.create_window(attributes).unwrap();

let adapter = Adapter::with_event_loop_proxy(&window, self.proxy.clone());
let adapter =
Adapter::with_event_loop_proxy(event_loop, &window, self.proxy.clone());
let window = Arc::new(window);
// https://github.com/rust-windowing/winit/issues/2308
#[cfg(target_os = "ios")]
Expand Down
8 changes: 4 additions & 4 deletions masonry_core/src/app/render_root.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::collections::{HashMap, VecDeque};

use accesskit::{ActionRequest, TreeUpdate};
use anymap3::AnyMap;
use parley::fontique::{self, Collection, CollectionOptions, SourceCache};
use parley::fontique::{self, Blob, Collection, CollectionOptions, SourceCache};
use parley::{FontContext, LayoutContext};
use tracing::{info_span, warn};
use tree_arena::{ArenaMut, TreeArena};
Expand Down Expand Up @@ -191,7 +191,7 @@ pub struct RenderRootOptions {
///
/// We expect to develop a much more fully-featured font API in the future, but
/// this is necessary for our testing of Masonry.
pub test_font: Option<Vec<u8>>,
pub test_font: Option<Blob<u8>>,
}

/// Objects emitted by the [`RenderRoot`] to signal that something has changed or require external actions.
Expand Down Expand Up @@ -428,12 +428,12 @@ impl RenderRoot {
/// added to that family.
pub fn register_fonts(
&mut self,
data: Vec<u8>,
data: Blob<u8>,
) -> Vec<(fontique::FamilyId, Vec<fontique::FontInfo>)> {
self.global_state
.font_context
.collection
.register_fonts(data)
.register_fonts(data, None)
}

/// Redraw the window.
Expand Down
10 changes: 7 additions & 3 deletions masonry_core/src/core/text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ pub fn render_text(
let PositionedLayoutItem::GlyphRun(glyph_run) = item else {
continue;
};
// We need to round the baseline to pixels to avoid blurry text.
// https://github.com/linebender/parley/pull/297#issuecomment-2751450235
// TODO: Better handling of fractional DPI scaling?
let glyph_run_baseline = glyph_run.baseline().round();
let style = glyph_run.style();
// We draw underlines under the text, then the strikethrough on top, following:
// https://drafts.csswg.org/css-text-decor/#painting-order
Expand All @@ -79,7 +83,7 @@ pub fn render_text(
// Remember that we are using a y-down coordinate system
// If there's a custom width, because this is an underline, we want the custom
// width to go down from the default expectation
let y = glyph_run.baseline() - offset + width / 2.;
let y = glyph_run_baseline - offset + width / 2.;

let line = Line::new(
(glyph_run.offset() as f64, y as f64),
Expand All @@ -94,7 +98,7 @@ pub fn render_text(
);
}
let mut x = glyph_run.offset();
let y = glyph_run.baseline();
let y = glyph_run_baseline;
let run = glyph_run.run();
let font = run.font();
let font_size = run.font_size();
Expand Down Expand Up @@ -141,7 +145,7 @@ pub fn render_text(
// so we calculate the middle y-position of the strikethrough based on the font's
// standard strikethrough width.
// Remember that we are using a y-down coordinate system
let y = glyph_run.baseline() - offset + run_metrics.strikethrough_size / 2.;
let y = glyph_run_baseline - offset + run_metrics.strikethrough_size / 2.;

let line = Line::new(
(glyph_run.offset() as f64, y as f64),
Expand Down
1 change: 0 additions & 1 deletion masonry_core/src/passes/accessibility.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,6 @@ pub(crate) fn run_accessibility_pass(root: &mut RenderRoot, scale_factor: f64) -
nodes: vec![],
tree: Some(Tree {
root: root.root.id().into(),
app_name: None,
toolkit_name: Some("Masonry".to_string()),
toolkit_version: Some(env!("CARGO_PKG_VERSION").to_string()),
}),
Expand Down
5 changes: 3 additions & 2 deletions masonry_core/src/testing/harness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use std::collections::VecDeque;
use std::io::Cursor;
use std::num::NonZeroUsize;
use std::path::PathBuf;
use std::sync::Arc;

use cursor_icon::CursorIcon;
use dpi::LogicalSize;
Expand All @@ -31,7 +32,7 @@ use crate::core::{
use crate::dpi::{LogicalPosition, PhysicalPosition, PhysicalSize};
use crate::kurbo::{Point, Size, Vec2};
use crate::passes::anim::run_update_anim_pass;
use crate::peniko::Color;
use crate::peniko::{Blob, Color};
use crate::testing::screenshots::get_image_diff;
use crate::testing::snapshot_utils::get_cargo_workspace;

Expand Down Expand Up @@ -242,7 +243,7 @@ impl TestHarness {
env!("CARGO_MANIFEST_DIR"),
"/resources/fonts/roboto/Roboto-Regular.ttf"
));
let data = ROBOTO.to_vec();
let data = Blob::new(Arc::new(ROBOTO));

let mut harness = Self {
render_root: RenderRoot::new(
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion masonry_core/src/widgets/text_area.rs
Original file line number Diff line number Diff line change
Expand Up @@ -967,7 +967,7 @@ impl<const EDITABLE: bool> Widget for TextArea<EDITABLE> {
let origin = Vec2::new(self.padding.get_left(is_rtl), self.padding.top);
let transform = Affine::translate(origin);
if ctx.is_focus_target() {
for rect in self.editor.selection_geometry().iter() {
for (rect, _) in self.editor.selection_geometry().iter() {
// TODO: If window not focused, use a different color
// TODO: Make configurable
scene.fill(
Expand Down
5 changes: 3 additions & 2 deletions xilem/examples/variable_clock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
//! This example uses variable fonts in a touch sensitive digital clock.
#![expect(clippy::shadow_unrelated, reason = "Idiomatic for Xilem users")]

use std::sync::Arc;
use std::time::Duration;

use time::error::IndeterminateOffset;
Expand All @@ -15,7 +16,7 @@ use xilem::view::{
Axis, FlexExt, FlexSpacer, button, flex, inline_prose, label, portal, prose, sized_box, task,
variable_label,
};
use xilem::{EventLoop, EventLoopBuilder, FontWeight, WidgetView, Xilem, palette};
use xilem::{Blob, EventLoop, EventLoopBuilder, FontWeight, WidgetView, Xilem, palette};

/// The state of the application, owned by Xilem and updated by the callbacks below.
struct Clocks {
Expand Down Expand Up @@ -191,7 +192,7 @@ fn run(event_loop: EventLoopBuilder) -> Result<(), EventLoopError> {
};

// Load Roboto Flex so that it can be used at runtime.
let app = Xilem::new(data, app_logic).with_font(ROBOTO_FLEX);
let app = Xilem::new(data, app_logic).with_font(Blob::new(Arc::new(ROBOTO_FLEX)));

app.run_windowed(event_loop, "Clocks".into())?;
Ok(())
Expand Down
3 changes: 2 additions & 1 deletion xilem/src/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use std::sync::Arc;

use masonry::app::{AppDriver, EventLoopProxy, MasonryState, MasonryUserEvent};
use masonry::core::WidgetId;
use masonry::peniko::Blob;
use masonry::widgets::RootWidget;

use crate::core::{DynMessage, MessageResult, ProxyError, RawProxy, ViewId};
Expand All @@ -19,7 +20,7 @@ pub struct MasonryDriver<State, Logic, View, ViewState> {
pub(crate) ctx: ViewCtx,
pub(crate) view_state: ViewState,
// Fonts which will be registered on startup.
pub(crate) fonts: Vec<Vec<u8>>,
pub(crate) fonts: Vec<Blob<u8>>,
}

/// The `WidgetId` which async events should be sent to.
Expand Down
6 changes: 3 additions & 3 deletions xilem/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ pub use masonry::app::{EventLoop, EventLoopBuilder};
pub use masonry::kurbo::{Affine, Vec2};
pub use masonry::parley::Alignment as TextAlignment;
pub use masonry::parley::style::FontWeight;
pub use masonry::peniko::Color;
pub use masonry::peniko::{Blob, Color};
pub use masonry::widgets::{InsertNewline, LineBreaking};
pub use masonry::{dpi, palette};
pub use xilem_core as core;
Expand All @@ -174,7 +174,7 @@ pub struct Xilem<State, Logic> {
runtime: tokio::runtime::Runtime,
background_color: Color,
// Font data to include in loading.
fonts: Vec<Vec<u8>>,
fonts: Vec<Blob<u8>>,
}

#[expect(missing_docs, reason = "TODO - Document these items")]
Expand All @@ -198,7 +198,7 @@ where
/// Load a font when this `Xilem` is run.
///
/// This is an interim API whilst font lifecycles are determined.
pub fn with_font(mut self, data: impl Into<Vec<u8>>) -> Self {
pub fn with_font(mut self, data: impl Into<Blob<u8>>) -> Self {
self.fonts.push(data.into());
self
}
Expand Down
Loading