Skip to main content

Pointer

Struct Pointer 

Source
pub struct Pointer {
    pub x: u32,
    pub y: u32,
}
Expand description

Pointer in pixmap (window) pixel space.

Fields§

§x: u32

X.

§y: u32

Y.

Implementations§

Source§

impl Pointer

Source

pub const fn new(x: u32, y: u32) -> Self

Construct.

Examples found in repository?
examples/gallery.rs (line 104)
96fn route(g: &Gallery, stream: &mut TcpStream, path: &str, query: &str) {
97    if path == "/" || path == "/index.html" {
98        let html = index_html(g);
99        respond(stream, "text/html; charset=utf-8", html.as_bytes());
100        return;
101    }
102    if let Some(rest) = path.strip_prefix("/i/") {
103        let pointer = match (query_u32(query, "x"), query_u32(query, "y")) {
104            (Some(x), Some(y)) => Some(Pointer::new(x, y)),
105            _ => None,
106        };
107        if let Some(id) = rest.strip_suffix("/tip.png") {
108            match g.tooltip(id, pointer) {
109                Ok(Some(png)) => respond(stream, "image/png", &png),
110                Ok(None) => respond_status(stream, 204, b""),
111                Err(_) => respond_status(stream, 500, b"render"),
112            }
113            return;
114        }
115        let id = rest.strip_suffix(".png").unwrap_or(rest);
116        match g.frame_png(id, pointer) {
117            Ok(png) => respond(stream, "image/png", &png),
118            Err(_) => respond_status(stream, 404, b"not found"),
119        }
120        return;
121    }
122    respond_status(stream, 404, b"not found");
123}
More examples
Hide additional examples
examples/scatter.rs (line 42)
15fn main() -> Result<(), Box<dyn std::error::Error>> {
16    let mut a = Vec::new();
17    let mut b = Vec::new();
18    for i in 0..28u32 {
19        let t = f64::from(i);
20        a.push(SeriesPoint::new(
21            6.0 + (t * 0.37).sin() * 5.0 + t * 0.12,
22            22.0 + (t * 0.51).cos() * 8.0,
23        ));
24        b.push(SeriesPoint::new(
25            18.0 + (t * 0.29).cos() * 6.0,
26            12.0 + (t * 0.41).sin() * 7.0 + t * 0.15,
27        ));
28    }
29    a[10] = SeriesPoint::new(12.0, 49.37);
30
31    let layout = SeriesLayout::try_new(vec![Series::new(0, "a", a), Series::new(1, "b", b)])?;
32    let dir = PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("examples/renders");
33    fs::create_dir_all(&dir)?;
34
35    let mut sealed = Surface::new(SurfaceMode::Sealed, LicenseLens::open());
36    let vp = Viewport::window(520, 240);
37    let rest = FrameRequest::full(vp).caption("scatter");
38    let idle = sealed.render_scatter(&layout, &rest)?;
39    fs::write(dir.join("sc_sealed.png"), &idle.png)?;
40    fs::write(dir.join("readme_scatter.png"), &idle.png)?;
41
42    let hit = sealed.render_scatter(&layout, &rest.clone().pointer(Pointer::new(240, 110)))?;
43    fs::write(dir.join("sc_crosshair.png"), &hit.png)?;
44    if let Some(tip) = &hit.tooltip_png {
45        fs::write(dir.join("sc_tooltip.png"), tip)?;
46    }
47    println!(
48        "sealed scatter audit={:?} tooltip={}",
49        hit.host.audit_text(),
50        hit.tooltip_png.as_ref().map_or(0, Vec::len)
51    );
52
53    sealed.set_mode(SurfaceMode::Copyable);
54    let copy = sealed.render_scatter(&layout, &rest)?;
55    fs::write(dir.join("sc_copyable.png"), &copy.png)?;
56
57    let trial = Surface::new(
58        SurfaceMode::Sealed,
59        LicenseLens::from_tier(AccessTier::Trial),
60    );
61    let t = trial.render_scatter(&layout, &rest)?;
62    fs::write(dir.join("sc_trial_lens.png"), &t.png)?;
63    println!(
64        "wrote scatter renders; trial viewed rows={}",
65        t.viewed.rows.len()
66    );
67    Ok(())
68}
examples/treemap.rs (line 51)
15fn main() -> Result<(), Box<dyn std::error::Error>> {
16    let layout = TreeLayout::try_new(TreeNode::branch(
17        0,
18        "catalog",
19        vec![
20            TreeNode::branch(
21                1,
22                "apparel",
23                vec![
24                    TreeNode::leaf(2, "shirts", 42.0),
25                    TreeNode::leaf(3, "pants", 18.0),
26                    TreeNode::leaf(4, "hats", 9.0),
27                ],
28            ),
29            TreeNode::branch(
30                5,
31                "home",
32                vec![
33                    TreeNode::leaf(6, "lamps", 21.0),
34                    TreeNode::leaf(7, "rugs", 14.0),
35                ],
36            ),
37            TreeNode::leaf(8, "other", 7.0),
38        ],
39    ))?;
40
41    let dir = PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("examples/renders");
42    fs::create_dir_all(&dir)?;
43
44    let mut sealed = Surface::new(SurfaceMode::Sealed, LicenseLens::open());
45    let vp = Viewport::window(520, 280);
46    let rest = FrameRequest::full(vp).caption("catalog");
47    let idle = sealed.render_tree(&layout, &rest)?;
48    fs::write(dir.join("tm_sealed.png"), &idle.png)?;
49    fs::write(dir.join("readme_tree.png"), &idle.png)?;
50
51    let hit = sealed.render_tree(&layout, &rest.clone().pointer(Pointer::new(80, 90)))?;
52    fs::write(dir.join("tm_hover.png"), &hit.png)?;
53    if let Some(tip) = &hit.tooltip_png {
54        fs::write(dir.join("tm_tooltip.png"), tip)?;
55    }
56    println!(
57        "sealed tree audit={:?} hits={} tooltip={}",
58        hit.host.audit_text(),
59        hit.hits.len(),
60        hit.tooltip_png.as_ref().map_or(0, Vec::len)
61    );
62
63    sealed.set_mode(SurfaceMode::Copyable);
64    let copy = sealed.render_tree(&layout, &rest)?;
65    fs::write(dir.join("tm_copyable.png"), &copy.png)?;
66    println!(
67        "copyable TSV (120): {:?}",
68        copy.host.audit_text().chars().take(120).collect::<String>()
69    );
70
71    let trial = Surface::new(
72        SurfaceMode::Sealed,
73        LicenseLens::from_tier(AccessTier::Trial),
74    );
75    let t = trial.render_tree(&layout, &rest)?;
76    fs::write(dir.join("tm_trial_lens.png"), &t.png)?;
77    println!(
78        "wrote treemap renders; trial viewed rows={}",
79        t.viewed.rows.len()
80    );
81    Ok(())
82}
examples/timeseries.rs (line 45)
15fn main() -> Result<(), Box<dyn std::error::Error>> {
16    let mut pts = Vec::new();
17    for i in 0..48u32 {
18        let x = f64::from(i);
19        let y = 40.0 + 12.0 * (x * 0.28).sin() + x * 0.35;
20        pts.push(SeriesPoint::new(x, y));
21    }
22    // Distinct sealed-contract values near the middle of the window.
23    pts[20] = SeriesPoint::new(20.0, 49.37);
24
25    let layout = SeriesLayout::try_new(vec![
26        Series::new(0, "px", pts),
27        Series::new(
28            1,
29            "qty",
30            (0..48u32)
31                .map(|i| {
32                    let x = f64::from(i);
33                    SeriesPoint::new(x, 8.0 + (x * 0.19).cos() * 3.0)
34                })
35                .collect(),
36        ),
37    ])?;
38
39    let dir = PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("examples/renders");
40    fs::create_dir_all(&dir)?;
41
42    let mut sealed = Surface::new(SurfaceMode::Sealed, LicenseLens::open());
43    let vp = Viewport::window(520, 240);
44    let rest = FrameRequest::full(vp).caption("px / qty");
45    let rest_hit = rest.clone().pointer(Pointer::new(240, 110));
46
47    let idle = sealed.render_series(&layout, &rest)?;
48    fs::write(dir.join("ts_sealed.png"), &idle.png)?;
49    fs::write(dir.join("readme_chart.png"), &idle.png)?;
50    let hit = sealed.render_series(&layout, &rest_hit)?;
51    fs::write(dir.join("ts_crosshair.png"), &hit.png)?;
52    if let Some(tip) = &hit.tooltip_png {
53        fs::write(dir.join("ts_tooltip.png"), tip)?;
54    }
55    println!(
56        "sealed audit (must be empty of values): {:?}",
57        hit.host.audit_text()
58    );
59    println!(
60        "crosshair tooltip_png={} hits={}",
61        hit.tooltip_png.as_ref().map_or(0, Vec::len),
62        hit.hits.len()
63    );
64
65    sealed.set_mode(SurfaceMode::Copyable);
66    let copy = sealed.render_series(&layout, &rest)?;
67    fs::write(dir.join("ts_copyable.png"), &copy.png)?;
68    println!("copyable TSV (first 120 chars): {:?}", {
69        let a = copy.host.audit_text();
70        a.chars().take(120).collect::<String>()
71    });
72
73    let trial = Surface::new(
74        SurfaceMode::Sealed,
75        LicenseLens::from_tier(AccessTier::Trial),
76    );
77    let t = trial.render_series(&layout, &rest)?;
78    fs::write(dir.join("ts_trial_lens.png"), &t.png)?;
79    println!(
80        "trial lens viewed rows={} (two sample points per series)",
81        t.viewed.rows.len()
82    );
83
84    println!("wrote {}", dir.display());
85    Ok(())
86}

Trait Implementations§

Source§

impl Clone for Pointer

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for Pointer

Source§

impl Debug for Pointer

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for Pointer

Source§

impl PartialEq for Pointer

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Pointer

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.