pub struct Viewport {
pub origin_x: u32,
pub origin_y: u32,
pub width: u32,
pub height: u32,
}Expand description
Pixel viewport. origin_* is the scroll; width/height is the window.
Fields§
§origin_x: u32Horizontal scroll in content pixels (header + body).
origin_y: u32Vertical scroll in body pixels (header is sticky).
width: u32Window width in pixels.
height: u32Window height in pixels.
Implementations§
Source§impl Viewport
impl Viewport
Sourcepub const fn window(width: u32, height: u32) -> Self
pub const fn window(width: u32, height: u32) -> Self
Window at origin (0, 0).
Examples found in repository?
examples/paint_grid.rs (line 125)
101fn write_readme_shots(renders: &std::path::Path) -> Result<(), Box<dyn std::error::Error>> {
102 let mut rows = Vec::new();
103 for i in 0..8u32 {
104 rows.push(Row::new(
105 i,
106 vec![
107 CellValue::text(format!("SKU-{i:03}")),
108 CellValue::float(12.0 + f64::from(i) * 2.15, 2),
109 CellValue::int(i64::from(i) * 4 + 3),
110 ],
111 ));
112 }
113 let grid = Grid::try_new(
114 vec![
115 Column::new(0, "sku"),
116 Column::new(1, "price"),
117 Column::new(2, "qty"),
118 ],
119 rows,
120 )?;
121 let surface = Surface::new(SurfaceMode::Sealed, LicenseLens::open());
122 let m = surface.metrics(&grid);
123 let frame = surface.render(
124 &grid,
125 &FrameRequest::full(Viewport::window(m.content_width.max(320), 200)),
126 )?;
127 fs::write(renders.join("readme_table.png"), &frame.png)?;
128 Ok(())
129}More examples
examples/scroll_resize.rs (line 40)
14fn main() -> Result<(), Box<dyn std::error::Error>> {
15 let mut rows = Vec::new();
16 for i in 0..40u32 {
17 rows.push(Row::new(
18 i,
19 vec![
20 CellValue::text(format!("SKU-{i:03}")),
21 CellValue::float(10.0 + f64::from(i), 2),
22 CellValue::int(i64::from(i) * 3),
23 ],
24 ));
25 }
26 let grid = Grid::try_new(
27 vec![
28 Column::new(0, "sku"),
29 Column::new(1, "price"),
30 Column::new(2, "qty"),
31 ],
32 rows,
33 )?;
34
35 let surface = Surface::new(SurfaceMode::Sealed, LicenseLens::open());
36 let metrics = surface.metrics(&grid);
37 let dir = renders_dir();
38 fs::create_dir_all(&dir)?;
39
40 let window = Viewport::window(420, 140);
41 let frames = [
42 ("scroll_y0.png", window.clamp_to(&metrics), None),
43 ("scroll_y90.png", window.scroll_by(0, 90, &metrics), None),
44 (
45 "scroll_clamped.png",
46 window.scroll_by(0, 9_999, &metrics),
47 None,
48 ),
49 (
50 "resize_sku200.png",
51 window,
52 Some(metrics.resize_column(0, 200)),
53 ),
54 ];
55
56 for (name, vp, widths) in frames {
57 let mut req = FrameRequest::full(vp);
58 if let Some(w) = widths {
59 req = req.column_widths(w);
60 }
61 let frame = surface.render(&grid, &req)?;
62 let path = dir.join(name);
63 fs::write(&path, &frame.png)?;
64 println!(
65 "{name}: origin_y={} visible {}..{} bytes={} -> {}",
66 vp.origin_y,
67 frame.visible_row_start,
68 frame.visible_row_end,
69 frame.png.len(),
70 path.display()
71 );
72 }
73 Ok(())
74}examples/scatter.rs (line 36)
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"), ©.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 45)
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"), ©.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 43)
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"), ©.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}examples/gallery.rs (line 246)
241 fn build() -> Result<Self, sealed_surface::Error> {
242 let grid = demo_grid();
243 let series = demo_series()?;
244 let scatter = demo_scatter()?;
245 let tree = demo_tree()?;
246 let vp_table = Viewport::window(520, 220);
247 let vp_chart = Viewport::window(640, 280);
248 let mut specs = BTreeMap::new();
249 let mut add = |id, spec: Spec| {
250 specs.insert(id, spec);
251 };
252
253 add(
254 "table-default",
255 Spec {
256 title: "Table · default (compact)",
257 blurb: "TypeScale::Compact — 5×7, row 18. Hover for PNG tooltip.",
258 kind: Kind::Table,
259 appearance: Appearance::default(),
260 mode: SurfaceMode::Sealed,
261 lens: LicenseLens::open(),
262 viewport: vp_table,
263 caption: None,
264 widths: None,
265 },
266 );
267 add(
268 "table-large",
269 Spec {
270 title: "Table · large (2×)",
271 blurb: "TypeScale::large() — opt-in; bigger bitmap, more strain.",
272 kind: Kind::Table,
273 appearance: Appearance::large(),
274 mode: SurfaceMode::Sealed,
275 lens: LicenseLens::open(),
276 viewport: Viewport::window(640, 280),
277 caption: None,
278 widths: None,
279 },
280 );
281 add(
282 "table-xlarge",
283 Spec {
284 title: "Table · xlarge (3×)",
285 blurb: "TypeScale::xlarge().",
286 kind: Kind::Table,
287 appearance: Appearance::xlarge(),
288 mode: SurfaceMode::Sealed,
289 lens: LicenseLens::open(),
290 viewport: Viewport::window(720, 320),
291 caption: None,
292 widths: None,
293 },
294 );
295 add(
296 "table-light",
297 Spec {
298 title: "Table · light",
299 blurb: "Theme::light(), compact glyphs.",
300 kind: Kind::Table,
301 appearance: Appearance::light(),
302 mode: SurfaceMode::Sealed,
303 lens: LicenseLens::open(),
304 viewport: vp_table,
305 caption: None,
306 widths: None,
307 },
308 );
309 add(
310 "table-hc",
311 Spec {
312 title: "Table · high contrast",
313 blurb: "Near-white text, strong grid.",
314 kind: Kind::Table,
315 appearance: Appearance::high_contrast(),
316 mode: SurfaceMode::Sealed,
317 lens: LicenseLens::open(),
318 viewport: vp_table,
319 caption: None,
320 widths: None,
321 },
322 );
323
324 let mut tmp = Surface::new(SurfaceMode::Sealed, LicenseLens::open());
325 tmp.set_appearance(Appearance::default());
326 let m = tmp.metrics(&grid);
327 add(
328 "table-scroll",
329 Spec {
330 title: "Table · scroll_by",
331 blurb: "Sticky header; body scrolled three rows.",
332 kind: Kind::Table,
333 appearance: Appearance::default(),
334 mode: SurfaceMode::Sealed,
335 lens: LicenseLens::open(),
336 viewport: vp_table.scroll_by(0, (m.row_height * 3) as i32, &m),
337 caption: None,
338 widths: None,
339 },
340 );
341 add(
342 "table-resize",
343 Spec {
344 title: "Table · column resize",
345 blurb: "SKU column forced to 220px.",
346 kind: Kind::Table,
347 appearance: Appearance::default(),
348 mode: SurfaceMode::Sealed,
349 lens: LicenseLens::open(),
350 viewport: vp_table,
351 caption: None,
352 widths: Some(m.resize_column(0, 220)),
353 },
354 );
355 add(
356 "table-copyable",
357 Spec {
358 title: "Table · copyable",
359 blurb: "Same pixels; TSV allowed. Tooltip still PNG.",
360 kind: Kind::Table,
361 appearance: Appearance::default(),
362 mode: SurfaceMode::Copyable,
363 lens: LicenseLens::open(),
364 viewport: vp_table,
365 caption: None,
366 widths: None,
367 },
368 );
369 add(
370 "table-trial",
371 Spec {
372 title: "Table · trial lens",
373 blurb: "Two clear rows; rest redacted before paint.",
374 kind: Kind::Table,
375 appearance: Appearance::default(),
376 mode: SurfaceMode::Sealed,
377 lens: LicenseLens::from_tier(AccessTier::Trial),
378 viewport: vp_table,
379 caption: None,
380 widths: None,
381 },
382 );
383 add(
384 "ts-default",
385 Spec {
386 title: "Timeseries · default",
387 blurb: "AA 2px stroke, area fill, nice ticks. Hover the line.",
388 kind: Kind::Series,
389 appearance: Appearance::default(),
390 mode: SurfaceMode::Sealed,
391 lens: LicenseLens::open(),
392 viewport: vp_chart,
393 caption: Some("px / qty"),
394 widths: None,
395 },
396 );
397 add(
398 "ts-large",
399 Spec {
400 title: "Timeseries · large type",
401 blurb: "Same chart, 2× tick glyphs.",
402 kind: Kind::Series,
403 appearance: Appearance::large(),
404 mode: SurfaceMode::Sealed,
405 lens: LicenseLens::open(),
406 viewport: vp_chart,
407 caption: Some("large"),
408 widths: None,
409 },
410 );
411 add(
412 "ts-light",
413 Spec {
414 title: "Timeseries · light",
415 blurb: "Light theme + derived ChartStyle.",
416 kind: Kind::Series,
417 appearance: Appearance::light(),
418 mode: SurfaceMode::Sealed,
419 lens: LicenseLens::open(),
420 viewport: vp_chart,
421 caption: Some("light"),
422 widths: None,
423 },
424 );
425 add(
426 "ts-hc",
427 Spec {
428 title: "Timeseries · high contrast",
429 blurb: "Strong grid and series colors.",
430 kind: Kind::Series,
431 appearance: Appearance::high_contrast(),
432 mode: SurfaceMode::Sealed,
433 lens: LicenseLens::open(),
434 viewport: vp_chart,
435 caption: Some("HC"),
436 widths: None,
437 },
438 );
439 add(
440 "ts-trial",
441 Spec {
442 title: "Timeseries · trial lens",
443 blurb: "Two samples kept per series.",
444 kind: Kind::Series,
445 appearance: Appearance::default(),
446 mode: SurfaceMode::Sealed,
447 lens: LicenseLens::from_tier(AccessTier::Trial),
448 viewport: vp_chart,
449 caption: Some("trial"),
450 widths: None,
451 },
452 );
453 add(
454 "sc-default",
455 Spec {
456 title: "Scatter · default",
457 blurb: "Unconnected markers. Same Series type, different encoding.",
458 kind: Kind::Scatter,
459 appearance: Appearance::default(),
460 mode: SurfaceMode::Sealed,
461 lens: LicenseLens::open(),
462 viewport: vp_chart,
463 caption: Some("scatter"),
464 widths: None,
465 },
466 );
467 add(
468 "sc-trial",
469 Spec {
470 title: "Scatter · trial lens",
471 blurb: "Two points kept per series.",
472 kind: Kind::Scatter,
473 appearance: Appearance::default(),
474 mode: SurfaceMode::Sealed,
475 lens: LicenseLens::from_tier(AccessTier::Trial),
476 viewport: vp_chart,
477 caption: Some("trial"),
478 widths: None,
479 },
480 );
481 add(
482 "tm-default",
483 Spec {
484 title: "Treemap · default",
485 blurb: "Squarified leaves. Hover a cell for PNG tooltip.",
486 kind: Kind::Tree,
487 appearance: Appearance::default(),
488 mode: SurfaceMode::Sealed,
489 lens: LicenseLens::open(),
490 viewport: Viewport::window(640, 320),
491 caption: Some("catalog"),
492 widths: None,
493 },
494 );
495 add(
496 "tm-trial",
497 Spec {
498 title: "Treemap · trial lens",
499 blurb: "Two leaves kept; areas reflow.",
500 kind: Kind::Tree,
501 appearance: Appearance::default(),
502 mode: SurfaceMode::Sealed,
503 lens: LicenseLens::from_tier(AccessTier::Trial),
504 viewport: Viewport::window(640, 320),
505 caption: Some("trial"),
506 widths: None,
507 },
508 );
509 add(
510 "tm-light",
511 Spec {
512 title: "Treemap · light",
513 blurb: "Same layout, light theme.",
514 kind: Kind::Tree,
515 appearance: Appearance::light(),
516 mode: SurfaceMode::Sealed,
517 lens: LicenseLens::open(),
518 viewport: Viewport::window(640, 320),
519 caption: Some("light"),
520 widths: None,
521 },
522 );
523
524 Ok(Self {
525 grid,
526 series,
527 scatter,
528 tree,
529 specs,
530 })
531 }Sourcepub const fn scrolled(self, origin_x: u32, origin_y: u32) -> Self
pub const fn scrolled(self, origin_x: u32, origin_y: u32) -> Self
Set scroll origins (body origin_y, table origin_x).
Sourcepub fn clamp_to(self, metrics: &TableMetrics) -> Self
pub fn clamp_to(self, metrics: &TableMetrics) -> Self
Clamp origins so they do not run past TableMetrics content.
Examples found in repository?
examples/scroll_resize.rs (line 42)
14fn main() -> Result<(), Box<dyn std::error::Error>> {
15 let mut rows = Vec::new();
16 for i in 0..40u32 {
17 rows.push(Row::new(
18 i,
19 vec![
20 CellValue::text(format!("SKU-{i:03}")),
21 CellValue::float(10.0 + f64::from(i), 2),
22 CellValue::int(i64::from(i) * 3),
23 ],
24 ));
25 }
26 let grid = Grid::try_new(
27 vec![
28 Column::new(0, "sku"),
29 Column::new(1, "price"),
30 Column::new(2, "qty"),
31 ],
32 rows,
33 )?;
34
35 let surface = Surface::new(SurfaceMode::Sealed, LicenseLens::open());
36 let metrics = surface.metrics(&grid);
37 let dir = renders_dir();
38 fs::create_dir_all(&dir)?;
39
40 let window = Viewport::window(420, 140);
41 let frames = [
42 ("scroll_y0.png", window.clamp_to(&metrics), None),
43 ("scroll_y90.png", window.scroll_by(0, 90, &metrics), None),
44 (
45 "scroll_clamped.png",
46 window.scroll_by(0, 9_999, &metrics),
47 None,
48 ),
49 (
50 "resize_sku200.png",
51 window,
52 Some(metrics.resize_column(0, 200)),
53 ),
54 ];
55
56 for (name, vp, widths) in frames {
57 let mut req = FrameRequest::full(vp);
58 if let Some(w) = widths {
59 req = req.column_widths(w);
60 }
61 let frame = surface.render(&grid, &req)?;
62 let path = dir.join(name);
63 fs::write(&path, &frame.png)?;
64 println!(
65 "{name}: origin_y={} visible {}..{} bytes={} -> {}",
66 vp.origin_y,
67 frame.visible_row_start,
68 frame.visible_row_end,
69 frame.png.len(),
70 path.display()
71 );
72 }
73 Ok(())
74}Sourcepub fn scroll_by(self, dx: i32, dy: i32, metrics: &TableMetrics) -> Self
pub fn scroll_by(self, dx: i32, dy: i32, metrics: &TableMetrics) -> Self
Pan by signed pixels, then Self::clamp_to.
Examples found in repository?
examples/scroll_resize.rs (line 43)
14fn main() -> Result<(), Box<dyn std::error::Error>> {
15 let mut rows = Vec::new();
16 for i in 0..40u32 {
17 rows.push(Row::new(
18 i,
19 vec![
20 CellValue::text(format!("SKU-{i:03}")),
21 CellValue::float(10.0 + f64::from(i), 2),
22 CellValue::int(i64::from(i) * 3),
23 ],
24 ));
25 }
26 let grid = Grid::try_new(
27 vec![
28 Column::new(0, "sku"),
29 Column::new(1, "price"),
30 Column::new(2, "qty"),
31 ],
32 rows,
33 )?;
34
35 let surface = Surface::new(SurfaceMode::Sealed, LicenseLens::open());
36 let metrics = surface.metrics(&grid);
37 let dir = renders_dir();
38 fs::create_dir_all(&dir)?;
39
40 let window = Viewport::window(420, 140);
41 let frames = [
42 ("scroll_y0.png", window.clamp_to(&metrics), None),
43 ("scroll_y90.png", window.scroll_by(0, 90, &metrics), None),
44 (
45 "scroll_clamped.png",
46 window.scroll_by(0, 9_999, &metrics),
47 None,
48 ),
49 (
50 "resize_sku200.png",
51 window,
52 Some(metrics.resize_column(0, 200)),
53 ),
54 ];
55
56 for (name, vp, widths) in frames {
57 let mut req = FrameRequest::full(vp);
58 if let Some(w) = widths {
59 req = req.column_widths(w);
60 }
61 let frame = surface.render(&grid, &req)?;
62 let path = dir.join(name);
63 fs::write(&path, &frame.png)?;
64 println!(
65 "{name}: origin_y={} visible {}..{} bytes={} -> {}",
66 vp.origin_y,
67 frame.visible_row_start,
68 frame.visible_row_end,
69 frame.png.len(),
70 path.display()
71 );
72 }
73 Ok(())
74}More examples
examples/gallery.rs (line 336)
241 fn build() -> Result<Self, sealed_surface::Error> {
242 let grid = demo_grid();
243 let series = demo_series()?;
244 let scatter = demo_scatter()?;
245 let tree = demo_tree()?;
246 let vp_table = Viewport::window(520, 220);
247 let vp_chart = Viewport::window(640, 280);
248 let mut specs = BTreeMap::new();
249 let mut add = |id, spec: Spec| {
250 specs.insert(id, spec);
251 };
252
253 add(
254 "table-default",
255 Spec {
256 title: "Table · default (compact)",
257 blurb: "TypeScale::Compact — 5×7, row 18. Hover for PNG tooltip.",
258 kind: Kind::Table,
259 appearance: Appearance::default(),
260 mode: SurfaceMode::Sealed,
261 lens: LicenseLens::open(),
262 viewport: vp_table,
263 caption: None,
264 widths: None,
265 },
266 );
267 add(
268 "table-large",
269 Spec {
270 title: "Table · large (2×)",
271 blurb: "TypeScale::large() — opt-in; bigger bitmap, more strain.",
272 kind: Kind::Table,
273 appearance: Appearance::large(),
274 mode: SurfaceMode::Sealed,
275 lens: LicenseLens::open(),
276 viewport: Viewport::window(640, 280),
277 caption: None,
278 widths: None,
279 },
280 );
281 add(
282 "table-xlarge",
283 Spec {
284 title: "Table · xlarge (3×)",
285 blurb: "TypeScale::xlarge().",
286 kind: Kind::Table,
287 appearance: Appearance::xlarge(),
288 mode: SurfaceMode::Sealed,
289 lens: LicenseLens::open(),
290 viewport: Viewport::window(720, 320),
291 caption: None,
292 widths: None,
293 },
294 );
295 add(
296 "table-light",
297 Spec {
298 title: "Table · light",
299 blurb: "Theme::light(), compact glyphs.",
300 kind: Kind::Table,
301 appearance: Appearance::light(),
302 mode: SurfaceMode::Sealed,
303 lens: LicenseLens::open(),
304 viewport: vp_table,
305 caption: None,
306 widths: None,
307 },
308 );
309 add(
310 "table-hc",
311 Spec {
312 title: "Table · high contrast",
313 blurb: "Near-white text, strong grid.",
314 kind: Kind::Table,
315 appearance: Appearance::high_contrast(),
316 mode: SurfaceMode::Sealed,
317 lens: LicenseLens::open(),
318 viewport: vp_table,
319 caption: None,
320 widths: None,
321 },
322 );
323
324 let mut tmp = Surface::new(SurfaceMode::Sealed, LicenseLens::open());
325 tmp.set_appearance(Appearance::default());
326 let m = tmp.metrics(&grid);
327 add(
328 "table-scroll",
329 Spec {
330 title: "Table · scroll_by",
331 blurb: "Sticky header; body scrolled three rows.",
332 kind: Kind::Table,
333 appearance: Appearance::default(),
334 mode: SurfaceMode::Sealed,
335 lens: LicenseLens::open(),
336 viewport: vp_table.scroll_by(0, (m.row_height * 3) as i32, &m),
337 caption: None,
338 widths: None,
339 },
340 );
341 add(
342 "table-resize",
343 Spec {
344 title: "Table · column resize",
345 blurb: "SKU column forced to 220px.",
346 kind: Kind::Table,
347 appearance: Appearance::default(),
348 mode: SurfaceMode::Sealed,
349 lens: LicenseLens::open(),
350 viewport: vp_table,
351 caption: None,
352 widths: Some(m.resize_column(0, 220)),
353 },
354 );
355 add(
356 "table-copyable",
357 Spec {
358 title: "Table · copyable",
359 blurb: "Same pixels; TSV allowed. Tooltip still PNG.",
360 kind: Kind::Table,
361 appearance: Appearance::default(),
362 mode: SurfaceMode::Copyable,
363 lens: LicenseLens::open(),
364 viewport: vp_table,
365 caption: None,
366 widths: None,
367 },
368 );
369 add(
370 "table-trial",
371 Spec {
372 title: "Table · trial lens",
373 blurb: "Two clear rows; rest redacted before paint.",
374 kind: Kind::Table,
375 appearance: Appearance::default(),
376 mode: SurfaceMode::Sealed,
377 lens: LicenseLens::from_tier(AccessTier::Trial),
378 viewport: vp_table,
379 caption: None,
380 widths: None,
381 },
382 );
383 add(
384 "ts-default",
385 Spec {
386 title: "Timeseries · default",
387 blurb: "AA 2px stroke, area fill, nice ticks. Hover the line.",
388 kind: Kind::Series,
389 appearance: Appearance::default(),
390 mode: SurfaceMode::Sealed,
391 lens: LicenseLens::open(),
392 viewport: vp_chart,
393 caption: Some("px / qty"),
394 widths: None,
395 },
396 );
397 add(
398 "ts-large",
399 Spec {
400 title: "Timeseries · large type",
401 blurb: "Same chart, 2× tick glyphs.",
402 kind: Kind::Series,
403 appearance: Appearance::large(),
404 mode: SurfaceMode::Sealed,
405 lens: LicenseLens::open(),
406 viewport: vp_chart,
407 caption: Some("large"),
408 widths: None,
409 },
410 );
411 add(
412 "ts-light",
413 Spec {
414 title: "Timeseries · light",
415 blurb: "Light theme + derived ChartStyle.",
416 kind: Kind::Series,
417 appearance: Appearance::light(),
418 mode: SurfaceMode::Sealed,
419 lens: LicenseLens::open(),
420 viewport: vp_chart,
421 caption: Some("light"),
422 widths: None,
423 },
424 );
425 add(
426 "ts-hc",
427 Spec {
428 title: "Timeseries · high contrast",
429 blurb: "Strong grid and series colors.",
430 kind: Kind::Series,
431 appearance: Appearance::high_contrast(),
432 mode: SurfaceMode::Sealed,
433 lens: LicenseLens::open(),
434 viewport: vp_chart,
435 caption: Some("HC"),
436 widths: None,
437 },
438 );
439 add(
440 "ts-trial",
441 Spec {
442 title: "Timeseries · trial lens",
443 blurb: "Two samples kept per series.",
444 kind: Kind::Series,
445 appearance: Appearance::default(),
446 mode: SurfaceMode::Sealed,
447 lens: LicenseLens::from_tier(AccessTier::Trial),
448 viewport: vp_chart,
449 caption: Some("trial"),
450 widths: None,
451 },
452 );
453 add(
454 "sc-default",
455 Spec {
456 title: "Scatter · default",
457 blurb: "Unconnected markers. Same Series type, different encoding.",
458 kind: Kind::Scatter,
459 appearance: Appearance::default(),
460 mode: SurfaceMode::Sealed,
461 lens: LicenseLens::open(),
462 viewport: vp_chart,
463 caption: Some("scatter"),
464 widths: None,
465 },
466 );
467 add(
468 "sc-trial",
469 Spec {
470 title: "Scatter · trial lens",
471 blurb: "Two points kept per series.",
472 kind: Kind::Scatter,
473 appearance: Appearance::default(),
474 mode: SurfaceMode::Sealed,
475 lens: LicenseLens::from_tier(AccessTier::Trial),
476 viewport: vp_chart,
477 caption: Some("trial"),
478 widths: None,
479 },
480 );
481 add(
482 "tm-default",
483 Spec {
484 title: "Treemap · default",
485 blurb: "Squarified leaves. Hover a cell for PNG tooltip.",
486 kind: Kind::Tree,
487 appearance: Appearance::default(),
488 mode: SurfaceMode::Sealed,
489 lens: LicenseLens::open(),
490 viewport: Viewport::window(640, 320),
491 caption: Some("catalog"),
492 widths: None,
493 },
494 );
495 add(
496 "tm-trial",
497 Spec {
498 title: "Treemap · trial lens",
499 blurb: "Two leaves kept; areas reflow.",
500 kind: Kind::Tree,
501 appearance: Appearance::default(),
502 mode: SurfaceMode::Sealed,
503 lens: LicenseLens::from_tier(AccessTier::Trial),
504 viewport: Viewport::window(640, 320),
505 caption: Some("trial"),
506 widths: None,
507 },
508 );
509 add(
510 "tm-light",
511 Spec {
512 title: "Treemap · light",
513 blurb: "Same layout, light theme.",
514 kind: Kind::Tree,
515 appearance: Appearance::light(),
516 mode: SurfaceMode::Sealed,
517 lens: LicenseLens::open(),
518 viewport: Viewport::window(640, 320),
519 caption: Some("light"),
520 widths: None,
521 },
522 );
523
524 Ok(Self {
525 grid,
526 series,
527 scatter,
528 tree,
529 specs,
530 })
531 }Trait Implementations§
impl Copy for Viewport
impl Eq for Viewport
impl StructuralPartialEq for Viewport
Auto Trait Implementations§
impl Forget for Viewport
impl Freeze for Viewport
impl Move for Viewport
impl RefUnwindSafe for Viewport
impl Send for Viewport
impl Sync for Viewport
impl Unpin for Viewport
impl UnsafeUnpin for Viewport
impl UnwindSafe for Viewport
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more