Skip to content
Merged
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
2 changes: 1 addition & 1 deletion masonry/src/app/render_root.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
use std::collections::{HashMap, VecDeque};

use accesskit::{ActionRequest, TreeUpdate};
use cursor_icon::CursorIcon;
use parley::fontique::{self, Blob, Collection, CollectionOptions, SourceCache};
use parley::{FontContext, LayoutContext};
use tracing::{info_span, warn};
Expand Down Expand Up @@ -36,7 +37,6 @@ use crate::passes::update::{
};
use crate::passes::{PassTracing, recurse_on_children};
use crate::util::AnyMap;
use cursor_icon::CursorIcon;

/// We ensure that any valid initial IME area is sent to the platform by storing an invalid initial
/// IME area as the `last_sent_ime_area`.
Expand Down
2 changes: 2 additions & 0 deletions masonry/src/core/box_constraints.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Copyright 2019 the Xilem Authors and the Druid Authors
// SPDX-License-Identifier: Apache-2.0

pub use crate::debug_panic;

use vello::kurbo::Size;

/// Constraints for layout.
Expand Down
3 changes: 2 additions & 1 deletion masonry/src/core/contexts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@ use dpi::{LogicalPosition, PhysicalPosition};
use parley::{FontContext, LayoutContext};
use tracing::{trace, warn};
use tree_arena::{ArenaMutList, ArenaRefList};
use vello::kurbo::{Affine, Insets, Point, Rect, Size, Vec2};

use crate::app::{MutateCallback, RenderRootSignal, RenderRootState};
use crate::core::{
Action, AllowRawMut, BoxConstraints, BrushIndex, CreateWidget, DefaultProperties,
FromDynWidget, PropertiesMut, PropertiesRef, ResizeDirection, Widget, WidgetId, WidgetMut,
WidgetPod, WidgetRef, WidgetState,
};
use crate::kurbo::{Affine, Insets, Point, Rect, Size, Vec2};
use crate::debug_panic;
use crate::passes::layout::run_layout_on;
use crate::peniko::Color;
use crate::util::{AnyMap, get_debug_color};
Expand Down
6 changes: 3 additions & 3 deletions masonry/src/core/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@

//! Events.

use ui_events::keyboard::KeyboardEvent;
use vello::kurbo::Rect;

use crate::dpi::PhysicalSize;
use crate::kurbo::Rect;
use crate::util::Duration;

use ui_events::keyboard::KeyboardEvent;

// TODO - Occluded(bool) event
// TODO - winit ActivationTokenDone thing
// TODO - Suspended/Resume/NewEvents/MemoryWarning
Expand Down
2 changes: 1 addition & 1 deletion masonry/src/core/object_fit.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright 2025 the Xilem Authors
// SPDX-License-Identifier: Apache-2.0

use crate::kurbo::{Affine, Size};
use vello::kurbo::{Affine, Size};

// These are based on https://developer.mozilla.org/en-US/docs/Web/CSS/object-fit
/// Strategies for inscribing a rectangle inside another rectangle.
Expand Down
3 changes: 1 addition & 2 deletions masonry/src/core/properties.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
// Copyright 2025 the Xilem Authors
// SPDX-License-Identifier: Apache-2.0

use crate::util::AnyMap;

use std::any::TypeId;
use std::collections::HashMap;
use std::default::Default;

use crate::core::Widget;
use crate::util::AnyMap;

/// A marker trait that indicates that a type is intended to be used as a widget's property.
///
Expand Down
2 changes: 1 addition & 1 deletion masonry/src/core/text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pub type ArcStr = std::sync::Arc<str>;
/// This enables updating of brush details without performing relayouts;
/// the inner values are indexes into the `brushes` argument to [`render_text()`].
///
/// [`Brush`]: crate::parley::Brush
/// [`Brush`]: parley::Brush
#[derive(Clone, PartialEq, Default, Debug)]
pub struct BrushIndex(pub usize);

Expand Down
2 changes: 1 addition & 1 deletion masonry/src/core/widget.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ use smallvec::SmallVec;
use tracing::field::DisplayValue;
use tracing::{Span, trace_span};
use vello::Scene;
use vello::kurbo::{Point, Size};

