pub struct Row {
pub id: RowId,
pub cells: Vec<CellValue>,
}Expand description
One data row.
Fields§
§id: RowIdOpaque id.
cells: Vec<CellValue>Cells aligned to Grid::columns.
Implementations§
Source§impl Row
impl Row
Sourcepub fn new(id: u32, cells: Vec<CellValue>) -> Self
pub fn new(id: u32, cells: Vec<CellValue>) -> Self
Construct a row. Length is checked in Grid::try_new.
Examples found in repository?
examples/gallery.rs (lines 600-607)
597fn demo_grid() -> Grid {
598 let mut rows = Vec::new();
599 for i in 0..16u32 {
600 rows.push(Row::new(
601 i,
602 vec![
603 CellValue::text(format!("SKU-{i:03}")),
604 CellValue::float(12.0 + f64::from(i) * 2.15, 2),
605 CellValue::int(i64::from(i) * 4 + 3),
606 ],
607 ));
608 }
609 Grid::try_new(
610 vec![
611 Column::new(0, "sku"),
612 Column::new(1, "price"),
613 Column::new(2, "qty"),
614 ],
615 rows,
616 )
617 .expect("grid")
618}More examples
examples/scroll_resize.rs (lines 17-24)
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/host_contract.rs (lines 40-46)
37fn main() -> Result<(), Box<dyn std::error::Error>> {
38 let mut rows = Vec::new();
39 for i in 0..80u32 {
40 rows.push(Row::new(
41 i,
42 vec![
43 CellValue::text(format!("ACME-SKU-{i}")),
44 CellValue::float(10.0 + f64::from(i), 2),
45 ],
46 ));
47 }
48 let grid = Grid::try_new(vec![Column::new(0, "sku"), Column::new(1, "price")], rows)?;
49
50 let surface = Surface::new(SurfaceMode::Sealed, LicenseLens::open());
51 let metrics = surface.metrics(&grid);
52
53 // Host scrollbar: window 480×160, content from metrics.
54 let window = Viewport {
55 origin_x: 0,
56 origin_y: 0,
57 width: 480,
58 height: 160,
59 };
60 println!(
61 "host scrollbar: content {}x{} window {}x{} max_origin_y={}",
62 metrics.content_width,
63 metrics.content_height,
64 window.width,
65 window.height,
66 metrics.content_height.saturating_sub(window.height)
67 );
68
69 let dir = std::env::temp_dir().join("sealed-surface-examples");
70 fs::create_dir_all(&dir)?;
71
72 for (name, origin_y) in [("y0", 0u32), ("y180", 180), ("y360", 360)] {
73 let mut req = FrameRequest::full(Viewport {
74 origin_x: 0,
75 origin_y,
76 width: window.width,
77 height: window.height,
78 });
79 req.pointer = Some(Pointer { x: 24, y: 40 });
80 let frame = surface.render(&grid, &req)?;
81 let path = dir.join(format!("host_{name}.png"));
82 fs::write(&path, &frame.png)?;
83 assert!(
84 frame.host.audit_text().is_empty(),
85 "sealed host leaked: {:?}",
86 frame.host.audit_text()
87 );
88 println!(
89 "{name}: rows {}..{} png={} tooltip={} file={}",
90 frame.visible_row_start,
91 frame.visible_row_end,
92 frame.png.len(),
93 frame.tooltip_png.as_ref().map_or(0, Vec::len),
94 path.display()
95 );
96 }
97
98 println!("forbidden: interpolating cell values, tooltip JSON, CSS blur over live rows");
99 println!("allowed: <img alt=\"\"> + tooltip PNG + metrics-driven origin");
100 Ok(())
101}examples/paint_grid.rs (lines 23-30)
15fn main() -> Result<(), Box<dyn std::error::Error>> {
16 let grid = Grid::try_new(
17 vec![
18 Column::new(0, "sku"),
19 Column::new(1, "price"),
20 Column::new(2, "qty"),
21 ],
22 vec![
23 Row::new(
24 0,
25 vec![
26 CellValue::text("ACME-SKU-1"),
27 CellValue::float(49.00, 2),
28 CellValue::int(12),
29 ],
30 ),
31 Row::new(
32 1,
33 vec![
34 CellValue::text("ACME-SKU-2"),
35 CellValue::float(19.50, 2),
36 CellValue::int(3),
37 ],
38 ),
39 Row::new(
40 2,
41 vec![
42 CellValue::text("SECRET-ROW"),
43 CellValue::float(999.00, 2),
44 CellValue::int(1),
45 ],
46 ),
47 ],
48 )?;
49
50 let mut surface = Surface::new(
51 SurfaceMode::Sealed,
52 LicenseLens::from_tier(AccessTier::Trial),
53 );
54 let metrics = surface.metrics(&grid);
55 let mut req = FrameRequest::full(Viewport {
56 origin_x: 0,
57 origin_y: 0,
58 width: metrics.content_width.clamp(320, 960),
59 height: metrics.content_height.clamp(120, 360),
60 });
61 req.pointer = Some(Pointer { x: 24, y: 36 });
62
63 let frame = surface.render(&grid, &req)?;
64 let dir = example_out_dir();
65 fs::create_dir_all(&dir)?;
66 let frame_path = dir.join("frame.png");
67 fs::write(&frame_path, &frame.png)?;
68 if let Some(tip) = &frame.tooltip_png {
69 fs::write(dir.join("tooltip.png"), tip)?;
70 }
71 let renders = PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("examples/renders");
72 fs::create_dir_all(&renders)?;
73 fs::write(renders.join("readme_table.png"), &frame.png)?;
74 if let Some(tip) = &frame.tooltip_png {
75 fs::write(renders.join("readme_tooltip.png"), tip)?;
76 }
77
78 println!("mode={:?} lens=trial", surface.mode());
79 println!(
80 "content={}x{} visible_rows={}..{} png_bytes={}",
81 frame.content_width,
82 frame.content_height,
83 frame.visible_row_start,
84 frame.visible_row_end,
85 frame.png.len()
86 );
87 println!(
88 "host audit (must not contain prices): {:?}",
89 frame.host.audit_text()
90 );
91 println!("wrote {}", frame_path.display());
92
93 surface.set_mode(SurfaceMode::Copyable);
94 let copyable = surface.render(&grid, &req)?;
95 println!("copyable TSV:\n{}", copyable.host.audit_text());
96
97 write_readme_shots(&renders)?;
98 Ok(())
99}
100
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}Trait Implementations§
impl StructuralPartialEq for Row
Auto Trait Implementations§
impl Forget for Row
impl Freeze for Row
impl Move for Row
impl RefUnwindSafe for Row
impl Send for Row
impl Sync for Row
impl Unpin for Row
impl UnsafeUnpin for Row
impl UnwindSafe for Row
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