Skip to content

Commit

Permalink
Reorganize Masonry modules
Browse files Browse the repository at this point in the history
  • Loading branch information
PoignardAzur committed Jan 23, 2025
1 parent 4674f6c commit e60f5a3
Show file tree
Hide file tree
Showing 223 changed files with 384 additions and 363 deletions.
2 changes: 1 addition & 1 deletion masonry/examples/calc_masonry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
use accesskit::{Node, Role};
use masonry::dpi::LogicalSize;
use masonry::text::StyleProperty;
use masonry::widget::{Align, CrossAxisAlignment, Flex, Label, RootWidget, SizedBox};
use masonry::widgets::{Align, CrossAxisAlignment, Flex, Label, RootWidget, SizedBox};
use masonry::{
AccessCtx, AccessEvent, Action, AppDriver, BoxConstraints, Color, DriverCtx, EventCtx,
LayoutCtx, PaintCtx, Point, PointerEvent, QueryCtx, RegisterCtx, Size, TextEvent, Update,
Expand Down
2 changes: 1 addition & 1 deletion masonry/examples/custom_widget.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

use accesskit::{Node, Role};
use masonry::kurbo::{BezPath, Stroke};
use masonry::widget::{ObjectFit, RootWidget};
use masonry::widgets::{ObjectFit, RootWidget};
use masonry::{
palette, AccessCtx, AccessEvent, Action, Affine, AppDriver, BoxConstraints, Color, DriverCtx,
EventCtx, LayoutCtx, PaintCtx, Point, PointerEvent, QueryCtx, Rect, RegisterCtx, Size,
Expand Down
2 changes: 1 addition & 1 deletion masonry/examples/grid_masonry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

use masonry::dpi::LogicalSize;
use masonry::text::StyleProperty;
use masonry::widget::{Button, Grid, GridParams, Prose, RootWidget, SizedBox, TextArea};
use masonry::widgets::{Button, Grid, GridParams, Prose, RootWidget, SizedBox, TextArea};
use masonry::{Action, AppDriver, Color, DriverCtx, PointerButton, WidgetId};
use parley::layout::Alignment;
use winit::window::Window;
Expand Down
2 changes: 1 addition & 1 deletion masonry/examples/hello_masonry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

use masonry::dpi::LogicalSize;
use masonry::text::StyleProperty;
use masonry::widget::{Button, Flex, Label, RootWidget};
use masonry::widgets::{Button, Flex, Label, RootWidget};
use masonry::{Action, AppDriver, DriverCtx, FontWeight, WidgetId};
use winit::window::Window;

Expand Down
2 changes: 1 addition & 1 deletion masonry/examples/simple_image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#![windows_subsystem = "windows"]

use masonry::dpi::LogicalSize;
use masonry::widget::{Image, ObjectFit, RootWidget};
use masonry::widgets::{Image, ObjectFit, RootWidget};
use masonry::{Action, AppDriver, DriverCtx, WidgetId};
use vello::peniko::{Image as ImageBuf, ImageFormat};
use winit::window::Window;
Expand Down
2 changes: 1 addition & 1 deletion masonry/examples/to_do_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#![windows_subsystem = "windows"]

use masonry::dpi::LogicalSize;
use masonry::widget::{Button, Flex, Label, Portal, RootWidget, TextArea, Textbox};
use masonry::widgets::{Button, Flex, Label, Portal, RootWidget, TextArea, Textbox};
use masonry::{Action, AppDriver, DriverCtx, Widget, WidgetId};
use winit::window::Window;

Expand Down
2 changes: 1 addition & 1 deletion masonry/examples/two_textboxes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#![windows_subsystem = "windows"]

use masonry::dpi::LogicalSize;
use masonry::widget::{Flex, RootWidget, Textbox};
use masonry::widgets::{Flex, RootWidget, Textbox};
use masonry::{Action, AppDriver, DriverCtx, WidgetId};
use winit::window::Window;

Expand Down
File renamed without changes.
File renamed without changes.
9 changes: 9 additions & 0 deletions masonry/src/app/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Copyright 2025 the Xilem Authors
// SPDX-License-Identifier: Apache-2.0

#![allow(missing_docs, reason = "WIP")]

pub(crate) mod app_driver;
pub mod event_loop_runner;
pub(crate) mod render_root;
pub(crate) mod tracing_backend;
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ use crate::passes::update::{
};
use crate::passes::{recurse_on_children, PassTracing};
use crate::text::BrushIndex;
use crate::widget::{WidgetArena, WidgetMut, WidgetRef, WidgetState};
use crate::widgets::{WidgetArena, WidgetMut, WidgetRef, WidgetState};
use crate::{AccessEvent, Action, CursorIcon, Handled, QueryCtx, Widget, WidgetId, WidgetPod};

/// We ensure that any valid initial IME area is sent to the platform by storing an invalid initial
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion masonry/src/contexts.rs → masonry/src/core/contexts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use crate::passes::layout::run_layout_on;
use crate::render_root::{MutateCallback, RenderRootSignal, RenderRootState};
use crate::text::BrushIndex;
use crate::theme::get_debug_color;
use crate::widget::{CreateWidget, WidgetMut, WidgetRef, WidgetState};
use crate::widgets::{CreateWidget, WidgetMut, WidgetRef, WidgetState};
use crate::{
Affine, AllowRawMut, BoxConstraints, Color, FromDynWidget, Insets, Point, Rect, Size, Vec2,
Widget, WidgetId, WidgetPod,
Expand Down
File renamed without changes.
10 changes: 10 additions & 0 deletions masonry/src/core/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Copyright 2025 the Xilem Authors
// SPDX-License-Identifier: Apache-2.0

#![allow(missing_docs, reason = "WIP")]

pub(crate) mod action;
pub(crate) mod box_constraints;
pub mod contexts;
pub mod event;
pub mod text;
40 changes: 36 additions & 4 deletions masonry/src/text/render_text.rs → masonry/src/core/text.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,47 @@
// Copyright 2020 the Xilem Authors and the Druid Authors
// Copyright 2018 the Xilem Authors and the Druid Authors
// SPDX-License-Identifier: Apache-2.0

//! Helper functions for working with text in Masonry.
//! Support for text display and rendering
//!
//! There are three kinds of text commonly needed:
//! 1) Non interactive text (e.g. a button's label)
//! 2) Selectable text (e.g. a paragraph of content)
//! 3) Editable text (e.g. a search bar)
//!
//! All of these have the same set of global styling options, and can contain rich text
use parley::GenericFamily;

/// A reference counted string slice.
///
/// This is a data-friendly way to represent strings in Masonry. Unlike `String`
/// it cannot be mutated, but unlike `String` it can be cheaply cloned.
pub type ArcStr = std::sync::Arc<str>;

/// The Parley [`parley::Brush`] used within Masonry.
///
/// This enables updating of brush details without performing relayouts;
/// the inner values are indexes into the `brushes` argument to [`render_text()`].
#[derive(Clone, PartialEq, Default, Debug)]
pub struct BrushIndex(pub usize);

/// A style property specialised for use within Masonry.
pub type StyleProperty = parley::StyleProperty<'static, BrushIndex>;

/// A set of styles specialised for use within Masonry.
pub type StyleSet = parley::StyleSet<BrushIndex>;

/// Applies the default text styles for Masonry into `styles`.
pub(crate) fn default_styles(styles: &mut StyleSet) {
styles.insert(StyleProperty::LineHeight(1.2));
styles.insert(GenericFamily::SystemUi.into());
}

use parley::{Layout, PositionedLayoutItem};
use vello::kurbo::{Affine, Line, Stroke};
use vello::peniko::{Brush, Fill};
use vello::Scene;

use super::BrushIndex;

/// A function that renders laid out glyphs to a [`Scene`].
///
/// The `BrushIndex` values of the runs are indices into `brushes`.
Expand Down
36 changes: 22 additions & 14 deletions masonry/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,21 +150,13 @@ mod util;
#[cfg(doc)]
pub mod doc;

mod action;
mod app_driver;
mod box_constraints;
mod contexts;
mod event;
mod paint_scene_helpers;
mod passes;
mod render_root;
mod tracing_backend;

pub mod event_loop_runner;
pub mod app;
pub mod core;
pub mod testing;
pub mod text;
pub mod theme;
pub mod widget;
pub mod widgets;

pub use cursor_icon;
pub use dpi;
Expand Down Expand Up @@ -192,7 +184,23 @@ pub use event::{
pub use paint_scene_helpers::UnitPoint;
pub use render_root::{RenderRoot, RenderRootOptions, RenderRootSignal, WindowSizePolicy};
pub use util::{AsAny, Handled};
pub use widget::widget::{AllowRawMut, FromDynWidget, Widget, WidgetId};
pub use widget::WidgetPod;
pub use widgets::widget::{AllowRawMut, FromDynWidget, Widget, WidgetId};
pub use widgets::WidgetPod;

pub(crate) use widget::WidgetState;
pub(crate) use widgets::WidgetState;

// TODO - Remove
use app::app_driver;
use app::render_root;
use app::tracing_backend;
use core::action;
use core::box_constraints;
use core::contexts;
use core::event;

pub use app::event_loop_runner;
pub use core::text;

mod paint_scene_helpers {
pub use crate::util::*;
}
89 changes: 0 additions & 89 deletions masonry/src/paint_scene_helpers.rs

This file was deleted.

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

use crate::passes::{enter_span_if, recurse_on_children};
use crate::render_root::{RenderRoot, RenderRootSignal, WindowSizePolicy};
use crate::widget::WidgetState;
use crate::widgets::WidgetState;
use crate::{BoxConstraints, LayoutCtx, Widget, WidgetPod};

// --- MARK: RUN LAYOUT ---
Expand Down
2 changes: 1 addition & 1 deletion masonry/src/passes/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use tracing::span::EnteredSpan;
use tree_arena::{ArenaMut, ArenaMutList, ArenaRef};

use crate::render_root::RenderRootState;
use crate::widget::WidgetArena;
use crate::widgets::WidgetArena;
use crate::{QueryCtx, Widget, WidgetId, WidgetState};

pub(crate) mod accessibility;
Expand Down
2 changes: 1 addition & 1 deletion masonry/src/passes/mutate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use tracing::info_span;

use crate::passes::merge_state_up;
use crate::render_root::RenderRoot;
use crate::widget::WidgetMut;
use crate::widgets::WidgetMut;
use crate::{MutateCtx, Widget, WidgetId};

pub(crate) fn mutate_widget<R>(
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 @@ -26,7 +26,7 @@ use crate::render_root::{RenderRoot, RenderRootOptions, RenderRootSignal, Window
use crate::testing::screenshots::get_image_diff;
use crate::testing::snapshot_utils::get_cargo_workspace;
use crate::tracing_backend::try_init_test_tracing;
use crate::widget::{WidgetMut, WidgetRef};
use crate::widgets::{WidgetMut, WidgetRef};
use crate::{Color, Handled, Point, Size, Vec2, Widget, WidgetId};

/// A safe headless environment to test widgets in.
Expand Down
4 changes: 2 additions & 2 deletions masonry/src/testing/helper_widgets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ use tracing::trace_span;
use vello::Scene;

use crate::event::{PointerEvent, TextEvent};
use crate::widget::widget::find_widget_at_pos;
use crate::widget::{SizedBox, WidgetRef};
use crate::widgets::widget::find_widget_at_pos;
use crate::widgets::{SizedBox, WidgetRef};
use crate::{
AccessCtx, AccessEvent, AsAny, BoxConstraints, ComposeCtx, CursorIcon, EventCtx, LayoutCtx,
PaintCtx, Point, QueryCtx, RegisterCtx, Size, Update, UpdateCtx, Widget, WidgetId, WidgetPod,
Expand Down
42 changes: 0 additions & 42 deletions masonry/src/text/mod.rs

This file was deleted.

Loading

0 comments on commit e60f5a3

Please sign in to comment.