1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
//! GTK rasteriser for [`crate::ProgressBar`].
//!
//! Painting is implemented in the shared
//! [`crate::primitives::progress::native_surface_paint::paint`].
//! This module carries [`gtk_progress_layout`], the backend-specific
//! pure geometry computation (no painting involved).
use crate::primitives::layout_metrics::pixel_progress_layout;
use crate::primitives::progress::{ProgressBar, ProgressBarLayout};
/// Compute the GTK pixel-unit layout for a [`ProgressBar`] without
/// painting. Shares its cancel-affordance width with
/// `mac_progress_layout` / `win_progress_layout` via
/// [`pixel_progress_layout`].
pub fn gtk_progress_layout(bar: &ProgressBar, x: f64, y: f64, w: f64, h: f64) -> ProgressBarLayout {
pixel_progress_layout(bar, x as f32, y as f32, w as f32, h as f32)
}
#[cfg(test)]
mod tests {
use super::*;
use crate::primitives::progress::ProgressBarHit;
use crate::types::WidgetId;
/// `progress_layout` is documented **ABSOLUTE**:
/// `fill_bounds` / `cancel_bounds` must start at the bar's own
/// origin, not (0, 0) — the case that hides a LOCAL/ABSOLUTE mixup.
fn round_trip_at(x: f64, y: f64) {
let bar = ProgressBar {
id: WidgetId::new("prog"),
label: String::new(),
value: Some(0.5),
frame_idx: 0,
cancellable: true,
accent: None,
};
let layout = gtk_progress_layout(&bar, x, y, 100.0, 20.0);
let fb = layout.fill_bounds.expect("determinate fill present");
assert_eq!(fb.x as f64, x);
assert_eq!(fb.y as f64, y);
let cb = layout.cancel_bounds.expect("cancel bounds present");
let ccx = cb.x + cb.width / 2.0;
let ccy = cb.y + cb.height / 2.0;
assert_eq!(
layout.hit_test(ccx, ccy),
ProgressBarHit::Cancel(bar.id.clone())
);
let bcx = fb.x + 1.0;
assert_eq!(
layout.hit_test(bcx, y as f32 + 1.0),
ProgressBarHit::Body(bar.id)
);
}
#[test]
fn paint_and_click_round_trip() {
round_trip_at(0.0, 0.0);
}
/// Regression guard: layout must be correct at non-zero origins.
#[test]
fn paint_and_click_round_trip_at_nonzero_origin() {
round_trip_at(7.0, 13.0);
}
}