Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor so functions show up in order on docs #184

Merged
merged 3 commits into from
Sep 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions examples/cupertino/cupertino_alert/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use iced::widget::{column, container, Text};
use iced::{alignment, executor, font, Application, Command, Element, Length, Settings, Theme};
use iced_aw::native::cupertino::cupertino_alert::{CupertinoAlert, CupertinoDialogAction};
use iced_aw::native::cupertino::cupertino_button::CupertinoButton;
use iced_aw::native::cupertino::cupertino_colours::system_red;
use iced_aw::native::cupertino::cupertino_colors::system_red;

pub fn main() -> iced::Result {
Alert::run(Settings {
Expand Down Expand Up @@ -97,7 +97,7 @@ impl Application for Alert {

let cancel_button: CupertinoButton<Message, _> = CupertinoButton::new()
.on_pressed(Some(Message::CancelEvent))
.colour(Some(system_red(1.0)))
.color(Some(system_red(1.0)))
.body(Text::new(ALLOW)
.size(24)
.width(Length::Fixed(100.0))
Expand Down
63 changes: 31 additions & 32 deletions src/core/clock.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
//! Helper functions for calculating the clock

use std::fmt::Display;

use iced_widget::core::Point;
use std::fmt::Display;

/// The size of the period on the clock based on the clock's size.
pub const PERIOD_PERCENTAGE: f32 = 0.1;
Expand Down Expand Up @@ -61,26 +60,26 @@ pub enum NearestRadius {
Second,
}

/// # Panics
/// Determining the nearest radius to the position of the cursor position based
/// on the distance to the center.
/// Will panic if distance vec can not compare a and b
/// Distributes the amount of points on a circle with the given radius around the
/// center.
#[must_use]
pub fn nearest_radius(
radii: &[(f32, NearestRadius)],
cursor_position: Point,
center: Point,
) -> NearestRadius {
let distance = cursor_position.distance(center);
pub fn circle_points(distance_radius: f32, center: Point, amount: u16) -> Vec<Point> {
let part = std::f32::consts::TAU / f32::from(amount);

let mut distance_vec: Vec<(f32, &NearestRadius)> = radii
let rotation =
|(x, y): (f32, f32), t: f32| (x * t.cos() - y * t.sin(), x * t.sin() + y * t.cos());

let points: Vec<(f32, f32)> = (0..amount).fold(Vec::new(), |mut v, i| {
v.push(rotation((0.0, -distance_radius), part * f32::from(i)));
v
});

let points: Vec<Point> = points
.iter()
.map(|(r, n)| ((r - distance).abs(), n))
.map(|p| Point::new(p.0 + center.x, p.1 + center.y))
.collect();

distance_vec.sort_by(|a, b| a.0.partial_cmp(&b.0).expect("Should be comparable"));

distance_vec[0].1.clone()
points
}

/// # Panics
Expand All @@ -100,26 +99,26 @@ pub fn nearest_point(points: &[Point], cursor_position: Point) -> usize {
distance_vec[0].0
}

/// Distributes the amount of points on a circle with the given radius around the
/// center.
/// # Panics
/// Determining the nearest radius to the position of the cursor position based
/// on the distance to the center.
/// Will panic if distance vec can not compare a and b
#[must_use]
pub fn circle_points(distance_radius: f32, center: Point, amount: u16) -> Vec<Point> {
let part = std::f32::consts::TAU / f32::from(amount);

let rotation =
|(x, y): (f32, f32), t: f32| (x * t.cos() - y * t.sin(), x * t.sin() + y * t.cos());

let points: Vec<(f32, f32)> = (0..amount).fold(Vec::new(), |mut v, i| {
v.push(rotation((0.0, -distance_radius), part * f32::from(i)));
v
});
pub fn nearest_radius(
radii: &[(f32, NearestRadius)],
cursor_position: Point,
center: Point,
) -> NearestRadius {
let distance = cursor_position.distance(center);

let points: Vec<Point> = points
let mut distance_vec: Vec<(f32, &NearestRadius)> = radii
.iter()
.map(|p| Point::new(p.0 + center.x, p.1 + center.y))
.map(|(r, n)| ((r - distance).abs(), n))
.collect();

points
distance_vec.sort_by(|a, b| a.0.partial_cmp(&b.0).expect("Should be comparable"));

distance_vec[0].1.clone()
}

#[cfg(test)]
Expand Down
8 changes: 2 additions & 6 deletions src/core/date.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
//! Helper functions for calculating dates

use std::fmt::Display;

use chrono::Local;

use chrono::{Datelike, Duration, NaiveDate};

use chrono::{Datelike, Duration, Local, NaiveDate};
use once_cell::sync::Lazy;
use std::fmt::Display;

/// The date value
#[derive(Clone, Copy, Debug, Default)]
Expand Down
1 change: 1 addition & 0 deletions src/core/overlay.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
//! Helper functions for overlays

use iced_widget::core::{layout, Point, Size};

/// Trait containing functions for positioning of nodes.
Expand Down
2 changes: 1 addition & 1 deletion src/core/time.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
//! Use a time picker as an input element for picking times.
//!
//! *This API requires the following crate features to be activated: `time_picker`*
use std::fmt::Display;

use chrono::{Local, Timelike};
use std::fmt::Display;

/// The time value
#[derive(Clone, Copy, Debug)]
Expand Down
1 change: 1 addition & 0 deletions src/graphics/icons.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
//! The default icon font of the widgets of this library.

use iced_widget::core::Font;

#[cfg(feature = "icons")]
Expand Down
30 changes: 15 additions & 15 deletions src/native/badge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,17 +74,17 @@ where
}
}

/// Sets the padding of the [`Badge`].
/// Sets the horizontal alignment of the content of the [`Badge`].
#[must_use]
pub fn padding(mut self, units: u16) -> Self {
self.padding = units;
pub fn align_x(mut self, alignment: Alignment) -> Self {
self.horizontal_alignment = alignment;
self
}

/// Sets the width of the [`Badge`].
/// Sets the vertical alignment of the content of the [`Badge`].
#[must_use]
pub fn width(mut self, width: Length) -> Self {
self.width = width;
pub fn align_y(mut self, alignment: Alignment) -> Self {
self.vertical_alignment = alignment;
self
}

Expand All @@ -95,24 +95,24 @@ where
self
}

/// Sets the horizontal alignment of the content of the [`Badge`].
/// Sets the padding of the [`Badge`].
#[must_use]
pub fn align_x(mut self, alignment: Alignment) -> Self {
self.horizontal_alignment = alignment;
pub fn padding(mut self, units: u16) -> Self {
self.padding = units;
self
}

/// Sets the vertical alignment of the content of the [`Badge`].
/// Sets the style of the [`Badge`].
#[must_use]
pub fn align_y(mut self, alignment: Alignment) -> Self {
self.vertical_alignment = alignment;
pub fn style(mut self, style: <Renderer::Theme as StyleSheet>::Style) -> Self {
self.style = style;
self
}

/// Sets the style of the [`Badge`].
/// Sets the width of the [`Badge`].
#[must_use]
pub fn style(mut self, style: <Renderer::Theme as StyleSheet>::Style) -> Self {
self.style = style;
pub fn width(mut self, width: Length) -> Self {
self.width = width;
self
}
}
Expand Down
51 changes: 26 additions & 25 deletions src/native/card.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
//!
//! *This API requires the following crate features to be activated: card*

use crate::graphics::icons::{Icon, ICON_FONT};

use iced_widget::{
core::{
self,
Expand All @@ -17,7 +19,6 @@ use iced_widget::{
text::LineHeight,
};

use crate::graphics::icons::{Icon, ICON_FONT};
pub use crate::style::card::{Appearance, StyleSheet};

/// The default padding of a [`Card`].
Expand Down Expand Up @@ -95,8 +96,8 @@ where
Card {
width: Length::Fill,
height: Length::Shrink,
max_width: 4_294_967_295.0,
max_height: 4_294_967_295.0,
max_width: u32::MAX as f32,
max_height: u32::MAX as f32,
padding_head: DEFAULT_PADDING,
padding_body: DEFAULT_PADDING,
padding_foot: DEFAULT_PADDING,
Expand All @@ -119,10 +120,10 @@ where
self
}

/// Sets the width of the [`Card`].
/// Sets the size of the close icon of the [`Card`].
#[must_use]
pub fn width(mut self, width: Length) -> Self {
self.width = width;
pub fn close_size(mut self, size: f32) -> Self {
self.close_size = Some(size);
self
}

Expand All @@ -133,17 +134,27 @@ where
self
}

/// Sets the maximum height of the [`Card`].
#[must_use]
pub fn max_height(mut self, height: f32) -> Self {
self.max_height = height;
self
}

/// Sets the maximum width of the [`Card`].
#[must_use]
pub fn max_width(mut self, width: f32) -> Self {
self.max_width = width;
self
}

/// Sets the maximum height of the [`Card`].
/// Sets the message that will be produced when the close icon of the
/// [`Card`] is pressed.
///
/// Setting this enables the drawing of a close icon on the [`Card`].
#[must_use]
pub fn max_height(mut self, height: f32) -> Self {
self.max_height = height;
pub fn on_close(mut self, msg: Message) -> Self {
self.on_close = Some(msg);
self
}

Expand Down Expand Up @@ -180,27 +191,17 @@ where
self
}

/// Sets the size of the close icon of the [`Card`].
#[must_use]
pub fn close_size(mut self, size: f32) -> Self {
self.close_size = Some(size);
self
}

/// Sets the message that will be produced when the close icon of the
/// [`Card`] is pressed.
///
/// Setting this enables the drawing of a close icon on the [`Card`].
/// Sets the style of the [`Card`].
#[must_use]
pub fn on_close(mut self, msg: Message) -> Self {
self.on_close = Some(msg);
pub fn style(mut self, style: <Renderer::Theme as StyleSheet>::Style) -> Self {
self.style = style;
self
}

/// Sets the style of the [`Card`].
/// Sets the width of the [`Card`].
#[must_use]
pub fn style(mut self, style: <Renderer::Theme as StyleSheet>::Style) -> Self {
self.style = style;
pub fn width(mut self, width: Length) -> Self {
self.width = width;
self
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/native/color_picker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
//!
//! *This API requires the following crate features to be activated: `color_picker`*

use super::overlay::color_picker::{
self, ColorBarDragged, ColorPickerOverlay, ColorPickerOverlayButtons,
};

use iced_widget::{
button,
core::{
Expand All @@ -20,10 +24,6 @@ use iced_widget::{

pub use crate::style::color_picker::{Appearance, StyleSheet};

use super::overlay::color_picker::{
self, ColorBarDragged, ColorPickerOverlay, ColorPickerOverlayButtons,
};

//TODO: Remove ignore when Null is updated. Temp fix for Test runs
/// An input element for picking colors.
///
Expand Down
Loading