use crate::core::{
AccessCtx, AccessEvent, BoxConstraints, ComposeCtx, EventCtx, LayoutCtx, PaintCtx,
PointerEvent, PropertiesMut, PropertiesRef, QueryCtx, RegisterCtx, TextEvent, Update,
UpdateCtx, WidgetRef,
};
use crate::kurbo::{Point, Size};

/// A unique identifier for a single [`Widget`].
///
Expand Down
3 changes: 2 additions & 1 deletion masonry/src/core/widget_mut.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@

use std::any::TypeId;

use vello::kurbo::Affine;

use crate::core::{FromDynWidget, MutateCtx, Property, Widget};
use crate::kurbo::Affine;

/// A rich mutable reference to a [`Widget`].
///
Expand Down
2 changes: 1 addition & 1 deletion masonry/src/doc/02_implementing_widget.md
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@ The next one is about creating a container widgets, and the complications it add
[`PaintCtx::size()`]: crate::core::PaintCtx::size
[`UpdateCtx::request_paint_only()`]: crate::core::UpdateCtx::request_paint_only
[`ButtonPressed`]: crate::core::Action::ButtonPressed
[`vello::Scene`]: crate::vello::Scene
[`vello::Scene`]: vello::Scene
[`Role::Button`]: accesskit::Role::Button
[`RenderRoot::edit_root_widget()`]: crate::app::RenderRoot::edit_root_widget
[`Label::set_text()`]: crate::widgets::Label::set_text
3 changes: 2 additions & 1 deletion masonry/src/passes/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ use tracing::{debug, info_span, trace};

use crate::Handled;
use crate::app::{RenderRoot, RenderRootSignal};
use crate::core::keyboard::{Key, KeyState, NamedKey};
use crate::core::{
AccessEvent, EventCtx, PointerEvent, PointerInfo, PointerUpdate, PropertiesMut, TextEvent,
Widget, WidgetId,
keyboard::{Key, KeyState, NamedKey},
};
use crate::debug_panic;
use crate::dpi::{LogicalPosition, PhysicalPosition};
use crate::passes::{enter_span, merge_state_up};

Expand Down
1 change: 1 addition & 0 deletions masonry/src/passes/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use vello::kurbo::{Point, Rect, Size};

use crate::app::{RenderRoot, RenderRootSignal, WindowSizePolicy};
use crate::core::{BoxConstraints, LayoutCtx, PropertiesMut, Widget, WidgetPod, WidgetState};
use crate::debug_panic;
use crate::passes::{enter_span_if, recurse_on_children};

// --- MARK: RUN LAYOUT
Expand Down
3 changes: 1 addition & 2 deletions masonry/src/passes/paint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,11 @@ use std::collections::HashMap;
use tracing::{info_span, trace};
use tree_arena::ArenaMut;
use vello::Scene;
use vello::kurbo::Affine;
use vello::kurbo::{Affine, Rect};
use vello::peniko::{Color, Fill, Mix};

use crate::app::{RenderRoot, RenderRootState};
use crate::core::{DefaultProperties, PaintCtx, PropertiesRef, Widget, WidgetId, WidgetState};
use crate::kurbo::Rect;
use crate::passes::{enter_span_if, recurse_on_children};
use crate::util::{AnyMap, get_debug_color, stroke};

Expand Down
3 changes: 2 additions & 1 deletion masonry/src/properties/background.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@

use std::any::TypeId;

use vello::kurbo::Rect;

use crate::core::{Property, UpdateCtx};
use crate::kurbo::Rect;
use crate::peniko::color::{AlphaColor, Srgb};
use crate::properties::types::Gradient;

Expand Down
3 changes: 2 additions & 1 deletion masonry/src/properties/border_width.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@

use std::any::TypeId;

use vello::kurbo::{Point, RoundedRect, Size, Vec2};

use crate::core::{BoxConstraints, Property, UpdateCtx};
use crate::kurbo::{Point, RoundedRect, Size, Vec2};
use crate::properties::CornerRadius;

/// The width of a widget's border, in logical pixels.
Expand Down
3 changes: 2 additions & 1 deletion masonry/src/properties/padding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@

use std::any::TypeId;

use vello::kurbo::{Point, Size, Vec2};

use crate::core::{BoxConstraints, Property, UpdateCtx};
use crate::kurbo::{Point, Size, Vec2};

/// The width of padding between a widget's border and its contents.
#[derive(Default, Clone, Copy, Debug, PartialEq)]
Expand Down
3 changes: 2 additions & 1 deletion masonry/src/properties/types/gradient.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
// Copyright 2025 the Xilem Authors
// SPDX-License-Identifier: Apache-2.0

