#[non_exhaustive]pub struct TableMetrics {
pub content_width: u32,
pub content_height: u32,
pub col_widths: Vec<u32>,
pub row_height: u32,
pub header_height: u32,
pub pad: u32,
pub row_count: u32,
pub col_count: u32,
}Expand description
Content size and column widths. Does not depend on the viewport.
Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.content_width: u32Full table width including padding.
content_height: u32Full table height including padding and header.
col_widths: Vec<u32>Per-column pixel widths (content, no pad).
row_height: u32Body row height.
header_height: u32Sticky header height.
pad: u32Outer padding.
row_count: u32Data row count.
col_count: u32Column count.
Implementations§
Source§impl TableMetrics
impl TableMetrics
Sourcepub fn max_origin_x(&self) -> u32
pub fn max_origin_x(&self) -> u32
Maximum origin_x a host should send (inclusive).
Sourcepub fn max_origin_y(&self) -> u32
pub fn max_origin_y(&self) -> u32
Maximum origin_y (body pixels) a host should send.
Sourcepub fn resize_column(&self, index: usize, width: u32) -> Vec<u32>
pub fn resize_column(&self, index: usize, width: u32) -> Vec<u32>
Column widths with index set to width (clamped to ≥ 8px).
Examples found in repository?
examples/scroll_resize.rs (line 52)
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 352)
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 fn with_resized_column(&self, index: usize, width: u32) -> Self
pub fn with_resized_column(&self, index: usize, width: u32) -> Self
Metrics after a column resize (content width recomputed).
Trait Implementations§
Source§impl Clone for TableMetrics
impl Clone for TableMetrics
Source§impl Debug for TableMetrics
impl Debug for TableMetrics
impl Eq for TableMetrics
Source§impl PartialEq for TableMetrics
impl PartialEq for TableMetrics
impl StructuralPartialEq for TableMetrics
Auto Trait Implementations§
impl Forget for TableMetrics
impl Freeze for TableMetrics
impl Move for TableMetrics
impl RefUnwindSafe for TableMetrics
impl Send for TableMetrics
impl Sync for TableMetrics
impl Unpin for TableMetrics
impl UnsafeUnpin for TableMetrics
impl UnwindSafe for TableMetrics
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