Skip to content
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

Use palette and Color from top level Xilem and Masonry #800

Merged
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
8 changes: 4 additions & 4 deletions masonry/examples/custom_widget.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ use accesskit::{Node, Role};
use masonry::kurbo::{BezPath, Stroke};
use masonry::widget::{ObjectFit, RootWidget};
use masonry::{
AccessCtx, AccessEvent, Action, Affine, AppDriver, BoxConstraints, Color, DriverCtx, EventCtx,
LayoutCtx, PaintCtx, Point, PointerEvent, QueryCtx, Rect, RegisterCtx, Size, TextEvent, Widget,
WidgetId,
palette, AccessCtx, AccessEvent, Action, Affine, AppDriver, BoxConstraints, Color, DriverCtx,
EventCtx, LayoutCtx, PaintCtx, Point, PointerEvent, QueryCtx, Rect, RegisterCtx, Size,
TextEvent, Widget, WidgetId,
};
use parley::layout::Alignment;
use parley::style::{FontFamily, FontStack, StyleProperty};
use smallvec::SmallVec;
use tracing::{trace_span, Span};
use vello::peniko::{color::palette, Fill, Image, ImageFormat};
use vello::peniko::{Fill, Image, ImageFormat};
use vello::Scene;
use winit::window::Window;

Expand Down
5 changes: 3 additions & 2 deletions masonry/src/contexts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ use parley::{FontContext, LayoutContext};
use tracing::{trace, warn};
use tree_arena::{ArenaMutChildren, ArenaRefChildren};
use vello::kurbo::Vec2;
use vello::peniko::Color;
use winit::window::ResizeDirection;

use crate::action::Action;
Expand All @@ -20,7 +19,9 @@ use crate::render_root::{MutateCallback, RenderRootSignal, RenderRootState};
use crate::text::BrushIndex;
use crate::theme::get_debug_color;
use crate::widget::{WidgetMut, WidgetRef, WidgetState};
use crate::{AllowRawMut, BoxConstraints, Insets, Point, Rect, Size, Widget, WidgetId, WidgetPod};
use crate::{
AllowRawMut, BoxConstraints, Color, Insets, Point, Rect, Size, Widget, WidgetId, WidgetPod,
};

// Note - Most methods defined in this file revolve around `WidgetState` fields.
// Consider reading `WidgetState` documentation (especially the documented naming scheme)
Expand Down
3 changes: 1 addition & 2 deletions masonry/src/event_loop_runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ use std::sync::Arc;
use accesskit_winit::Adapter;
use tracing::{debug, info_span, warn};
use vello::kurbo::Affine;
use vello::peniko::Color;
use vello::util::{RenderContext, RenderSurface};
use vello::{AaSupport, RenderParams, Renderer, RendererOptions, Scene};
use wgpu::PresentMode;
Expand All @@ -24,7 +23,7 @@ use crate::app_driver::{AppDriver, DriverCtx};
use crate::dpi::LogicalPosition;
use crate::event::{PointerButton, PointerState, WindowEvent};
use crate::render_root::{self, RenderRoot, WindowSizePolicy};
use crate::{PointerEvent, TextEvent, Widget, WidgetId};
use crate::{Color, PointerEvent, TextEvent, Widget, WidgetId};

