Skip to content

Commit

Permalink
cargo fmt and clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
genusistimelord committed Jan 23, 2024
1 parent 7421aa3 commit 80cbb5c
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 85 deletions.
17 changes: 9 additions & 8 deletions src/core/overlay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,21 @@ use iced_widget::core::{layout, Point, Size};
pub trait Position {
/// Centers this node around the given position. If the node is over the
/// specified bounds it's bouncing back to be fully visible on screen.
fn center_and_bounce(self, position: Point, bounds: Size) -> Self;
fn center_and_bounce(&mut self, position: Point, bounds: Size);
}

impl Position for layout::Node {
fn center_and_bounce(self, position: Point, bounds: Size) -> Self {
fn center_and_bounce(&mut self, position: Point, bounds: Size) {
let size = self.size();
let new_self = self.move_to(Point::new(
(position.x - size.width / 2.0).max(0.0),
(position.y - size.height / 2.0).max(0.0),

self.move_to_mut(Point::new(
(position.x - (size.width / 2.0)).max(0.0),
(position.y - (size.height / 2.0)).max(0.0),
));

let new_self_bounds = new_self.bounds();
let new_self_bounds = self.bounds();

new_self.move_to(Point::new(
self.move_to_mut(Point::new(
if new_self_bounds.x + new_self_bounds.width > bounds.width {
(new_self_bounds.x - (new_self_bounds.width - (bounds.width - new_self_bounds.x)))
.max(0.0)
Expand All @@ -32,6 +33,6 @@ impl Position for layout::Node {
} else {
new_self_bounds.y
},
))
));
}
}
6 changes: 4 additions & 2 deletions src/native/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,8 @@ pub fn selection_list_with<'a, T, Message, Theme, Renderer>(
where
Message: 'a + Clone,
Renderer: 'a + core::Renderer + core::text::Renderer<Font = core::Font>,
Theme: 'a + crate::style::selection_list::StyleSheet
Theme: 'a
+ crate::style::selection_list::StyleSheet
+ iced_widget::container::StyleSheet
+ iced_widget::scrollable::StyleSheet,
T: Clone + Display + Eq + Hash,
Expand Down Expand Up @@ -383,7 +384,8 @@ pub fn selection_list<'a, T, Message, Theme, Renderer>(
where
Message: 'a + Clone,
Renderer: 'a + core::Renderer + core::text::Renderer<Font = core::Font>,
Theme: 'a + crate::style::selection_list::StyleSheet
Theme: 'a
+ crate::style::selection_list::StyleSheet
+ iced_widget::container::StyleSheet
+ iced_widget::scrollable::StyleSheet,
T: Clone + Display + Eq + Hash,
Expand Down
32 changes: 7 additions & 25 deletions src/native/number_input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@ where
{
cursor::State::Index(mut idx) => {
if T::zero().eq(&self.value) {
new_val = c.to_string();
new_val = c.to_owned();
} else {
for char in c.chars() {
new_val.insert(idx, char);
Expand All @@ -468,7 +468,7 @@ where
{
new_val.replace_range(
if start > end { end..start } else { start..end },
&c.to_string(),
c,
);
}
}
Expand All @@ -480,14 +480,8 @@ where
self.value = val;
shell.publish((self.on_change)(self.value));
self.content.on_event(
child,
event.clone(),
content,
cursor,
renderer,
clipboard,
shell,
viewport,
child, event, content, cursor, renderer, clipboard,
shell, viewport,
)
} else {
event::Status::Ignored
Expand Down Expand Up @@ -553,14 +547,8 @@ where
self.value = val;
shell.publish((self.on_change)(self.value));
self.content.on_event(
child,
event.clone(),
content,
cursor,
renderer,
clipboard,
shell,
viewport,
child, event, content, cursor, renderer,
clipboard, shell, viewport,
)
} else {
event::Status::Ignored
Expand All @@ -571,13 +559,7 @@ where
}
}
_ => self.content.on_event(
child,
event.clone(),
content,
cursor,
renderer,
clipboard,
shell,
child, event, content, cursor, renderer, clipboard, shell,
viewport,
),
},
Expand Down
42 changes: 22 additions & 20 deletions src/native/overlay/color_picker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -476,13 +476,15 @@ where
let mut value = i32::from(hsv_color.hue);

match key_code {
keyboard::Key::Named(keyboard::key::Named::ArrowLeft)
| keyboard::Key::Named(keyboard::key::Named::ArrowDown) => {
keyboard::Key::Named(
keyboard::key::Named::ArrowLeft | keyboard::key::Named::ArrowDown,
) => {
value -= HUE_STEP;
status = event::Status::Captured;
}
keyboard::Key::Named(keyboard::key::Named::ArrowRight)
| keyboard::Key::Named(keyboard::key::Named::ArrowUp) => {
keyboard::Key::Named(
keyboard::key::Named::ArrowRight | keyboard::key::Named::ArrowUp,
) => {
value += HUE_STEP;
status = event::Status::Captured;
}
Expand All @@ -504,13 +506,15 @@ where
let mut status = event::Status::Captured;

match key_code {
keyboard::Key::Named(keyboard::key::Named::ArrowLeft)
| keyboard::Key::Named(keyboard::key::Named::ArrowDown) => {
keyboard::Key::Named(
keyboard::key::Named::ArrowLeft | keyboard::key::Named::ArrowDown,
) => {
byte_value -= RGBA_STEP;
status = event::Status::Captured;
}
keyboard::Key::Named(keyboard::key::Named::ArrowRight)
| keyboard::Key::Named(keyboard::key::Named::ArrowUp) => {
keyboard::Key::Named(
keyboard::key::Named::ArrowRight | keyboard::key::Named::ArrowUp,
) => {
byte_value += RGBA_STEP;
status = event::Status::Captured;
}
Expand Down Expand Up @@ -611,9 +615,11 @@ where
)
};

let node = Node::with_children(Size::new(width, height), vec![block1_node, block2_node]);
let mut node =
Node::with_children(Size::new(width, height), vec![block1_node, block2_node]);

node.center_and_bounce(position, bounds)
node.center_and_bounce(position, bounds);
node
}

fn on_event(
Expand Down Expand Up @@ -1105,7 +1111,7 @@ fn block2<Message, Theme>(
let rgba_color_layout = block2_children
.next()
.expect("Graphics: Layout should have a RGBA color layout");
rgba_color::<Theme>(
rgba_color(
renderer,
rgba_color_layout,
&color_picker.state.color,
Expand All @@ -1119,7 +1125,7 @@ fn block2<Message, Theme>(
let hex_text_layout = block2_children
.next()
.expect("Graphics: Layout should have a hex text layout");
hex_text::<Theme>(
hex_text(
renderer,
hex_text_layout,
&color_picker.state.color,
Expand Down Expand Up @@ -1375,17 +1381,15 @@ fn hsv_color<Message, Theme>(

/// Draws the RGBA color area.
#[allow(clippy::too_many_lines)]
fn rgba_color<Theme>(
fn rgba_color(
renderer: &mut Renderer,
layout: Layout<'_>,
color: &Color,
cursor: Cursor,
style: &renderer::Style,
style_sheet: &HashMap<StyleState, Appearance>,
focus: Focus,
) where
Theme: StyleSheet + button::StyleSheet + widget::text::StyleSheet,
{
) {
let mut rgba_color_children = layout.children();

let f = |renderer: &mut Renderer,
Expand Down Expand Up @@ -1593,17 +1597,15 @@ fn rgba_color<Theme>(
}

/// Draws the hex text representation of the color.
fn hex_text<Theme>(
fn hex_text(
renderer: &mut Renderer,
layout: Layout<'_>,
color: &Color,
cursor: Cursor,
_style: &renderer::Style,
style_sheet: &HashMap<StyleState, Appearance>,
_focus: Focus,
) where
Theme: StyleSheet + button::StyleSheet + widget::text::StyleSheet,
{
) {
let hsv: Hsv = (*color).into();

let hex_text_style_state = if cursor.is_over(layout.bounds()) {
Expand Down
39 changes: 16 additions & 23 deletions src/native/overlay/date_picker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -521,14 +521,15 @@ where
y: submit_bounds.y + col.bounds().height + PADDING + SPACING,
});

Node::with_children(
let mut node = Node::with_children(
Size::new(
col.bounds().width + (2.0 * PADDING),
col.bounds().height + cancel_button.bounds().height + (2.0 * PADDING) + SPACING,
),
vec![col, cancel_button, submit_button],
)
.center_and_bounce(position, bounds)
);
node.center_and_bounce(position, bounds);
node
}

fn on_event(
Expand Down Expand Up @@ -782,7 +783,7 @@ where
.next()
.expect("Graphics: Layout should have a month/year layout");

month_year::<Theme>(
month_year(
renderer,
month_year_layout,
&self.month_as_string(),
Expand All @@ -800,7 +801,7 @@ where
.next()
.expect("Graphics: Layout should have a days layout");

days::<Theme>(
days(
renderer,
days_layout,
self.state.date,
Expand Down Expand Up @@ -1053,7 +1054,7 @@ impl Default for Focus {
}

/// Draws the month/year row
fn month_year<Theme>(
fn month_year(
renderer: &mut Renderer,
layout: Layout<'_>,
month: &str,
Expand All @@ -1062,9 +1063,7 @@ fn month_year<Theme>(
//style: &Style,
style: &HashMap<StyleState, Appearance>,
focus: Focus,
) where
Theme: StyleSheet + button::StyleSheet + container::StyleSheet + text::StyleSheet,
{
) {
let mut children = layout.children();

let month_layout = children
Expand Down Expand Up @@ -1201,36 +1200,32 @@ fn month_year<Theme>(
}

/// Draws the days
fn days<Theme>(
fn days(
renderer: &mut Renderer,
layout: Layout<'_>,
date: chrono::NaiveDate,
cursor: Point,
//style: &Style,
style: &HashMap<StyleState, Appearance>,
focus: Focus,
) where
Theme: StyleSheet + button::StyleSheet + container::StyleSheet + text::StyleSheet,
{
) {
let mut children = layout.children();

let day_labels_layout = children
.next()
.expect("Graphics: Layout should have a day labels layout");
day_labels::<Theme>(renderer, day_labels_layout, style, focus);
day_labels(renderer, day_labels_layout, style, focus);

day_table::<Theme>(renderer, &mut children, date, cursor, style, focus);
day_table(renderer, &mut children, date, cursor, style, focus);
}

/// Draws the day labels
fn day_labels<Theme>(
fn day_labels(
renderer: &mut Renderer,
layout: Layout<'_>,
style: &HashMap<StyleState, Appearance>,
_focus: Focus,
) where
Theme: StyleSheet + button::StyleSheet + container::StyleSheet + text::StyleSheet,
{
) {
for (i, label) in layout.children().enumerate() {
let bounds = label.bounds();

Expand All @@ -1256,16 +1251,14 @@ fn day_labels<Theme>(
}

/// Draws the day table
fn day_table<Theme>(
fn day_table(
renderer: &mut Renderer,
children: &mut dyn Iterator<Item = Layout<'_>>,
date: chrono::NaiveDate,
cursor: Point,
style: &HashMap<StyleState, Appearance>,
focus: Focus,
) where
Theme: StyleSheet + button::StyleSheet + container::StyleSheet + text::StyleSheet,
{
) {
for (y, row) in children.enumerate() {
for (x, label) in row.children().enumerate() {
let bounds = label.bounds();
Expand Down
8 changes: 7 additions & 1 deletion src/native/overlay/floating_element.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,13 @@ use iced_widget::core::{
/// The internal overlay of a [`FloatingElement`](crate::FloatingElement) for
/// rendering a [`Element`](iced_widget::core::Element) as an overlay.
#[allow(missing_debug_implementations)]
pub struct FloatingElementOverlay<'a, 'b, Message, Theme = iced_widget::Theme, Renderer = iced_widget::Renderer> {
pub struct FloatingElementOverlay<
'a,
'b,
Message,
Theme = iced_widget::Theme,
Renderer = iced_widget::Renderer,
> {
/// The state of the element.
state: &'b mut Tree,
/// The floating element
Expand Down
Loading

0 comments on commit 80cbb5c

Please sign in to comment.