From 82f0990512c477ab09aa3298891148a095e01a3d Mon Sep 17 00:00:00 2001 From: Bruce Mitchener Date: Fri, 20 Dec 2024 11:20:00 -0500 Subject: [PATCH] Use `palette` and `Color` from top level Xilem and Masonry --- masonry/examples/custom_widget.rs | 8 ++++---- masonry/src/contexts.rs | 5 +++-- masonry/src/event_loop_runner.rs | 3 +-- masonry/src/lib.rs | 2 +- masonry/src/theme.rs | 4 +--- masonry/src/widget/sized_box.rs | 3 +-- masonry/src/widget/spinner.rs | 3 +-- masonry/src/widget/text_area.rs | 10 +++++----- masonry/src/widget/textbox.rs | 5 ++--- xilem/examples/calc.rs | 3 +-- xilem/examples/http_cats.rs | 3 +-- xilem/examples/mason.rs | 5 +++-- xilem/examples/variable_clock.rs | 3 +-- xilem/src/lib.rs | 2 +- xilem/src/view/sized_box.rs | 2 +- 15 files changed, 27 insertions(+), 34 deletions(-) diff --git a/masonry/examples/custom_widget.rs b/masonry/examples/custom_widget.rs index df0353054..4dd7c7a97 100644 --- a/masonry/examples/custom_widget.rs +++ b/masonry/examples/custom_widget.rs @@ -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; diff --git a/masonry/src/contexts.rs b/masonry/src/contexts.rs index da78ce259..ae8a36098 100644 --- a/masonry/src/contexts.rs +++ b/masonry/src/contexts.rs @@ -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; @@ -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) diff --git a/masonry/src/event_loop_runner.rs b/masonry/src/event_loop_runner.rs index b8c6d68b5..d1ef29525 100644 --- a/masonry/src/event_loop_runner.rs +++ b/masonry/src/event_loop_runner.rs @@ -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; @@ -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 { diff --git a/masonry/src/lib.rs b/masonry/src/lib.rs index 454c5ef28..99c8c23f1 100644 --- a/masonry/src/lib.rs +++ b/masonry/src/lib.rs @@ -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}; pub use action::Action; pub use app_driver::{AppDriver, DriverCtx}; diff --git a/masonry/src/theme.rs b/masonry/src/theme.rs index bcb7956dc..3f82ef580 100644 --- a/masonry/src/theme.rs +++ b/masonry/src/theme.rs @@ -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) diff --git a/masonry/src/widget/sized_box.rs b/masonry/src/widget/sized_box.rs index badcf341e..4c4c401b4 100644 --- a/masonry/src/widget/sized_box.rs +++ b/masonry/src/widget/sized_box.rs @@ -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 diff --git a/masonry/src/widget/spinner.rs b/masonry/src/widget/spinner.rs index 748a2a091..2be598ebe 100644 --- a/masonry/src/widget/spinner.rs +++ b/masonry/src/widget/spinner.rs @@ -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() { diff --git a/masonry/src/widget/text_area.rs b/masonry/src/widget/text_area.rs index 23075dcaf..8780afed1 100644 --- a/masonry/src/widget/text_area.rs +++ b/masonry/src/widget/text_area.rs @@ -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. @@ -975,7 +975,7 @@ impl Widget for TextArea { #[cfg(test)] mod tests { - use vello::{kurbo::Size, peniko::color::palette}; + use vello::kurbo::Size; use super::*; use crate::testing::TestHarness; diff --git a/masonry/src/widget/textbox.rs b/masonry/src/widget/textbox.rs index d3a13630d..dcbc2e221 100644 --- a/masonry/src/widget/textbox.rs +++ b/masonry/src/widget/textbox.rs @@ -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}; diff --git a/xilem/examples/calc.rs b/xilem/examples/calc.rs index 713c0b395..249178430 100644 --- a/xilem/examples/calc.rs +++ b/xilem/examples/calc.rs @@ -6,7 +6,6 @@ #![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; @@ -14,7 +13,7 @@ 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 { diff --git a/xilem/examples/http_cats.rs b/xilem/examples/http_cats.rs index 9c399c47f..fd351f586 100644 --- a/xilem/examples/http_cats.rs +++ b/xilem/examples/http_cats.rs @@ -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; @@ -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 { diff --git a/xilem/examples/mason.rs b/xilem/examples/mason.rs index 3ee3fcfec..b48f7478c 100644 --- a/xilem/examples/mason.rs +++ b/xilem/examples/mason.rs @@ -9,7 +9,6 @@ use std::time::Duration; -use vello::peniko::color::palette; use winit::error::EventLoopError; use xilem::core::{fork, run_once}; use xilem::tokio::time; @@ -17,7 +16,9 @@ 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. "; diff --git a/xilem/examples/variable_clock.rs b/xilem/examples/variable_clock.rs index 83279c429..3578c377f 100644 --- a/xilem/examples/variable_clock.rs +++ b/xilem/examples/variable_clock.rs @@ -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 { diff --git a/xilem/src/lib.rs b/xilem/src/lib.rs index 7955052b0..d94f810fa 100644 --- a/xilem/src/lib.rs +++ b/xilem/src/lib.rs @@ -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. diff --git a/xilem/src/view/sized_box.rs b/xilem/src/view/sized_box.rs index 2bf9fece5..b73dd8c9c 100644 --- a/xilem/src/view/sized_box.rs +++ b/xilem/src/view/sized_box.rs @@ -92,7 +92,7 @@ impl SizedBox { /// 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) -> Self { self.background = Some(brush.into());