Merge branch 'master' into text-editor

This commit is contained in:
Héctor Ramón Jiménez 2023-10-27 03:58:45 +02:00
commit 6582387579
No known key found for this signature in database
GPG key ID: 7CC46565708259A7
109 changed files with 370 additions and 413 deletions

55
.cargo/config.toml Normal file
View file

@ -0,0 +1,55 @@
[alias]
lint = """
clippy --workspace --no-deps -- \
-D warnings \
-A clippy::type_complexity \
-D clippy::semicolon_if_nothing_returned \
-D clippy::trivially-copy-pass-by-ref \
-D clippy::default_trait_access \
-D clippy::match-wildcard-for-single-variants \
-D clippy::redundant-closure-for-method-calls \
-D clippy::filter_map_next \
-D clippy::manual_let_else \
-D clippy::unused_async \
-D clippy::from_over_into \
-D clippy::needless_borrow \
-D clippy::new_without_default \
-D clippy::useless_conversion
"""
#![allow(clippy::inherent_to_string, clippy::type_complexity)]
nitpick = """
clippy --workspace --no-deps -- \
-D warnings \
-D clippy::pedantic \
-A clippy::type_complexity \
-A clippy::must_use_candidate \
-A clippy::return_self_not_must_use \
-A clippy::needless_pass_by_value \
-A clippy::cast_precision_loss \
-A clippy::cast_sign_loss \
-A clippy::cast_possible_truncation \
-A clippy::match_same_arms \
-A clippy::missing-errors-doc \
-A clippy::missing-panics-doc \
-A clippy::cast_lossless \
-A clippy::doc_markdown \
-A clippy::items_after_statements \
-A clippy::too_many_lines \
-A clippy::module_name_repetitions \
-A clippy::if_not_else \
-A clippy::redundant_else \
-A clippy::used_underscore_binding \
-A clippy::cast_possible_wrap \
-A clippy::unnecessary_wraps \
-A clippy::struct-excessive-bools \
-A clippy::float-cmp \
-A clippy::single_match_else \
-A clippy::unreadable_literal \
-A clippy::explicit_deref_methods \
-A clippy::map_unwrap_or \
-A clippy::unnested_or_patterns \
-A clippy::similar_names \
-A clippy::unused_self
"""

View file

@ -12,6 +12,8 @@ jobs:
- name: Install cargo-audit - name: Install cargo-audit
run: cargo install cargo-audit run: cargo install cargo-audit
- uses: actions/checkout@master - uses: actions/checkout@master
- name: Resolve dependencies
run: cargo update
- name: Audit vulnerabilities - name: Audit vulnerabilities
run: cargo audit run: cargo audit

View file

@ -40,7 +40,6 @@ jobs:
- uses: actions/checkout@master - uses: actions/checkout@master
- name: Enable static CRT linkage - name: Enable static CRT linkage
run: | run: |
mkdir .cargo
echo '[target.x86_64-pc-windows-msvc]' >> .cargo/config echo '[target.x86_64-pc-windows-msvc]' >> .cargo/config
echo 'rustflags = ["-Ctarget-feature=+crt-static"]' >> .cargo/config echo 'rustflags = ["-Ctarget-feature=+crt-static"]' >> .cargo/config
- name: Run the application without starting the shell - name: Run the application without starting the shell

View file

@ -9,4 +9,4 @@ jobs:
components: clippy components: clippy
- uses: actions/checkout@master - uses: actions/checkout@master
- name: Check lints - name: Check lints
run: cargo clippy --workspace --all-features --all-targets --no-deps -- -D warnings run: cargo lint

1
.gitignore vendored
View file

@ -2,6 +2,5 @@ target/
pkg/ pkg/
**/*.rs.bk **/*.rs.bk
Cargo.lock Cargo.lock
.cargo/
dist/ dist/
traces/ traces/

View file

@ -1,7 +1,7 @@
#[cfg(feature = "palette")] #[cfg(feature = "palette")]
use palette::rgb::{Srgb, Srgba}; use palette::rgb::{Srgb, Srgba};
/// A color in the sRGB color space. /// A color in the `sRGB` color space.
#[derive(Debug, Clone, Copy, PartialEq, Default)] #[derive(Debug, Clone, Copy, PartialEq, Default)]
pub struct Color { pub struct Color {
/// Red component, 0.0 - 1.0 /// Red component, 0.0 - 1.0

View file

@ -293,7 +293,7 @@ where
} }
fn diff(&self, tree: &mut Tree) { fn diff(&self, tree: &mut Tree) {
self.widget.diff(tree) self.widget.diff(tree);
} }
fn width(&self) -> Length { fn width(&self) -> Length {
@ -418,7 +418,7 @@ where
viewport: &Rectangle, viewport: &Rectangle,
) { ) {
self.widget self.widget
.draw(tree, renderer, theme, style, layout, cursor, viewport) .draw(tree, renderer, theme, style, layout, cursor, viewport);
} }
fn mouse_interaction( fn mouse_interaction(
@ -508,7 +508,7 @@ where
) { ) {
self.element self.element
.widget .widget
.operate(state, layout, renderer, operation) .operate(state, layout, renderer, operation);
} }
fn on_event( fn on_event(

View file

@ -94,8 +94,8 @@ impl Linear {
mut self, mut self,
stops: impl IntoIterator<Item = ColorStop>, stops: impl IntoIterator<Item = ColorStop>,
) -> Self { ) -> Self {
for stop in stops.into_iter() { for stop in stops {
self = self.add_stop(stop.offset, stop.color) self = self.add_stop(stop.offset, stop.color);
} }
self self

View file

@ -4,7 +4,7 @@ pub struct Hasher(twox_hash::XxHash64);
impl core::hash::Hasher for Hasher { impl core::hash::Hasher for Hasher {
fn write(&mut self, bytes: &[u8]) { fn write(&mut self, bytes: &[u8]) {
self.0.write(bytes) self.0.write(bytes);
} }
fn finish(&self) -> u64 { fn finish(&self) -> u64 {

View file

@ -14,14 +14,8 @@
missing_debug_implementations, missing_debug_implementations,
// missing_docs, // missing_docs,
unused_results, unused_results,
clippy::extra_unused_lifetimes,
clippy::from_over_into,
clippy::needless_borrow,
clippy::new_without_default,
clippy::useless_conversion,
rustdoc::broken_intra_doc_links rustdoc::broken_intra_doc_links
)] )]
#![allow(clippy::inherent_to_string, clippy::type_complexity)]
pub mod alignment; pub mod alignment;
pub mod clipboard; pub mod clipboard;
pub mod event; pub mod event;

View file

@ -24,7 +24,7 @@ pub enum Kind {
} }
impl Kind { impl Kind {
fn next(&self) -> Kind { fn next(self) -> Kind {
match self { match self {
Kind::Single => Kind::Double, Kind::Single => Kind::Double,
Kind::Double => Kind::Triple, Kind::Double => Kind::Triple,

View file

@ -98,7 +98,7 @@ where
layout: Layout<'_>, layout: Layout<'_>,
cursor: mouse::Cursor, cursor: mouse::Cursor,
) { ) {
self.overlay.draw(renderer, theme, style, layout, cursor) self.overlay.draw(renderer, theme, style, layout, cursor);
} }
/// Applies a [`widget::Operation`] to the [`Element`]. /// Applies a [`widget::Operation`] to the [`Element`].
@ -205,7 +205,7 @@ where
state: &mut dyn widget::operation::TextInput, state: &mut dyn widget::operation::TextInput,
id: Option<&widget::Id>, id: Option<&widget::Id>,
) { ) {
self.operation.text_input(state, id) self.operation.text_input(state, id);
} }
fn custom(&mut self, state: &mut dyn Any, id: Option<&widget::Id>) { fn custom(&mut self, state: &mut dyn Any, id: Option<&widget::Id>) {
@ -262,7 +262,7 @@ where
layout: Layout<'_>, layout: Layout<'_>,
cursor: mouse::Cursor, cursor: mouse::Cursor,
) { ) {
self.content.draw(renderer, theme, style, layout, cursor) self.content.draw(renderer, theme, style, layout, cursor);
} }
fn is_over( fn is_over(

View file

@ -143,7 +143,7 @@ where
|(child, layout)| { |(child, layout)| {
child.operate(layout, renderer, operation); child.operate(layout, renderer, operation);
}, },
) );
}); });
} }

View file

@ -71,7 +71,7 @@ impl<'a, Message> Shell<'a, Message> {
if self.is_layout_invalid { if self.is_layout_invalid {
self.is_layout_invalid = false; self.is_layout_invalid = false;
f() f();
} }
} }

View file

@ -49,7 +49,7 @@ pub fn focus<T>(target: Id) -> impl Operation<T> {
_bounds: Rectangle, _bounds: Rectangle,
operate_on_children: &mut dyn FnMut(&mut dyn Operation<T>), operate_on_children: &mut dyn FnMut(&mut dyn Operation<T>),
) { ) {
operate_on_children(self) operate_on_children(self);
} }
} }
@ -85,7 +85,7 @@ where
_bounds: Rectangle, _bounds: Rectangle,
operate_on_children: &mut dyn FnMut(&mut dyn Operation<T>), operate_on_children: &mut dyn FnMut(&mut dyn Operation<T>),
) { ) {
operate_on_children(self) operate_on_children(self);
} }
fn finish(&self) -> Outcome<T> { fn finish(&self) -> Outcome<T> {
@ -132,7 +132,7 @@ pub fn focus_previous<T>() -> impl Operation<T> {
_bounds: Rectangle, _bounds: Rectangle,
operate_on_children: &mut dyn FnMut(&mut dyn Operation<T>), operate_on_children: &mut dyn FnMut(&mut dyn Operation<T>),
) { ) {
operate_on_children(self) operate_on_children(self);
} }
} }
@ -166,7 +166,7 @@ pub fn focus_next<T>() -> impl Operation<T> {
_bounds: Rectangle, _bounds: Rectangle,
operate_on_children: &mut dyn FnMut(&mut dyn Operation<T>), operate_on_children: &mut dyn FnMut(&mut dyn Operation<T>),
) { ) {
operate_on_children(self) operate_on_children(self);
} }
} }
@ -193,7 +193,7 @@ pub fn find_focused() -> impl Operation<Id> {
_bounds: Rectangle, _bounds: Rectangle,
operate_on_children: &mut dyn FnMut(&mut dyn Operation<Id>), operate_on_children: &mut dyn FnMut(&mut dyn Operation<Id>),
) { ) {
operate_on_children(self) operate_on_children(self);
} }
fn finish(&self) -> Outcome<Id> { fn finish(&self) -> Outcome<Id> {

View file

@ -26,7 +26,7 @@ pub fn snap_to<T>(target: Id, offset: RelativeOffset) -> impl Operation<T> {
_bounds: Rectangle, _bounds: Rectangle,
operate_on_children: &mut dyn FnMut(&mut dyn Operation<T>), operate_on_children: &mut dyn FnMut(&mut dyn Operation<T>),
) { ) {
operate_on_children(self) operate_on_children(self);
} }
fn scrollable( fn scrollable(
@ -60,7 +60,7 @@ pub fn scroll_to<T>(target: Id, offset: AbsoluteOffset) -> impl Operation<T> {
_bounds: Rectangle, _bounds: Rectangle,
operate_on_children: &mut dyn FnMut(&mut dyn Operation<T>), operate_on_children: &mut dyn FnMut(&mut dyn Operation<T>),
) { ) {
operate_on_children(self) operate_on_children(self);
} }
fn scrollable( fn scrollable(

View file

@ -38,7 +38,7 @@ pub fn move_cursor_to_front<T>(target: Id) -> impl Operation<T> {
_bounds: Rectangle, _bounds: Rectangle,
operate_on_children: &mut dyn FnMut(&mut dyn Operation<T>), operate_on_children: &mut dyn FnMut(&mut dyn Operation<T>),
) { ) {
operate_on_children(self) operate_on_children(self);
} }
} }
@ -68,7 +68,7 @@ pub fn move_cursor_to_end<T>(target: Id) -> impl Operation<T> {
_bounds: Rectangle, _bounds: Rectangle,
operate_on_children: &mut dyn FnMut(&mut dyn Operation<T>), operate_on_children: &mut dyn FnMut(&mut dyn Operation<T>),
) { ) {
operate_on_children(self) operate_on_children(self);
} }
} }
@ -99,7 +99,7 @@ pub fn move_cursor_to<T>(target: Id, position: usize) -> impl Operation<T> {
_bounds: Rectangle, _bounds: Rectangle,
operate_on_children: &mut dyn FnMut(&mut dyn Operation<T>), operate_on_children: &mut dyn FnMut(&mut dyn Operation<T>),
) { ) {
operate_on_children(self) operate_on_children(self);
} }
} }
@ -128,7 +128,7 @@ pub fn select_all<T>(target: Id) -> impl Operation<T> {
_bounds: Rectangle, _bounds: Rectangle,
operate_on_children: &mut dyn FnMut(&mut dyn Operation<T>), operate_on_children: &mut dyn FnMut(&mut dyn Operation<T>),
) { ) {
operate_on_children(self) operate_on_children(self);
} }
} }

