Fix progress bar now has flat egde.
This commit is contained in:
parent
dc4e89596a
commit
9b8c48a328
1 changed files with 80 additions and 34 deletions
|
|
@ -197,33 +197,60 @@ where
|
||||||
let border_color = custom_style.border_color.unwrap_or(custom_style.bar_color);
|
let border_color = custom_style.border_color.unwrap_or(custom_style.bar_color);
|
||||||
let radius = custom_style.border_radius;
|
let radius = custom_style.border_radius;
|
||||||
|
|
||||||
let mut draw_quad =
|
let mut draw_quad = |x: f32,
|
||||||
|x: f32, width: f32, color: iced::Color, border: iced::Border, marker_segment: bool| {
|
width: f32,
|
||||||
let height = if width * bounds.width
|
color: iced::Color,
|
||||||
< border.radius.top_left.max(border.radius.bottom_left)
|
mut border: iced::Border,
|
||||||
&& !marker_segment
|
is_track: bool,
|
||||||
{
|
total_progress_width: f32| {
|
||||||
(bounds.height - (2.0 * radius).min(bounds.height) + width * bounds.width * 2.0)
|
let mut height = bounds.height;
|
||||||
.min(bounds.height)
|
if !is_track {
|
||||||
|
// For progress that is at the end of completion
|
||||||
|
if total_progress_width > bounds.width - radius {
|
||||||
|
let border_radius =
|
||||||
|
radius.min(bounds.height / 2.0) - (bounds.width - total_progress_width);
|
||||||
|
border.radius.top_right = border_radius;
|
||||||
|
border.radius.bottom_right = border_radius;
|
||||||
} else {
|
} else {
|
||||||
bounds.height
|
border.radius.top_right = 0.0;
|
||||||
};
|
border.radius.bottom_right = 0.0;
|
||||||
|
}
|
||||||
|
|
||||||
renderer.fill_quad(
|
// For indeterminate mode or when progress has just started
|
||||||
renderer::Quad {
|
if x < radius.min(bounds.height / 2.0) {
|
||||||
bounds: Rectangle {
|
let border_radius = radius.min(bounds.height / 2.0) - x;
|
||||||
x: bounds.x + x * bounds.width,
|
border.radius.top_left = border_radius;
|
||||||
y: bounds.y + (bounds.height - height) / 2.0,
|
border.radius.bottom_left = border_radius;
|
||||||
width: width * bounds.width,
|
|
||||||
height,
|
if total_progress_width < radius.min(bounds.height / 2.0) {
|
||||||
},
|
height =
|
||||||
border,
|
bounds.height - 2.0 * radius.min(bounds.height / 2.0) + total_progress_width * 2.0;
|
||||||
snap: true,
|
}
|
||||||
..renderer::Quad::default()
|
} else {
|
||||||
|
border.radius.top_left = 0.0;
|
||||||
|
border.radius.bottom_left = 0.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if x > bounds.width - radius.min(bounds.height / 2.0) {
|
||||||
|
height = bounds.height - 2.0 * radius.min(bounds.height / 2.0) + width * 2.0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
renderer.fill_quad(
|
||||||
|
renderer::Quad {
|
||||||
|
bounds: Rectangle {
|
||||||
|
x: bounds.x + x,
|
||||||
|
y: bounds.y + (bounds.height - height) / 2.0,
|
||||||
|
width,
|
||||||
|
height,
|
||||||
},
|
},
|
||||||
color,
|
border,
|
||||||
);
|
snap: true,
|
||||||
};
|
..renderer::Quad::default()
|
||||||
|
},
|
||||||
|
color,
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
if self.progress.is_some() {
|
if self.progress.is_some() {
|
||||||
let current_p = state.progress.current;
|
let current_p = state.progress.current;
|
||||||
|
|
@ -238,6 +265,7 @@ where
|
||||||
};
|
};
|
||||||
let drawable = 1.0 - gap * len as f32;
|
let drawable = 1.0 - gap * len as f32;
|
||||||
|
|
||||||
|
let mut absolute_width = 0.0;
|
||||||
for i in 0..=len {
|
for i in 0..=len {
|
||||||
let (seg_lo, r_left) = if i == 0 {
|
let (seg_lo, r_left) = if i == 0 {
|
||||||
(0.0, radius)
|
(0.0, radius)
|
||||||
|
|
@ -255,29 +283,32 @@ where
|
||||||
|
|
||||||
// draw track segment
|
// draw track segment
|
||||||
draw_quad(
|
draw_quad(
|
||||||
x_start,
|
x_start * bounds.width,
|
||||||
x_width,
|
x_width * bounds.width,
|
||||||
custom_style.track_color,
|
custom_style.track_color,
|
||||||
iced::Border {
|
iced::Border {
|
||||||
width: border_width,
|
width: border_width,
|
||||||
color: border_color,
|
color: border_color,
|
||||||
radius: segment_radius,
|
radius: segment_radius,
|
||||||
},
|
},
|
||||||
false,
|
true,
|
||||||
|
bounds.width,
|
||||||
);
|
);
|
||||||
|
|
||||||
// draw bar segment
|
// draw bar segment
|
||||||
if current_p > seg_lo {
|
if current_p > seg_lo {
|
||||||
let fill = ((current_p - seg_lo) / (seg_hi - seg_lo)).min(1.0);
|
let fill = ((current_p - seg_lo) / (seg_hi - seg_lo)).min(1.0);
|
||||||
|
absolute_width += x_width * fill;
|
||||||
draw_quad(
|
draw_quad(
|
||||||
x_start,
|
x_start * bounds.width,
|
||||||
x_width * fill,
|
x_width * fill * bounds.width,
|
||||||
custom_style.bar_color,
|
custom_style.bar_color,
|
||||||
iced::Border {
|
iced::Border {
|
||||||
radius: segment_radius,
|
radius: segment_radius,
|
||||||
..iced::Border::default()
|
..iced::Border::default()
|
||||||
},
|
},
|
||||||
i != 0,
|
false,
|
||||||
|
absolute_width * bounds.width,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -285,14 +316,15 @@ where
|
||||||
// draw track
|
// draw track
|
||||||
draw_quad(
|
draw_quad(
|
||||||
0.0,
|
0.0,
|
||||||
1.0,
|
bounds.width,
|
||||||
custom_style.track_color,
|
custom_style.track_color,
|
||||||
iced::Border {
|
iced::Border {
|
||||||
width: border_width,
|
width: border_width,
|
||||||
color: border_color,
|
color: border_color,
|
||||||
radius: radius.into(),
|
radius: radius.into(),
|
||||||
},
|
},
|
||||||
false,
|
true,
|
||||||
|
bounds.width,
|
||||||
);
|
);
|
||||||
|
|
||||||
// draw bar
|
// draw bar
|
||||||
|
|
@ -309,8 +341,22 @@ where
|
||||||
..iced::Border::default()
|
..iced::Border::default()
|
||||||
};
|
};
|
||||||
|
|
||||||
draw_quad(start, right_width, custom_style.bar_color, border, false);
|
draw_quad(
|
||||||
draw_quad(0.0, left_width, custom_style.bar_color, border, false);
|
start * bounds.width,
|
||||||
|
right_width * bounds.width,
|
||||||
|
custom_style.bar_color,
|
||||||
|
border,
|
||||||
|
false,
|
||||||
|
(right_width + start) * bounds.width,
|
||||||
|
);
|
||||||
|
draw_quad(
|
||||||
|
0.0,
|
||||||
|
left_width * bounds.width,
|
||||||
|
custom_style.bar_color,
|
||||||
|
border,
|
||||||
|
false,
|
||||||
|
left_width * bounds.width,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue