Fix progress bar showing incorrectly with small width. (#1307)
- [x] I have disclosed use of any AI generated code in my commit messages. - If you are using an LLM, and do not fully understand the changes it is making to the code base, do not create a PR. - In our experience, AI generated code often results in overly complex code that lacks enough context for a proper fix or feature inclusion. This results in considerably longer code reviews. Due to this, AI authored or partially authored PRs may be closed without comment. - [x] I understand these changes in full and will be able to respond to review comments. - [x] My change is accurately described in the commit message. - [x] My contribution is tested and working as described. - [x] I have read the [Developer Certificate of Origin](https://developercertificate.org/) and certify my contribution under its conditions. https://github.com/user-attachments/assets/0efa09fc-0b41-4e28-acfa-3967eee8e443 Fix for this pop-os/cosmic-monitor#8 Need feedback on UI if this is intended design for progress on low value.
This commit is contained in:
commit
ad5ea1621c
1 changed files with 81 additions and 24 deletions
|
|
@ -197,24 +197,59 @@ 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 = |x: f32, width: f32, color: iced::Color, border: iced::Border| {
|
let mut draw_quad = |x: f32,
|
||||||
// don't draw if width is less than 0.1 pixels
|
width: f32,
|
||||||
if width * bounds.width > 0.1 {
|
color: iced::Color,
|
||||||
renderer.fill_quad(
|
mut border: iced::Border,
|
||||||
renderer::Quad {
|
is_track: bool,
|
||||||
bounds: Rectangle {
|
total_progress_width: f32| {
|
||||||
x: bounds.x + x * bounds.width,
|
let mut height = bounds.height;
|
||||||
y: bounds.y,
|
if !is_track {
|
||||||
width: width * bounds.width,
|
// For progress that is at the end of completion
|
||||||
height: bounds.height,
|
if total_progress_width > bounds.width - radius {
|
||||||
},
|
let border_radius =
|
||||||
border,
|
radius.min(bounds.height / 2.0) - (bounds.width - total_progress_width);
|
||||||
snap: true,
|
border.radius.top_right = border_radius;
|
||||||
..renderer::Quad::default()
|
border.radius.bottom_right = border_radius;
|
||||||
},
|
} else {
|
||||||
color,
|
border.radius.top_right = 0.0;
|
||||||
);
|
border.radius.bottom_right = 0.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// For indeterminate mode or when progress has just started
|
||||||
|
if x < radius.min(bounds.height / 2.0) {
|
||||||
|
let border_radius = radius.min(bounds.height / 2.0) - x;
|
||||||
|
border.radius.top_left = border_radius;
|
||||||
|
border.radius.bottom_left = border_radius;
|
||||||
|
|
||||||
|
if total_progress_width < radius.min(bounds.height / 2.0) {
|
||||||
|
height =
|
||||||
|
bounds.height - 2.0 * radius.min(bounds.height / 2.0) + total_progress_width * 2.0;
|
||||||
|
}
|
||||||
|
} 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,
|
||||||
|
},
|
||||||
|
border,
|
||||||
|
snap: true,
|
||||||
|
..renderer::Quad::default()
|
||||||
|
},
|
||||||
|
color,
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
if self.progress.is_some() {
|
if self.progress.is_some() {
|
||||||
|
|
@ -230,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)
|
||||||
|
|
@ -247,27 +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,
|
||||||
},
|
},
|
||||||
|
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()
|
||||||
},
|
},
|
||||||
|
false,
|
||||||
|
absolute_width * bounds.width,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -275,13 +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(),
|
||||||
},
|
},
|
||||||
|
true,
|
||||||
|
bounds.width,
|
||||||
);
|
);
|
||||||
|
|
||||||
// draw bar
|
// draw bar
|
||||||
|
|
@ -298,8 +341,22 @@ where
|
||||||
..iced::Border::default()
|
..iced::Border::default()
|
||||||
};
|
};
|
||||||
|
|
||||||
draw_quad(start, right_width, custom_style.bar_color, border);
|
draw_quad(
|
||||||
draw_quad(0.0, left_width, custom_style.bar_color, border);
|
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