Skip to content
Open
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
6 changes: 3 additions & 3 deletions src/components/bar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ impl Bar {
self
}

/// Set the number of the ticks, number below 2 disables the ticks
/// Set the number of the ticks, 0 disables the ticks (default)
pub fn ticks(mut self, n: usize) -> Self {
self.ticks = n;
self
Expand Down Expand Up @@ -154,7 +154,7 @@ impl Bar {
FontId::proportional(self.font_size),
text_color,
);
if self.ticks > 1 {
if self.ticks > 0 {
let diff = bar_rect.width() / 2.0 + 2.0;
let cx = bar_rect.center().x;
for i in 1..self.ticks + 1 {
Expand Down Expand Up @@ -248,7 +248,7 @@ impl egui::Widget for Bar {
});
},
);
if self.ticks > 1 {
if self.ticks > 0 {
if let Some(pb_response) = progress_bar_response {
let bar_rect = pb_response.rect;
let diff = bar_rect.height() / 2.0 + 2.0;
Expand Down
21 changes: 14 additions & 7 deletions src/components/gauge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ impl Gauge {
self
}

/// Set the number of the ticks, number below 2 disables the ticks
/// Set the number of the ticks, 0 disables the ticks
pub fn ticks(mut self, n: usize) -> Self {
self.ticks = n;
self
Expand All @@ -107,7 +107,7 @@ impl Gauge {
}

fn gauge_width(&self) -> f32 {
if self.ticks > 1 {
if self.ticks > 0 {
self.size - self.text_clearance() * 2.0
} else {
self.size
Expand Down Expand Up @@ -146,7 +146,7 @@ impl Gauge {
}

fn paint(&mut self, ui: &mut Ui, outer_rect: Rect, value: f64) {
let rect = if self.ticks > 1 {
let rect = if self.ticks > 0 {
outer_rect.shrink(self.text_clearance())
} else {
outer_rect
Expand All @@ -170,7 +170,7 @@ impl Gauge {
self.paint_point(ui, rect, max_angle);
}

if self.ticks >= 2 {
if self.ticks > 0 {
self.paint_ticks(ui, rect);
}

Expand Down Expand Up @@ -228,14 +228,21 @@ impl Gauge {
let font_size = self.gauge_width() / 15.0;

for i in 0..self.ticks {
if i == self.ticks - 1 && self.angle_range.end() - self.angle_range.start() >= 360 {
if self.ticks != 1
&& i == self.ticks - 1
&& self.angle_range.end() - self.angle_range.start() >= 360
{
continue;
}
#[allow(clippy::cast_precision_loss)]
let tick_value = *self.value_range.start() + step * i as f64;
let tick_value = if self.ticks == 1 {
*self.value_range.start() + value_range / 2.0
} else {
*self.value_range.start() + step * i as f64
};
let angle = self.value_to_angle(tick_value);

if self.ticks >= 2 {
if self.ticks > 0 {
let tick_inner = position_from_angle(rect, angle, self.radius() - self.tick_size);
let tick_outer = position_from_angle(rect, angle, self.radius() + self.tick_size);
ui.painter()
Expand Down