#[derive(Debug)]
pub enum MasonryUserEvent {
Expand Down
2 changes: 1 addition & 1 deletion masonry/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ pub use cursor_icon::{CursorIcon, ParseError as CursorIconParseError};
pub use kurbo::{Affine, Insets, Point, Rect, Size, Vec2};
pub use parley::layout::Alignment as TextAlignment;
pub use parley::style::FontWeight;
pub use vello::peniko::{Color, Gradient};
pub use vello::peniko::{color::palette, Color, Gradient};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For reviewers, this is the new change to public API (it wasn't obvious to me on a first pass).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And a similar in xilem/src/lib.rs re-exporting from here (as it already did for Color).


pub use action::Action;
pub use app_driver::{AppDriver, DriverCtx};
Expand Down
4 changes: 1 addition & 3 deletions masonry/src/theme.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@
#![allow(missing_docs)]

use vello::peniko::Color;

use crate::Insets;
use crate::{Color, Insets};

// 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
3 changes: 1 addition & 2 deletions masonry/src/widget/sized_box.rs
Original file line number Diff line number Diff line change
Expand Up @@ -574,13 +574,12 @@ impl Widget for SizedBox {
#[cfg(test)]
mod tests {
use insta::assert_debug_snapshot;
use vello::peniko::color::palette;
use vello::peniko::Gradient;

use super::*;
use crate::assert_render_snapshot;
use crate::testing::TestHarness;
use crate::widget::Label;
use crate::{assert_render_snapshot, palette};

// TODO - Add WidgetMut tests

Expand Down
3 changes: 1 addition & 2 deletions masonry/src/widget/spinner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,8 @@ impl Widget for Spinner {
#[cfg(test)]
mod tests {
use super::*;
use crate::assert_render_snapshot;
use crate::testing::TestHarness;
use crate::vello::peniko::color::palette;
use crate::{assert_render_snapshot, palette};

#[test]
fn simple_spinner() {
Expand Down
10 changes: 5 additions & 5 deletions masonry/src/widget/text_area.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@ use parley::PlainEditor;
use smallvec::SmallVec;
use tracing::{trace_span, Span};
use vello::kurbo::{Rect, Vec2};
use vello::peniko::{color::palette, Brush, Fill};
use vello::peniko::{Brush, Fill};
use vello::Scene;
use winit::keyboard::{Key, NamedKey};

use crate::text::{BrushIndex, StyleProperty};
use crate::widget::{Padding, WidgetMut};
use crate::{
theme, AccessCtx, AccessEvent, BoxConstraints, CursorIcon, EventCtx, LayoutCtx, PaintCtx,
PointerButton, PointerEvent, QueryCtx, RegisterCtx, TextEvent, Update, UpdateCtx, Widget,
WidgetId,
palette, theme, AccessCtx, AccessEvent, BoxConstraints, CursorIcon, EventCtx, LayoutCtx,
PaintCtx, PointerButton, PointerEvent, QueryCtx, RegisterCtx, TextEvent, Update, UpdateCtx,
Widget, WidgetId,
};

/// `TextArea` implements the core of interactive text.
Expand Down Expand Up @@ -975,7 +975,7 @@ impl<const EDITABLE: bool> Widget for TextArea<EDITABLE> {

#[cfg(test)]
mod tests {
use vello::{kurbo::Size, peniko::color::palette};
use vello::kurbo::Size;

use super::*;
use crate::testing::TestHarness;
Expand Down
5 changes: 2 additions & 3 deletions masonry/src/widget/textbox.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,12 @@ use accesskit::{Node, Role};
use smallvec::{smallvec, SmallVec};
use tracing::{trace_span, Span};
use vello::kurbo::{Affine, Insets, Point, Rect, Size, Stroke};
use vello::peniko::Color;
use vello::Scene;

use crate::widget::WidgetMut;
use crate::{
AccessCtx, AccessEvent, BoxConstraints, EventCtx, LayoutCtx, PaintCtx, PointerEvent, QueryCtx,
RegisterCtx, TextEvent, Update, UpdateCtx, Widget, WidgetId,
AccessCtx, AccessEvent, BoxConstraints, Color, EventCtx, LayoutCtx, PaintCtx, PointerEvent,
QueryCtx, RegisterCtx, TextEvent, Update, UpdateCtx, Widget, WidgetId,
};

use super::{Padding, TextArea, WidgetPod};
Expand Down
3 changes: 1 addition & 2 deletions xilem/examples/calc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,14 @@
#![expect(clippy::cast_possible_truncation, reason = "Deferred: Noisy")]

use masonry::widget::{CrossAxisAlignment, GridParams, MainAxisAlignment};
use vello::peniko::color::palette;
use winit::dpi::LogicalSize;
use winit::error::EventLoopError;
use winit::window::Window;
use xilem::view::{
button, flex, grid, label, sized_box, Axis, Flex, FlexSequence, FlexSpacer, GridExt,
GridSequence, Label,
};
use xilem::{EventLoop, EventLoopBuilder, WidgetView, Xilem};
use xilem::{palette, EventLoop, EventLoopBuilder, WidgetView, Xilem};

#[derive(Copy, Clone)]
enum MathOperator {
Expand Down
3 changes: 1 addition & 2 deletions xilem/examples/http_cats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

use std::sync::Arc;

use vello::peniko::color::palette;
use vello::peniko::{Blob, Image};
use winit::dpi::LogicalSize;
use winit::error::EventLoopError;
Expand All @@ -20,7 +19,7 @@ use xilem::view::{
button, flex, image, inline_prose, portal, prose, sized_box, spinner, worker, Axis, FlexExt,
FlexSpacer, Padding,
};
use xilem::{EventLoop, EventLoopBuilder, TextAlignment, WidgetView, Xilem};
use xilem::{palette, EventLoop, EventLoopBuilder, TextAlignment, WidgetView, Xilem};

/// The main state of the application.
struct HttpCats {
Expand Down
5 changes: 3 additions & 2 deletions xilem/examples/mason.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,16 @@

use std::time::Duration;

use vello::peniko::color::palette;
use winit::error::EventLoopError;
use xilem::core::{fork, run_once};
use xilem::tokio::time;
use xilem::view::{
button, button_any_pointer, checkbox, flex, label, prose, task, textbox, Axis, FlexExt as _,
FlexSpacer,
};
use xilem::{Color, EventLoop, EventLoopBuilder, FontWeight, TextAlignment, WidgetView, Xilem};
use xilem::{
palette, Color, EventLoop, EventLoopBuilder, FontWeight, TextAlignment, WidgetView, Xilem,
};
const LOREM: &str = r"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi cursus mi sed euismod euismod. Orci varius natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Nullam placerat efficitur tellus at semper. Morbi ac risus magna. Donec ut cursus ex. Etiam quis posuere tellus. Mauris posuere dui et turpis mollis, vitae luctus tellus consectetur. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur eu facilisis nisl.
Phasellus in viverra dolor, vitae facilisis est. Maecenas malesuada massa vel ultricies feugiat. Vivamus venenatis et nibh nec pharetra. Phasellus vestibulum elit enim, nec scelerisque orci faucibus id. Vivamus consequat purus sit amet orci egestas, non iaculis massa porttitor. Vestibulum ut eros leo. In fermentum convallis magna in finibus. Donec justo leo, maximus ac laoreet id, volutpat ut elit. Mauris sed leo non neque laoreet faucibus. Aliquam orci arcu, faucibus in molestie eget, ornare non dui. Donec volutpat nulla in fringilla elementum. Aliquam vitae ante egestas ligula tempus vestibulum sit amet sed ante. ";
Expand Down
3 changes: 1 addition & 2 deletions xilem/examples/variable_clock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,13 @@ use std::time::Duration;
use time::error::IndeterminateOffset;
use time::macros::format_description;
use time::{OffsetDateTime, UtcOffset};
use vello::peniko::color::palette;
use winit::error::EventLoopError;
use xilem::core::fork;
use xilem::view::{
button, flex, inline_prose, label, portal, prose, sized_box, task, variable_label, Axis,
FlexExt, FlexSpacer,
};
use xilem::{EventLoop, EventLoopBuilder, FontWeight, WidgetView, Xilem};
use xilem::{palette, EventLoop, EventLoopBuilder, FontWeight, WidgetView, Xilem};

/// The state of the application, owned by Xilem and updated by the callbacks below.
struct Clocks {
Expand Down
2 changes: 1 addition & 1 deletion xilem/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ use crate::core::{
ViewPathTracker, ViewSequence,
};
pub use masonry::event_loop_runner::{EventLoop, EventLoopBuilder};
pub use masonry::{dpi, Color, FontWeight, TextAlignment};
pub use masonry::{dpi, palette, Color, FontWeight, TextAlignment};
pub use xilem_core as core;

/// Tokio is the async runner used with Xilem.
Expand Down
2 changes: 1 addition & 1 deletion xilem/src/view/sized_box.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ impl<V, State, Action> SizedBox<V, State, Action> {
/// This can be passed anything which can be represented by a [`Brush`];
/// notably, it can be any [`Color`], any gradient, or an [`Image`].
///
/// [`Color`]: vello::peniko::Color
/// [`Color`]: crate::Color
/// [`Image`]: vello::peniko::Image
pub fn background(mut self, brush: impl Into<Brush>) -> Self {
self.background = Some(brush.into());
Expand Down
Loading