Skip to content

Commit 6108271

Browse files
committed
Fix clippy/fmt issues
1 parent 80cfa9a commit 6108271

File tree

11 files changed

+178
-176
lines changed

11 files changed

+178
-176
lines changed

configurator/src/models/fields.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ impl ToolbarLayoutModeOption {
195195
}
196196
}
197197

198-
pub fn to_mode(&self) -> ToolbarLayoutMode {
198+
pub fn to_mode(self) -> ToolbarLayoutMode {
199199
match self {
200200
ToolbarLayoutModeOption::Simple => ToolbarLayoutMode::Simple,
201201
ToolbarLayoutModeOption::Regular => ToolbarLayoutMode::Regular,
@@ -262,6 +262,7 @@ impl std::fmt::Display for OverrideOption {
262262
}
263263

264264
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
265+
#[allow(clippy::enum_variant_names)]
265266
pub enum ToolbarOverrideField {
266267
ShowPresets,
267268
ShowActionsSection,

src/backend/wayland/toolbar/layout.rs

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -290,9 +290,9 @@ impl ToolbarLayoutSpec {
290290
return 0.0;
291291
}
292292

293-
let basic_count = if show_actions_section { 3 } else { 0 };
293+
let basic_count: usize = if show_actions_section { 3 } else { 0 };
294294
let show_delay_actions = snapshot.show_step_section && snapshot.show_delay_sliders;
295-
let advanced_count = if show_actions_advanced {
295+
let advanced_count: usize = if show_actions_advanced {
296296
if show_delay_actions { 9 } else { 7 }
297297
} else {
298298
0
@@ -304,7 +304,7 @@ impl ToolbarLayoutSpec {
304304
let total_icons = basic_count + advanced_count;
305305
let icons_per_row = 6usize;
306306
let rows = if total_icons > 0 {
307-
(total_icons + icons_per_row - 1) / icons_per_row
307+
total_icons.div_ceil(icons_per_row)
308308
} else {
309309
0
310310
};
@@ -322,7 +322,7 @@ impl ToolbarLayoutSpec {
322322
0.0
323323
};
324324
let advanced_rows = if advanced_count > 0 {
325-
((advanced_count + 1) / 2) as usize
325+
advanced_count.div_ceil(2)
326326
} else {
327327
0
328328
};
@@ -488,24 +488,25 @@ pub fn build_top_hits(
488488
fill_anchor = Some((rect_x, circle_end_x - rect_x));
489489
}
490490

491-
if fill_tool_active && !(is_simple && snapshot.shape_picker_open) {
492-
if let Some((fill_x, fill_w)) = fill_anchor {
493-
let fill_y = y + btn_size + ToolbarLayoutSpec::TOP_ICON_FILL_OFFSET;
494-
hits.push(HitRegion {
495-
rect: (
496-
fill_x,
497-
fill_y,
498-
fill_w,
499-
ToolbarLayoutSpec::TOP_ICON_FILL_HEIGHT,
500-
),
501-
event: ToolbarEvent::ToggleFill(!snapshot.fill_enabled),
502-
kind: HitKind::Click,
503-
tooltip: Some(super::format_binding_label(
504-
"Fill",
505-
snapshot.binding_hints.fill.as_deref(),
506-
)),
507-
});
508-
}
491+
if fill_tool_active
492+
&& !(is_simple && snapshot.shape_picker_open)
493+
&& let Some((fill_x, fill_w)) = fill_anchor
494+
{
495+
let fill_y = y + btn_size + ToolbarLayoutSpec::TOP_ICON_FILL_OFFSET;
496+
hits.push(HitRegion {
497+
rect: (
498+
fill_x,
499+
fill_y,
500+
fill_w,
501+
ToolbarLayoutSpec::TOP_ICON_FILL_HEIGHT,
502+
),
503+
event: ToolbarEvent::ToggleFill(!snapshot.fill_enabled),
504+
kind: HitKind::Click,
505+
tooltip: Some(super::format_binding_label(
506+
"Fill",
507+
snapshot.binding_hints.fill.as_deref(),
508+
)),
509+
});
509510
}
510511

511512
hits.push(HitRegion {

src/backend/wayland/toolbar/render.rs

Lines changed: 71 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -208,32 +208,33 @@ pub fn render_top_strip(
208208
fill_anchor = Some((rect_x, circle_end_x - rect_x));
209209
}
210210

211-
if fill_tool_active && !(is_simple && snapshot.shape_picker_open) {
212-
if let Some((fill_x, fill_w)) = fill_anchor {
213-
let fill_y = y + btn_size + ToolbarLayoutSpec::TOP_ICON_FILL_OFFSET;
214-
let fill_hover = hover
215-
.map(|(hx, hy)| point_in_rect(hx, hy, fill_x, fill_y, fill_w, fill_h))
216-
.unwrap_or(false);
217-
draw_mini_checkbox(
218-
ctx,
219-
fill_x,
220-
fill_y,
221-
fill_w,
222-
fill_h,
223-
snapshot.fill_enabled,
224-
fill_hover,
211+
if fill_tool_active
212+
&& !(is_simple && snapshot.shape_picker_open)
213+
&& let Some((fill_x, fill_w)) = fill_anchor
214+
{
215+
let fill_y = y + btn_size + ToolbarLayoutSpec::TOP_ICON_FILL_OFFSET;
216+
let fill_hover = hover
217+
.map(|(hx, hy)| point_in_rect(hx, hy, fill_x, fill_y, fill_w, fill_h))
218+
.unwrap_or(false);
219+
draw_mini_checkbox(
220+
ctx,
221+
fill_x,
222+
fill_y,
223+
fill_w,
224+
fill_h,
225+
snapshot.fill_enabled,
226+
fill_hover,
227+
"Fill",
228+
);
229+
hits.push(HitRegion {
230+
rect: (fill_x, fill_y, fill_w, fill_h),
231+
event: ToolbarEvent::ToggleFill(!snapshot.fill_enabled),
232+
kind: HitKind::Click,
233+
tooltip: Some(format_binding_label(
225234
"Fill",
226-
);
227-
hits.push(HitRegion {
228-
rect: (fill_x, fill_y, fill_w, fill_h),
229-
event: ToolbarEvent::ToggleFill(!snapshot.fill_enabled),
230-
kind: HitKind::Click,
231-
tooltip: Some(format_binding_label(
232-
"Fill",
233-
snapshot.binding_hints.fill.as_deref(),
234-
)),
235-
});
236-
}
235+
snapshot.binding_hints.fill.as_deref(),
236+
)),
237+
});
237238
}
238239

239240
let is_hover = hover
@@ -887,7 +888,10 @@ pub fn render_side_palette(
887888
if value.chars().count() <= max_chars {
888889
value.to_string()
889890
} else {
890-
let mut truncated = value.chars().take(max_chars.saturating_sub(3)).collect::<String>();
891+
let mut truncated = value
892+
.chars()
893+
.take(max_chars.saturating_sub(3))
894+
.collect::<String>();
891895
truncated.push_str("...");
892896
truncated
893897
}
@@ -1059,40 +1063,38 @@ pub fn render_side_palette(
10591063
draw_round_rect(ctx, swatch_x, swatch_y, swatch_size, swatch_size, 4.0);
10601064
let _ = ctx.stroke();
10611065

1062-
if slot_hover {
1063-
if let Some(name) = preset_name {
1064-
let display_name = truncate_label(name, 12);
1065-
ctx.select_font_face(
1066-
"Sans",
1067-
cairo::FontSlant::Normal,
1068-
cairo::FontWeight::Normal,
1069-
);
1070-
ctx.set_font_size(10.0);
1071-
if let Ok(extents) = ctx.text_extents(&display_name) {
1072-
let pad_x = 5.0;
1073-
let pad_y = 2.0;
1074-
let label_w = extents.width() + pad_x * 2.0;
1075-
let label_h = extents.height() + pad_y * 2.0;
1076-
let mut label_x = slot_x + (slot_size - label_w) / 2.0;
1077-
let label_y = (slot_row_y - label_h - 2.0).max(y + 2.0);
1078-
let min_x = card_x + 2.0;
1079-
let max_x = card_x + card_w - label_w - 2.0;
1080-
if label_x < min_x {
1081-
label_x = min_x;
1082-
}
1083-
if label_x > max_x {
1084-
label_x = max_x;
1085-
}
1086-
ctx.set_source_rgba(0.12, 0.12, 0.18, 0.92);
1087-
draw_round_rect(ctx, label_x, label_y, label_w, label_h, 4.0);
1088-
let _ = ctx.fill();
1089-
ctx.set_source_rgba(1.0, 1.0, 1.0, 0.95);
1090-
ctx.move_to(
1091-
label_x + pad_x - extents.x_bearing(),
1092-
label_y + pad_y - extents.y_bearing(),
1093-
);
1094-
let _ = ctx.show_text(&display_name);
1066+
if slot_hover && let Some(name) = preset_name {
1067+
let display_name = truncate_label(name, 12);
1068+
ctx.select_font_face(
1069+
"Sans",
1070+
cairo::FontSlant::Normal,
1071+
cairo::FontWeight::Normal,
1072+
);
1073+
ctx.set_font_size(10.0);
1074+
if let Ok(extents) = ctx.text_extents(&display_name) {
1075+
let pad_x = 5.0;
1076+
let pad_y = 2.0;
1077+
let label_w = extents.width() + pad_x * 2.0;
1078+
let label_h = extents.height() + pad_y * 2.0;
1079+
let mut label_x = slot_x + (slot_size - label_w) / 2.0;
1080+
let label_y = (slot_row_y - label_h - 2.0).max(y + 2.0);
1081+
let min_x = card_x + 2.0;
1082+
let max_x = card_x + card_w - label_w - 2.0;
1083+
if label_x < min_x {
1084+
label_x = min_x;
1085+
}
1086+
if label_x > max_x {
1087+
label_x = max_x;
10951088
}
1089+
ctx.set_source_rgba(0.12, 0.12, 0.18, 0.92);
1090+
draw_round_rect(ctx, label_x, label_y, label_w, label_h, 4.0);
1091+
let _ = ctx.fill();
1092+
ctx.set_source_rgba(1.0, 1.0, 1.0, 0.95);
1093+
ctx.move_to(
1094+
label_x + pad_x - extents.x_bearing(),
1095+
label_y + pad_y - extents.y_bearing(),
1096+
);
1097+
let _ = ctx.show_text(&display_name);
10961098
}
10971099
}
10981100
} else {
@@ -1770,16 +1772,16 @@ pub fn render_side_palette(
17701772
let icons_per_row = 6usize;
17711773
let total_icons = actions.len();
17721774
let rows = if total_icons > 0 {
1773-
(total_icons + icons_per_row - 1) / icons_per_row
1775+
total_icons.div_ceil(icons_per_row)
17741776
} else {
17751777
0
17761778
};
17771779
for row in 0..rows {
17781780
let row_start = row * icons_per_row;
17791781
let row_end = (row_start + icons_per_row).min(total_icons);
17801782
let icons_in_row = row_end - row_start;
1781-
let row_width = icons_in_row as f64 * icon_btn_size
1782-
+ (icons_in_row as f64 - 1.0) * icon_gap;
1783+
let row_width =
1784+
icons_in_row as f64 * icon_btn_size + (icons_in_row as f64 - 1.0) * icon_gap;
17831785
let row_x = x + (content_width - row_width) / 2.0;
17841786
for col in 0..icons_in_row {
17851787
let idx = row_start + col;
@@ -2102,15 +2104,9 @@ pub fn render_side_palette(
21022104
HitKind::DragCustomRedoDelay
21032105
},
21042106
tooltip: Some(if is_undo {
2105-
format!(
2106-
"Undo step delay: {:.1}s (drag)",
2107-
delay_ms as f64 / 1000.0
2108-
)
2107+
format!("Undo step delay: {:.1}s (drag)", delay_ms as f64 / 1000.0)
21092108
} else {
2110-
format!(
2111-
"Redo step delay: {:.1}s (drag)",
2112-
delay_ms as f64 / 1000.0
2113-
)
2109+
format!("Redo step delay: {:.1}s (drag)", delay_ms as f64 / 1000.0)
21142110
}),
21152111
});
21162112

@@ -2272,7 +2268,7 @@ pub fn render_side_palette(
22722268
let toggle_col_gap = toggle_gap;
22732269
let toggle_col_w = (content_width - toggle_col_gap) / 2.0;
22742270
ctx.set_font_size(12.0);
2275-
for row in 0..((toggles.len() + 1) / 2) {
2271+
for row in 0..toggles.len().div_ceil(2) {
22762272
for col in 0..2 {
22772273
let idx = row * 2 + col;
22782274
if idx >= toggles.len() {
@@ -2281,7 +2277,9 @@ pub fn render_side_palette(
22812277
let (label, value, event, tooltip) = &toggles[idx];
22822278
let toggle_x = x + col as f64 * (toggle_col_w + toggle_col_gap);
22832279
let toggle_hover = hover
2284-
.map(|(hx, hy)| point_in_rect(hx, hy, toggle_x, toggle_y, toggle_col_w, toggle_h))
2280+
.map(|(hx, hy)| {
2281+
point_in_rect(hx, hy, toggle_x, toggle_y, toggle_col_w, toggle_h)
2282+
})
22852283
.unwrap_or(false);
22862284
draw_checkbox(
22872285
ctx,
@@ -2300,7 +2298,7 @@ pub fn render_side_palette(
23002298
tooltip: tooltip.map(|text| text.to_string()),
23012299
});
23022300
}
2303-
if row + 1 < (toggles.len() + 1) / 2 {
2301+
if row + 1 < toggles.len().div_ceil(2) {
23042302
toggle_y += toggle_h + toggle_gap;
23052303
} else {
23062304
toggle_y += toggle_h;

src/config/mod.rs

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -582,48 +582,48 @@ impl Config {
582582
.clamp(MIN_STROKE_THICKNESS, MAX_STROKE_THICKNESS);
583583
}
584584

585-
if let Some(opacity) = preset.marker_opacity.as_mut() {
586-
if !(0.05..=0.9).contains(opacity) {
587-
log::warn!(
588-
"Invalid marker_opacity {:.2} in preset slot {}, clamping to 0.05-0.90 range",
589-
*opacity,
590-
slot
591-
);
592-
*opacity = opacity.clamp(0.05, 0.9);
593-
}
585+
if let Some(opacity) = preset.marker_opacity.as_mut()
586+
&& !(0.05..=0.9).contains(opacity)
587+
{
588+
log::warn!(
589+
"Invalid marker_opacity {:.2} in preset slot {}, clamping to 0.05-0.90 range",
590+
*opacity,
591+
slot
592+
);
593+
*opacity = opacity.clamp(0.05, 0.9);
594594
}
595595

596-
if let Some(size) = preset.font_size.as_mut() {
597-
if !(8.0..=72.0).contains(size) {
598-
log::warn!(
599-
"Invalid font_size {:.1} in preset slot {}, clamping to 8.0-72.0 range",
600-
*size,
601-
slot
602-
);
603-
*size = size.clamp(8.0, 72.0);
604-
}
596+
if let Some(size) = preset.font_size.as_mut()
597+
&& !(8.0..=72.0).contains(size)
598+
{
599+
log::warn!(
600+
"Invalid font_size {:.1} in preset slot {}, clamping to 8.0-72.0 range",
601+
*size,
602+
slot
603+
);
604+
*size = size.clamp(8.0, 72.0);
605605
}
606606

607-
if let Some(length) = preset.arrow_length.as_mut() {
608-
if !(5.0..=50.0).contains(length) {
609-
log::warn!(
610-
"Invalid arrow_length {:.1} in preset slot {}, clamping to 5.0-50.0 range",
611-
*length,
612-
slot
613-
);
614-
*length = length.clamp(5.0, 50.0);
615-
}
607+
if let Some(length) = preset.arrow_length.as_mut()
608+
&& !(5.0..=50.0).contains(length)
609+
{
610+
log::warn!(
611+
"Invalid arrow_length {:.1} in preset slot {}, clamping to 5.0-50.0 range",
612+
*length,
613+
slot
614+
);
615+
*length = length.clamp(5.0, 50.0);
616616
}
617617

618-
if let Some(angle) = preset.arrow_angle.as_mut() {
619-
if !(15.0..=60.0).contains(angle) {
620-
log::warn!(
621-
"Invalid arrow_angle {:.1} in preset slot {}, clamping to 15.0-60.0 range",
622-
*angle,
623-
slot
624-
);
625-
*angle = angle.clamp(15.0, 60.0);
626-
}
618+
if let Some(angle) = preset.arrow_angle.as_mut()
619+
&& !(15.0..=60.0).contains(angle)
620+
{
621+
log::warn!(
622+
"Invalid arrow_angle {:.1} in preset slot {}, clamping to 15.0-60.0 range",
623+
*angle,
624+
slot
625+
);
626+
*angle = angle.clamp(15.0, 60.0);
627627
}
628628
};
629629

0 commit comments

Comments
 (0)