use crate::kurbo::{Point, Rect};
use vello::kurbo::{Point, Rect};

use crate::peniko::color::{ColorSpaceTag, HueDirection};
use crate::peniko::{ColorStops, ColorStopsSource, Extend};

Expand Down
2 changes: 1 addition & 1 deletion masonry/src/testing/harness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use image::{DynamicImage, ImageFormat, ImageReader, Rgba, RgbaImage};
use oxipng::{Options, optimize_from_memory};
use tracing::debug;
use vello::RendererOptions;
use vello::kurbo::{Point, Size, Vec2};
use vello::util::{RenderContext, block_on_wgpu};
use wgpu::{
BufferDescriptor, BufferUsages, CommandEncoderDescriptor, Extent3d, TexelCopyBufferInfo,
Expand All @@ -31,7 +32,6 @@ use crate::core::{
WidgetRef, WindowEvent,
};
use crate::dpi::{LogicalPosition, PhysicalPosition, PhysicalSize};
use crate::kurbo::{Point, Size, Vec2};
use crate::peniko::{Blob, Color};
use crate::testing::screenshots::get_image_diff;
use crate::util::Duration;
Expand Down
3 changes: 1 addition & 2 deletions masonry/src/testing/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ mod recorder_widget;
mod screenshots;
mod wrapper_widget;

pub use crate::assert_failing_render_snapshot;
pub use crate::assert_render_snapshot;
pub use crate::{assert_failing_render_snapshot, assert_render_snapshot};

pub use harness::{PRIMARY_MOUSE, TestHarness, TestHarnessParams};
pub use modular_widget::ModularWidget;
Expand Down
2 changes: 1 addition & 1 deletion masonry/src/testing/modular_widget.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ use cursor_icon::CursorIcon;
use smallvec::SmallVec;
use tracing::trace_span;
use vello::Scene;
use vello::kurbo::{Point, Size};

use crate::core::{
AccessCtx, AccessEvent, BoxConstraints, ComposeCtx, EventCtx, LayoutCtx, PaintCtx,
PointerEvent, PropertiesMut, PropertiesRef, QueryCtx, RegisterCtx, TextEvent, Update,
UpdateCtx, Widget, WidgetId, WidgetRef, find_widget_under_pointer,
};
use crate::kurbo::{Point, Size};

pub type PointerEventFn<S> =
dyn FnMut(&mut S, &mut EventCtx, &mut PropertiesMut<'_>, &PointerEvent);
Expand Down
2 changes: 1 addition & 1 deletion masonry/src/testing/recorder_widget.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ use accesskit::{Node, Role};
use cursor_icon::CursorIcon;
use smallvec::SmallVec;
use vello::Scene;
use vello::kurbo::{Point, Size};

use crate::core::{
AccessCtx, AccessEvent, BoxConstraints, ComposeCtx, EventCtx, LayoutCtx, PaintCtx,
PointerEvent, PropertiesMut, PropertiesRef, QueryCtx, RegisterCtx, TextEvent, Update,
UpdateCtx, Widget, WidgetId, WidgetRef,
};
use crate::kurbo::{Point, Size};

/// A wrapper widget that records each time one of its methods is called.
///
Expand Down
2 changes: 1 addition & 1 deletion masonry/src/testing/wrapper_widget.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ use std::any::TypeId;
use accesskit::{Node, Role};
use smallvec::{SmallVec, smallvec};
use vello::Scene;
use vello::kurbo::{Point, Size};

use crate::core::{
AccessCtx, AccessEvent, BoxConstraints, ComposeCtx, EventCtx, LayoutCtx, PaintCtx,
PointerEvent, PropertiesMut, PropertiesRef, RegisterCtx, TextEvent, Update, UpdateCtx, Widget,
WidgetId, WidgetMut, WidgetPod,
};
use crate::kurbo::{Point, Size};

/// A basic wrapper widget that can replace its child.
pub struct WrapperWidget {
Expand Down
6 changes: 3 additions & 3 deletions masonry/src/theme.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@

#![allow(missing_docs, reason = "Names are self-explanatory.")]

use parley::GenericFamily;
use vello::kurbo::Insets;

use crate::core::{DefaultProperties, StyleProperty, StyleSet};
use crate::kurbo::Insets;
use crate::peniko::Color;
use crate::properties::types::Gradient;
use crate::properties::{
Expand All @@ -15,8 +17,6 @@ use crate::properties::{
};
use crate::widgets::Button;

use parley::GenericFamily;

// Colors are from https://sashat.me/2017/01/11/list-of-20-simple-distinct-colors/
// They're picked for visual distinction and accessibility (99 percent)

Expand Down
17 changes: 5 additions & 12 deletions masonry/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@ use std::any::Any;
use std::hash::Hash;

use vello::Scene;
use vello::kurbo::Join;
use vello::kurbo::{
Affine, Rect, Shape, Stroke, {self},
};
use vello::kurbo::{Affine, Join, Point, Rect, Shape, Stroke};
use vello::peniko::{BrushRef, Color, ColorStopsSource, Fill, Gradient};

/// Panic in debug and `tracing::error` in release mode.
Expand Down Expand Up @@ -126,8 +123,8 @@ impl UnitPoint {
}

/// Given a rectangle, resolve the point within the rectangle.
pub fn resolve(self, rect: Rect) -> kurbo::Point {
kurbo::Point::new(
pub fn resolve(self, rect: Rect) -> Point {
Point::new(
rect.x0 + self.u * (rect.x1 - rect.x0),
rect.y0 + self.v * (rect.y1 - rect.y0),
)
Expand Down Expand Up @@ -164,14 +161,10 @@ pub fn fill_color(scene: &mut Scene, path: &impl Shape, color: Color) {
// ---

#[cfg(not(target_arch = "wasm32"))]
pub use std::time::Instant;
#[cfg(target_arch = "wasm32")]
pub use web_time::Instant;
pub use std::time::{Duration, Instant};

#[cfg(not(target_arch = "wasm32"))]
pub use std::time::Duration;
#[cfg(target_arch = "wasm32")]
pub use web_time::Duration;
pub use web_time::{Duration, Instant};

// ---

Expand Down
2 changes: 1 addition & 1 deletion masonry/src/widgets/align.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ use accesskit::{Node, Role};
use smallvec::{SmallVec, smallvec};
use tracing::{Span, trace_span};
use vello::Scene;
use vello::kurbo::{Rect, Size};

use crate::core::{
AccessCtx, AccessEvent, BoxConstraints, EventCtx, LayoutCtx, PaintCtx, PointerEvent,
PropertiesMut, PropertiesRef, QueryCtx, RegisterCtx, TextEvent, Widget, WidgetId, WidgetPod,
};
use crate::kurbo::{Rect, Size};
use crate::util::UnitPoint;

// TODO - Have child widget type as generic argument
Expand Down
3 changes: 1 addition & 2 deletions masonry/src/widgets/button.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,13 @@ use accesskit::{Node, Role};
use smallvec::{SmallVec, smallvec};
use tracing::{Span, trace, trace_span};
use vello::Scene;
use vello::kurbo::Affine;
use vello::kurbo::{Affine, Size};

use crate::core::{
AccessCtx, AccessEvent, Action, ArcStr, BoxConstraints, EventCtx, LayoutCtx, PaintCtx,
PointerEvent, PropertiesMut, PropertiesRef, QueryCtx, RegisterCtx, TextEvent, Update,
UpdateCtx, Widget, WidgetId, WidgetMut, WidgetPod,
};
use crate::kurbo::Size;
use crate::properties::*;
use crate::theme;
use crate::util::{fill, stroke};
Expand Down
4 changes: 2 additions & 2 deletions masonry/src/widgets/flex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ use smallvec::SmallVec;
use tracing::{Span, trace_span};
use vello::Scene;
use vello::kurbo::common::FloatExt;
use vello::kurbo::{Affine, Line, Stroke, Vec2};
use vello::kurbo::{Affine, Line, Point, Rect, Size, Stroke, Vec2};

use crate::core::{
AccessCtx, AccessEvent, BoxConstraints, EventCtx, LayoutCtx, PaintCtx, PointerEvent,
PropertiesMut, PropertiesRef, QueryCtx, RegisterCtx, TextEvent, Widget, WidgetId, WidgetMut,
WidgetPod,
};
use crate::kurbo::{Point, Rect, Size};
use crate::debug_panic;

/// A container with either horizontal or vertical layout.
///
Expand Down
Loading
Loading