View file

@ -218,9 +218,9 @@ where
size, size,
line_height, line_height,
font, font,
shaping,
horizontal_alignment, horizontal_alignment,
vertical_alignment, vertical_alignment,
shaping,
}); });
let size = limits.resolve(paragraph.min_bounds()); let size = limits.resolve(paragraph.min_bounds());

View file

@ -61,7 +61,7 @@ impl Tree {
Renderer: crate::Renderer, Renderer: crate::Renderer,
{ {
if self.tag == new.borrow().tag() { if self.tag == new.borrow().tag() {
new.borrow().diff(self) new.borrow().diff(self);
} else { } else {
*self = Self::new(new); *self = Self::new(new);
} }
@ -78,7 +78,7 @@ impl Tree {
new_children, new_children,
|tree, widget| tree.diff(widget.borrow()), |tree, widget| tree.diff(widget.borrow()),
|widget| Self::new(widget.borrow()), |widget| Self::new(widget.borrow()),
) );
} }
/// Reconciliates the children of the tree with the provided list of widgets using custom /// Reconciliates the children of the tree with the provided list of widgets using custom

View file

@ -3,7 +3,7 @@ use crate::Size;
use std::mem; use std::mem;
/// Builds an [`Icon`] from its RGBA pixels in the sRGB color space. /// Builds an [`Icon`] from its RGBA pixels in the `sRGB` color space.
pub fn from_rgba( pub fn from_rgba(
rgba: Vec<u8>, rgba: Vec<u8>,
width: u32, width: u32,

View file

@ -37,7 +37,7 @@ impl Application for Arc {
( (
Arc { Arc {
start: Instant::now(), start: Instant::now(),
cache: Default::default(), cache: Cache::default(),
}, },
Command::none(), Command::none(),
) )

View file

@ -81,7 +81,7 @@ mod bezier {
} }
pub fn request_redraw(&mut self) { pub fn request_redraw(&mut self) {
self.cache.clear() self.cache.clear();
} }
} }
@ -100,12 +100,9 @@ mod bezier {
bounds: Rectangle, bounds: Rectangle,
cursor: mouse::Cursor, cursor: mouse::Cursor,
) -> (event::Status, Option<Curve>) { ) -> (event::Status, Option<Curve>) {
let cursor_position = let Some(cursor_position) = cursor.position_in(bounds) else {
if let Some(position) = cursor.position_in(bounds) { return (event::Status::Ignored, None);
position };
} else {
return (event::Status::Ignored, None);
};
match event { match event {
Event::Mouse(mouse_event) => { Event::Mouse(mouse_event) => {

View file

@ -35,7 +35,7 @@ impl Application for Clock {
Clock { Clock {
now: time::OffsetDateTime::now_local() now: time::OffsetDateTime::now_local()
.unwrap_or_else(|_| time::OffsetDateTime::now_utc()), .unwrap_or_else(|_| time::OffsetDateTime::now_utc()),
clock: Default::default(), clock: Cache::default(),
}, },
Command::none(), Command::none(),
) )
@ -141,7 +141,7 @@ impl<Message> canvas::Program<Message, Renderer> for Clock {
frame.with_save(|frame| { frame.with_save(|frame| {
frame.rotate(hand_rotation(self.now.second(), 60)); frame.rotate(hand_rotation(self.now.second(), 60));
frame.stroke(&long_hand, thin_stroke()); frame.stroke(&long_hand, thin_stroke());
}) });
}); });
vec![clock] vec![clock]

View file

@ -123,7 +123,7 @@ impl Download {
| State::Errored { .. } => { | State::Errored { .. } => {
self.state = State::Downloading { progress: 0.0 }; self.state = State::Downloading { progress: 0.0 };
} }
_ => {} State::Downloading { .. } => {}
} }
} }

View file

@ -406,12 +406,9 @@ mod grid {
*interaction = Interaction::None; *interaction = Interaction::None;
} }
let cursor_position = let Some(cursor_position) = cursor.position_in(bounds) else {
if let Some(position) = cursor.position_in(bounds) { return (event::Status::Ignored, None);
position };
} else {
return (event::Status::Ignored, None);
};
let cell = Cell::at(self.project(cursor_position, bounds.size())); let cell = Cell::at(self.project(cursor_position, bounds.size()));
let is_populated = self.state.contains(&cell); let is_populated = self.state.contains(&cell);
@ -472,7 +469,7 @@ mod grid {
* (1.0 / self.scaling), * (1.0 / self.scaling),
)) ))
} }
_ => None, Interaction::None => None,
}; };
let event_status = match interaction { let event_status = match interaction {
@ -610,8 +607,7 @@ mod grid {
frame.fill_text(Text { frame.fill_text(Text {
content: format!( content: format!(
"{} cell{} @ {:?} ({})", "{cell_count} cell{} @ {:?} ({})",
cell_count,
if cell_count == 1 { "" } else { "s" }, if cell_count == 1 { "" } else { "s" },
self.last_tick_duration, self.last_tick_duration,
self.last_queued_ticks self.last_queued_ticks
@ -677,7 +673,7 @@ mod grid {
Interaction::None if cursor.is_over(bounds) => { Interaction::None if cursor.is_over(bounds) => {
mouse::Interaction::Crosshair mouse::Interaction::Crosshair
} }
_ => mouse::Interaction::default(), Interaction::None => mouse::Interaction::default(),
} }
} }
} }
@ -793,7 +789,7 @@ mod grid {
} }
} }
for (cell, amount) in adjacent_life.iter() { for (cell, amount) in &adjacent_life {
match amount { match amount {
2 => {} 2 => {}
3 => { 3 => {

View file

@ -19,7 +19,7 @@ impl Controls {
pub fn new() -> Controls { pub fn new() -> Controls {
Controls { Controls {
background_color: Color::BLACK, background_color: Color::BLACK,
text: Default::default(), text: String::default(),
} }
} }

View file

@ -254,7 +254,7 @@ pub fn main() -> Result<(), Box<dyn std::error::Error>> {
{ {
// We clear the frame // We clear the frame
let mut render_pass = scene.clear( let mut render_pass = Scene::clear(
&view, &view,
&mut encoder, &mut encoder,
program.background_color(), program.background_color(),

View file

@ -16,7 +16,6 @@ impl Scene {
} }
pub fn clear<'a>( pub fn clear<'a>(
&self,
target: &'a wgpu::TextureView, target: &'a wgpu::TextureView,
encoder: &'a mut wgpu::CommandEncoder, encoder: &'a mut wgpu::CommandEncoder,
background_color: Color, background_color: Color,

View file

@ -27,7 +27,7 @@ impl Default for App {
.into_iter() .into_iter()
.map(From::from) .map(From::from)
.collect(), .collect(),
input: Default::default(), input: String::default(),
order: Order::Ascending, order: Order::Ascending,
} }
} }
@ -107,7 +107,7 @@ impl From<&str> for Item {
fn from(s: &str) -> Self { fn from(s: &str) -> Self {
Self { Self {
name: s.to_owned(), name: s.to_owned(),
color: Default::default(), color: Color::default(),
} }
} }
} }

View file

@ -228,7 +228,9 @@ mod modal {
use iced::alignment::Alignment; use iced::alignment::Alignment;
use iced::event; use iced::event;
use iced::mouse; use iced::mouse;
use iced::{Color, Element, Event, Length, Point, Rectangle, Size}; use iced::{
BorderRadius, Color, Element, Event, Length, Point, Rectangle, Size,
};
/// A widget that centers a modal element over some base element /// A widget that centers a modal element over some base element
pub struct Modal<'a, Message, Renderer> { pub struct Modal<'a, Message, Renderer> {
@ -474,7 +476,7 @@ mod modal {
renderer.fill_quad( renderer.fill_quad(
renderer::Quad { renderer::Quad {
bounds: layout.bounds(), bounds: layout.bounds(),
border_radius: Default::default(), border_radius: BorderRadius::default(),
border_width: 0.0, border_width: 0.0,
border_color: Color::TRANSPARENT, border_color: Color::TRANSPARENT,
}, },

View file

@ -61,11 +61,8 @@ impl Application for Example {
fn update(&mut self, message: Message) -> Command<Message> { fn update(&mut self, message: Message) -> Command<Message> {
match message { match message {
Message::Split(axis, pane) => { Message::Split(axis, pane) => {
let result = self.panes.split( let result =
axis, self.panes.split(axis, pane, Pane::new(self.panes_created));
&pane,
Pane::new(self.panes_created),
);
if let Some((pane, _)) = result { if let Some((pane, _)) = result {
self.focus = Some(pane); self.focus = Some(pane);
@ -77,7 +74,7 @@ impl Application for Example {
if let Some(pane) = self.focus { if let Some(pane) = self.focus {
let result = self.panes.split( let result = self.panes.split(
axis, axis,
&pane, pane,
Pane::new(self.panes_created), Pane::new(self.panes_created),
); );
@ -90,8 +87,7 @@ impl Application for Example {
} }
Message::FocusAdjacent(direction) => { Message::FocusAdjacent(direction) => {
if let Some(pane) = self.focus { if let Some(pane) = self.focus {
if let Some(adjacent) = if let Some(adjacent) = self.panes.adjacent(pane, direction)
self.panes.adjacent(&pane, direction)
{ {
self.focus = Some(adjacent); self.focus = Some(adjacent);
} }
@ -101,37 +97,34 @@ impl Application for Example {
self.focus = Some(pane); self.focus = Some(pane);
} }
Message::Resized(pane_grid::ResizeEvent { split, ratio }) => { Message::Resized(pane_grid::ResizeEvent { split, ratio }) => {
self.panes.resize(&split, ratio); self.panes.resize(split, ratio);
} }
Message::Dragged(pane_grid::DragEvent::Dropped { Message::Dragged(pane_grid::DragEvent::Dropped {
pane, pane,
target, target,
}) => { }) => {
self.panes.drop(&pane, target); self.panes.drop(pane, target);
} }
Message::Dragged(_) => {} Message::Dragged(_) => {}
Message::TogglePin(pane) => { Message::TogglePin(pane) => {
if let Some(Pane { is_pinned, .. }) = self.panes.get_mut(&pane) if let Some(Pane { is_pinned, .. }) = self.panes.get_mut(pane) {
{
*is_pinned = !*is_pinned; *is_pinned = !*is_pinned;
} }
} }
Message::Maximize(pane) => self.panes.maximize(&pane), Message::Maximize(pane) => self.panes.maximize(pane),
Message::Restore => { Message::Restore => {
self.panes.restore(); self.panes.restore();
} }
Message::Close(pane) => { Message::Close(pane) => {
if let Some((_, sibling)) = self.panes.close(&pane) { if let Some((_, sibling)) = self.panes.close(pane) {
self.focus = Some(sibling); self.focus = Some(sibling);
} }
} }
Message::CloseFocused => { Message::CloseFocused => {
if let Some(pane) = self.focus { if let Some(pane) = self.focus {
if let Some(Pane { is_pinned, .. }) = self.panes.get(&pane) if let Some(Pane { is_pinned, .. }) = self.panes.get(pane) {
{
if !is_pinned { if !is_pinned {
if let Some((_, sibling)) = self.panes.close(&pane) if let Some((_, sibling)) = self.panes.close(pane) {
{
self.focus = Some(sibling); self.focus = Some(sibling);
} }
} }

View file

@ -7,7 +7,11 @@ publish = false
[dependencies] [dependencies]
iced.workspace = true iced.workspace = true
iced.features = ["debug", "image", "advanced"] iced.features = ["debug", "image", "advanced", "tokio"]
image.workspace = true
image.features = ["png"]
tokio.workspace = true
image = { workspace = true, features = ["png"]}
tracing-subscriber = "0.3" tracing-subscriber = "0.3"

View file

@ -184,8 +184,8 @@ impl Application for Example {
.align_items(Alignment::Center); .align_items(Alignment::Center);
if let Some(crop_error) = &self.crop_error { if let Some(crop_error) = &self.crop_error {
crop_controls = crop_controls crop_controls =
.push(text(format!("Crop error! \n{}", crop_error))); crop_controls.push(text(format!("Crop error! \n{crop_error}")));
} }
let mut controls = column![ let mut controls = column![
@ -221,9 +221,9 @@ impl Application for Example {
if let Some(png_result) = &self.saved_png_path { if let Some(png_result) = &self.saved_png_path {
let msg = match png_result { let msg = match png_result {
Ok(path) => format!("Png saved as: {:?}!", path), Ok(path) => format!("Png saved as: {path:?}!"),
Err(msg) => { Err(msg) => {
format!("Png could not be saved due to:\n{:?}", msg) format!("Png could not be saved due to:\n{msg:?}")
} }
}; };
@ -273,15 +273,20 @@ impl Application for Example {
async fn save_to_png(screenshot: Screenshot) -> Result<String, PngError> { async fn save_to_png(screenshot: Screenshot) -> Result<String, PngError> {
let path = "screenshot.png".to_string(); let path = "screenshot.png".to_string();
img::save_buffer(
&path, tokio::task::spawn_blocking(move || {
&screenshot.bytes, img::save_buffer(
screenshot.size.width, &path,
screenshot.size.height, &screenshot.bytes,
ColorType::Rgba8, screenshot.size.width,
) screenshot.size.height,
.map(|_| path) ColorType::Rgba8,
.map_err(|err| PngError(format!("{:?}", err))) )
.map(|_| path)
.map_err(|err| PngError(format!("{err:?}")))
})
.await
.expect("Blocking task to finish")
} }
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
@ -293,10 +298,7 @@ fn numeric_input(
) -> Element<'_, Option<u32>> { ) -> Element<'_, Option<u32>> {
text_input( text_input(
placeholder, placeholder,
&value &value.as_ref().map(ToString::to_string).unwrap_or_default(),
.as_ref()
.map(ToString::to_string)
.unwrap_or_else(String::new),
) )
.on_input(move |text| { .on_input(move |text| {
if text.is_empty() { if text.is_empty() {

View file

@ -389,14 +389,14 @@ impl scrollable::StyleSheet for ScrollbarCustomStyle {
background: style background: style
.active(&theme::Scrollable::default()) .active(&theme::Scrollable::default())
.background, .background,
border_radius: 0.0.into(), border_radius: 2.0.into(),
border_width: 0.0, border_width: 0.0,
border_color: Default::default(), border_color: Color::default(),
scroller: Scroller { scroller: Scroller {
color: Color::from_rgb8(250, 85, 134), color: Color::from_rgb8(250, 85, 134),
border_radius: 0.0.into(), border_radius: 2.0.into(),
border_width: 0.0, border_width: 0.0,
border_color: Default::default(), border_color: Color::default(),
}, },
} }
} else { } else {

View file

@ -108,10 +108,7 @@ impl canvas::Program<Message> for SierpinskiGraph {
bounds: Rectangle, bounds: Rectangle,
cursor: mouse::Cursor, cursor: mouse::Cursor,
) -> (event::Status, Option<Message>) { ) -> (event::Status, Option<Message>) {
let cursor_position = if let Some(position) = cursor.position_in(bounds) let Some(cursor_position) = cursor.position_in(bounds) else {
{
position
} else {
return (event::Status::Ignored, None); return (event::Status::Ignored, None);
}; };

View file

@ -117,8 +117,8 @@ impl State {
let (width, height) = window::Settings::default().size; let (width, height) = window::Settings::default().size;
State { State {
space_cache: Default::default(), space_cache: canvas::Cache::default(),
system_cache: Default::default(), system_cache: canvas::Cache::default(),
start: now, start: now,
now, now,
stars: Self::generate_stars(width, height), stars: Self::generate_stars(width, height),

View file

@ -105,8 +105,8 @@ impl Application for Example {
ByteSize::kb(information.memory_total).to_string(); ByteSize::kb(information.memory_total).to_string();
let memory_total = text(format!( let memory_total = text(format!(
"Memory (total): {} kb ({})", "Memory (total): {} kb ({memory_readable})",
information.memory_total, memory_readable information.memory_total,
)); ));
let memory_text = if let Some(memory_used) = let memory_text = if let Some(memory_used) =

View file

@ -639,7 +639,7 @@ mod toast {
child child
.as_widget() .as_widget()
.operate(state, layout, renderer, operation); .operate(state, layout, renderer, operation);
}) });
}); });
} }

View file

@ -415,8 +415,7 @@ fn view_controls(tasks: &[Task], current_filter: Filter) -> Element<Message> {
row![ row![
text(format!( text(format!(
"{} {} left", "{tasks_left} {} left",
tasks_left,
if tasks_left == 1 { "task" } else { "tasks" } if tasks_left == 1 { "task" } else { "tasks" }
)) ))
.width(Length::Fill), .width(Length::Fill),
@ -444,7 +443,7 @@ pub enum Filter {
} }
impl Filter { impl Filter {
fn matches(&self, task: &Task) -> bool { fn matches(self, task: &Task) -> bool {
match self { match self {
Filter::All => true, Filter::All => true,
Filter::Active => !task.completed, Filter::Active => !task.completed,

View file

@ -40,7 +40,7 @@ impl Sandbox for Example {
Position::Right => Position::FollowCursor, Position::Right => Position::FollowCursor,
}; };
self.position = position self.position = position;
} }
} }
} }

View file

@ -285,7 +285,7 @@ impl<'a> Step {
is_showing_icon, .. is_showing_icon, ..
} = self } = self
{ {
*is_showing_icon = toggle *is_showing_icon = toggle;
} }
} }
}; };
@ -482,7 +482,7 @@ impl<'a> Step {
column( column(
Language::all() Language::all()
.iter() .iter()
.cloned() .copied()
.map(|language| { .map(|language| {
radio( radio(
language, language,

View file

@ -94,7 +94,7 @@ impl Application for Example {
data_row( data_row(
label, label,
match bounds { match bounds {
Some(bounds) => format!("{:?}", bounds), Some(bounds) => format!("{bounds:?}"),
None => "not visible".to_string(), None => "not visible".to_string(),
}, },
if bounds if bounds

View file

@ -47,10 +47,7 @@ async fn user_connected(ws: WebSocket) {
}); });
while let Some(result) = user_ws_rx.next().await { while let Some(result) = user_ws_rx.next().await {
let msg = match result { let Ok(msg) = result else { break };
Ok(msg) => msg,
Err(_) => break,
};
let _ = tx.send(msg).await; let _ = tx.send(msg).await;
} }

View file

@ -9,14 +9,8 @@
missing_debug_implementations, missing_debug_implementations,
missing_docs, missing_docs,
unused_results, unused_results,
clippy::extra_unused_lifetimes,
clippy::from_over_into,
clippy::needless_borrow,
clippy::new_without_default,
clippy::useless_conversion,
rustdoc::broken_intra_doc_links rustdoc::broken_intra_doc_links
)] )]
#![allow(clippy::inherent_to_string, clippy::type_complexity)]
#![cfg_attr(docsrs, feature(doc_auto_cfg))] #![cfg_attr(docsrs, feature(doc_auto_cfg))]
pub use futures; pub use futures;
pub use iced_core as core; pub use iced_core as core;

View file

@ -25,7 +25,7 @@ pub type EventStream = BoxStream<(Event, event::Status)>;
/// A [`Subscription`] is normally provided to some runtime, like a `Command`, /// A [`Subscription`] is normally provided to some runtime, like a `Command`,
/// and it will generate events as long as the user keeps requesting it. /// and it will generate events as long as the user keeps requesting it.
/// ///
/// For instance, you can use a [`Subscription`] to listen to a WebSocket /// For instance, you can use a [`Subscription`] to listen to a `WebSocket`
/// connection, keyboard presses, mouse events, time ticks, etc. /// connection, keyboard presses, mouse events, time ticks, etc.
#[must_use = "`Subscription` must be returned to runtime to take effect"] #[must_use = "`Subscription` must be returned to runtime to take effect"]
pub struct Subscription<Message> { pub struct Subscription<Message> {
@ -355,7 +355,7 @@ where
/// } /// }
/// ``` /// ```
/// ///
/// Check out the [`websocket`] example, which showcases this pattern to maintain a WebSocket /// Check out the [`websocket`] example, which showcases this pattern to maintain a `WebSocket`
/// connection open. /// connection open.
/// ///
/// [`websocket`]: https://github.com/iced-rs/iced/tree/0.10/examples/websocket /// [`websocket`]: https://github.com/iced-rs/iced/tree/0.10/examples/websocket

View file

@ -147,8 +147,7 @@ impl Tracker {
.for_each(|listener| { .for_each(|listener| {
if let Err(error) = listener.try_send((event.clone(), status)) { if let Err(error) = listener.try_send((event.clone(), status)) {
log::warn!( log::warn!(
"Error sending event to subscription: {:?}", "Error sending event to subscription: {error:?}"
error
); );
} }
}); });

View file

@ -61,7 +61,7 @@ pub trait Compositor: Sized {
) -> Result<(), SurfaceError>; ) -> Result<(), SurfaceError>;
/// Screenshots the current [`Renderer`] primitives to an offscreen texture, and returns the bytes of /// Screenshots the current [`Renderer`] primitives to an offscreen texture, and returns the bytes of
/// the texture ordered as `RGBA` in the sRGB color space. /// the texture ordered as `RGBA` in the `sRGB` color space.
/// ///
/// [`Renderer`]: Self::Renderer /// [`Renderer`]: Self::Renderer
fn screenshot<T: AsRef<str>>( fn screenshot<T: AsRef<str>>(

View file

@ -174,7 +174,7 @@ impl Builder {
/// the starting point. /// the starting point.
#[inline] #[inline]
pub fn close(&mut self) { pub fn close(&mut self) {
self.raw.close() self.raw.close();
} }
/// Builds the [`Path`] of this [`Builder`]. /// Builds the [`Path`] of this [`Builder`].

View file

@ -87,8 +87,8 @@ impl Linear {
mut self, mut self,
stops: impl IntoIterator<Item = ColorStop>, stops: impl IntoIterator<Item = ColorStop>,
) -> Self { ) -> Self {
for stop in stops.into_iter() { for stop in stops {
self = self.add_stop(stop.offset, stop.color) self = self.add_stop(stop.offset, stop.color);
} }
self self

View file

@ -79,7 +79,7 @@ impl Operation {
use image::imageops; use image::imageops;
if self.contains(Self::FLIP_DIAGONALLY) { if self.contains(Self::FLIP_DIAGONALLY) {
imageops::flip_vertical_in_place(&mut image) imageops::flip_vertical_in_place(&mut image);
} }
if self.contains(Self::ROTATE_180) { if self.contains(Self::ROTATE_180) {

View file

@ -13,14 +13,8 @@
//missing_docs, //missing_docs,
unsafe_code, unsafe_code,
unused_results, unused_results,
clippy::extra_unused_lifetimes,
clippy::from_over_into,
clippy::needless_borrow,
clippy::new_without_default,
clippy::useless_conversion,
rustdoc::broken_intra_doc_links rustdoc::broken_intra_doc_links
)] )]
#![allow(clippy::inherent_to_string, clippy::type_complexity)]
#![cfg_attr(docsrs, feature(doc_auto_cfg))] #![cfg_attr(docsrs, feature(doc_auto_cfg))]
mod antialiasing; mod antialiasing;
mod error; mod error;

View file

@ -216,7 +216,7 @@ where
} }
fn draw(&mut self, handle: image::Handle, bounds: Rectangle) { fn draw(&mut self, handle: image::Handle, bounds: Rectangle) {
self.primitives.push(Primitive::Image { handle, bounds }) self.primitives.push(Primitive::Image { handle, bounds });
} }
} }
@ -238,6 +238,6 @@ where
handle, handle,
color, color,
bounds, bounds,
}) });
} }
} }

View file

@ -186,7 +186,7 @@ impl Theme {
} }
} }
fn key(&self) -> &'static str { fn key(self) -> &'static str {
match self { match self {
Theme::SolarizedDark => "Solarized (dark)", Theme::SolarizedDark => "Solarized (dark)",
Theme::Base16Mocha => "base16-mocha.dark", Theme::Base16Mocha => "base16-mocha.dark",

View file

@ -35,7 +35,7 @@ impl Cache {
/// Creates a new empty [`Cache`]. /// Creates a new empty [`Cache`].
pub fn new() -> Self { pub fn new() -> Self {
Cache { Cache {
state: Default::default(), state: RefCell::default(),
} }
} }

View file

@ -1,15 +1,5 @@
#![forbid(rust_2018_idioms)] #![forbid(rust_2018_idioms)]
#![deny( #![deny(unsafe_code, unused_results, rustdoc::broken_intra_doc_links)]
unsafe_code,
unused_results,
clippy::extra_unused_lifetimes,
clippy::from_over_into,
clippy::needless_borrow,
clippy::new_without_default,
clippy::useless_conversion,
rustdoc::broken_intra_doc_links
)]
#![allow(clippy::inherent_to_string, clippy::type_complexity)]
#![cfg_attr(docsrs, feature(doc_auto_cfg))] #![cfg_attr(docsrs, feature(doc_auto_cfg))]
pub mod compositor; pub mod compositor;
@ -59,7 +49,7 @@ impl<T> Renderer<T> {
pub fn draw_mesh(&mut self, mesh: Mesh) { pub fn draw_mesh(&mut self, mesh: Mesh) {
match self { match self {
Self::TinySkia(_) => { Self::TinySkia(_) => {
log::warn!("Unsupported mesh primitive: {:?}", mesh) log::warn!("Unsupported mesh primitive: {mesh:?}");
} }
#[cfg(feature = "wgpu")] #[cfg(feature = "wgpu")]
Self::Wgpu(renderer) => { Self::Wgpu(renderer) => {
@ -241,7 +231,7 @@ impl<T> crate::core::svg::Renderer for Renderer<T> {
color: Option<crate::core::Color>, color: Option<crate::core::Color>,
bounds: Rectangle, bounds: Rectangle,
) { ) {
delegate!(self, renderer, renderer.draw(handle, color, bounds)) delegate!(self, renderer, renderer.draw(handle, color, bounds));
} }
} }
@ -257,7 +247,7 @@ impl<T> crate::graphics::geometry::Renderer for Renderer<T> {
crate::Geometry::TinySkia(primitive) => { crate::Geometry::TinySkia(primitive) => {
renderer.draw_primitive(primitive); renderer.draw_primitive(primitive);
} }
_ => unreachable!(), crate::Geometry::Wgpu(_) => unreachable!(),
} }
} }
} }
@ -268,7 +258,7 @@ impl<T> crate::graphics::geometry::Renderer for Renderer<T> {
crate::Geometry::Wgpu(primitive) => { crate::Geometry::Wgpu(primitive) => {
renderer.draw_primitive(primitive); renderer.draw_primitive(primitive);
} }
_ => unreachable!(), crate::Geometry::TinySkia(_) => unreachable!(),
} }
} }
} }

View file

@ -40,9 +40,9 @@ impl<T> Command<T> {
/// Creates a [`Command`] that performs the action of the given future. /// Creates a [`Command`] that performs the action of the given future.
pub fn perform<A>( pub fn perform<A>(
future: impl Future<Output = T> + 'static + MaybeSend, future: impl Future<Output = A> + 'static + MaybeSend,
f: impl FnOnce(T) -> A + 'static + MaybeSend, f: impl FnOnce(A) -> T + 'static + MaybeSend,
) -> Command<A> { ) -> Command<T> {
use iced_futures::futures::FutureExt; use iced_futures::futures::FutureExt;
Command::single(Action::Future(Box::pin(future.map(f)))) Command::single(Action::Future(Box::pin(future.map(f))))

View file

@ -75,7 +75,7 @@ impl Debug {
} }
pub fn startup_finished(&mut self) { pub fn startup_finished(&mut self) {
self.startup_duration = time::Instant::now() - self.startup_start; self.startup_duration = self.startup_start.elapsed();
} }
pub fn update_started(&mut self) { pub fn update_started(&mut self) {
@ -83,8 +83,7 @@ impl Debug {
} }
pub fn update_finished(&mut self) { pub fn update_finished(&mut self) {
self.update_durations self.update_durations.push(self.update_start.elapsed());
.push(time::Instant::now() - self.update_start);
} }
pub fn view_started(&mut self) { pub fn view_started(&mut self) {
@ -92,8 +91,7 @@ impl Debug {
} }
pub fn view_finished(&mut self) { pub fn view_finished(&mut self) {
self.view_durations self.view_durations.push(self.view_start.elapsed());
.push(time::Instant::now() - self.view_start);
} }
pub fn layout_started(&mut self) { pub fn layout_started(&mut self) {
@ -101,8 +99,7 @@ impl Debug {
} }
pub fn layout_finished(&mut self) { pub fn layout_finished(&mut self) {
self.layout_durations self.layout_durations.push(self.layout_start.elapsed());
.push(time::Instant::now() - self.layout_start);
} }
pub fn event_processing_started(&mut self) { pub fn event_processing_started(&mut self) {
@ -110,8 +107,7 @@ impl Debug {
} }
pub fn event_processing_finished(&mut self) { pub fn event_processing_finished(&mut self) {
self.event_durations self.event_durations.push(self.event_start.elapsed());
.push(time::Instant::now() - self.event_start);
} }
pub fn draw_started(&mut self) { pub fn draw_started(&mut self) {
@ -119,8 +115,7 @@ impl Debug {
} }
pub fn draw_finished(&mut self) { pub fn draw_finished(&mut self) {
self.draw_durations self.draw_durations.push(self.draw_start.elapsed());
.push(time::Instant::now() - self.draw_start);
} }
pub fn render_started(&mut self) { pub fn render_started(&mut self) {
@ -128,8 +123,7 @@ impl Debug {
} }
pub fn render_finished(&mut self) { pub fn render_finished(&mut self) {
self.render_durations self.render_durations.push(self.render_start.elapsed());
.push(time::Instant::now() - self.render_start);
} }
pub fn log_message<Message: std::fmt::Debug>(&mut self, message: &Message) { pub fn log_message<Message: std::fmt::Debug>(&mut self, message: &Message) {

View file

@ -13,11 +13,6 @@
missing_debug_implementations, missing_debug_implementations,
missing_docs, missing_docs,
unused_results, unused_results,
clippy::extra_unused_lifetimes,
clippy::from_over_into,
clippy::needless_borrow,
clippy::new_without_default,
clippy::useless_conversion,
rustdoc::broken_intra_doc_links rustdoc::broken_intra_doc_links
)] )]
#![cfg_attr(docsrs, feature(doc_auto_cfg))] #![cfg_attr(docsrs, feature(doc_auto_cfg))]

View file

@ -164,7 +164,7 @@ where
} }
} }
recurse(&mut self.overlay, layout, renderer, operation) recurse(&mut self.overlay, layout, renderer, operation);
} }
/// Processes a runtime [`Event`]. /// Processes a runtime [`Event`].

View file

@ -200,7 +200,7 @@ where
match operation.finish() { match operation.finish() {
operation::Outcome::None => {} operation::Outcome::None => {}
operation::Outcome::Some(message) => { operation::Outcome::Some(message) => {
self.queued_messages.push(message) self.queued_messages.push(message);
} }
operation::Outcome::Chain(next) => { operation::Outcome::Chain(next) => {
current_operation = Some(next); current_operation = Some(next);

View file

@ -6,7 +6,7 @@ use std::sync::Arc;
/// Data of a screenshot, captured with `window::screenshot()`. /// Data of a screenshot, captured with `window::screenshot()`.
/// ///
/// The `bytes` of this screenshot will always be ordered as `RGBA` in the sRGB color space. /// The `bytes` of this screenshot will always be ordered as `RGBA` in the `sRGB` color space.
#[derive(Clone)] #[derive(Clone)]
pub struct Screenshot { pub struct Screenshot {
/// The bytes of the [`Screenshot`]. /// The bytes of the [`Screenshot`].

View file

@ -156,14 +156,8 @@
missing_debug_implementations, missing_debug_implementations,
missing_docs, missing_docs,
unused_results, unused_results,
clippy::extra_unused_lifetimes,
clippy::from_over_into,
clippy::needless_borrow,
clippy::new_without_default,
clippy::useless_conversion,
rustdoc::broken_intra_doc_links rustdoc::broken_intra_doc_links
)] )]
#![allow(clippy::inherent_to_string, clippy::type_complexity)]
#![cfg_attr(docsrs, feature(doc_auto_cfg))] #![cfg_attr(docsrs, feature(doc_auto_cfg))]
use iced_widget::graphics; use iced_widget::graphics;
use iced_widget::renderer; use iced_widget::renderer;

View file

@ -83,10 +83,10 @@ where
fn default() -> Self { fn default() -> Self {
Self { Self {
id: None, id: None,
window: Default::default(), window: window::Settings::default(),
flags: Default::default(), flags: Default::default(),
fonts: Default::default(), fonts: Vec::new(),
default_font: Default::default(), default_font: Font::default(),
default_text_size: Pixels(16.0), default_text_size: Pixels(16.0),
antialiasing: false, antialiasing: false,
exit_on_close_request: true, exit_on_close_request: true,

View file

@ -52,7 +52,7 @@ impl Default for Settings {
transparent: false, transparent: false,
level: Level::default(), level: Level::default(),
icon: None, icon: None,
platform_specific: Default::default(), platform_specific: PlatformSpecific::default(),
} }
} }
} }

View file

@ -10,16 +10,10 @@
#![forbid(unsafe_code, rust_2018_idioms)] #![forbid(unsafe_code, rust_2018_idioms)]
#![deny( #![deny(
unused_results, unused_results,
clippy::extra_unused_lifetimes,
clippy::from_over_into,
clippy::needless_borrow,
clippy::new_without_default,
clippy::useless_conversion,
// missing_docs, // missing_docs,
unused_results, unused_results,
rustdoc::broken_intra_doc_links rustdoc::broken_intra_doc_links
)] )]
#![allow(clippy::inherent_to_string, clippy::type_complexity)]
pub use iced_core as core; pub use iced_core as core;
pub mod application; pub mod application;

View file

@ -47,7 +47,7 @@ impl FillMode {
/// ///
/// # Returns /// # Returns
/// ///
/// * (starting_offset, length) /// * (`starting_offset`, `length`)
pub fn fill(&self, space: f32) -> (f32, f32) { pub fn fill(&self, space: f32) -> (f32, f32) {
match *self { match *self {
FillMode::Full => (0.0, space), FillMode::Full => (0.0, space),

View file

@ -394,7 +394,7 @@ impl container::StyleSheet for Theme {
fn appearance(&self, style: &Self::Style) -> container::Appearance { fn appearance(&self, style: &Self::Style) -> container::Appearance {
match style { match style {
Container::Transparent => Default::default(), Container::Transparent => container::Appearance::default(),
Container::Box => { Container::Box => {
let palette = self.extended_palette(); let palette = self.extended_palette();
@ -905,7 +905,7 @@ impl svg::StyleSheet for Theme {
fn appearance(&self, style: &Self::Style) -> svg::Appearance { fn appearance(&self, style: &Self::Style) -> svg::Appearance {
match style { match style {
Svg::Default => Default::default(), Svg::Default => svg::Appearance::default(),
Svg::Custom(custom) => custom.appearance(self), Svg::Custom(custom) => custom.appearance(self),
} }
} }
@ -1054,7 +1054,7 @@ impl text::StyleSheet for Theme {
fn appearance(&self, style: Self::Style) -> text::Appearance { fn appearance(&self, style: Self::Style) -> text::Appearance {
match style { match style {
Text::Default => Default::default(), Text::Default => text::Appearance::default(),
Text::Color(c) => text::Appearance { color: Some(c) }, Text::Color(c) => text::Appearance { color: Some(c) },
} }
} }

View file

@ -467,8 +467,7 @@ impl Backend {
#[cfg(not(feature = "image"))] #[cfg(not(feature = "image"))]
Primitive::Image { .. } => { Primitive::Image { .. } => {
log::warn!( log::warn!(
"Unsupported primitive in `iced_tiny_skia`: {:?}", "Unsupported primitive in `iced_tiny_skia`: {primitive:?}",
primitive
); );
} }
#[cfg(feature = "svg")] #[cfg(feature = "svg")]
@ -497,8 +496,7 @@ impl Backend {
#[cfg(not(feature = "svg"))] #[cfg(not(feature = "svg"))]
Primitive::Svg { .. } => { Primitive::Svg { .. } => {
log::warn!( log::warn!(
"Unsupported primitive in `iced_tiny_skia`: {:?}", "Unsupported primitive in `iced_tiny_skia`: {primitive:?}",
primitive
); );
} }
Primitive::Custom(primitive::Custom::Fill { Primitive::Custom(primitive::Custom::Fill {

View file

@ -180,9 +180,9 @@ fn convert_path(path: &Path) -> Option<tiny_skia::Path> {
use iced_graphics::geometry::path::lyon_path; use iced_graphics::geometry::path::lyon_path;
let mut builder = tiny_skia::PathBuilder::new(); let mut builder = tiny_skia::PathBuilder::new();
let mut last_point = Default::default(); let mut last_point = lyon_path::math::Point::default();
for event in path.raw().iter() { for event in path.raw() {
match event { match event {
lyon_path::Event::Begin { at } => { lyon_path::Event::Begin { at } => {
builder.move_to(at.x, at.y); builder.move_to(at.x, at.y);

View file

@ -1,15 +1,5 @@
#![forbid(rust_2018_idioms)] #![forbid(rust_2018_idioms)]
#![deny( #![deny(unsafe_code, unused_results, rustdoc::broken_intra_doc_links)]
unsafe_code,
unused_results,
clippy::extra_unused_lifetimes,
clippy::from_over_into,
clippy::needless_borrow,
clippy::new_without_default,
clippy::useless_conversion,
rustdoc::broken_intra_doc_links
)]
#![allow(clippy::inherent_to_string, clippy::type_complexity)]
#![cfg_attr(docsrs, feature(doc_auto_cfg))] #![cfg_attr(docsrs, feature(doc_auto_cfg))]
pub mod window; pub mod window;

View file

@ -172,9 +172,9 @@ impl Cache {
for pixel in for pixel in
bytemuck::cast_slice_mut::<u8, u32>(image.data_mut()) bytemuck::cast_slice_mut::<u8, u32>(image.data_mut())
{ {
*pixel = *pixel & 0xFF00FF00 *pixel = *pixel & 0xFF00_FF00
| ((0x000000FF & *pixel) << 16) | ((0x0000_00FF & *pixel) << 16)
| ((0x00FF0000 & *pixel) >> 16); | ((0x00FF_0000 & *pixel) >> 16);
} }
} }

View file

@ -87,7 +87,7 @@ impl<T: bytemuck::Pod> Buffer<T> {
/// Clears any temporary data (i.e. offsets) from the buffer. /// Clears any temporary data (i.e. offsets) from the buffer.
pub fn clear(&mut self) { pub fn clear(&mut self) {
self.offsets.clear() self.offsets.clear();
} }
/// Returns the offset at `index`, if it exists. /// Returns the offset at `index`, if it exists.

View file

@ -12,7 +12,7 @@ pub fn convert(
let sampler = device.create_sampler(&wgpu::SamplerDescriptor { let sampler = device.create_sampler(&wgpu::SamplerDescriptor {
label: Some("iced_wgpu.offscreen.sampler"), label: Some("iced_wgpu.offscreen.sampler"),
..Default::default() ..wgpu::SamplerDescriptor::default()
}); });
//sampler in 0 //sampler in 0
@ -102,10 +102,10 @@ pub fn convert(
primitive: wgpu::PrimitiveState { primitive: wgpu::PrimitiveState {
topology: wgpu::PrimitiveTopology::TriangleList, topology: wgpu::PrimitiveTopology::TriangleList,
front_face: wgpu::FrontFace::Cw, front_face: wgpu::FrontFace::Cw,
..Default::default() ..wgpu::PrimitiveState::default()
}, },
depth_stencil: None, depth_stencil: None,
multisample: Default::default(), multisample: wgpu::MultisampleState::default(),
multiview: None, multiview: None,
}); });

View file

@ -480,7 +480,7 @@ impl Frame {
}, },
size: self.size, size: self.size,
}), }),
)) ));
} }
} }
Buffer::Gradient(buffer) => { Buffer::Gradient(buffer) => {
@ -493,7 +493,7 @@ impl Frame {
}, },
size: self.size, size: self.size,
}), }),
)) ));
} }
} }
} }

View file

@ -86,7 +86,7 @@ impl Atlas {
entry entry
}; };
log::info!("Allocated atlas entry: {:?}", entry); log::info!("Allocated atlas entry: {entry:?}");
// It is a webgpu requirement that: // It is a webgpu requirement that:
// BufferCopyView.layout.bytes_per_row % wgpu::COPY_BYTES_PER_ROW_ALIGNMENT == 0 // BufferCopyView.layout.bytes_per_row % wgpu::COPY_BYTES_PER_ROW_ALIGNMENT == 0
@ -104,7 +104,7 @@ impl Atlas {
padded_data[offset..offset + 4 * width as usize].copy_from_slice( padded_data[offset..offset + 4 * width as usize].copy_from_slice(
&data[row * 4 * width as usize..(row + 1) * 4 * width as usize], &data[row * 4 * width as usize..(row + 1) * 4 * width as usize],
) );
} }
match &entry { match &entry {
@ -139,13 +139,13 @@ impl Atlas {
} }
} }
log::info!("Current atlas: {:?}", self); log::info!("Current atlas: {self:?}");
Some(entry) Some(entry)
} }
pub fn remove(&mut self, entry: &Entry) { pub fn remove(&mut self, entry: &Entry) {
log::info!("Removing atlas entry: {:?}", entry); log::info!("Removing atlas entry: {entry:?}");
match entry { match entry {
Entry::Contiguous(allocation) => { Entry::Contiguous(allocation) => {
@ -237,7 +237,7 @@ impl Atlas {
})); }));
} }
} }
_ => {} Layer::Full => {}
} }
} }
@ -258,7 +258,7 @@ impl Atlas {
} }
fn deallocate(&mut self, allocation: &Allocation) { fn deallocate(&mut self, allocation: &Allocation) {
log::info!("Deallocating atlas: {:?}", allocation); log::info!("Deallocating atlas: {allocation:?}");
match allocation { match allocation {
Allocation::Full { layer } => { Allocation::Full { layer } => {

View file

@ -152,7 +152,7 @@ impl Cache {
let allocation = let allocation =
atlas.upload(device, encoder, width, height, &rgba)?; atlas.upload(device, encoder, width, height, &rgba)?;
log::debug!("allocating {} {}x{}", id, width, height); log::debug!("allocating {id} {width}x{height}");
let _ = self.svg_hits.insert(id); let _ = self.svg_hits.insert(id);
let _ = self.rasterized_hits.insert(key); let _ = self.rasterized_hits.insert(key);

View file

@ -215,7 +215,7 @@ impl<'a> Layer<'a> {
translation, translation,
primitive, primitive,
current_layer, current_layer,
) );
} }
} }
Primitive::Clip { bounds, content } => { Primitive::Clip { bounds, content } => {

View file

@ -26,14 +26,8 @@
//missing_docs, //missing_docs,
unsafe_code, unsafe_code,
unused_results, unused_results,
clippy::extra_unused_lifetimes,
clippy::from_over_into,
clippy::needless_borrow,
clippy::new_without_default,
clippy::useless_conversion,
rustdoc::broken_intra_doc_links rustdoc::broken_intra_doc_links
)] )]
#![allow(clippy::inherent_to_string, clippy::type_complexity)]
#![cfg_attr(docsrs, feature(doc_auto_cfg))] #![cfg_attr(docsrs, feature(doc_auto_cfg))]
pub mod layer; pub mod layer;
pub mod primitive; pub mod primitive;

View file

@ -61,7 +61,7 @@ impl Pipeline {
self.renderers.push(glyphon::TextRenderer::new( self.renderers.push(glyphon::TextRenderer::new(
&mut self.atlas, &mut self.atlas,
device, device,
Default::default(), wgpu::MultisampleState::default(),
None, None,
)); ));
} }

View file

@ -329,12 +329,12 @@ impl Pipeline {
fn fragment_target( fn fragment_target(
texture_format: wgpu::TextureFormat, texture_format: wgpu::TextureFormat,
) -> Option<wgpu::ColorTargetState> { ) -> wgpu::ColorTargetState {
Some(wgpu::ColorTargetState { wgpu::ColorTargetState {
format: texture_format, format: texture_format,
blend: Some(wgpu::BlendState::ALPHA_BLENDING), blend: Some(wgpu::BlendState::ALPHA_BLENDING),
write_mask: wgpu::ColorWrites::ALL, write_mask: wgpu::ColorWrites::ALL,
}) }
} }
fn primitive_state() -> wgpu::PrimitiveState { fn primitive_state() -> wgpu::PrimitiveState {
@ -349,7 +349,7 @@ fn multisample_state(
antialiasing: Option<Antialiasing>, antialiasing: Option<Antialiasing>,
) -> wgpu::MultisampleState { ) -> wgpu::MultisampleState {
wgpu::MultisampleState { wgpu::MultisampleState {
count: antialiasing.map(|a| a.sample_count()).unwrap_or(1), count: antialiasing.map(Antialiasing::sample_count).unwrap_or(1),
mask: !0, mask: !0,
alpha_to_coverage_enabled: false, alpha_to_coverage_enabled: false,
} }
@ -521,7 +521,7 @@ mod solid {
fragment: Some(wgpu::FragmentState { fragment: Some(wgpu::FragmentState {
module: &shader, module: &shader,
entry_point: "solid_fs_main", entry_point: "solid_fs_main",
targets: &[triangle::fragment_target(format)], targets: &[Some(triangle::fragment_target(format))],
}), }),
primitive: triangle::primitive_state(), primitive: triangle::primitive_state(),
depth_stencil: None, depth_stencil: None,
@ -698,7 +698,7 @@ mod gradient {
fragment: Some(wgpu::FragmentState { fragment: Some(wgpu::FragmentState {
module: &shader, module: &shader,
entry_point: "gradient_fs_main", entry_point: "gradient_fs_main",
targets: &[triangle::fragment_target(format)], targets: &[Some(triangle::fragment_target(format))],
}), }),
primitive: triangle::primitive_state(), primitive: triangle::primitive_state(),
depth_stencil: None, depth_stencil: None,

View file

@ -35,7 +35,7 @@ impl<Theme> Compositor<Theme> {
..Default::default() ..Default::default()
}); });
log::info!("{:#?}", settings); log::info!("{settings:#?}");
#[cfg(not(target_arch = "wasm32"))] #[cfg(not(target_arch = "wasm32"))]
if log::max_level() >= log::LevelFilter::Info { if log::max_level() >= log::LevelFilter::Info {
@ -43,7 +43,7 @@ impl<Theme> Compositor<Theme> {
.enumerate_adapters(settings.internal_backend) .enumerate_adapters(settings.internal_backend)
.map(|adapter| adapter.get_info()) .map(|adapter| adapter.get_info())
.collect(); .collect();
log::info!("Available adapters: {:#?}", available_adapters); log::info!("Available adapters: {available_adapters:#?}");
} }
#[allow(unsafe_code)] #[allow(unsafe_code)]
@ -83,7 +83,7 @@ impl<Theme> Compositor<Theme> {
}) })
})?; })?;
log::info!("Selected format: {:?}", format); log::info!("Selected format: {format:?}");
#[cfg(target_arch = "wasm32")] #[cfg(target_arch = "wasm32")]
let limits = [wgpu::Limits::downlevel_webgl2_defaults() let limits = [wgpu::Limits::downlevel_webgl2_defaults()

View file

@ -146,7 +146,7 @@ where
} }
fn diff(&self, tree: &mut Tree) { fn diff(&self, tree: &mut Tree) {
tree.diff_children(std::slice::from_ref(&self.content)) tree.diff_children(std::slice::from_ref(&self.content));
} }
fn width(&self) -> Length { fn width(&self) -> Length {

View file

@ -159,7 +159,7 @@ where
child child
.as_widget() .as_widget()
.operate(state, layout, renderer, operation); .operate(state, layout, renderer, operation);
}) });
}); });
} }

View file

@ -141,14 +141,14 @@ pub fn draw<Renderer, Handle>(
..bounds ..bounds
}; };
renderer.draw(handle.clone(), drawing_bounds + offset) renderer.draw(handle.clone(), drawing_bounds + offset);
}; };
if adjusted_fit.width > bounds.width || adjusted_fit.height > bounds.height if adjusted_fit.width > bounds.width || adjusted_fit.height > bounds.height
{ {
renderer.with_layer(bounds, render); renderer.with_layer(bounds, render);
} else { } else {
render(renderer) render(renderer);
} }
} }
@ -191,7 +191,7 @@ where
_cursor: mouse::Cursor, _cursor: mouse::Cursor,
_viewport: &Rectangle, _viewport: &Rectangle,
) { ) {
draw(renderer, layout, &self.handle, self.content_fit) draw(renderer, layout, &self.handle, self.content_fit);
} }
} }

View file

@ -334,7 +334,7 @@ where
y: bounds.y, y: bounds.y,
..Rectangle::with_size(image_size) ..Rectangle::with_size(image_size)
}, },
) );
}); });
}); });
} }

View file

@ -220,7 +220,7 @@ where
child child
.as_widget() .as_widget()
.operate(state, layout, renderer, operation); .operate(state, layout, renderer, operation);
}) });
}); });
} }

View file

@ -135,7 +135,7 @@ where
(*self.element.borrow_mut()) = Some(current.element.clone()); (*self.element.borrow_mut()) = Some(current.element.clone());
self.with_element(|element| { self.with_element(|element| {
tree.diff_children(std::slice::from_ref(&element.as_widget())) tree.diff_children(std::slice::from_ref(&element.as_widget()));
}); });
} else { } else {
(*self.element.borrow_mut()) = Some(current.element.clone()); (*self.element.borrow_mut()) = Some(current.element.clone());
@ -243,8 +243,8 @@ where
layout, layout,
cursor, cursor,
viewport, viewport,
) );
}) });
} }
fn overlay<'b>( fn overlay<'b>(

View file

@ -511,7 +511,7 @@ impl<'a, 'b, Message, Renderer, Event, S> Drop
for Overlay<'a, 'b, Message, Renderer, Event, S> for Overlay<'a, 'b, Message, Renderer, Event, S>
{ {
fn drop(&mut self) { fn drop(&mut self) {
if let Some(heads) = self.0.take().map(|inner| inner.into_heads()) { if let Some(heads) = self.0.take().map(Inner::into_heads) {
*heads.instance.tree.borrow_mut().borrow_mut() = Some(heads.tree); *heads.instance.tree.borrow_mut().borrow_mut() = Some(heads.tree);
} }
} }

View file

@ -240,9 +240,9 @@ where
|tree, renderer, layout, element| { |tree, renderer, layout, element| {
element.as_widget().draw( element.as_widget().draw(
tree, renderer, theme, style, layout, cursor, viewport, tree, renderer, theme, style, layout, cursor, viewport,
) );
}, },
) );
} }
fn mouse_interaction( fn mouse_interaction(

View file

@ -7,14 +7,8 @@
// missing_debug_implementations, // missing_debug_implementations,
// missing_docs, // missing_docs,
unused_results, unused_results,
clippy::extra_unused_lifetimes,
clippy::from_over_into,
clippy::needless_borrow,
clippy::new_without_default,
clippy::useless_conversion,
rustdoc::broken_intra_doc_links rustdoc::broken_intra_doc_links
)] )]
#![allow(clippy::inherent_to_string, clippy::type_complexity)]
#![cfg_attr(docsrs, feature(doc_auto_cfg))] #![cfg_attr(docsrs, feature(doc_auto_cfg))]
pub use iced_renderer as renderer; pub use iced_renderer as renderer;
pub use iced_renderer::graphics; pub use iced_renderer::graphics;

View file

@ -308,7 +308,7 @@ where
.zip(layout.children()) .zip(layout.children())
.for_each(|(((_pane, content), state), layout)| { .for_each(|(((_pane, content), state), layout)| {
content.operate(state, layout, renderer, operation); content.operate(state, layout, renderer, operation);
}) });
}); });
} }
@ -436,7 +436,7 @@ where
tree, renderer, theme, style, layout, cursor, rectangle, tree, renderer, theme, style, layout, cursor, rectangle,
); );
}, },
) );
} }
fn overlay<'b>( fn overlay<'b>(
@ -606,11 +606,10 @@ pub fn update<'a, Message, T: Draggable>(
} else { } else {
let dropped_region = contents let dropped_region = contents
.zip(layout.children()) .zip(layout.children())
.filter_map(|(target, layout)| { .find_map(|(target, layout)| {
layout_region(layout, cursor_position) layout_region(layout, cursor_position)
.map(|region| (target, region)) .map(|region| (target, region))
}) });
.next();
match dropped_region { match dropped_region {
Some(((target, _), region)) Some(((target, _), region))
@ -1151,21 +1150,19 @@ pub struct ResizeEvent {
* Helpers * Helpers
*/ */
fn hovered_split<'a>( fn hovered_split<'a>(
splits: impl Iterator<Item = (&'a Split, &'a (Axis, Rectangle, f32))>, mut splits: impl Iterator<Item = (&'a Split, &'a (Axis, Rectangle, f32))>,
spacing: f32, spacing: f32,
cursor_position: Point, cursor_position: Point,
) -> Option<(Split, Axis, Rectangle)> { ) -> Option<(Split, Axis, Rectangle)> {
splits splits.find_map(|(split, (axis, region, ratio))| {
.filter_map(|(split, (axis, region, ratio))| { let bounds = axis.split_line_bounds(*region, *ratio, spacing);
let bounds = axis.split_line_bounds(*region, *ratio, spacing);
if bounds.contains(cursor_position) { if bounds.contains(cursor_position) {
Some((*split, *axis, bounds)) Some((*split, *axis, bounds))
} else { } else {
None None
} }
}) })
.next()
} }
/// The visible contents of the [`PaneGrid`] /// The visible contents of the [`PaneGrid`]

View file

@ -95,13 +95,13 @@ impl Node {
splits splits
} }
pub(crate) fn find(&mut self, pane: &Pane) -> Option<&mut Node> { pub(crate) fn find(&mut self, pane: Pane) -> Option<&mut Node> {
match self { match self {
Node::Split { a, b, .. } => { Node::Split { a, b, .. } => {
a.find(pane).or_else(move || b.find(pane)) a.find(pane).or_else(move || b.find(pane))
} }
Node::Pane(p) => { Node::Pane(p) => {
if p == pane { if *p == pane {
Some(self) Some(self)
} else { } else {
None None
@ -139,12 +139,12 @@ impl Node {
f(self); f(self);
} }
pub(crate) fn resize(&mut self, split: &Split, percentage: f32) -> bool { pub(crate) fn resize(&mut self, split: Split, percentage: f32) -> bool {
match self { match self {
Node::Split { Node::Split {
id, ratio, a, b, .. id, ratio, a, b, ..
} => { } => {
if id == split { if *id == split {
*ratio = percentage; *ratio = percentage;
true true
@ -158,13 +158,13 @@ impl Node {
} }
} }
pub(crate) fn remove(&mut self, pane: &Pane) -> Option<Pane> { pub(crate) fn remove(&mut self, pane: Pane) -> Option<Pane> {
match self { match self {
Node::Split { a, b, .. } => { Node::Split { a, b, .. } => {
if a.pane() == Some(*pane) { if a.pane() == Some(pane) {
*self = *b.clone(); *self = *b.clone();
Some(self.first_pane()) Some(self.first_pane())
} else if b.pane() == Some(*pane) { } else if b.pane() == Some(pane) {
*self = *a.clone(); *self = *a.clone();
Some(self.first_pane()) Some(self.first_pane())
} else { } else {

View file

@ -75,14 +75,14 @@ impl<T> State<T> {
} }
/// Returns the internal state of the given [`Pane`], if it exists. /// Returns the internal state of the given [`Pane`], if it exists.
pub fn get(&self, pane: &Pane) -> Option<&T> { pub fn get(&self, pane: Pane) -> Option<&T> {
self.panes.get(pane) self.panes.get(&pane)
} }
/// Returns the internal state of the given [`Pane`] with mutability, if it /// Returns the internal state of the given [`Pane`] with mutability, if it
/// exists. /// exists.
pub fn get_mut(&mut self, pane: &Pane) -> Option<&mut T> { pub fn get_mut(&mut self, pane: Pane) -> Option<&mut T> {
self.panes.get_mut(pane) self.panes.get_mut(&pane)
} }
/// Returns an iterator over all the panes of the [`State`], alongside its /// Returns an iterator over all the panes of the [`State`], alongside its
@ -104,13 +104,13 @@ impl<T> State<T> {
/// Returns the adjacent [`Pane`] of another [`Pane`] in the given /// Returns the adjacent [`Pane`] of another [`Pane`] in the given
/// direction, if there is one. /// direction, if there is one.
pub fn adjacent(&self, pane: &Pane, direction: Direction) -> Option<Pane> { pub fn adjacent(&self, pane: Pane, direction: Direction) -> Option<Pane> {
let regions = self let regions = self
.internal .internal
.layout .layout
.pane_regions(0.0, Size::new(4096.0, 4096.0)); .pane_regions(0.0, Size::new(4096.0, 4096.0));
let current_region = regions.get(pane)?; let current_region = regions.get(&pane)?;
let target = match direction { let target = match direction {
Direction::Left => { Direction::Left => {
@ -142,7 +142,7 @@ impl<T> State<T> {
pub fn split( pub fn split(
&mut self, &mut self,
axis: Axis, axis: Axis,
pane: &Pane, pane: Pane,
state: T, state: T,
) -> Option<(Pane, Split)> { ) -> Option<(Pane, Split)> {
self.split_node(axis, Some(pane), state, false) self.split_node(axis, Some(pane), state, false)
@ -151,32 +151,32 @@ impl<T> State<T> {
/// Split a target [`Pane`] with a given [`Pane`] on a given [`Region`]. /// Split a target [`Pane`] with a given [`Pane`] on a given [`Region`].
/// ///
/// Panes will be swapped by default for [`Region::Center`]. /// Panes will be swapped by default for [`Region::Center`].
pub fn split_with(&mut self, target: &Pane, pane: &Pane, region: Region) { pub fn split_with(&mut self, target: Pane, pane: Pane, region: Region) {
match region { match region {
Region::Center => self.swap(pane, target), Region::Center => self.swap(pane, target),
Region::Edge(edge) => match edge { Region::Edge(edge) => match edge {
Edge::Top => { Edge::Top => {
self.split_and_swap(Axis::Horizontal, target, pane, true) self.split_and_swap(Axis::Horizontal, target, pane, true);
} }
Edge::Bottom => { Edge::Bottom => {
self.split_and_swap(Axis::Horizontal, target, pane, false) self.split_and_swap(Axis::Horizontal, target, pane, false);
} }
Edge::Left => { Edge::Left => {
self.split_and_swap(Axis::Vertical, target, pane, true) self.split_and_swap(Axis::Vertical, target, pane, true);
} }
Edge::Right => { Edge::Right => {
self.split_and_swap(Axis::Vertical, target, pane, false) self.split_and_swap(Axis::Vertical, target, pane, false);
} }
}, },
} }
} }
/// Drops the given [`Pane`] into the provided [`Target`]. /// Drops the given [`Pane`] into the provided [`Target`].
pub fn drop(&mut self, pane: &Pane, target: Target) { pub fn drop(&mut self, pane: Pane, target: Target) {
match target { match target {
Target::Edge(edge) => self.move_to_edge(pane, edge), Target::Edge(edge) => self.move_to_edge(pane, edge),
Target::Pane(target, region) => { Target::Pane(target, region) => {
self.split_with(&target, pane, region) self.split_with(target, pane, region);
} }
} }
} }
@ -184,7 +184,7 @@ impl<T> State<T> {
fn split_node( fn split_node(
&mut self, &mut self,
axis: Axis, axis: Axis,
pane: Option<&Pane>, pane: Option<Pane>,
state: T, state: T,
inverse: bool, inverse: bool,
) -> Option<(Pane, Split)> { ) -> Option<(Pane, Split)> {
@ -222,14 +222,14 @@ impl<T> State<T> {
fn split_and_swap( fn split_and_swap(
&mut self, &mut self,
axis: Axis, axis: Axis,
target: &Pane, target: Pane,
pane: &Pane, pane: Pane,
swap: bool, swap: bool,
) { ) {
if let Some((state, _)) = self.close(pane) { if let Some((state, _)) = self.close(pane) {
if let Some((new_pane, _)) = self.split(axis, target, state) { if let Some((new_pane, _)) = self.split(axis, target, state) {
if swap { if swap {
self.swap(target, &new_pane); self.swap(target, new_pane);
} }
} }
} }
@ -238,19 +238,19 @@ impl<T> State<T> {
/// Move [`Pane`] to an [`Edge`] of the [`PaneGrid`]. /// Move [`Pane`] to an [`Edge`] of the [`PaneGrid`].
/// ///
/// [`PaneGrid`]: super::PaneGrid /// [`PaneGrid`]: super::PaneGrid
pub fn move_to_edge(&mut self, pane: &Pane, edge: Edge) { pub fn move_to_edge(&mut self, pane: Pane, edge: Edge) {
match edge { match edge {
Edge::Top => { Edge::Top => {
self.split_major_node_and_swap(Axis::Horizontal, pane, true) self.split_major_node_and_swap(Axis::Horizontal, pane, true);
} }
Edge::Bottom => { Edge::Bottom => {
self.split_major_node_and_swap(Axis::Horizontal, pane, false) self.split_major_node_and_swap(Axis::Horizontal, pane, false);
} }
Edge::Left => { Edge::Left => {
self.split_major_node_and_swap(Axis::Vertical, pane, true) self.split_major_node_and_swap(Axis::Vertical, pane, true);
} }
Edge::Right => { Edge::Right => {
self.split_major_node_and_swap(Axis::Vertical, pane, false) self.split_major_node_and_swap(Axis::Vertical, pane, false);
} }
} }
} }
@ -258,7 +258,7 @@ impl<T> State<T> {
fn split_major_node_and_swap( fn split_major_node_and_swap(
&mut self, &mut self,
axis: Axis, axis: Axis,
pane: &Pane, pane: Pane,
swap: bool, swap: bool,
) { ) {
if let Some((state, _)) = self.close(pane) { if let Some((state, _)) = self.close(pane) {
@ -273,14 +273,14 @@ impl<T> State<T> {
/// ///
/// [`PaneGrid`]: super::PaneGrid /// [`PaneGrid`]: super::PaneGrid
/// [`DragEvent`]: super::DragEvent /// [`DragEvent`]: super::DragEvent
pub fn swap(&mut self, a: &Pane, b: &Pane) { pub fn swap(&mut self, a: Pane, b: Pane) {
self.internal.layout.update(&|node| match node { self.internal.layout.update(&|node| match node {
Node::Split { .. } => {} Node::Split { .. } => {}
Node::Pane(pane) => { Node::Pane(pane) => {
if pane == a { if *pane == a {
*node = Node::Pane(*b); *node = Node::Pane(b);
} else if pane == b { } else if *pane == b {
*node = Node::Pane(*a); *node = Node::Pane(a);
} }
} }
}); });
@ -296,19 +296,19 @@ impl<T> State<T> {
/// ///
/// [`PaneGrid`]: super::PaneGrid /// [`PaneGrid`]: super::PaneGrid
/// [`ResizeEvent`]: super::ResizeEvent /// [`ResizeEvent`]: super::ResizeEvent
pub fn resize(&mut self, split: &Split, ratio: f32) { pub fn resize(&mut self, split: Split, ratio: f32) {
let _ = self.internal.layout.resize(split, ratio); let _ = self.internal.layout.resize(split, ratio);
} }
/// Closes the given [`Pane`] and returns its internal state and its closest /// Closes the given [`Pane`] and returns its internal state and its closest
/// sibling, if it exists. /// sibling, if it exists.
pub fn close(&mut self, pane: &Pane) -> Option<(T, Pane)> { pub fn close(&mut self, pane: Pane) -> Option<(T, Pane)> {
if self.maximized == Some(*pane) { if self.maximized == Some(pane) {
let _ = self.maximized.take(); let _ = self.maximized.take();
} }
if let Some(sibling) = self.internal.layout.remove(pane) { if let Some(sibling) = self.internal.layout.remove(pane) {
self.panes.remove(pane).map(|state| (state, sibling)) self.panes.remove(&pane).map(|state| (state, sibling))
} else { } else {
None None
} }
@ -318,8 +318,8 @@ impl<T> State<T> {
/// [`PaneGrid`] until [`Self::restore()`] is called. /// [`PaneGrid`] until [`Self::restore()`] is called.
/// ///
/// [`PaneGrid`]: super::PaneGrid /// [`PaneGrid`]: super::PaneGrid
pub fn maximize(&mut self, pane: &Pane) { pub fn maximize(&mut self, pane: Pane) {
self.maximized = Some(*pane); self.maximized = Some(pane);
} }
/// Restore the currently maximized [`Pane`] to it's normal size. All panes /// Restore the currently maximized [`Pane`] to it's normal size. All panes

View file

@ -286,7 +286,7 @@ where
controls_layout, controls_layout,
renderer, renderer,
operation, operation,
) );
}; };
if show_title { if show_title {
@ -295,7 +295,7 @@ where
title_layout, title_layout,
renderer, renderer,
operation, operation,
) );
} }
} }

View file

@ -76,7 +76,7 @@ where
text_line_height: text::LineHeight::default(), text_line_height: text::LineHeight::default(),
text_shaping: text::Shaping::Basic, text_shaping: text::Shaping::Basic,
font: None, font: None,
handle: Default::default(), handle: Handle::default(),
style: Default::default(), style: Default::default(),
} }
} }
@ -253,7 +253,7 @@ where
&self.handle, &self.handle,
&self.style, &self.style,
|| tree.state.downcast_ref::<State<Renderer::Paragraph>>(), || tree.state.downcast_ref::<State<Renderer::Paragraph>>(),
) );
} }
fn overlay<'b>( fn overlay<'b>(

View file

@ -101,7 +101,7 @@ where
} }
fn diff(&self, tree: &mut Tree) { fn diff(&self, tree: &mut Tree) {
tree.diff_children(&self.children) tree.diff_children(&self.children);
} }
fn width(&self) -> Length { fn width(&self) -> Length {
@ -148,7 +148,7 @@ where
child child
.as_widget() .as_widget()
.operate(state, layout, renderer, operation); .operate(state, layout, renderer, operation);
}) });
}); });
} }

View file

@ -46,7 +46,7 @@ where
id: None, id: None,
width: Length::Shrink, width: Length::Shrink,
height: Length::Shrink, height: Length::Shrink,
direction: Default::default(), direction: Direction::default(),
content: content.into(), content: content.into(),
on_scroll: None, on_scroll: None,
style: Default::default(), style: Default::default(),
@ -117,7 +117,7 @@ impl Direction {
match self { match self {
Self::Horizontal(properties) => Some(properties), Self::Horizontal(properties) => Some(properties),
Self::Both { horizontal, .. } => Some(horizontal), Self::Both { horizontal, .. } => Some(horizontal),
_ => None, Self::Vertical(_) => None,
} }
} }
@ -126,7 +126,7 @@ impl Direction {
match self { match self {
Self::Vertical(properties) => Some(properties), Self::Vertical(properties) => Some(properties),
Self::Both { vertical, .. } => Some(vertical), Self::Both { vertical, .. } => Some(vertical),
_ => None, Self::Horizontal(_) => None,
} }
} }
} }
@ -217,7 +217,7 @@ where
} }
fn diff(&self, tree: &mut Tree) { fn diff(&self, tree: &mut Tree) {
tree.diff_children(std::slice::from_ref(&self.content)) tree.diff_children(std::slice::from_ref(&self.content));
} }
fn width(&self) -> Length { fn width(&self) -> Length {
@ -348,9 +348,9 @@ where
layout, layout,
cursor, cursor,
viewport, viewport,
) );
}, },
) );
} }
fn mouse_interaction( fn mouse_interaction(
@ -1069,7 +1069,7 @@ impl operation::Scrollable for State {
} }
fn scroll_to(&mut self, offset: AbsoluteOffset) { fn scroll_to(&mut self, offset: AbsoluteOffset) {
State::scroll_to(self, offset) State::scroll_to(self, offset);
} }
} }
@ -1203,7 +1203,7 @@ impl State {
(self.offset_y.absolute(bounds.height, content_bounds.height) (self.offset_y.absolute(bounds.height, content_bounds.height)
- delta.y) - delta.y)
.clamp(0.0, content_bounds.height - bounds.height), .clamp(0.0, content_bounds.height - bounds.height),
) );
} }
if bounds.width < content_bounds.width { if bounds.width < content_bounds.width {
@ -1364,15 +1364,15 @@ impl Scrollbars {
let ratio = bounds.height / content_bounds.height; let ratio = bounds.height / content_bounds.height;
// min height for easier grabbing with super tall content // min height for easier grabbing with super tall content
let scroller_height = (bounds.height * ratio).max(2.0); let scroller_height = (scrollbar_bounds.height * ratio).max(2.0);
let scroller_offset = translation.y * ratio; let scroller_offset =
translation.y * ratio * scrollbar_bounds.height / bounds.height;
let scroller_bounds = Rectangle { let scroller_bounds = Rectangle {
x: bounds.x + bounds.width x: bounds.x + bounds.width
- total_scrollbar_width / 2.0 - total_scrollbar_width / 2.0
- scroller_width / 2.0, - scroller_width / 2.0,
y: (scrollbar_bounds.y + scroller_offset - x_scrollbar_height) y: (scrollbar_bounds.y + scroller_offset).max(0.0),
.max(0.0),
width: scroller_width, width: scroller_width,
height: scroller_height, height: scroller_height,
}; };
@ -1399,8 +1399,8 @@ impl Scrollbars {
// Need to adjust the width of the horizontal scrollbar if the vertical scrollbar // Need to adjust the width of the horizontal scrollbar if the vertical scrollbar
// is present // is present
let scrollbar_y_width = show_scrollbar_y let scrollbar_y_width = y_scrollbar
.map_or(0.0, |v| v.width.max(v.scroller_width) + v.margin); .map_or(0.0, |scrollbar| scrollbar.total_bounds.width);
let total_scrollbar_height = let total_scrollbar_height =
width.max(scroller_width) + 2.0 * margin; width.max(scroller_width) + 2.0 * margin;
@ -1425,12 +1425,12 @@ impl Scrollbars {
let ratio = bounds.width / content_bounds.width; let ratio = bounds.width / content_bounds.width;
// min width for easier grabbing with extra wide content // min width for easier grabbing with extra wide content
let scroller_length = (bounds.width * ratio).max(2.0); let scroller_length = (scrollbar_bounds.width * ratio).max(2.0);
let scroller_offset = translation.x * ratio; let scroller_offset =
translation.x * ratio * scrollbar_bounds.width / bounds.width;
let scroller_bounds = Rectangle { let scroller_bounds = Rectangle {
x: (scrollbar_bounds.x + scroller_offset - scrollbar_y_width) x: (scrollbar_bounds.x + scroller_offset).max(0.0),
.max(0.0),
y: bounds.y + bounds.height y: bounds.y + bounds.height
- total_scrollbar_height / 2.0 - total_scrollbar_height / 2.0
- scroller_width / 2.0, - scroller_width / 2.0,

View file

@ -223,7 +223,7 @@ where
&self.range, &self.range,
theme, theme,
&self.style, &self.style,
) );
} }
fn mouse_interaction( fn mouse_interaction(

View file

@ -250,7 +250,7 @@ where
self.is_secure, self.is_secure,
self.icon.as_ref(), self.icon.as_ref(),
&self.style, &self.style,
) );
} }
} }
@ -375,7 +375,7 @@ where
self.is_secure, self.is_secure,
self.icon.as_ref(), self.icon.as_ref(),
&self.style, &self.style,
) );
} }
fn mouse_interaction( fn mouse_interaction(
@ -619,7 +619,7 @@ where
font, font,
size, size,
line_height, line_height,
) );
}; };
match event { match event {
@ -846,7 +846,7 @@ where
state.cursor.move_left_by_words(value); state.cursor.move_left_by_words(value);
} }
} else if modifiers.shift() { } else if modifiers.shift() {
state.cursor.select_left(value) state.cursor.select_left(value);
} else { } else {
state.cursor.move_left(value); state.cursor.move_left(value);
} }
@ -861,7 +861,7 @@ where
state.cursor.move_right_by_words(value); state.cursor.move_right_by_words(value);
} }
} else if modifiers.shift() { } else if modifiers.shift() {
state.cursor.select_right(value) state.cursor.select_right(value);
} else { } else {
state.cursor.move_right(value); state.cursor.move_right(value);
} }
@ -1217,7 +1217,7 @@ pub fn draw<Renderer>(
if text_width > text_bounds.width { if text_width > text_bounds.width {
renderer.with_layer(text_bounds, |renderer| { renderer.with_layer(text_bounds, |renderer| {
renderer.with_translation(Vector::new(-offset, 0.0), render) renderer.with_translation(Vector::new(-offset, 0.0), render);
}); });
} else { } else {
render(renderer); render(renderer);
@ -1339,29 +1339,29 @@ impl<P: text::Paragraph> operation::Focusable for State<P> {
} }
fn focus(&mut self) { fn focus(&mut self) {
State::focus(self) State::focus(self);
} }
fn unfocus(&mut self) { fn unfocus(&mut self) {
State::unfocus(self) State::unfocus(self);
} }
} }
impl<P: text::Paragraph> operation::TextInput for State<P> { impl<P: text::Paragraph> operation::TextInput for State<P> {
fn move_cursor_to_front(&mut self) { fn move_cursor_to_front(&mut self) {
State::move_cursor_to_front(self) State::move_cursor_to_front(self);
} }
fn move_cursor_to_end(&mut self) { fn move_cursor_to_end(&mut self) {
State::move_cursor_to_end(self) State::move_cursor_to_end(self);
} }
fn move_cursor_to(&mut self, position: usize) { fn move_cursor_to(&mut self, position: usize) {
State::move_cursor_to(self, position) State::move_cursor_to(self, position);
} }
fn select_all(&mut self) { fn select_all(&mut self) {
State::select_all(self) State::select_all(self);
} }
} }

