mirror of https://github.com/linebender/xilem
Switch to Edition 2024 (#880)
I've ignored most of the changes and the projects still compile and test fine. Changes I did commit: Add `+ use<>` after functions. Remove `ref mut` from some patterns. Bump MSRV. Apply new rustfmt format.
This commit is contained in:
parent
8147465350
commit
bc8e9fecd2
|
@ -8,7 +8,7 @@ env:
|
|||
# If the compilation fails, then the version specified here needs to be bumped up to reality.
|
||||
# Be sure to also update the rust-version property in the workspace Cargo.toml file,
|
||||
# plus all the README.md files of the affected packages.
|
||||
RUST_MIN_VER: "1.82"
|
||||
RUST_MIN_VER: "1.85"
|
||||
# List of packages that can not target Wasm.
|
||||
NO_WASM_PKGS: "--exclude masonry --exclude xilem"
|
||||
# Only some of our examples support Android (primarily due to extra required boilerplate).
|
||||
|
|
|
@ -20,9 +20,9 @@ members = [
|
|||
]
|
||||
|
||||
[workspace.package]
|
||||
edition = "2021"
|
||||
edition = "2024"
|
||||
# Keep in sync with RUST_MIN_VER in .github/workflows/ci.yml, with the relevant README.md files.
|
||||
rust-version = "1.82"
|
||||
rust-version = "1.85"
|
||||
license = "Apache-2.0"
|
||||
repository = "https://github.com/linebender/xilem"
|
||||
homepage = "https://xilem.dev/"
|
||||
|
@ -30,7 +30,7 @@ homepage = "https://xilem.dev/"
|
|||
[workspace.lints]
|
||||
# unsafe code is not allowed in Xilem or Masonry
|
||||
# We would like to set this to `forbid`, but we have to use `deny` because `android_activity`
|
||||
# requires us to use the unsafe `#[no_mangle]` attribute
|
||||
# requires us to use the `#[unsafe(no_mangle)]` attribute
|
||||
# (And cargo doesn't let us have platform specific lints here)
|
||||
rust.unsafe_code = "deny"
|
||||
|
||||
|
|
|
@ -137,7 +137,7 @@ sudo apt-get install clang libwayland-dev libxkbcommon-x11-dev libvulkan-dev
|
|||
|
||||
## Minimum supported Rust Version (MSRV)
|
||||
|
||||
This version of Xilem has been verified to compile with **Rust 1.82** and later.
|
||||
This version of Xilem has been verified to compile with **Rust 1.85** and later.
|
||||
|
||||
Future versions of Xilem might increase the Rust version requirement.
|
||||
It will not be treated as a breaking change and as such can even happen with small patch releases.
|
||||
|
|
|
@ -124,7 +124,7 @@ Masonry apps currently ship with two debugging features built in:
|
|||
|
||||
## Minimum supported Rust Version (MSRV)
|
||||
|
||||
This version of Masonry has been verified to compile with **Rust 1.82** and later.
|
||||
This version of Masonry has been verified to compile with **Rust 1.85** and later.
|
||||
|
||||
Future versions of Masonry might increase the Rust version requirement.
|
||||
It will not be treated as a breaking change and as such can even happen with small patch releases.
|
||||
|
|
|
@ -23,8 +23,8 @@ use masonry::dpi::LogicalSize;
|
|||
use masonry::kurbo::{Point, Size};
|
||||
use masonry::peniko::Color;
|
||||
use masonry::widgets::{Align, CrossAxisAlignment, Flex, Label, RootWidget, SizedBox};
|
||||
use smallvec::{smallvec, SmallVec};
|
||||
use tracing::{trace, trace_span, Span};
|
||||
use smallvec::{SmallVec, smallvec};
|
||||
use tracing::{Span, trace, trace_span};
|
||||
use vello::Scene;
|
||||
use winit::window::Window;
|
||||
|
||||
|
|
|
@ -23,9 +23,9 @@ use masonry::widgets::RootWidget;
|
|||
use parley::layout::Alignment;
|
||||
use parley::style::{FontFamily, FontStack, StyleProperty};
|
||||
use smallvec::SmallVec;
|
||||
use tracing::{trace_span, Span};
|
||||
use vello::peniko::{Fill, Image, ImageFormat};
|
||||
use tracing::{Span, trace_span};
|
||||
use vello::Scene;
|
||||
use vello::peniko::{Fill, Image, ImageFormat};
|
||||
use winit::window::Window;
|
||||
|
||||
struct Driver;
|
||||
|
|
|
@ -10,7 +10,7 @@ mod tracing_backend;
|
|||
|
||||
pub use app_driver::{AppDriver, DriverCtx};
|
||||
pub use event_loop_runner::{
|
||||
run, run_with, EventLoop, EventLoopBuilder, EventLoopProxy, MasonryState, MasonryUserEvent,
|
||||
EventLoop, EventLoopBuilder, EventLoopProxy, MasonryState, MasonryUserEvent, run, run_with,
|
||||
};
|
||||
pub use render_root::{RenderRoot, RenderRootOptions, RenderRootSignal, WindowSizePolicy};
|
||||
|
||||
|
|
|
@ -8,10 +8,10 @@ use parley::fontique::{self, Collection, CollectionOptions, SourceCache};
|
|||
use parley::{FontContext, LayoutContext};
|
||||
use tracing::{info_span, warn};
|
||||
use tree_arena::{ArenaMut, TreeArena};
|
||||
use vello::Scene;
|
||||
use vello::kurbo::{
|
||||
Rect, {self},
|
||||
};
|
||||
use vello::Scene;
|
||||
use winit::window::ResizeDirection;
|
||||
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
|
@ -19,6 +19,7 @@ use std::time::Instant;
|
|||
#[cfg(target_arch = "wasm32")]
|
||||
use web_time::Instant;
|
||||
|
||||
use crate::Handled;
|
||||
use crate::core::{
|
||||
AccessEvent, Action, BrushIndex, PointerEvent, QueryCtx, TextEvent, Widget, WidgetArena,
|
||||
WidgetId, WidgetMut, WidgetPod, WidgetRef, WidgetState, WindowEvent,
|
||||
|
@ -38,8 +39,7 @@ use crate::passes::update::{
|
|||
run_update_pointer_pass, run_update_scroll_pass, run_update_stashed_pass,
|
||||
run_update_widget_tree_pass,
|
||||
};
|
||||
use crate::passes::{recurse_on_children, PassTracing};
|
||||
use crate::Handled;
|
||||
use crate::passes::{PassTracing, recurse_on_children};
|
||||
use cursor_icon::CursorIcon;
|
||||
|
||||
/// We ensure that any valid initial IME area is sent to the platform by storing an invalid initial
|
||||
|
@ -578,7 +578,9 @@ impl RenderRoot {
|
|||
}
|
||||
|
||||
if self.root_state().needs_rewrite_passes() || self.global_state.needs_rewrite_passes() {
|
||||
warn!("All rewrite passes have run {REWRITE_PASSES_MAX} times, but invalidations are still set");
|
||||
warn!(
|
||||
"All rewrite passes have run {REWRITE_PASSES_MAX} times, but invalidations are still set"
|
||||
);
|
||||
// To avoid an infinite loop, we delay re-running the passes until the next frame.
|
||||
self.global_state
|
||||
.emit_signal(RenderRootSignal::RequestRedraw);
|
||||
|
|
|
@ -16,10 +16,10 @@ use std::time::UNIX_EPOCH;
|
|||
|
||||
use time::macros::format_description;
|
||||
use tracing::subscriber::SetGlobalDefaultError;
|
||||
use tracing_subscriber::EnvFilter;
|
||||
use tracing_subscriber::filter::LevelFilter;
|
||||
use tracing_subscriber::fmt::time::UtcTime;
|
||||
use tracing_subscriber::prelude::*;
|
||||
use tracing_subscriber::EnvFilter;
|
||||
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
/// Initialise tracing for a non-web platform with the given `default_level`.
|
||||
|
|
|
@ -30,7 +30,7 @@ pub use event::{
|
|||
WindowTheme,
|
||||
};
|
||||
pub use object_fit::ObjectFit;
|
||||
pub use text::{render_text, ArcStr, BrushIndex, StyleProperty, StyleSet};
|
||||
pub use text::{ArcStr, BrushIndex, StyleProperty, StyleSet, render_text};
|
||||
pub use widget::find_widget_at_pos;
|
||||
pub use widget::{AllowRawMut, FromDynWidget, Widget, WidgetId};
|
||||
pub use widget_mut::WidgetMut;
|
||||
|
|
|
@ -40,9 +40,9 @@ pub(crate) fn default_styles(styles: &mut StyleSet) {
|
|||
}
|
||||
|
||||
use parley::{Layout, PositionedLayoutItem};
|
||||
use vello::Scene;
|
||||
use vello::kurbo::{Affine, Line, Stroke};
|
||||
use vello::peniko::{Brush, Fill};
|
||||
use vello::Scene;
|
||||
|
||||
/// A function that renders laid out glyphs to a [`Scene`].
|
||||
///
|
||||
|
|
|
@ -10,15 +10,15 @@ use accesskit::{Node, Role};
|
|||
use cursor_icon::CursorIcon;
|
||||
use smallvec::SmallVec;
|
||||
use tracing::field::DisplayValue;
|
||||
use tracing::{trace_span, Span};
|
||||
use tracing::{Span, trace_span};
|
||||
use vello::Scene;
|
||||
|
||||
use crate::AsAny;
|
||||
use crate::core::{
|
||||
AccessCtx, AccessEvent, BoxConstraints, ComposeCtx, EventCtx, LayoutCtx, PaintCtx,
|
||||
PointerEvent, QueryCtx, RegisterCtx, TextEvent, Update, UpdateCtx, WidgetRef,
|
||||
};
|
||||
use crate::kurbo::{Point, Size};
|
||||
use crate::AsAny;
|
||||
|
||||
/// A unique identifier for a single [`Widget`].
|
||||
///
|
||||
|
|
|
@ -174,7 +174,7 @@ impl WidgetRef<'_, dyn Widget> {
|
|||
mod tests {
|
||||
use assert_matches::assert_matches;
|
||||
|
||||
use crate::testing::{widget_ids, TestHarness, TestWidgetExt as _};
|
||||
use crate::testing::{TestHarness, TestWidgetExt as _, widget_ids};
|
||||
use crate::widgets::{Button, Label};
|
||||
|
||||
#[test]
|
||||
|
|
|
@ -6,10 +6,10 @@ use tracing::{debug, info_span, trace};
|
|||
use winit::event::ElementState;
|
||||
use winit::keyboard::{KeyCode, PhysicalKey};
|
||||
|
||||
use crate::Handled;
|
||||
use crate::app::{RenderRoot, RenderRootSignal};
|
||||
use crate::core::{AccessEvent, EventCtx, PointerEvent, TextEvent, Widget, WidgetId};
|
||||
use crate::passes::{enter_span, merge_state_up};
|
||||
use crate::Handled;
|
||||
|
||||
// --- MARK: HELPERS ---
|
||||
fn get_pointer_target(
|
||||
|
|
|
@ -117,9 +117,7 @@ pub(crate) fn run_layout_on<W: Widget + ?Sized>(
|
|||
if trace {
|
||||
trace!(
|
||||
"Computed layout: size={}, baseline={}, insets={:?}",
|
||||
new_size,
|
||||
state.item.baseline_offset,
|
||||
state.item.paint_insets,
|
||||
new_size, state.item.baseline_offset, state.item.paint_insets,
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -5,9 +5,9 @@ use std::collections::HashMap;
|
|||
|
||||
use tracing::{info_span, trace};
|
||||
use tree_arena::ArenaMut;
|
||||
use vello::Scene;
|
||||
use vello::kurbo::Affine;
|
||||
use vello::peniko::{Color, Fill, Mix};
|
||||
use vello::Scene;
|
||||
|
||||
use crate::app::{RenderRoot, RenderRootState};
|
||||
use crate::core::{PaintCtx, Widget, WidgetId, WidgetState};
|
||||
|
|
|
@ -10,16 +10,17 @@ use cursor_icon::CursorIcon;
|
|||
use dpi::LogicalSize;
|
||||
use image::{DynamicImage, ImageReader, Rgba, RgbaImage};
|
||||
use tracing::debug;
|
||||
use vello::util::{block_on_wgpu, RenderContext};
|
||||
use vello::RendererOptions;
|
||||
use vello::util::{RenderContext, block_on_wgpu};
|
||||
use wgpu::{
|
||||
BufferDescriptor, BufferUsages, CommandEncoderDescriptor, Extent3d, ImageCopyBuffer,
|
||||
TextureDescriptor, TextureFormat, TextureUsages,
|
||||
};
|
||||
use winit::event::Ime;
|
||||
|
||||
use crate::Handled;
|
||||
use crate::app::{
|
||||
try_init_test_tracing, RenderRoot, RenderRootOptions, RenderRootSignal, WindowSizePolicy,
|
||||
RenderRoot, RenderRootOptions, RenderRootSignal, WindowSizePolicy, try_init_test_tracing,
|
||||
};
|
||||
use crate::core::{
|
||||
Action, PointerButton, PointerEvent, PointerState, TextEvent, Widget, WidgetId, WidgetMut,
|
||||
|
@ -31,7 +32,6 @@ use crate::passes::anim::run_update_anim_pass;
|
|||
use crate::peniko::Color;
|
||||
use crate::testing::screenshots::get_image_diff;
|
||||
use crate::testing::snapshot_utils::get_cargo_workspace;
|
||||
use crate::Handled;
|
||||
|
||||
/// A safe headless environment to test widgets in.
|
||||
///
|
||||
|
|
|
@ -17,14 +17,14 @@ use smallvec::SmallVec;
|
|||
use tracing::trace_span;
|
||||
use vello::Scene;
|
||||
|
||||
use crate::AsAny;
|
||||
use crate::core::{
|
||||
find_widget_at_pos, AccessCtx, AccessEvent, BoxConstraints, ComposeCtx, EventCtx, LayoutCtx,
|
||||
PaintCtx, PointerEvent, QueryCtx, RegisterCtx, TextEvent, Update, UpdateCtx, Widget, WidgetId,
|
||||
WidgetPod, WidgetRef,
|
||||
AccessCtx, AccessEvent, BoxConstraints, ComposeCtx, EventCtx, LayoutCtx, PaintCtx,
|
||||
PointerEvent, QueryCtx, RegisterCtx, TextEvent, Update, UpdateCtx, Widget, WidgetId, WidgetPod,
|
||||
WidgetRef, find_widget_at_pos,
|
||||
};
|
||||
use crate::kurbo::{Point, Size};
|
||||
use crate::widgets::SizedBox;
|
||||
use crate::AsAny;
|
||||
use cursor_icon::CursorIcon;
|
||||
|
||||
pub type PointerEventFn<S> = dyn FnMut(&mut S, &mut EventCtx, &PointerEvent);
|
||||
|
@ -334,11 +334,7 @@ impl<S: 'static> Widget for ModularWidget<S> {
|
|||
}
|
||||
|
||||
fn layout(&mut self, ctx: &mut LayoutCtx, bc: &BoxConstraints) -> Size {
|
||||
let Self {
|
||||
ref mut state,
|
||||
ref mut layout,
|
||||
..
|
||||
} = self;
|
||||
let Self { state, layout, .. } = self;
|
||||
layout
|
||||
.as_mut()
|
||||
.map(|f| f(state, ctx, bc))
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
//! Helper functions for writing snapshot tests and comparing images.
|
||||
|
||||
use image::{GenericImageView as _, RgbImage};
|
||||
use nv_flip::{FlipImageRgb8, DEFAULT_PIXELS_PER_DEGREE};
|
||||
use nv_flip::{DEFAULT_PIXELS_PER_DEGREE, FlipImageRgb8};
|
||||
|
||||
#[cfg(docsrs)]
|
||||
#[doc(hidden)]
|
||||
|
|
|
@ -6,11 +6,11 @@
|
|||
use std::any::Any;
|
||||
use std::hash::Hash;
|
||||
|
||||
use vello::Scene;
|
||||
use vello::kurbo::{
|
||||
Affine, Rect, Shape, Stroke, {self},
|
||||
};
|
||||
use vello::peniko::{BrushRef, Color, ColorStopsSource, Fill, Gradient};
|
||||
use vello::Scene;
|
||||
|
||||
/// Panic in debug and `tracing::error` in release mode.
|
||||
///
|
||||
|
@ -56,11 +56,7 @@ impl Handled {
|
|||
impl From<bool> for Handled {
|
||||
/// Returns `Handled::Yes` if `handled` is true, and `Handled::No` otherwise.
|
||||
fn from(handled: bool) -> Self {
|
||||
if handled {
|
||||
Self::Yes
|
||||
} else {
|
||||
Self::No
|
||||
}
|
||||
if handled { Self::Yes } else { Self::No }
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -9,8 +9,8 @@
|
|||
// its computed size. See https://github.com/linebender/xilem/issues/378
|
||||
|
||||
use accesskit::{Node, Role};
|
||||
use smallvec::{smallvec, SmallVec};
|
||||
use tracing::{trace_span, Span};
|
||||
use smallvec::{SmallVec, smallvec};
|
||||
use tracing::{Span, trace_span};
|
||||
use vello::Scene;
|
||||
|
||||
use crate::core::{
|
||||
|
|
|
@ -4,8 +4,8 @@
|
|||
//! A button widget.
|
||||
|
||||
use accesskit::{Node, Role};
|
||||
use smallvec::{smallvec, SmallVec};
|
||||
use tracing::{trace, trace_span, Span};
|
||||
use smallvec::{SmallVec, smallvec};
|
||||
use tracing::{Span, trace, trace_span};
|
||||
use vello::Scene;
|
||||
|
||||
use crate::core::{
|
||||
|
@ -15,7 +15,7 @@ use crate::core::{
|
|||
};
|
||||
use crate::kurbo::{Insets, Size};
|
||||
use crate::theme;
|
||||
use crate::util::{fill_lin_gradient, stroke, UnitPoint};
|
||||
use crate::util::{UnitPoint, fill_lin_gradient, stroke};
|
||||
use crate::widgets::Label;
|
||||
|
||||
// The minimum padding added to a button.
|
||||
|
@ -226,7 +226,7 @@ mod tests {
|
|||
use super::*;
|
||||
use crate::assert_render_snapshot;
|
||||
use crate::core::StyleProperty;
|
||||
use crate::testing::{widget_ids, TestHarness, TestWidgetExt};
|
||||
use crate::testing::{TestHarness, TestWidgetExt, widget_ids};
|
||||
use crate::theme::PRIMARY_LIGHT;
|
||||
|
||||
#[test]
|
||||
|
|
|
@ -4,10 +4,10 @@
|
|||
//! A checkbox widget.
|
||||
|
||||
use accesskit::{Node, Role, Toggled};
|
||||
use smallvec::{smallvec, SmallVec};
|
||||
use tracing::{trace, trace_span, Span};
|
||||
use vello::kurbo::{Affine, BezPath, Cap, Join, Size, Stroke};
|
||||
use smallvec::{SmallVec, smallvec};
|
||||
use tracing::{Span, trace, trace_span};
|
||||
use vello::Scene;
|
||||
use vello::kurbo::{Affine, BezPath, Cap, Join, Size, Stroke};
|
||||
|
||||
use crate::core::{
|
||||
AccessCtx, AccessEvent, Action, ArcStr, BoxConstraints, EventCtx, LayoutCtx, PaintCtx,
|
||||
|
@ -15,7 +15,7 @@ use crate::core::{
|
|||
WidgetPod,
|
||||
};
|
||||
use crate::theme;
|
||||
use crate::util::{fill_lin_gradient, stroke, UnitPoint};
|
||||
use crate::util::{UnitPoint, fill_lin_gradient, stroke};
|
||||
use crate::widgets::Label;
|
||||
|
||||
/// A checkbox that can be toggled.
|
||||
|
@ -235,7 +235,7 @@ mod tests {
|
|||
use super::*;
|
||||
use crate::assert_render_snapshot;
|
||||
use crate::core::StyleProperty;
|
||||
use crate::testing::{widget_ids, TestHarness, TestWidgetExt};
|
||||
use crate::testing::{TestHarness, TestWidgetExt, widget_ids};
|
||||
use crate::theme::PRIMARY_LIGHT;
|
||||
|
||||
#[test]
|
||||
|
|
|
@ -5,10 +5,10 @@
|
|||
|
||||
use accesskit::{Node, Role};
|
||||
use smallvec::SmallVec;
|
||||
use tracing::{trace_span, Span};
|
||||
use tracing::{Span, trace_span};
|
||||
use vello::Scene;
|
||||
use vello::kurbo::common::FloatExt;
|
||||
use vello::kurbo::{Affine, Line, Stroke, Vec2};
|
||||
use vello::Scene;
|
||||
|
||||
use crate::core::{
|
||||
AccessCtx, AccessEvent, BoxConstraints, EventCtx, LayoutCtx, PaintCtx, PointerEvent, QueryCtx,
|
||||
|
@ -893,7 +893,9 @@ fn new_flex_child(params: FlexParams, widget: WidgetPod<dyn Widget>) -> Child {
|
|||
flex,
|
||||
}
|
||||
} else {
|
||||
tracing::warn!("Flex value should be > 0.0 (was {flex}). See the docs for masonry::widgets::Flex for more information");
|
||||
tracing::warn!(
|
||||
"Flex value should be > 0.0 (was {flex}). See the docs for masonry::widgets::Flex for more information"
|
||||
);
|
||||
Child::Fixed {
|
||||
widget,
|
||||
alignment: params.alignment,
|
||||
|
|
|
@ -3,9 +3,9 @@
|
|||
|
||||
use accesskit::{Node, Role};
|
||||
use smallvec::SmallVec;
|
||||
use tracing::{trace_span, Span};
|
||||
use vello::kurbo::{Affine, Line, Stroke};
|
||||
use tracing::{Span, trace_span};
|
||||
use vello::Scene;
|
||||
use vello::kurbo::{Affine, Line, Stroke};
|
||||
|
||||
use crate::core::{
|
||||
AccessCtx, AccessEvent, BoxConstraints, EventCtx, LayoutCtx, PaintCtx, PointerEvent, QueryCtx,
|
||||
|
|
|
@ -6,10 +6,10 @@
|
|||
|
||||
use accesskit::{Node, Role};
|
||||
use smallvec::SmallVec;
|
||||
use tracing::{trace_span, Span};
|
||||
use tracing::{Span, trace_span};
|
||||
use vello::Scene;
|
||||
use vello::kurbo::Affine;
|
||||
use vello::peniko::{BlendMode, Image as ImageBuf};
|
||||
use vello::Scene;
|
||||
|
||||
use crate::core::{
|
||||
AccessCtx, AccessEvent, BoxConstraints, EventCtx, LayoutCtx, ObjectFit, PaintCtx, PointerEvent,
|
||||
|
|
|
@ -11,15 +11,15 @@ use accesskit::{Node, NodeId, Role};
|
|||
use parley::layout::Alignment;
|
||||
use parley::{Layout, LayoutAccessibility};
|
||||
use smallvec::SmallVec;
|
||||
use tracing::{trace_span, Span};
|
||||
use tracing::{Span, trace_span};
|
||||
use vello::Scene;
|
||||
use vello::kurbo::{Affine, Size};
|
||||
use vello::peniko::{BlendMode, Brush};
|
||||
use vello::Scene;
|
||||
|
||||
use crate::core::{
|
||||
default_styles, render_text, AccessCtx, AccessEvent, ArcStr, BoxConstraints, BrushIndex,
|
||||
EventCtx, LayoutCtx, PaintCtx, PointerEvent, QueryCtx, RegisterCtx, StyleProperty, StyleSet,
|
||||
TextEvent, Update, UpdateCtx, Widget, WidgetId, WidgetMut,
|
||||
AccessCtx, AccessEvent, ArcStr, BoxConstraints, BrushIndex, EventCtx, LayoutCtx, PaintCtx,
|
||||
PointerEvent, QueryCtx, RegisterCtx, StyleProperty, StyleSet, TextEvent, Update, UpdateCtx,
|
||||
Widget, WidgetId, WidgetMut, default_styles, render_text,
|
||||
};
|
||||
use crate::theme;
|
||||
|
||||
|
|
|
@ -6,10 +6,10 @@
|
|||
use std::ops::Range;
|
||||
|
||||
use accesskit::{Node, Role};
|
||||
use smallvec::{smallvec, SmallVec};
|
||||
use tracing::{trace_span, Span};
|
||||
use vello::kurbo::{Point, Rect, Size, Vec2};
|
||||
use smallvec::{SmallVec, smallvec};
|
||||
use tracing::{Span, trace_span};
|
||||
use vello::Scene;
|
||||
use vello::kurbo::{Point, Rect, Size, Vec2};
|
||||
|
||||
use crate::core::{
|
||||
AccessCtx, AccessEvent, BoxConstraints, ComposeCtx, EventCtx, FromDynWidget, LayoutCtx,
|
||||
|
@ -482,7 +482,7 @@ mod tests {
|
|||
|
||||
use super::*;
|
||||
use crate::assert_render_snapshot;
|
||||
use crate::testing::{widget_ids, TestHarness};
|
||||
use crate::testing::{TestHarness, widget_ids};
|
||||
use crate::widgets::{Button, Flex, SizedBox};
|
||||
|
||||
fn button(text: &'static str) -> impl Widget {
|
||||
|
|
|
@ -4,8 +4,8 @@
|
|||
//! A progress bar widget.
|
||||
|
||||
use accesskit::{Node, Role};
|
||||
use smallvec::{smallvec, SmallVec};
|
||||
use tracing::{trace_span, Span};
|
||||
use smallvec::{SmallVec, smallvec};
|
||||
use tracing::{Span, trace_span};
|
||||
use vello::Scene;
|
||||
|
||||
use crate::core::{
|
||||
|
@ -14,7 +14,7 @@ use crate::core::{
|
|||
};
|
||||
use crate::kurbo::{Point, Size};
|
||||
use crate::theme;
|
||||
use crate::util::{fill_lin_gradient, stroke, UnitPoint};
|
||||
use crate::util::{UnitPoint, fill_lin_gradient, stroke};
|
||||
use crate::widgets::{Label, LineBreaking};
|
||||
|
||||
/// A progress bar.
|
||||
|
@ -190,7 +190,7 @@ mod tests {
|
|||
|
||||
use super::*;
|
||||
use crate::assert_render_snapshot;
|
||||
use crate::testing::{widget_ids, TestHarness, TestWidgetExt};
|
||||
use crate::testing::{TestHarness, TestWidgetExt, widget_ids};
|
||||
|
||||
#[test]
|
||||
fn indeterminate_progressbar() {
|
||||
|
|
|
@ -4,10 +4,10 @@
|
|||
#![warn(missing_docs)]
|
||||
|
||||
use accesskit::{Node, Role};
|
||||
use smallvec::{smallvec, SmallVec};
|
||||
use tracing::{trace_span, Span};
|
||||
use vello::kurbo::{Point, Rect, Size};
|
||||
use smallvec::{SmallVec, smallvec};
|
||||
use tracing::{Span, trace_span};
|
||||
use vello::Scene;
|
||||
use vello::kurbo::{Point, Rect, Size};
|
||||
|
||||
use crate::core::{
|
||||
AccessCtx, AccessEvent, BoxConstraints, EventCtx, LayoutCtx, PaintCtx, PointerEvent, QueryCtx,
|
||||
|
@ -161,8 +161,8 @@ impl Widget for Prose {
|
|||
// TODO - Add more tests
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use parley::layout::Alignment;
|
||||
use parley::StyleProperty;
|
||||
use parley::layout::Alignment;
|
||||
use vello::kurbo::Size;
|
||||
|
||||
use super::*;
|
||||
|
|
|
@ -2,10 +2,10 @@
|
|||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
use accesskit::{Node, Role};
|
||||
use smallvec::{smallvec, SmallVec};
|
||||
use tracing::{trace_span, Span};
|
||||
use vello::kurbo::Point;
|
||||
use smallvec::{SmallVec, smallvec};
|
||||
use tracing::{Span, trace_span};
|
||||
use vello::Scene;
|
||||
use vello::kurbo::Point;
|
||||
|
||||
use crate::core::{
|
||||
AccessCtx, AccessEvent, BoxConstraints, EventCtx, FromDynWidget, LayoutCtx, PaintCtx,
|
||||
|
|
|
@ -5,9 +5,9 @@
|
|||
|
||||
use accesskit::{Node, Role};
|
||||
use smallvec::SmallVec;
|
||||
use tracing::{trace_span, Span};
|
||||
use vello::kurbo::Rect;
|
||||
use tracing::{Span, trace_span};
|
||||
use vello::Scene;
|
||||
use vello::kurbo::Rect;
|
||||
|
||||
use crate::core::{
|
||||
AccessCtx, AccessEvent, AllowRawMut, BoxConstraints, EventCtx, LayoutCtx, PaintCtx,
|
||||
|
@ -234,7 +234,7 @@ mod tests {
|
|||
use super::*;
|
||||
use crate::assert_render_snapshot;
|
||||
use crate::core::PointerButton;
|
||||
use crate::testing::{widget_ids, TestHarness, TestWidgetExt};
|
||||
use crate::testing::{TestHarness, TestWidgetExt, widget_ids};
|
||||
|
||||
#[test]
|
||||
fn simple_scrollbar() {
|
||||
|
|
|
@ -4,11 +4,11 @@
|
|||
//! A widget with predefined size.
|
||||
|
||||
use accesskit::{Node, Role};
|
||||
use smallvec::{smallvec, SmallVec};
|
||||
use tracing::{trace_span, warn, Span};
|
||||
use smallvec::{SmallVec, smallvec};
|
||||
use tracing::{Span, trace_span, warn};
|
||||
use vello::Scene;
|
||||
use vello::kurbo::{Affine, RoundedRectRadii};
|
||||
use vello::peniko::{Brush, Fill};
|
||||
use vello::Scene;
|
||||
|
||||
use crate::core::{
|
||||
AccessCtx, AccessEvent, BoxConstraints, EventCtx, LayoutCtx, PaintCtx, PointerEvent, QueryCtx,
|
||||
|
@ -139,20 +139,12 @@ impl Padding {
|
|||
|
||||
/// Get the padding to the left, given whether we're in a right-to-left context.
|
||||
pub const fn get_left(self, is_rtl: bool) -> f64 {
|
||||
if is_rtl {
|
||||
self.trailing
|
||||
} else {
|
||||
self.leading
|
||||
}
|
||||
if is_rtl { self.trailing } else { self.leading }
|
||||
}
|
||||
|
||||
/// Get the padding to the right, given whether we're in a right-to-left context.
|
||||
pub const fn get_right(self, is_rtl: bool) -> f64 {
|
||||
if is_rtl {
|
||||
self.leading
|
||||
} else {
|
||||
self.trailing
|
||||
}
|
||||
if is_rtl { self.leading } else { self.trailing }
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -7,9 +7,9 @@ use std::f64::consts::PI;
|
|||
|
||||
use accesskit::{Node, Role};
|
||||
use smallvec::SmallVec;
|
||||
use tracing::{trace_span, Span};
|
||||
use vello::kurbo::{Affine, Cap, Line, Stroke};
|
||||
use tracing::{Span, trace_span};
|
||||
use vello::Scene;
|
||||
use vello::kurbo::{Affine, Cap, Line, Stroke};
|
||||
|
||||
use crate::core::{
|
||||
AccessCtx, AccessEvent, BoxConstraints, EventCtx, LayoutCtx, PaintCtx, PointerEvent, QueryCtx,
|
||||
|
|
|
@ -4,8 +4,8 @@
|
|||
//! A widget which splits an area in two, with a settable ratio, and optional draggable resizing.
|
||||
|
||||
use accesskit::{Node, Role};
|
||||
use smallvec::{smallvec, SmallVec};
|
||||
use tracing::{trace_span, warn, Span};
|
||||
use smallvec::{SmallVec, smallvec};
|
||||
use tracing::{Span, trace_span, warn};
|
||||
use vello::Scene;
|
||||
|
||||
use crate::core::{
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
|
||||
use vello::kurbo::{Insets, Size};
|
||||
|
||||
use crate::testing::{widget_ids, ModularWidget, TestHarness, TestWidgetExt};
|
||||
use crate::testing::{ModularWidget, TestHarness, TestWidgetExt, widget_ids};
|
||||
use crate::widgets::{Flex, SizedBox};
|
||||
|
||||
#[test]
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
use insta::assert_debug_snapshot;
|
||||
|
||||
use crate::testing::{
|
||||
widget_ids, Record, Recording, ReplaceChild, TestHarness, TestWidgetExt as _,
|
||||
Record, Recording, ReplaceChild, TestHarness, TestWidgetExt as _, widget_ids,
|
||||
};
|
||||
use crate::widgets::{Flex, Label, SizedBox};
|
||||
use crate::*;
|
||||
|
|
|
@ -8,7 +8,7 @@ use std::rc::Rc;
|
|||
|
||||
use smallvec::smallvec;
|
||||
|
||||
use crate::testing::{widget_ids, ModularWidget, TestHarness, TestWidgetExt as _};
|
||||
use crate::testing::{ModularWidget, TestHarness, TestWidgetExt as _, widget_ids};
|
||||
use crate::widgets::Flex;
|
||||
use crate::*;
|
||||
|
||||
|
@ -112,7 +112,14 @@ fn disable_tree() {
|
|||
.collect()
|
||||
}
|
||||
|
||||
let [root_id, group_1_id, sub_group_1_id, group_2_id, leaf_1_id, leaf_2_id] = widget_ids();
|
||||
let [
|
||||
root_id,
|
||||
group_1_id,
|
||||
sub_group_1_id,
|
||||
group_2_id,
|
||||
leaf_1_id,
|
||||
leaf_2_id,
|
||||
] = widget_ids();
|
||||
|
||||
// Our widget hierarchy is:
|
||||
// - root
|
||||
|
|
|
@ -8,7 +8,7 @@ use std::rc::Rc;
|
|||
|
||||
use smallvec::smallvec;
|
||||
|
||||
use crate::testing::{widget_ids, ModularWidget, ReplaceChild, TestHarness, TestWidgetExt as _};
|
||||
use crate::testing::{ModularWidget, ReplaceChild, TestHarness, TestWidgetExt as _, widget_ids};
|
||||
use crate::widgets::Flex;
|
||||
use crate::*;
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@ use assert_matches::assert_matches;
|
|||
|
||||
use crate::core::{PointerButton, PointerEvent, PointerState, Update, WidgetId};
|
||||
use crate::kurbo::Vec2;
|
||||
use crate::testing::{widget_ids, Record, Recording, TestHarness, TestWidgetExt as _};
|
||||
use crate::testing::{Record, Recording, TestHarness, TestWidgetExt as _, widget_ids};
|
||||
use crate::widgets::{Button, Flex, SizedBox};
|
||||
|
||||
fn next_pointer_event(recording: &Recording) -> Option<PointerEvent> {
|
||||
|
@ -189,11 +189,7 @@ fn update_hovered_from_layout() {
|
|||
})
|
||||
.layout_fn(
|
||||
move |collapsed, _ctx, _bc| {
|
||||
if *collapsed {
|
||||
Size::ZERO
|
||||
} else {
|
||||
BOX_SIZE
|
||||
}
|
||||
if *collapsed { Size::ZERO } else { BOX_SIZE }
|
||||
},
|
||||
);
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
use insta::assert_debug_snapshot;
|
||||
|
||||
use crate::testing::{widget_ids, TestHarness};
|
||||
use crate::testing::{TestHarness, widget_ids};
|
||||
use crate::widgets::{Flex, Label};
|
||||
|
||||
#[test]
|
||||
|
|
|
@ -7,20 +7,20 @@ use std::mem::Discriminant;
|
|||
use std::time::Instant;
|
||||
|
||||
use accesskit::{Node, NodeId, Role};
|
||||
use parley::PlainEditor;
|
||||
use parley::editor::{Generation, SplitString};
|
||||
use parley::layout::Alignment;
|
||||
use parley::PlainEditor;
|
||||
use smallvec::SmallVec;
|
||||
use tracing::{trace_span, Span};
|
||||
use tracing::{Span, trace_span};
|
||||
use vello::Scene;
|
||||
use vello::kurbo::{Affine, Point, Rect, Size, Vec2};
|
||||
use vello::peniko::{Brush, Fill};
|
||||
use vello::Scene;
|
||||
use winit::keyboard::{Key, NamedKey};
|
||||
|
||||
use crate::core::{
|
||||
default_styles, render_text, AccessCtx, AccessEvent, BoxConstraints, BrushIndex, EventCtx,
|
||||
LayoutCtx, PaintCtx, PointerButton, PointerEvent, QueryCtx, RegisterCtx, StyleProperty,
|
||||
TextEvent, Update, UpdateCtx, Widget, WidgetId, WidgetMut,
|
||||
AccessCtx, AccessEvent, BoxConstraints, BrushIndex, EventCtx, LayoutCtx, PaintCtx,
|
||||
PointerButton, PointerEvent, QueryCtx, RegisterCtx, StyleProperty, TextEvent, Update,
|
||||
UpdateCtx, Widget, WidgetId, WidgetMut, default_styles, render_text,
|
||||
};
|
||||
use crate::widgets::Padding;
|
||||
use crate::{palette, theme};
|
||||
|
|
|
@ -4,10 +4,10 @@
|
|||
#![warn(missing_docs)]
|
||||
|
||||
use accesskit::{Node, Role};
|
||||
use smallvec::{smallvec, SmallVec};
|
||||
use tracing::{trace_span, Span};
|
||||
use vello::kurbo::{Affine, Insets, Point, Rect, Size, Stroke};
|
||||
use smallvec::{SmallVec, smallvec};
|
||||
use tracing::{Span, trace_span};
|
||||
use vello::Scene;
|
||||
use vello::kurbo::{Affine, Insets, Point, Rect, Size, Stroke};
|
||||
|
||||
use crate::core::{
|
||||
AccessCtx, AccessEvent, BoxConstraints, EventCtx, LayoutCtx, PaintCtx, PointerEvent, QueryCtx,
|
||||
|
|
|
@ -6,10 +6,10 @@
|
|||
use std::cmp::Ordering;
|
||||
|
||||
use accesskit::{Node, Role};
|
||||
use smallvec::{smallvec, SmallVec};
|
||||
use tracing::{trace_span, Span};
|
||||
use vello::kurbo::{Point, Size};
|
||||
use smallvec::{SmallVec, smallvec};
|
||||
use tracing::{Span, trace_span};
|
||||
use vello::Scene;
|
||||
use vello::kurbo::{Point, Size};
|
||||
|
||||
use crate::core::{
|
||||
AccessCtx, AccessEvent, ArcStr, BoxConstraints, EventCtx, LayoutCtx, PaintCtx, PointerEvent,
|
||||
|
|
|
@ -78,7 +78,7 @@ struct Counter {
|
|||
num: i32,
|
||||
}
|
||||
|
||||
fn app_logic(data: &mut Counter) -> impl WidgetView<Counter> {
|
||||
fn app_logic(data: &mut Counter) -> impl WidgetView<Counter> + use<> {
|
||||
flex((
|
||||
label(format!("{}", data.num)),
|
||||
button("increment", |data: &mut Counter| data.num += 1),
|
||||
|
@ -149,7 +149,7 @@ You should also expect to use the adapters from Xilem Core, including:
|
|||
|
||||
## Minimum supported Rust Version (MSRV)
|
||||
|
||||
This version of Xilem has been verified to compile with **Rust 1.82** and later.
|
||||
This version of Xilem has been verified to compile with **Rust 1.85** and later.
|
||||
|
||||
Future versions of Xilem might increase the Rust version requirement.
|
||||
It will not be treated as a breaking change and as such can even happen with small patch releases.
|
||||
|
|
|
@ -9,10 +9,10 @@ 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,
|
||||
Axis, Flex, FlexSequence, FlexSpacer, GridExt, GridSequence, Label, button, flex, grid, label,
|
||||
sized_box,
|
||||
};
|
||||
use xilem::{palette, EventLoop, EventLoopBuilder, WidgetView, Xilem};
|
||||
use xilem::{EventLoop, EventLoopBuilder, WidgetView, Xilem, palette};
|
||||
|
||||
#[derive(Copy, Clone)]
|
||||
enum MathOperator {
|
||||
|
@ -200,7 +200,7 @@ fn num_row(nums: [&'static str; 3], row: i32) -> impl GridSequence<Calculator> {
|
|||
|
||||
const DISPLAY_FONT_SIZE: f32 = 30.;
|
||||
const GRID_GAP: f64 = 2.;
|
||||
fn app_logic(data: &mut Calculator) -> impl WidgetView<Calculator> {
|
||||
fn app_logic(data: &mut Calculator) -> impl WidgetView<Calculator> + use<> {
|
||||
grid(
|
||||
(
|
||||
// Display
|
||||
|
@ -259,7 +259,7 @@ pub fn centered_flex_row<State, Seq: FlexSequence<State>>(sequence: Seq) -> Flex
|
|||
|
||||
/// Returns a label intended to be used in the calculator's top display.
|
||||
/// The default text size is out of proportion for this use case.
|
||||
fn display_label(text: &str) -> impl WidgetView<Calculator> {
|
||||
fn display_label(text: &str) -> impl WidgetView<Calculator> + use<> {
|
||||
label(text).text_size(DISPLAY_FONT_SIZE)
|
||||
}
|
||||
|
||||
|
@ -332,7 +332,7 @@ fn main() -> Result<(), EventLoopError> {
|
|||
unsafe_code,
|
||||
reason = "We believe that there are no other declarations using this name in the compiled objects here"
|
||||
)]
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
fn android_main(app: winit::platform::android::activity::AndroidApp) {
|
||||
use winit::platform::android::EventLoopBuilderExtAndroid;
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
use masonry::widgets::MainAxisAlignment;
|
||||
use winit::error::EventLoopError;
|
||||
use xilem::core::lens;
|
||||
use xilem::view::{button, flex, label, Axis};
|
||||
use xilem::view::{Axis, button, flex, label};
|
||||
use xilem::{EventLoop, WidgetView, Xilem};
|
||||
|
||||
#[derive(Default)]
|
||||
|
@ -17,7 +17,7 @@ struct AppState {
|
|||
global_count: i32,
|
||||
}
|
||||
|
||||
fn modular_counter(count: &mut i32) -> impl WidgetView<i32> {
|
||||
fn modular_counter(count: &mut i32) -> impl WidgetView<i32> + use<> {
|
||||
flex((
|
||||
label(format!("modularized count: {count}")),
|
||||
button("+", |count| *count += 1),
|
||||
|
@ -25,7 +25,7 @@ fn modular_counter(count: &mut i32) -> impl WidgetView<i32> {
|
|||
))
|
||||
}
|
||||
|
||||
fn app_logic(state: &mut AppState) -> impl WidgetView<AppState> {
|
||||
fn app_logic(state: &mut AppState) -> impl WidgetView<AppState> + use<> {
|
||||
flex((
|
||||
lens(modular_counter, state, |state| &mut state.modularized_count),
|
||||
button(
|
||||
|
|
|
@ -9,8 +9,8 @@
|
|||
|
||||
use masonry::widgets::{CrossAxisAlignment, MainAxisAlignment};
|
||||
use winit::error::EventLoopError;
|
||||
use xilem::core::{adapt, map_action, MessageResult};
|
||||
use xilem::view::{button, flex, label, Axis};
|
||||
use xilem::core::{MessageResult, adapt, map_action};
|
||||
use xilem::view::{Axis, button, flex, label};
|
||||
use xilem::{EventLoop, WidgetView, Xilem};
|
||||
|
||||
#[derive(Default)]
|
||||
|
@ -65,7 +65,7 @@ fn adapt_counter(count: i32) -> impl WidgetView<i32, AdaptMessage> {
|
|||
.direction(Axis::Horizontal)
|
||||
}
|
||||
|
||||
fn app_logic(state: &mut AppState) -> impl WidgetView<AppState> {
|
||||
fn app_logic(state: &mut AppState) -> impl WidgetView<AppState> + use<> {
|
||||
flex((
|
||||
map_action(
|
||||
elm_counter(state.map_action_count),
|
||||
|
|
|
@ -8,11 +8,11 @@
|
|||
use winit::error::EventLoopError;
|
||||
use xilem::core::map_state;
|
||||
use xilem::view::{
|
||||
button, flex, grid, label, prose, sized_box, Axis, FlexExt, FlexSpacer, GridExt,
|
||||
Axis, FlexExt, FlexSpacer, GridExt, button, flex, grid, label, prose, sized_box,
|
||||
};
|
||||
use xilem::{palette, Color, EventLoop, EventLoopBuilder, WidgetView, Xilem};
|
||||
use xilem::{Color, EventLoop, EventLoopBuilder, WidgetView, Xilem, palette};
|
||||
|
||||
fn app_logic(data: &mut EmojiPagination) -> impl WidgetView<EmojiPagination> {
|
||||
fn app_logic(data: &mut EmojiPagination) -> impl WidgetView<EmojiPagination> + use<> {
|
||||
flex((
|
||||
sized_box(flex(()).must_fill_major_axis(true)).height(50.), // Padding because of the info bar on Android
|
||||
flex((
|
||||
|
@ -43,7 +43,7 @@ fn app_logic(data: &mut EmojiPagination) -> impl WidgetView<EmojiPagination> {
|
|||
.must_fill_major_axis(true)
|
||||
}
|
||||
|
||||
fn picker(data: &mut EmojiPagination) -> impl WidgetView<EmojiPagination> {
|
||||
fn picker(data: &mut EmojiPagination) -> impl WidgetView<EmojiPagination> + use<> {
|
||||
let mut grid_items = vec![];
|
||||
'outer: for y in 0..data.size as usize {
|
||||
let row_idx = data.start_index + y * data.size as usize;
|
||||
|
@ -186,7 +186,7 @@ fn main() -> Result<(), EventLoopError> {
|
|||
unsafe_code,
|
||||
reason = "We believe that there are no other declarations using this name in the compiled objects here"
|
||||
)]
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
fn android_main(app: winit::platform::android::activity::AndroidApp) {
|
||||
use winit::platform::android::EventLoopBuilderExtAndroid;
|
||||
|
||||
|
|
|
@ -16,7 +16,7 @@ use winit::application::ApplicationHandler;
|
|||
use winit::error::EventLoopError;
|
||||
use winit::event::ElementState;
|
||||
use winit::keyboard::{KeyCode, PhysicalKey};
|
||||
use xilem::view::{button, flex, label, sized_box, Axis, Label};
|
||||
use xilem::view::{Axis, Label, button, flex, label, sized_box};
|
||||
use xilem::{EventLoop, MasonryProxy, WidgetView, Xilem};
|
||||
|
||||
/// A component to make a bigger than usual button
|
||||
|
@ -27,7 +27,7 @@ fn big_button(
|
|||
sized_box(button(label, callback)).width(40.).height(40.)
|
||||
}
|
||||
|
||||
fn app_logic(data: &mut i32) -> impl WidgetView<i32> {
|
||||
fn app_logic(data: &mut i32) -> impl WidgetView<i32> + use<> {
|
||||
flex((
|
||||
big_button("-", |data| {
|
||||
*data -= 1;
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
#![expect(clippy::shadow_unrelated, reason = "Idiomatic for Xilem users")]
|
||||
use masonry::widgets::{CrossAxisAlignment, MainAxisAlignment};
|
||||
use winit::error::EventLoopError;
|
||||
use xilem::view::{button, flex, label, sized_box, Axis, FlexExt as _, FlexSpacer, Label};
|
||||
use xilem::view::{Axis, FlexExt as _, FlexSpacer, Label, button, flex, label, sized_box};
|
||||
use xilem::{EventLoop, WidgetView, Xilem};
|
||||
|
||||
/// A component to make a bigger than usual button
|
||||
|
@ -17,7 +17,7 @@ fn big_button(
|
|||
sized_box(button(label, callback)).width(40.).height(40.)
|
||||
}
|
||||
|
||||
fn app_logic(data: &mut i32) -> impl WidgetView<i32> {
|
||||
fn app_logic(data: &mut i32) -> impl WidgetView<i32> + use<> {
|
||||
flex((
|
||||
FlexSpacer::Fixed(30.0),
|
||||
big_button("-", |data| {
|
||||
|
|
|
@ -16,10 +16,10 @@ use winit::window::Window;
|
|||
use xilem::core::fork;
|
||||
use xilem::core::one_of::OneOf3;
|
||||
use xilem::view::{
|
||||
button, flex, image, inline_prose, portal, prose, sized_box, spinner, worker, zstack, Axis,
|
||||
FlexExt, FlexSpacer, Padding, ZStackExt,
|
||||
Axis, FlexExt, FlexSpacer, Padding, ZStackExt, button, flex, image, inline_prose, portal,
|
||||
prose, sized_box, spinner, worker, zstack,
|
||||
};
|
||||
use xilem::{palette, EventLoop, EventLoopBuilder, TextAlignment, WidgetView, Xilem};
|
||||
use xilem::{EventLoop, EventLoopBuilder, TextAlignment, WidgetView, Xilem, palette};
|
||||
|
||||
/// The main state of the application.
|
||||
struct HttpCats {
|
||||
|
@ -45,7 +45,7 @@ enum ImageState {
|
|||
}
|
||||
|
||||
impl HttpCats {
|
||||
fn view(&mut self) -> impl WidgetView<Self> {
|
||||
fn view(&mut self) -> impl WidgetView<Self> + use<> {
|
||||
let left_column = sized_box(portal(flex((
|
||||
prose("Status"),
|
||||
self.statuses
|
||||
|
@ -163,7 +163,7 @@ async fn image_from_url(url: &str) -> anyhow::Result<Image> {
|
|||
}
|
||||
|
||||
impl Status {
|
||||
fn list_view(&mut self) -> impl WidgetView<HttpCats> {
|
||||
fn list_view(&mut self) -> impl WidgetView<HttpCats> + use<> {
|
||||
let code = self.code;
|
||||
flex((
|
||||
// TODO: Reduce allocations here?
|
||||
|
@ -180,7 +180,7 @@ impl Status {
|
|||
.direction(Axis::Horizontal)
|
||||
}
|
||||
|
||||
fn details_view(&mut self) -> impl WidgetView<HttpCats> {
|
||||
fn details_view(&mut self) -> impl WidgetView<HttpCats> + use<> {
|
||||
let image = match &self.image {
|
||||
ImageState::NotRequested => OneOf3::A(
|
||||
prose("Failed to start fetching image. This is a bug!")
|
||||
|
@ -276,7 +276,7 @@ fn main() -> Result<(), EventLoopError> {
|
|||
unsafe_code,
|
||||
reason = "We believe that there are no other declarations using this name in the compiled objects here"
|
||||
)]
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
fn android_main(app: winit::platform::android::activity::AndroidApp) {
|
||||
use winit::platform::android::EventLoopBuilderExtAndroid;
|
||||
|
||||
|
|
|
@ -13,17 +13,17 @@ 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, PointerButton,
|
||||
Axis, FlexExt as _, FlexSpacer, PointerButton, button, button_any_pointer, checkbox, flex,
|
||||
label, prose, task, textbox,
|
||||
};
|
||||
use xilem::{
|
||||
palette, Color, EventLoop, EventLoopBuilder, FontWeight, TextAlignment, WidgetView, Xilem,
|
||||
Color, EventLoop, EventLoopBuilder, FontWeight, TextAlignment, WidgetView, Xilem, palette,
|
||||
};
|
||||
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. ";
|
||||
|
||||
fn app_logic(data: &mut AppData) -> impl WidgetView<AppData> {
|
||||
fn app_logic(data: &mut AppData) -> impl WidgetView<AppData> + use<> {
|
||||
// here's some logic, deriving state for the view from our state
|
||||
let count = data.count;
|
||||
let button_label = if count == 1 {
|
||||
|
@ -119,7 +119,7 @@ fn app_logic(data: &mut AppData) -> impl WidgetView<AppData> {
|
|||
)
|
||||
}
|
||||
|
||||
fn toggleable(data: &mut AppData) -> impl WidgetView<AppData> {
|
||||
fn toggleable(data: &mut AppData) -> impl WidgetView<AppData> + use<> {
|
||||
if data.active {
|
||||
fork(
|
||||
flex((
|
||||
|
@ -173,7 +173,7 @@ fn main() -> Result<(), EventLoopError> {
|
|||
unsafe_code,
|
||||
reason = "We believe that there are no other declarations using this name in the compiled objects here"
|
||||
)]
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
fn android_main(app: winit::platform::android::activity::AndroidApp) {
|
||||
use winit::platform::android::EventLoopBuilderExtAndroid;
|
||||
|
||||
|
|
|
@ -42,7 +42,7 @@ fn increase_button(state: &mut AppState) -> Arc<AnyWidgetView<AppState>> {
|
|||
|
||||
// This is the alternative with Memoize
|
||||
// Note how this requires a closure that returns the memoized view, while Arc does not
|
||||
fn decrease_button(state: &AppState) -> impl WidgetView<AppState> {
|
||||
fn decrease_button(state: &AppState) -> impl WidgetView<AppState> + use<> {
|
||||
memoize(state.count, |count| {
|
||||
button(
|
||||
format!("decrease the count: {count}"),
|
||||
|
@ -57,7 +57,7 @@ fn reset_button() -> impl WidgetView<AppState> {
|
|||
frozen(|| button("reset", |data: &mut AppState| data.count = 0))
|
||||
}
|
||||
|
||||
fn app_logic(state: &mut AppState) -> impl WidgetView<AppState> {
|
||||
fn app_logic(state: &mut AppState) -> impl WidgetView<AppState> + use<> {
|
||||
flex((
|
||||
increase_button(state),
|
||||
decrease_button(state),
|
||||
|
|
|
@ -28,7 +28,7 @@ enum IsEven {
|
|||
Success,
|
||||
}
|
||||
|
||||
fn state_machine(app_data: &mut StateMachine) -> impl WidgetView<StateMachine> {
|
||||
fn state_machine(app_data: &mut StateMachine) -> impl WidgetView<StateMachine> + use<> {
|
||||
match app_data.state {
|
||||
// The first time we use `OneOf` in a conditional statement, we need
|
||||
// to specify the number of `OneOf` variants used - 3 in this case.
|
||||
|
@ -59,7 +59,7 @@ fn sequence_button(value: &'static str, target_state: IsEven) -> impl WidgetView
|
|||
})
|
||||
}
|
||||
|
||||
fn app_logic(app_data: &mut StateMachine) -> impl WidgetView<StateMachine> {
|
||||
fn app_logic(app_data: &mut StateMachine) -> impl WidgetView<StateMachine> + use<> {
|
||||
flex((
|
||||
button("Reset", |app_data: &mut StateMachine| {
|
||||
app_data.history.clear();
|
||||
|
|
|
@ -17,7 +17,7 @@ use winit::error::EventLoopError;
|
|||
use winit::window::Window;
|
||||
use xilem::core::fork;
|
||||
use xilem::core::one_of::Either;
|
||||
use xilem::view::{button, flex, label, task, FlexSequence, FlexSpacer};
|
||||
use xilem::view::{FlexSequence, FlexSpacer, button, flex, label, task};
|
||||
use xilem::{WidgetView, Xilem};
|
||||
|
||||
/// The state of the entire application.
|
||||
|
@ -108,7 +108,7 @@ fn get_formatted_duration(dur: Duration) -> String {
|
|||
format!("{hours}:{minutes:0>2}:{seconds:0>4.1}")
|
||||
}
|
||||
|
||||
fn app_logic(data: &mut Stopwatch) -> impl WidgetView<Stopwatch> {
|
||||
fn app_logic(data: &mut Stopwatch) -> impl WidgetView<Stopwatch> + use<> {
|
||||
fork(
|
||||
flex((
|
||||
FlexSpacer::Fixed(5.0),
|
||||
|
@ -139,7 +139,7 @@ fn app_logic(data: &mut Stopwatch) -> impl WidgetView<Stopwatch> {
|
|||
}
|
||||
|
||||
/// Creates a list of items that shows the lap number, split time, and total cumulative time.
|
||||
fn laps_section(data: &mut Stopwatch) -> impl FlexSequence<Stopwatch> {
|
||||
fn laps_section(data: &mut Stopwatch) -> impl FlexSequence<Stopwatch> + use<> {
|
||||
let mut items = Vec::new();
|
||||
let mut total_dur = Duration::ZERO;
|
||||
let current_lap = data.completed_lap_splits.len();
|
||||
|
@ -176,7 +176,7 @@ fn single_lap(
|
|||
.must_fill_major_axis(true)
|
||||
}
|
||||
|
||||
fn start_stop_button(data: &mut Stopwatch) -> impl WidgetView<Stopwatch> {
|
||||
fn start_stop_button(data: &mut Stopwatch) -> impl WidgetView<Stopwatch> + use<> {
|
||||
if data.active {
|
||||
Either::A(button("Stop", |data: &mut Stopwatch| {
|
||||
data.stop();
|
||||
|
@ -188,7 +188,7 @@ fn start_stop_button(data: &mut Stopwatch) -> impl WidgetView<Stopwatch> {
|
|||
}
|
||||
}
|
||||
|
||||
fn lap_reset_button(data: &mut Stopwatch) -> impl WidgetView<Stopwatch> {
|
||||
fn lap_reset_button(data: &mut Stopwatch) -> impl WidgetView<Stopwatch> + use<> {
|
||||
if data.active {
|
||||
Either::A(button(" Lap ", |data: &mut Stopwatch| {
|
||||
data.lap();
|
||||
|
@ -240,7 +240,7 @@ fn main() -> Result<(), EventLoopError> {
|
|||
unsafe_code,
|
||||
reason = "We believe that there are no other declarations using this name in the compiled objects here"
|
||||
)]
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
fn android_main(app: winit::platform::android::activity::AndroidApp) {
|
||||
use winit::platform::android::EventLoopBuilderExtAndroid;
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
#![expect(clippy::shadow_unrelated, reason = "Idiomatic for Xilem users")]
|
||||
|
||||
use winit::error::EventLoopError;
|
||||
use xilem::view::{button, checkbox, flex, textbox, Axis, FlexSpacer};
|
||||
use xilem::view::{Axis, FlexSpacer, button, checkbox, flex, textbox};
|
||||
use xilem::{EventLoop, EventLoopBuilder, WidgetView, Xilem};
|
||||
|
||||
struct Task {
|
||||
|
@ -33,7 +33,7 @@ impl TaskList {
|
|||
}
|
||||
}
|
||||
|
||||
fn app_logic(task_list: &mut TaskList) -> impl WidgetView<TaskList> {
|
||||
fn app_logic(task_list: &mut TaskList) -> impl WidgetView<TaskList> + use<> {
|
||||
let input_box = textbox(
|
||||
task_list.next_task.clone(),
|
||||
|task_list: &mut TaskList, new_value| {
|
||||
|
@ -117,7 +117,7 @@ fn main() -> Result<(), EventLoopError> {
|
|||
unsafe_code,
|
||||
reason = "We believe that there are no other declarations using this name in the compiled objects here"
|
||||
)]
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
fn android_main(app: winit::platform::android::activity::AndroidApp) {
|
||||
use winit::platform::android::EventLoopBuilderExtAndroid;
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
use std::f64::consts::{PI, TAU};
|
||||
|
||||
use winit::error::EventLoopError;
|
||||
use xilem::view::{button, grid, label, sized_box, transformed, GridExt as _};
|
||||
use xilem::view::{GridExt as _, button, grid, label, sized_box, transformed};
|
||||
use xilem::{Affine, Color, EventLoop, Vec2, WidgetView, Xilem};
|
||||
|
||||
struct TransformsGame {
|
||||
|
@ -16,7 +16,7 @@ struct TransformsGame {
|
|||
}
|
||||
|
||||
impl TransformsGame {
|
||||
fn view(&mut self) -> impl WidgetView<Self> {
|
||||
fn view(&mut self) -> impl WidgetView<Self> + use<> {
|
||||
let rotation_correct = (self.rotation % TAU).abs() < 0.001;
|
||||
let scale_correct = self.scale >= 0.99 && self.scale <= 1.01;
|
||||
let translation_correct = self.translation.x == 0.0 && self.translation.y == 0.0;
|
||||
|
|
|
@ -12,10 +12,10 @@ use time::{OffsetDateTime, UtcOffset};
|
|||
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,
|
||||
Axis, FlexExt, FlexSpacer, button, flex, inline_prose, label, portal, prose, sized_box, task,
|
||||
variable_label,
|
||||
};
|
||||
use xilem::{palette, EventLoop, EventLoopBuilder, FontWeight, WidgetView, Xilem};
|
||||
use xilem::{EventLoop, EventLoopBuilder, FontWeight, WidgetView, Xilem, palette};
|
||||
|
||||
/// The state of the application, owned by Xilem and updated by the callbacks below.
|
||||
struct Clocks {
|
||||
|
@ -35,7 +35,7 @@ struct TimeZone {
|
|||
offset: UtcOffset,
|
||||
}
|
||||
|
||||
fn app_logic(data: &mut Clocks) -> impl WidgetView<Clocks> {
|
||||
fn app_logic(data: &mut Clocks) -> impl WidgetView<Clocks> + use<> {
|
||||
let view = flex((
|
||||
// HACK: We add a spacer at the top for Android. See https://github.com/rust-windowing/winit/issues/2308
|
||||
FlexSpacer::Fixed(40.),
|
||||
|
@ -68,7 +68,7 @@ fn app_logic(data: &mut Clocks) -> impl WidgetView<Clocks> {
|
|||
|
||||
/// Shows the current system time on a best-effort basis.
|
||||
// TODO: Maybe make this have a larger font size?
|
||||
fn local_time(data: &mut Clocks) -> impl WidgetView<Clocks> {
|
||||
fn local_time(data: &mut Clocks) -> impl WidgetView<Clocks> + use<> {
|
||||
let (error_view, offset) = if let Ok(offset) = data.local_offset {
|
||||
(None, offset)
|
||||
} else {
|
||||
|
@ -112,7 +112,7 @@ fn controls() -> impl WidgetView<Clocks> {
|
|||
|
||||
impl TimeZone {
|
||||
/// Display this timezone as a row, designed to be shown in a list of time zones.
|
||||
fn view(&self, data: &mut Clocks) -> impl WidgetView<Clocks> {
|
||||
fn view(&self, data: &mut Clocks) -> impl WidgetView<Clocks> + use<> {
|
||||
let date_time_in_self = data.now_utc.to_offset(self.offset);
|
||||
sized_box(flex((
|
||||
flex((
|
||||
|
@ -252,7 +252,7 @@ fn main() -> Result<(), EventLoopError> {
|
|||
unsafe_code,
|
||||
reason = "We believe that there are no other declarations using this name in the compiled objects here"
|
||||
)]
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
fn android_main(app: winit::platform::android::activity::AndroidApp) {
|
||||
use winit::platform::android::EventLoopBuilderExtAndroid;
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@ use masonry::dpi::LogicalSize;
|
|||
use winit::error::EventLoopError;
|
||||
use winit::window::Window;
|
||||
use xilem::core::adapt;
|
||||
use xilem::view::{button, checkbox, flex, flex_item, progress_bar, sized_box, Axis, FlexSpacer};
|
||||
use xilem::view::{Axis, FlexSpacer, button, checkbox, flex, flex_item, progress_bar, sized_box};
|
||||
use xilem::{Color, WidgetView, Xilem};
|
||||
|
||||
const SPACER_WIDTH: f64 = 10.;
|
||||
|
@ -36,7 +36,7 @@ fn progress_bar_view(data: Option<f64>) -> impl WidgetView<Option<f64>> {
|
|||
},
|
||||
),
|
||||
button("change progress", |state: &mut Option<f64>| match state {
|
||||
Some(ref mut v) => *v = (*v + 0.1).rem_euclid(1.),
|
||||
Some(v) => *v = (*v + 0.1).rem_euclid(1.),
|
||||
None => *state = Some(0.5),
|
||||
}),
|
||||
))
|
||||
|
@ -66,7 +66,7 @@ fn border_box<State: 'static, Action: 'static>(
|
|||
}
|
||||
|
||||
/// Top-level view
|
||||
fn app_logic(data: &mut WidgetGallery) -> impl WidgetView<WidgetGallery> {
|
||||
fn app_logic(data: &mut WidgetGallery) -> impl WidgetView<WidgetGallery> + use<> {
|
||||
// Use a `sized_box` to pad the window contents
|
||||
sized_box(
|
||||
flex((
|
||||
|
@ -121,7 +121,7 @@ fn main() -> Result<(), EventLoopError> {
|
|||
unsafe_code,
|
||||
reason = "We believe that there are no other declarations using this name in the compiled objects here"
|
||||
)]
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
fn android_main(app: winit::platform::android::activity::AndroidApp) {
|
||||
use winit::platform::android::EventLoopBuilderExtAndroid;
|
||||
|
||||
|
|
|
@ -7,8 +7,8 @@ use masonry::core::{
|
|||
PointerEvent, QueryCtx, RegisterCtx, TextEvent, Widget, WidgetId, WidgetMut, WidgetPod,
|
||||
};
|
||||
use masonry::kurbo::{Point, Size};
|
||||
use smallvec::{smallvec, SmallVec};
|
||||
use tracing::{trace_span, Span};
|
||||
use smallvec::{SmallVec, smallvec};
|
||||
use tracing::{Span, trace_span};
|
||||
use vello::Scene;
|
||||
|
||||
use crate::core::{AnyElement, AnyView, Mut, SuperElement};
|
||||
|
|
|
@ -91,7 +91,9 @@ where
|
|||
&mut self.state,
|
||||
)
|
||||
} else {
|
||||
tracing::error!("Got action {action:?} for unknown widget. Did you forget to use `with_action_widget`?");
|
||||
tracing::error!(
|
||||
"Got action {action:?} for unknown widget. Did you forget to use `with_action_widget`?"
|
||||
);
|
||||
return;
|
||||
};
|
||||
let rebuild = match message_result {
|
||||
|
|
|
@ -34,7 +34,7 @@
|
|||
//! num: i32,
|
||||
//! }
|
||||
//!
|
||||
//! fn app_logic(data: &mut Counter) -> impl WidgetView<Counter> {
|
||||
//! fn app_logic(data: &mut Counter) -> impl WidgetView<Counter> + use<> {
|
||||
//! flex((
|
||||
//! label(format!("{}", data.num)),
|
||||
//! button("increment", |data: &mut Counter| data.num += 1),
|
||||
|
@ -136,7 +136,7 @@ use std::sync::Arc;
|
|||
use masonry::core::{FromDynWidget, Widget, WidgetId, WidgetMut, WidgetPod};
|
||||
use masonry::dpi::LogicalSize;
|
||||
use masonry::widgets::RootWidget;
|
||||
use view::{transformed, Transformed};
|
||||
use view::{Transformed, transformed};
|
||||
use winit::error::EventLoopError;
|
||||
use winit::window::{Window, WindowAttributes};
|
||||
|
||||
|
@ -146,8 +146,8 @@ use crate::core::{
|
|||
};
|
||||
pub use masonry::app::{EventLoop, EventLoopBuilder};
|
||||
pub use masonry::kurbo::{Affine, Vec2};
|
||||
pub use masonry::parley::style::FontWeight;
|
||||
pub use masonry::parley::Alignment as TextAlignment;
|
||||
pub use masonry::parley::style::FontWeight;
|
||||
pub use masonry::peniko::Color;
|
||||
pub use masonry::widgets::LineBreaking;
|
||||
pub use masonry::{dpi, palette};
|
||||
|
@ -164,7 +164,7 @@ mod one_of;
|
|||
|
||||
pub mod view;
|
||||
pub use any_view::AnyWidgetView;
|
||||
pub use driver::{async_action, MasonryDriver, MasonryProxy, ASYNC_MARKER_WIDGET};
|
||||
pub use driver::{ASYNC_MARKER_WIDGET, MasonryDriver, MasonryProxy, async_action};
|
||||
|
||||
/// Runtime builder.
|
||||
#[must_use = "A Xilem app does nothing unless ran."]
|
||||
|
@ -376,7 +376,7 @@ pub trait WidgetView<State, Action = ()>:
|
|||
/// ```
|
||||
/// use xilem::{view::label, WidgetView};
|
||||
///
|
||||
/// # fn view<State: 'static>() -> impl WidgetView<State> {
|
||||
/// # fn view<State: 'static>() -> impl WidgetView<State> + use<State> {
|
||||
/// label("a label").boxed()
|
||||
/// # }
|
||||
///
|
||||
|
|
|
@ -9,24 +9,24 @@ use masonry::core::{
|
|||
PointerEvent, RegisterCtx, TextEvent, Widget, WidgetId, WidgetPod,
|
||||
};
|
||||
use masonry::kurbo::{Point, Size};
|
||||
use smallvec::{smallvec, SmallVec};
|
||||
use smallvec::{SmallVec, smallvec};
|
||||
use vello::Scene;
|
||||
|
||||
use crate::core::one_of::OneOf;
|
||||
use crate::core::Mut;
|
||||
use crate::core::one_of::OneOf;
|
||||
use crate::{Pod, ViewCtx};
|
||||
|
||||
impl<
|
||||
A: Widget + FromDynWidget + ?Sized,
|
||||
B: Widget + FromDynWidget + ?Sized,
|
||||
C: Widget + FromDynWidget + ?Sized,
|
||||
D: Widget + FromDynWidget + ?Sized,
|
||||
E: Widget + FromDynWidget + ?Sized,
|
||||
F: Widget + FromDynWidget + ?Sized,
|
||||
G: Widget + FromDynWidget + ?Sized,
|
||||
H: Widget + FromDynWidget + ?Sized,
|
||||
I: Widget + FromDynWidget + ?Sized,
|
||||
>
|
||||
A: Widget + FromDynWidget + ?Sized,
|
||||
B: Widget + FromDynWidget + ?Sized,
|
||||
C: Widget + FromDynWidget + ?Sized,
|
||||
D: Widget + FromDynWidget + ?Sized,
|
||||
E: Widget + FromDynWidget + ?Sized,
|
||||
F: Widget + FromDynWidget + ?Sized,
|
||||
G: Widget + FromDynWidget + ?Sized,
|
||||
H: Widget + FromDynWidget + ?Sized,
|
||||
I: Widget + FromDynWidget + ?Sized,
|
||||
>
|
||||
crate::core::one_of::OneOfCtx<
|
||||
Pod<A>,
|
||||
Pod<B>,
|
||||
|
@ -171,16 +171,16 @@ pub enum OneOfWidget<
|
|||
}
|
||||
|
||||
impl<
|
||||
A: Widget + FromDynWidget + ?Sized,
|
||||
B: Widget + FromDynWidget + ?Sized,
|
||||
C: Widget + FromDynWidget + ?Sized,
|
||||
D: Widget + FromDynWidget + ?Sized,
|
||||
E: Widget + FromDynWidget + ?Sized,
|
||||
F: Widget + FromDynWidget + ?Sized,
|
||||
G: Widget + FromDynWidget + ?Sized,
|
||||
H: Widget + FromDynWidget + ?Sized,
|
||||
I: Widget + FromDynWidget + ?Sized,
|
||||
> Widget for OneOfWidget<A, B, C, D, E, F, G, H, I>
|
||||
A: Widget + FromDynWidget + ?Sized,
|
||||
B: Widget + FromDynWidget + ?Sized,
|
||||
C: Widget + FromDynWidget + ?Sized,
|
||||
D: Widget + FromDynWidget + ?Sized,
|
||||
E: Widget + FromDynWidget + ?Sized,
|
||||
F: Widget + FromDynWidget + ?Sized,
|
||||
G: Widget + FromDynWidget + ?Sized,
|
||||
H: Widget + FromDynWidget + ?Sized,
|
||||
I: Widget + FromDynWidget + ?Sized,
|
||||
> Widget for OneOfWidget<A, B, C, D, E, F, G, H, I>
|
||||
{
|
||||
fn on_pointer_event(&mut self, _ctx: &mut EventCtx, _event: &PointerEvent) {}
|
||||
fn on_text_event(&mut self, _ctx: &mut EventCtx, _event: &TextEvent) {}
|
||||
|
|
|
@ -30,7 +30,7 @@ use crate::{AnyWidgetView, Pod, ViewCtx, WidgetView};
|
|||
/// sized_box(button(label, callback)).width(40.).height(40.)
|
||||
/// }
|
||||
///
|
||||
/// fn app_logic(data: &mut i32) -> impl WidgetView<i32> {
|
||||
/// fn app_logic(data: &mut i32) -> impl WidgetView<i32> + use<> {
|
||||
/// flex((
|
||||
/// FlexSpacer::Fixed(30.0),
|
||||
/// big_button("-", |data| {
|
||||
|
|
|
@ -80,7 +80,9 @@ impl<State, Action> View<State, Action, ViewCtx> for Image {
|
|||
message: DynMessage,
|
||||
_: &mut State,
|
||||
) -> MessageResult<Action> {
|
||||
tracing::error!("Message arrived in Label::message, but Label doesn't consume any messages, this is a bug");
|
||||
tracing::error!(
|
||||
"Message arrived in Label::message, but Label doesn't consume any messages, this is a bug"
|
||||
);
|
||||
MessageResult::Stale(message)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -162,7 +162,9 @@ impl<State, Action> View<State, Action, ViewCtx> for Label {
|
|||
message: DynMessage,
|
||||
_app_state: &mut State,
|
||||
) -> MessageResult<Action> {
|
||||
tracing::error!("Message arrived in Label::message, but Label doesn't consume any messages, this is a bug");
|
||||
tracing::error!(
|
||||
"Message arrived in Label::message, but Label doesn't consume any messages, this is a bug"
|
||||
);
|
||||
MessageResult::Stale(message)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -46,7 +46,9 @@ impl<State, Action> View<State, Action, ViewCtx> for ProgressBar {
|
|||
message: DynMessage,
|
||||
_app_state: &mut State,
|
||||
) -> MessageResult<Action> {
|
||||
tracing::error!("Message arrived in ProgressBar::message, but ProgressBar doesn't consume any messages, this is a bug");
|
||||
tracing::error!(
|
||||
"Message arrived in ProgressBar::message, but ProgressBar doesn't consume any messages, this is a bug"
|
||||
);
|
||||
MessageResult::Stale(message)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -129,7 +129,9 @@ impl<State, Action> View<State, Action, ViewCtx> for Prose {
|
|||
message: DynMessage,
|
||||
_app_state: &mut State,
|
||||
) -> MessageResult<Action> {
|
||||
tracing::error!("Message arrived in Prose::message, but Prose doesn't consume any messages, this is a bug");
|
||||
tracing::error!(
|
||||
"Message arrived in Prose::message, but Prose doesn't consume any messages, this is a bug"
|
||||
);
|
||||
MessageResult::Stale(message)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -86,7 +86,9 @@ impl<State, Action> View<State, Action, ViewCtx> for Spinner {
|
|||
message: DynMessage,
|
||||
_: &mut State,
|
||||
) -> MessageResult<Action> {
|
||||
tracing::error!("Message arrived in Label::message, but Label doesn't consume any messages, this is a bug");
|
||||
tracing::error!(
|
||||
"Message arrived in Label::message, but Label doesn't consume any messages, this is a bug"
|
||||
);
|
||||
MessageResult::Stale(message)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,11 +7,11 @@ use std::sync::Arc;
|
|||
|
||||
use tokio::task::JoinHandle;
|
||||
|
||||
use crate::ViewCtx;
|
||||
use crate::core::{
|
||||
DynMessage, Message, MessageProxy, MessageResult, Mut, NoElement, View, ViewId, ViewMarker,
|
||||
ViewPathTracker,
|
||||
};
|
||||
use crate::ViewCtx;
|
||||
|
||||
/// Launch a task which will run until the view is no longer in the tree.
|
||||
/// `init_future` is given a [`MessageProxy`], which it will store in the future it returns.
|
||||
|
|
|
@ -2,13 +2,13 @@
|
|||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
use masonry::core::ArcStr;
|
||||
use masonry::parley::style::{FontStack, FontWeight};
|
||||
use masonry::parley::Alignment as TextAlignment;
|
||||
use masonry::parley::style::{FontStack, FontWeight};
|
||||
use masonry::widgets;
|
||||
use vello::peniko::Brush;
|
||||
use xilem_core::ViewPathTracker;
|
||||
|
||||
use super::{label, Label};
|
||||
use super::{Label, label};
|
||||
use crate::core::{DynMessage, Mut, ViewMarker};
|
||||
use crate::{MessageResult, Pod, View, ViewCtx, ViewId};
|
||||
|
||||
|
@ -150,7 +150,9 @@ impl<State, Action> View<State, Action, ViewCtx> for VariableLabel {
|
|||
assert_eq!(first.routing_id(), 0);
|
||||
self.label.message(&mut (), remainder, message, app_state)
|
||||
} else {
|
||||
tracing::error!("Message arrived in Label::message, but Label doesn't consume any messages, this is a bug");
|
||||
tracing::error!(
|
||||
"Message arrived in Label::message, but Label doesn't consume any messages, this is a bug"
|
||||
);
|
||||
MessageResult::Stale(message)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,11 +8,11 @@ use std::sync::Arc;
|
|||
use tokio::sync::mpsc::{UnboundedReceiver, UnboundedSender};
|
||||
use tokio::task::JoinHandle;
|
||||
|
||||
use crate::ViewCtx;
|
||||
use crate::core::{
|
||||
DynMessage, Message, MessageProxy, MessageResult, Mut, NoElement, View, ViewId, ViewMarker,
|
||||
ViewPathTracker,
|
||||
};
|
||||
use crate::ViewCtx;
|
||||
|
||||
/// Launch a task which will run until the view is no longer in the tree.
|
||||
///
|
||||
|
|
|
@ -47,7 +47,7 @@ If you wish to use Xilem Core in environments where an allocator is not availabl
|
|||
|
||||
## Minimum supported Rust Version (MSRV)
|
||||
|
||||
This version of Xilem Core has been verified to compile with **Rust 1.82** and later.
|
||||
This version of Xilem Core has been verified to compile with **Rust 1.85** and later.
|
||||
|
||||
Future versions of Xilem Core might increase the Rust version requirement.
|
||||
It will not be treated as a breaking change and as such can even happen with small patch releases.
|
||||
|
|
|
@ -17,14 +17,14 @@ enum State {
|
|||
Complex(String),
|
||||
}
|
||||
|
||||
fn complex_state(value: &str) -> impl FileView<State> {
|
||||
fn complex_state(value: &str) -> impl FileView<State> + use<> {
|
||||
File {
|
||||
name: value.to_string(),
|
||||
contents: value.to_string(),
|
||||
}
|
||||
}
|
||||
|
||||
fn app_logic(state: &mut State) -> impl FileView<State> {
|
||||
fn app_logic(state: &mut State) -> impl FileView<State> + use<> {
|
||||
let res: DynFileView<State> = match state {
|
||||
State::Setup => Box::new(File {
|
||||
name: "file1.txt".into(),
|
||||
|
|
|
@ -10,7 +10,7 @@ use xilem_core::{
|
|||
ViewPathTracker,
|
||||
};
|
||||
|
||||
fn app_logic(_: &mut u32) -> impl WidgetView<u32> {
|
||||
fn app_logic(_: &mut u32) -> impl WidgetView<u32> + use<> {
|
||||
Button {}
|
||||
}
|
||||
|
||||
|
|
|
@ -173,12 +173,8 @@ pub struct AnyViewState {
|
|||
generation: u64,
|
||||
}
|
||||
|
||||
impl<State, Action, Context, Element, Message> ViewMarker
|
||||
for dyn AnyView<State, Action, Context, Element, Message>
|
||||
{
|
||||
}
|
||||
impl<State, Action, Context, Element, Message> View<State, Action, Context, Message>
|
||||
for dyn AnyView<State, Action, Context, Element, Message>
|
||||
impl<State, Action, Context, Element, Message> ViewMarker for dyn AnyView<State, Action, Context, Element, Message> {}
|
||||
impl<State, Action, Context, Element, Message> View<State, Action, Context, Message> for dyn AnyView<State, Action, Context, Element, Message>
|
||||
where
|
||||
// Element must be `static` so it can be downcasted
|
||||
Element: ViewElement + 'static,
|
||||
|
|
|
@ -35,7 +35,7 @@
|
|||
//! # struct InterestingPrimitive;
|
||||
//! ```
|
||||
|
||||
use crate::{run_once, View, ViewPathTracker};
|
||||
use crate::{View, ViewPathTracker, run_once};
|
||||
|
||||
/// A type used for documentation
|
||||
#[derive(Debug)]
|
||||
|
@ -68,7 +68,7 @@ impl<V, State, Action> DocsView<State, Action> for V where V: View<State, Action
|
|||
pub struct State;
|
||||
|
||||
/// A minimal component.
|
||||
pub fn some_component<Action>(_: &mut State) -> impl DocsView<State, Action> {
|
||||
pub fn some_component<Action>(_: &mut State) -> impl DocsView<State, Action> + use<Action> {
|
||||
// The view which does nothing already exists in `run_once`.
|
||||
run_once(|| {})
|
||||
}
|
||||
|
|
|
@ -41,8 +41,8 @@ pub use view::{View, ViewId, ViewMarker, ViewPathTracker};
|
|||
|
||||
mod views;
|
||||
pub use views::{
|
||||
adapt, fork, frozen, lens, map_action, map_state, memoize, one_of, run_once, run_once_raw,
|
||||
Adapt, AdaptThunk, Fork, Frozen, MapAction, MapState, Memoize, OrphanView, RunOnce,
|
||||
Adapt, AdaptThunk, Fork, Frozen, MapAction, MapState, Memoize, OrphanView, RunOnce, adapt,
|
||||
fork, frozen, lens, map_action, map_state, memoize, one_of, run_once, run_once_raw,
|
||||
};
|
||||
|
||||
mod message;
|
||||
|
|
|
@ -2,22 +2,22 @@
|
|||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
mod run_once;
|
||||
pub use run_once::{run_once, run_once_raw, RunOnce};
|
||||
pub use run_once::{RunOnce, run_once, run_once_raw};
|
||||
|
||||
mod adapt;
|
||||
pub use adapt::{adapt, Adapt, AdaptThunk};
|
||||
pub use adapt::{Adapt, AdaptThunk, adapt};
|
||||
|
||||
mod map_state;
|
||||
pub use map_state::{lens, map_state, MapState};
|
||||
pub use map_state::{MapState, lens, map_state};
|
||||
|
||||
mod map_action;
|
||||
pub use map_action::{map_action, MapAction};
|
||||
pub use map_action::{MapAction, map_action};
|
||||
|
||||
mod fork;
|
||||
pub use fork::{fork, Fork};
|
||||
pub use fork::{Fork, fork};
|
||||
|
||||
mod memoize;
|
||||
pub use memoize::{frozen, memoize, Frozen, Memoize};
|
||||
pub use memoize::{Frozen, Memoize, frozen, memoize};
|
||||
|
||||
pub mod one_of;
|
||||
|
||||
|
|
|
@ -286,7 +286,7 @@ where
|
|||
let id = ViewId::new(view_state.generation);
|
||||
// If both elements are of the same type, do a simple rebuild
|
||||
match (self, prev, &mut view_state.inner_state) {
|
||||
(Self::A(this), Self::A(prev), OneOf::A(ref mut state)) => {
|
||||
(Self::A(this), Self::A(prev), OneOf::A(state)) => {
|
||||
ctx.with_id(id, |ctx| {
|
||||
Context::with_downcast_a(&mut element, |element| {
|
||||
this.rebuild(prev, state, ctx, element);
|
||||
|
@ -294,7 +294,7 @@ where
|
|||
});
|
||||
return;
|
||||
}
|
||||
(Self::B(this), Self::B(prev), OneOf::B(ref mut state)) => {
|
||||
(Self::B(this), Self::B(prev), OneOf::B(state)) => {
|
||||
ctx.with_id(id, |ctx| {
|
||||
Context::with_downcast_b(&mut element, |element| {
|
||||
this.rebuild(prev, state, ctx, element);
|
||||
|
@ -302,7 +302,7 @@ where
|
|||
});
|
||||
return;
|
||||
}
|
||||
(Self::C(this), Self::C(prev), OneOf::C(ref mut state)) => {
|
||||
(Self::C(this), Self::C(prev), OneOf::C(state)) => {
|
||||
ctx.with_id(id, |ctx| {
|
||||
Context::with_downcast_c(&mut element, |element| {
|
||||
this.rebuild(prev, state, ctx, element);
|
||||
|
@ -310,7 +310,7 @@ where
|
|||
});
|
||||
return;
|
||||
}
|
||||
(Self::D(this), Self::D(prev), OneOf::D(ref mut state)) => {
|
||||
(Self::D(this), Self::D(prev), OneOf::D(state)) => {
|
||||
ctx.with_id(id, |ctx| {
|
||||
Context::with_downcast_d(&mut element, |element| {
|
||||
this.rebuild(prev, state, ctx, element);
|
||||
|
@ -318,7 +318,7 @@ where
|
|||
});
|
||||
return;
|
||||
}
|
||||
(Self::E(this), Self::E(prev), OneOf::E(ref mut state)) => {
|
||||
(Self::E(this), Self::E(prev), OneOf::E(state)) => {
|
||||
ctx.with_id(id, |ctx| {
|
||||
Context::with_downcast_e(&mut element, |element| {
|
||||
this.rebuild(prev, state, ctx, element);
|
||||
|
@ -326,7 +326,7 @@ where
|
|||
});
|
||||
return;
|
||||
}
|
||||
(Self::F(this), Self::F(prev), OneOf::F(ref mut state)) => {
|
||||
(Self::F(this), Self::F(prev), OneOf::F(state)) => {
|
||||
ctx.with_id(id, |ctx| {
|
||||
Context::with_downcast_f(&mut element, |element| {
|
||||
this.rebuild(prev, state, ctx, element);
|
||||
|
@ -334,7 +334,7 @@ where
|
|||
});
|
||||
return;
|
||||
}
|
||||
(Self::G(this), Self::G(prev), OneOf::G(ref mut state)) => {
|
||||
(Self::G(this), Self::G(prev), OneOf::G(state)) => {
|
||||
ctx.with_id(id, |ctx| {
|
||||
Context::with_downcast_g(&mut element, |element| {
|
||||
this.rebuild(prev, state, ctx, element);
|
||||
|
@ -342,7 +342,7 @@ where
|
|||
});
|
||||
return;
|
||||
}
|
||||
(Self::H(this), Self::H(prev), OneOf::H(ref mut state)) => {
|
||||
(Self::H(this), Self::H(prev), OneOf::H(state)) => {
|
||||
ctx.with_id(id, |ctx| {
|
||||
Context::with_downcast_h(&mut element, |element| {
|
||||
this.rebuild(prev, state, ctx, element);
|
||||
|
@ -350,7 +350,7 @@ where
|
|||
});
|
||||
return;
|
||||
}
|
||||
(Self::I(this), Self::I(prev), OneOf::I(ref mut state)) => {
|
||||
(Self::I(this), Self::I(prev), OneOf::I(state)) => {
|
||||
ctx.with_id(id, |ctx| {
|
||||
Context::with_downcast_i(&mut element, |element| {
|
||||
this.rebuild(prev, state, ctx, element);
|
||||
|
@ -363,47 +363,47 @@ where
|
|||
|
||||
// We're changing the type of the view. Teardown the old version
|
||||
ctx.with_id(id, |ctx| match (prev, &mut view_state.inner_state) {
|
||||
(Self::A(prev), OneOf::A(ref mut state)) => {
|
||||
(Self::A(prev), OneOf::A(state)) => {
|
||||
Context::with_downcast_a(&mut element, |element| {
|
||||
prev.teardown(state, ctx, element);
|
||||
});
|
||||
}
|
||||
(Self::B(prev), OneOf::B(ref mut state)) => {
|
||||
(Self::B(prev), OneOf::B(state)) => {
|
||||
Context::with_downcast_b(&mut element, |element| {
|
||||
prev.teardown(state, ctx, element);
|
||||
});
|
||||
}
|
||||
(Self::C(prev), OneOf::C(ref mut state)) => {
|
||||
(Self::C(prev), OneOf::C(state)) => {
|
||||
Context::with_downcast_c(&mut element, |element| {
|
||||
prev.teardown(state, ctx, element);
|
||||
});
|
||||
}
|
||||
(Self::D(prev), OneOf::D(ref mut state)) => {
|
||||
(Self::D(prev), OneOf::D(state)) => {
|
||||
Context::with_downcast_d(&mut element, |element| {
|
||||
prev.teardown(state, ctx, element);
|
||||
});
|
||||
}
|
||||
(Self::E(prev), OneOf::E(ref mut state)) => {
|
||||
(Self::E(prev), OneOf::E(state)) => {
|
||||
Context::with_downcast_e(&mut element, |element| {
|
||||
prev.teardown(state, ctx, element);
|
||||
});
|
||||
}
|
||||
(Self::F(prev), OneOf::F(ref mut state)) => {
|
||||
(Self::F(prev), OneOf::F(state)) => {
|
||||
Context::with_downcast_f(&mut element, |element| {
|
||||
prev.teardown(state, ctx, element);
|
||||
});
|
||||
}
|
||||
(Self::G(prev), OneOf::G(ref mut state)) => {
|
||||
(Self::G(prev), OneOf::G(state)) => {
|
||||
Context::with_downcast_g(&mut element, |element| {
|
||||
prev.teardown(state, ctx, element);
|
||||
});
|
||||
}
|
||||
(Self::H(prev), OneOf::H(ref mut state)) => {
|
||||
(Self::H(prev), OneOf::H(state)) => {
|
||||
Context::with_downcast_h(&mut element, |element| {
|
||||
prev.teardown(state, ctx, element);
|
||||
});
|
||||
}
|
||||
(Self::I(prev), OneOf::I(ref mut state)) => {
|
||||
(Self::I(prev), OneOf::I(state)) => {
|
||||
Context::with_downcast_i(&mut element, |element| {
|
||||
prev.teardown(state, ctx, element);
|
||||
});
|
||||
|
@ -468,47 +468,47 @@ where
|
|||
) {
|
||||
ctx.with_id(ViewId::new(view_state.generation), |ctx| {
|
||||
match (self, &mut view_state.inner_state) {
|
||||
(Self::A(v), OneOf::A(ref mut state)) => {
|
||||
(Self::A(v), OneOf::A(state)) => {
|
||||
Context::with_downcast_a(&mut element, |element| {
|
||||
v.teardown(state, ctx, element);
|
||||
});
|
||||
}
|
||||
(Self::B(v), OneOf::B(ref mut state)) => {
|
||||
(Self::B(v), OneOf::B(state)) => {
|
||||
Context::with_downcast_b(&mut element, |element| {
|
||||
v.teardown(state, ctx, element);
|
||||
});
|
||||
}
|
||||
(Self::C(v), OneOf::C(ref mut state)) => {
|
||||
(Self::C(v), OneOf::C(state)) => {
|
||||
Context::with_downcast_c(&mut element, |element| {
|
||||
v.teardown(state, ctx, element);
|
||||
});
|
||||
}
|
||||
(Self::D(v), OneOf::D(ref mut state)) => {
|
||||
(Self::D(v), OneOf::D(state)) => {
|
||||
Context::with_downcast_d(&mut element, |element| {
|
||||
v.teardown(state, ctx, element);
|
||||
});
|
||||
}
|
||||
(Self::E(v), OneOf::E(ref mut state)) => {
|
||||
(Self::E(v), OneOf::E(state)) => {
|
||||
Context::with_downcast_e(&mut element, |element| {
|
||||
v.teardown(state, ctx, element);
|
||||
});
|
||||
}
|
||||
(Self::F(v), OneOf::F(ref mut state)) => {
|
||||
(Self::F(v), OneOf::F(state)) => {
|
||||
Context::with_downcast_f(&mut element, |element| {
|
||||
v.teardown(state, ctx, element);
|
||||
});
|
||||
}
|
||||
(Self::G(v), OneOf::G(ref mut state)) => {
|
||||
(Self::G(v), OneOf::G(state)) => {
|
||||
Context::with_downcast_g(&mut element, |element| {
|
||||
v.teardown(state, ctx, element);
|
||||
});
|
||||
}
|
||||
(Self::H(v), OneOf::H(ref mut state)) => {
|
||||
(Self::H(v), OneOf::H(state)) => {
|
||||
Context::with_downcast_h(&mut element, |element| {
|
||||
v.teardown(state, ctx, element);
|
||||
});
|
||||
}
|
||||
(Self::I(v), OneOf::I(ref mut state)) => {
|
||||
(Self::I(v), OneOf::I(state)) => {
|
||||
Context::with_downcast_i(&mut element, |element| {
|
||||
v.teardown(state, ctx, element);
|
||||
});
|
||||
|
@ -533,15 +533,15 @@ where
|
|||
return MessageResult::Stale(message);
|
||||
}
|
||||
match (self, &mut view_state.inner_state) {
|
||||
(Self::A(v), OneOf::A(ref mut state)) => v.message(state, rest, message, app_state),
|
||||
(Self::B(v), OneOf::B(ref mut state)) => v.message(state, rest, message, app_state),
|
||||
(Self::C(v), OneOf::C(ref mut state)) => v.message(state, rest, message, app_state),
|
||||
(Self::D(v), OneOf::D(ref mut state)) => v.message(state, rest, message, app_state),
|
||||
(Self::E(v), OneOf::E(ref mut state)) => v.message(state, rest, message, app_state),
|
||||
(Self::F(v), OneOf::F(ref mut state)) => v.message(state, rest, message, app_state),
|
||||
(Self::G(v), OneOf::G(ref mut state)) => v.message(state, rest, message, app_state),
|
||||
(Self::H(v), OneOf::H(ref mut state)) => v.message(state, rest, message, app_state),
|
||||
(Self::I(v), OneOf::I(ref mut state)) => v.message(state, rest, message, app_state),
|
||||
(Self::A(v), OneOf::A(state)) => v.message(state, rest, message, app_state),
|
||||
(Self::B(v), OneOf::B(state)) => v.message(state, rest, message, app_state),
|
||||
(Self::C(v), OneOf::C(state)) => v.message(state, rest, message, app_state),
|
||||
(Self::D(v), OneOf::D(state)) => v.message(state, rest, message, app_state),
|
||||
(Self::E(v), OneOf::E(state)) => v.message(state, rest, message, app_state),
|
||||
(Self::F(v), OneOf::F(state)) => v.message(state, rest, message, app_state),
|
||||
(Self::G(v), OneOf::G(state)) => v.message(state, rest, message, app_state),
|
||||
(Self::H(v), OneOf::H(state)) => v.message(state, rest, message, app_state),
|
||||
(Self::I(v), OneOf::I(state)) => v.message(state, rest, message, app_state),
|
||||
_ => unreachable!(),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -37,7 +37,7 @@ use xilem_web::{
|
|||
App,
|
||||
};
|
||||
|
||||
fn app_logic(clicks: &mut u32) -> impl HtmlDivElement<u32> {
|
||||
fn app_logic(clicks: &mut u32) -> impl HtmlDivElement<u32> + use<> {
|
||||
div((
|
||||
button(format!("clicked {clicks} times")).on_click(|clicks: &mut u32, _event| *clicks += 1),
|
||||
(*clicks >= 5).then_some(p("Huzzah, clicked at least 5 times")),
|
||||
|
@ -52,7 +52,7 @@ pub fn main() {
|
|||
|
||||
## Minimum supported Rust Version (MSRV)
|
||||
|
||||
This version of Xilem Web has been verified to compile with **Rust 1.82** and later.
|
||||
This version of Xilem Web has been verified to compile with **Rust 1.85** and later.
|
||||
|
||||
Future versions of Xilem Web might increase the Rust version requirement.
|
||||
It will not be treated as a breaking change and as such can even happen with small patch releases.
|
||||
|
|
|
@ -4,10 +4,10 @@
|
|||
//! Async views, allowing concurrent operations, like fetching data from a server
|
||||
|
||||
mod task;
|
||||
pub use task::{task, task_raw, ShutdownSignal, Task, TaskProxy};
|
||||
pub use task::{ShutdownSignal, Task, TaskProxy, task, task_raw};
|
||||
|
||||
mod interval;
|
||||
pub use interval::{interval, Interval};
|
||||
pub use interval::{Interval, interval};
|
||||
|
||||
mod memoized_await;
|
||||
pub use memoized_await::{memoized_await, MemoizedAwait};
|
||||
pub use memoized_await::{MemoizedAwait, memoized_await};
|
||||
|
|
|
@ -5,8 +5,8 @@ use std::future::Future;
|
|||
use std::marker::PhantomData;
|
||||
use std::rc::Rc;
|
||||
|
||||
use futures::channel::oneshot;
|
||||
use futures::FutureExt;
|
||||
use futures::channel::oneshot;
|
||||
use wasm_bindgen::UnwrapThrowExt;
|
||||
use wasm_bindgen_futures::spawn_local;
|
||||
|
||||
|
|
|
@ -6,10 +6,10 @@ use std::rc::Rc;
|
|||
|
||||
use wasm_bindgen_futures::spawn_local;
|
||||
|
||||
use crate::Message;
|
||||
use crate::app::{AppMessage, AppRunner};
|
||||
use crate::core::{ViewId, ViewPathTracker};
|
||||
use crate::vecmap::VecMap;
|
||||
use crate::Message;
|
||||
|
||||
/// A thunk to send messages to the views, it's being used for example in event callbacks
|
||||
pub struct MessageThunk {
|
||||
|
|
|
@ -14,7 +14,7 @@ use crate::core::{AppendVec, ElementSplice, MessageResult, Mut, View, ViewId, Vi
|
|||
use crate::modifiers::Children;
|
||||
use crate::vec_splice::VecSplice;
|
||||
use crate::{
|
||||
document, AnyPod, DomFragment, DomNode, DynMessage, FromWithContext, Pod, ViewCtx, HTML_NS,
|
||||
AnyPod, DomFragment, DomNode, DynMessage, FromWithContext, HTML_NS, Pod, ViewCtx, document,
|
||||
};
|
||||
|
||||
// sealed, because this should only cover `ViewSequences` with the blanket impl below
|
||||
|
|
|
@ -5,8 +5,8 @@ use std::borrow::Cow;
|
|||
use std::marker::PhantomData;
|
||||
|
||||
use wasm_bindgen::prelude::Closure;
|
||||
use wasm_bindgen::{throw_str, JsCast, UnwrapThrowExt};
|
||||
use web_sys::{js_sys, AddEventListenerOptions};
|
||||
use wasm_bindgen::{JsCast, UnwrapThrowExt, throw_str};
|
||||
use web_sys::{AddEventListenerOptions, js_sys};
|
||||
|
||||
use crate::core::{MessageResult, Mut, View, ViewId, ViewMarker, ViewPathTracker};
|
||||
use crate::{DomView, DynMessage, OptionalAction, ViewCtx};
|
||||
|
|
|
@ -18,7 +18,7 @@ use wasm_bindgen::JsCast;
|
|||
|
||||
use crate::modifiers::{Attr, Class, ClassIter, Rotate, Scale, ScaleValue, Style, StyleIter};
|
||||
use crate::props::{WithElementProps, WithHtmlInputElementProps};
|
||||
use crate::{events, DomNode, DomView, IntoAttributeValue, OptionalAction, Pointer, PointerMsg};
|
||||
use crate::{DomNode, DomView, IntoAttributeValue, OptionalAction, Pointer, PointerMsg, events};
|
||||
|
||||
macro_rules! event_handler_mixin {
|
||||
($(($event_ty: ident, $fn_name:ident, $event:expr, $web_sys_event_type:ident),)*) => {
|
||||
|
@ -807,10 +807,10 @@ use crate::modifiers::html_input_element;
|
|||
// #[cfg(feature = "HtmlInputElement")]
|
||||
pub trait HtmlInputElement<State, Action = ()>:
|
||||
HtmlElement<
|
||||
State,
|
||||
Action,
|
||||
DomNode: DomNode<Props: WithHtmlInputElementProps> + AsRef<web_sys::HtmlInputElement>,
|
||||
>
|
||||
State,
|
||||
Action,
|
||||
DomNode: DomNode<Props: WithHtmlInputElementProps> + AsRef<web_sys::HtmlInputElement>,
|
||||
>
|
||||
{
|
||||
/// See <https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement/checked> for more details.
|
||||
///
|
||||
|
|
|
@ -78,7 +78,7 @@ pub mod props;
|
|||
pub mod svg;
|
||||
|
||||
pub use self::after_update::{
|
||||
after_build, after_rebuild, before_teardown, AfterBuild, AfterRebuild, BeforeTeardown,
|
||||
AfterBuild, AfterRebuild, BeforeTeardown, after_build, after_rebuild, before_teardown,
|
||||
};
|
||||
pub use self::app::App;
|
||||
pub use self::attribute_value::{AttributeValue, IntoAttributeValue};
|
||||
|
@ -89,7 +89,7 @@ pub use self::optional_action::{Action, OptionalAction};
|
|||
pub use self::pod::{AnyPod, Pod, PodFlags, PodMut};
|
||||
pub use self::pointer::{Pointer, PointerDetails, PointerMsg};
|
||||
|
||||
pub use templated::{templated, Templated};
|
||||
pub use templated::{Templated, templated};
|
||||
|
||||
pub use xilem_core as core;
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@ use std::marker::PhantomData;
|
|||
use wasm_bindgen::{JsCast, UnwrapThrowExt};
|
||||
|
||||
use crate::core::{MessageResult, Mut, View, ViewElement, ViewId, ViewMarker};
|
||||
use crate::diff::{diff_iters, Diff};
|
||||
use crate::diff::{Diff, diff_iters};
|
||||
use crate::modifiers::{Modifier, WithModifier};
|
||||
use crate::vecmap::VecMap;
|
||||
use crate::{DomView, DynMessage, ViewCtx};
|
||||
|
|
|
@ -184,10 +184,10 @@ macro_rules! overwrite_bool_modifier_view {
|
|||
State: 'static,
|
||||
Action: 'static,
|
||||
V: $crate::DomView<
|
||||
State,
|
||||
Action,
|
||||
Element: $crate::modifiers::WithModifier<super::$modifier>,
|
||||
>,
|
||||
State,
|
||||
Action,
|
||||
Element: $crate::modifiers::WithModifier<super::$modifier>,
|
||||
>,
|
||||
for<'a> <V::Element as $crate::core::ViewElement>::Mut<'a>:
|
||||
$crate::modifiers::WithModifier<super::$modifier>,
|
||||
{
|
||||
|
|
|
@ -11,7 +11,7 @@ use wasm_bindgen::{JsCast, UnwrapThrowExt};
|
|||
|
||||
use super::{Modifier, WithModifier};
|
||||
use crate::core::{MessageResult, Mut, View, ViewElement, ViewId, ViewMarker};
|
||||
use crate::diff::{diff_iters, Diff};
|
||||
use crate::diff::{Diff, diff_iters};
|
||||
use crate::vecmap::VecMap;
|
||||
use crate::{DomView, DynMessage, ViewCtx};
|
||||
|
||||
|
|
|
@ -3,8 +3,8 @@
|
|||
|
||||
use wasm_bindgen::UnwrapThrowExt;
|
||||
|
||||
use crate::core::one_of::{OneOf, OneOfCtx, PhantomElementCtx};
|
||||
use crate::core::Mut;
|
||||
use crate::core::one_of::{OneOf, OneOfCtx, PhantomElementCtx};
|
||||
use crate::{DomNode, Pod, PodFlags, PodMut, ViewCtx};
|
||||
|
||||
impl<N1, N2, N3, N4, N5, N6, N7, N8, N9>
|
||||
|
|
|
@ -7,7 +7,7 @@ use std::marker::PhantomData;
|
|||
|
||||
use peniko::kurbo::Point;
|
||||
use wasm_bindgen::prelude::Closure;
|
||||
use wasm_bindgen::{throw_str, JsCast, UnwrapThrowExt};
|
||||
use wasm_bindgen::{JsCast, UnwrapThrowExt, throw_str};
|
||||
use web_sys::PointerEvent;
|
||||
|
||||
use crate::core::{MessageResult, Mut, View, ViewId, ViewMarker, ViewPathTracker};
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
use wasm_bindgen::{JsCast, UnwrapThrowExt};
|
||||
|
||||
use crate::modifiers::{Attributes, Children, Classes, Modifier, Styles};
|
||||
use crate::{document, AnyPod, Pod, PodFlags, ViewCtx};
|
||||
use crate::{AnyPod, Pod, PodFlags, ViewCtx, document};
|
||||
|
||||
// Lazy access to attributes etc. to avoid allocating unnecessary memory when it isn't needed
|
||||
// Benchmarks have shown, that this can significantly increase performance and reduce memory usage...
|
||||
|
|
|
@ -5,7 +5,7 @@ use wasm_bindgen::JsCast as _;
|
|||
|
||||
use super::WithElementProps;
|
||||
use crate::modifiers::html_input_element::{Checked, DefaultChecked, Disabled, Multiple, Required};
|
||||
use crate::{props, FromWithContext, Pod, PodFlags, ViewCtx};
|
||||
use crate::{FromWithContext, Pod, PodFlags, ViewCtx, props};
|
||||
|
||||
/// Props specific to an input element.
|
||||
pub struct HtmlInputElement {
|
||||
|
@ -123,12 +123,12 @@ pub trait WithHtmlInputElementProps:
|
|||
{
|
||||
}
|
||||
impl<
|
||||
T: WithElementProps
|
||||
+ AsMut<Checked>
|
||||
+ AsMut<DefaultChecked>
|
||||
+ AsMut<Disabled>
|
||||
+ AsMut<Required>
|
||||
+ AsMut<Multiple>,
|
||||
> WithHtmlInputElementProps for T
|
||||
T: WithElementProps
|
||||
+ AsMut<Checked>
|
||||
+ AsMut<DefaultChecked>
|
||||
+ AsMut<Disabled>
|
||||
+ AsMut<Required>
|
||||
+ AsMut<Multiple>,
|
||||
> WithHtmlInputElementProps for T
|
||||
{
|
||||
}
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
use std::fmt::Write as _;
|
||||
use std::marker::PhantomData;
|
||||
|
||||
use peniko::{kurbo, Brush};
|
||||
use peniko::{Brush, kurbo};
|
||||
|
||||
use crate::core::{MessageResult, Mut, View, ViewElement, ViewId, ViewMarker};
|
||||
use crate::modifiers::{AttributeModifier, Attributes, Modifier, WithModifier};
|
||||
|
@ -86,11 +86,7 @@ fn opacity_attr_modifier(attr: &'static str, brush: &Brush) -> AttributeModifier
|
|||
let opacity = match brush {
|
||||
Brush::Solid(color) => {
|
||||
let a = color.components[3];
|
||||
if a < 1.0 {
|
||||
Some(a as f64)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
if a < 1.0 { Some(a as f64) } else { None }
|
||||
}
|
||||
_ => None,
|
||||
};
|
||||
|
@ -295,8 +291,8 @@ where
|
|||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use peniko::color::palette;
|
||||
use peniko::Brush;
|
||||
use peniko::color::palette;
|
||||
|
||||
use super::brush_to_string;
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@ use peniko::kurbo::{BezPath, Circle, Line, Rect};
|
|||
|
||||
use crate::core::{MessageResult, Mut, OrphanView, ViewId};
|
||||
use crate::modifiers::{Attributes, WithModifier};
|
||||
use crate::{DynMessage, FromWithContext, Pod, ViewCtx, SVG_NS};
|
||||
use crate::{DynMessage, FromWithContext, Pod, SVG_NS, ViewCtx};
|
||||
|
||||
fn create_element<R>(
|
||||
name: &str,
|
||||
|
|
|
@ -6,6 +6,6 @@
|
|||
pub(crate) mod common_attrs;
|
||||
pub(crate) mod kurbo_shape;
|
||||
|
||||
pub use common_attrs::{fill, stroke, Fill, Stroke};
|
||||
pub use common_attrs::{Fill, Stroke, fill, stroke};
|
||||
pub use peniko;
|
||||
pub use peniko::kurbo;
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
|
||||
use xilem_web::elements::html as el;
|
||||
use xilem_web::interfaces::{Element, HtmlButtonElement};
|
||||
use xilem_web::{document_body, App, DomFragment};
|
||||
use xilem_web::{App, DomFragment, document_body};
|
||||
|
||||
#[derive(Default)]
|
||||
struct AppState {
|
||||
|
@ -51,12 +51,12 @@ fn btn(
|
|||
}
|
||||
|
||||
/// And functions that return a sequence of views.
|
||||
fn huzzah(state: &mut AppState) -> impl DomFragment<AppState> {
|
||||
fn huzzah(state: &mut AppState) -> impl DomFragment<AppState> + use<> {
|
||||
(state.clicks >= 5).then_some("Huzzah, clicked at least 5 times")
|
||||
}
|
||||
|
||||
/// Even the root `app_logic` can return a sequence of views
|
||||
fn app_logic(state: &mut AppState) -> impl DomFragment<AppState> {
|
||||
fn app_logic(state: &mut AppState) -> impl DomFragment<AppState> + use<> {
|
||||
(
|
||||
el::span(format!("clicked {} times", state.clicks)).class(state.class),
|
||||
el::br(()),
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue