Skip to content

Commit

Permalink
Merge branch 'iced-rs:master' into qr-code-borrow
Browse files Browse the repository at this point in the history
  • Loading branch information
boondocklabs authored Oct 30, 2024
2 parents 9d47d99 + 50340b4 commit e9ad312
Show file tree
Hide file tree
Showing 22 changed files with 276 additions and 178 deletions.
2 changes: 1 addition & 1 deletion core/src/mouse/click.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ impl Click {
None
};

self.position == new_position
self.position.distance(new_position) < 6.0
&& duration
.map(|duration| duration.as_millis() <= 300)
.unwrap_or(false)
Expand Down
2 changes: 1 addition & 1 deletion core/src/widget/text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ where
}

/// The appearance of some text.
#[derive(Debug, Clone, Copy, Default)]
#[derive(Debug, Clone, Copy, PartialEq, Default)]
pub struct Style {
/// The [`Color`] of the text.
///
Expand Down
3 changes: 3 additions & 0 deletions examples/changelog/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ authors = ["Héctor Ramón Jiménez <[email protected]>"]
edition = "2021"
publish = false

[lints.clippy]
large_enum_variant = "allow"

[dependencies]
iced.workspace = true
iced.features = ["tokio", "markdown", "highlighter", "debug"]
Expand Down
5 changes: 1 addition & 4 deletions graphics/src/damage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,12 @@ pub fn list<T>(
/// Groups the given damage regions that are close together inside the given
/// bounds.
pub fn group(mut damage: Vec<Rectangle>, bounds: Rectangle) -> Vec<Rectangle> {
use std::cmp::Ordering;

const AREA_THRESHOLD: f32 = 20_000.0;

damage.sort_by(|a, b| {
a.center()
.distance(Point::ORIGIN)
.partial_cmp(&b.center().distance(Point::ORIGIN))
.unwrap_or(Ordering::Equal)
.total_cmp(&b.center().distance(Point::ORIGIN))
});

let mut output = Vec::new();
Expand Down
51 changes: 51 additions & 0 deletions widget/src/button.rs
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,9 @@ pub enum Status {
}

/// The style of a button.
///
/// If not specified with [`Button::style`]
/// the theme will provide the style.
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct Style {
/// The [`Background`] of the button.
Expand Down Expand Up @@ -505,6 +508,54 @@ impl Default for Style {
}

/// The theme catalog of a [`Button`].
///
/// All themes that can be used with [`Button`]
/// must implement this trait.
///
/// # Example
/// ```no_run
/// # use iced_widget::core::{Color, Background};
/// # use iced_widget::button::{Catalog, Status, Style};
/// # struct MyTheme;
/// #[derive(Debug, Default)]
/// pub enum ButtonClass {
/// #[default]
/// Primary,
/// Secondary,
/// Danger
/// }
///
/// impl Catalog for MyTheme {
/// type Class<'a> = ButtonClass;
///
/// fn default<'a>() -> Self::Class<'a> {
/// ButtonClass::default()
/// }
///
///
/// fn style(&self, class: &Self::Class<'_>, status: Status) -> Style {
/// let mut style = Style::default();
///
/// match class {
/// ButtonClass::Primary => {
/// style.background = Some(Background::Color(Color::from_rgb(0.529, 0.808, 0.921)));
/// },
/// ButtonClass::Secondary => {
/// style.background = Some(Background::Color(Color::WHITE));
/// },
/// ButtonClass::Danger => {
/// style.background = Some(Background::Color(Color::from_rgb(0.941, 0.502, 0.502)));
/// },
/// }
///
/// style
/// }
/// }
/// ```
///
/// Although, in order to use [`Button::style`]
/// with `MyTheme`, [`Catalog::Class`] must implement
/// `From<StyleFn<'_, MyTheme>>`.
pub trait Catalog {
/// The item class of the [`Catalog`].
type Class<'a>;
Expand Down
2 changes: 1 addition & 1 deletion widget/src/checkbox.rs
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,7 @@ pub enum Status {
}

/// The style of a checkbox.
#[derive(Debug, Clone, Copy)]
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct Style {
/// The [`Background`] of the checkbox.
pub background: Background,
Expand Down
2 changes: 1 addition & 1 deletion widget/src/container.rs
Original file line number Diff line number Diff line change
Expand Up @@ -572,7 +572,7 @@ pub fn visible_bounds(id: Id) -> Task<Option<Rectangle>> {
}

/// The appearance of a container.
#[derive(Debug, Clone, Copy, Default)]
#[derive(Debug, Clone, Copy, PartialEq, Default)]
pub struct Style {
/// The text [`Color`] of the container.
pub text_color: Option<Color>,
Expand Down
2 changes: 1 addition & 1 deletion widget/src/lazy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ where
layout: Layout<'_>,
renderer: &Renderer,
translation: Vector,
) -> Option<overlay::Element<'_, Message, Theme, Renderer>> {
) -> Option<overlay::Element<'b, Message, Theme, Renderer>> {
let overlay = InnerBuilder {
cell: self.element.borrow().as_ref().unwrap().clone(),
element: self
Expand Down
5 changes: 4 additions & 1 deletion widget/src/lazy/responsive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,10 @@ where
new_size: Size,
view: &dyn Fn(Size) -> Element<'a, Message, Theme, Renderer>,
) {
if self.size == new_size {
let is_tree_empty =
tree.tag == tree::Tag::stateless() && tree.children.is_empty();

if !is_tree_empty && self.size == new_size {
return;
}

Expand Down
2 changes: 1 addition & 1 deletion widget/src/overlay/menu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,7 @@ where
}

/// The appearance of a [`Menu`].
#[derive(Debug, Clone, Copy)]
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct Style {
/// The [`Background`] of the menu.
pub background: Background,
Expand Down
Loading

0 comments on commit e9ad312

Please sign in to comment.