View file

@ -56,7 +56,7 @@ impl Cursor {
State::Selection { start, end } => { State::Selection { start, end } => {
Some((start.min(end), start.max(end))) Some((start.min(end), start.max(end)))
} }
_ => None, State::Index(_) => None,
} }
} }
@ -65,11 +65,11 @@ impl Cursor {
} }
pub(crate) fn move_right(&mut self, value: &Value) { pub(crate) fn move_right(&mut self, value: &Value) {
self.move_right_by_amount(value, 1) self.move_right_by_amount(value, 1);
} }
pub(crate) fn move_right_by_words(&mut self, value: &Value) { pub(crate) fn move_right_by_words(&mut self, value: &Value) {
self.move_to(value.next_end_of_word(self.right(value))) self.move_to(value.next_end_of_word(self.right(value)));
} }
pub(crate) fn move_right_by_amount( pub(crate) fn move_right_by_amount(
@ -79,7 +79,7 @@ impl Cursor {
) { ) {
match self.state(value) { match self.state(value) {
State::Index(index) => { State::Index(index) => {
self.move_to(index.saturating_add(amount).min(value.len())) self.move_to(index.saturating_add(amount).min(value.len()));
} }
State::Selection { start, end } => self.move_to(end.max(start)), State::Selection { start, end } => self.move_to(end.max(start)),
} }
@ -89,7 +89,7 @@ impl Cursor {
match self.state(value) { match self.state(value) {
State::Index(index) if index > 0 => self.move_to(index - 1), State::Index(index) if index > 0 => self.move_to(index - 1),
State::Selection { start, end } => self.move_to(start.min(end)), State::Selection { start, end } => self.move_to(start.min(end)),
_ => self.move_to(0), State::Index(_) => self.move_to(0),
} }
} }
@ -108,10 +108,10 @@ impl Cursor {
pub(crate) fn select_left(&mut self, value: &Value) { pub(crate) fn select_left(&mut self, value: &Value) {
match self.state(value) { match self.state(value) {
State::Index(index) if index > 0 => { State::Index(index) if index > 0 => {
self.select_range(index, index - 1) self.select_range(index, index - 1);
} }
State::Selection { start, end } if end > 0 => { State::Selection { start, end } if end > 0 => {
self.select_range(start, end - 1) self.select_range(start, end - 1);
} }
_ => {} _ => {}
} }
@ -120,10 +120,10 @@ impl Cursor {
pub(crate) fn select_right(&mut self, value: &Value) { pub(crate) fn select_right(&mut self, value: &Value) {
match self.state(value) { match self.state(value) {
State::Index(index) if index < value.len() => { State::Index(index) if index < value.len() => {
self.select_range(index, index + 1) self.select_range(index, index + 1);
} }
State::Selection { start, end } if end < value.len() => { State::Selection { start, end } if end < value.len() => {
self.select_range(start, end + 1) self.select_range(start, end + 1);
} }
_ => {} _ => {}
} }
@ -132,10 +132,10 @@ impl Cursor {
pub(crate) fn select_left_by_words(&mut self, value: &Value) { pub(crate) fn select_left_by_words(&mut self, value: &Value) {
match self.state(value) { match self.state(value) {
State::Index(index) => { State::Index(index) => {
self.select_range(index, value.previous_start_of_word(index)) self.select_range(index, value.previous_start_of_word(index));
} }
State::Selection { start, end } => { State::Selection { start, end } => {
self.select_range(start, value.previous_start_of_word(end)) self.select_range(start, value.previous_start_of_word(end));
} }
} }
} }
@ -143,10 +143,10 @@ impl Cursor {
pub(crate) fn select_right_by_words(&mut self, value: &Value) { pub(crate) fn select_right_by_words(&mut self, value: &Value) {
match self.state(value) { match self.state(value) {
State::Index(index) => { State::Index(index) => {
self.select_range(index, value.next_end_of_word(index)) self.select_range(index, value.next_end_of_word(index));
} }
State::Selection { start, end } => { State::Selection { start, end } => {
self.select_range(start, value.next_end_of_word(end)) self.select_range(start, value.next_end_of_word(end));
} }
} }
} }

Some files were not shown because too many files have changed in this diff Show more