From: Andrea Zagli Date: Mon, 2 Jan 2023 14:47:18 +0000 (+0100) Subject: Adding column. X-Git-Url: https://saetta.ns0.it/gitweb?a=commitdiff_plain;h=029d2e4b1c1a93daa6288338967f1c2cef9b9a97;p=rust%2Fzakgrid Adding column. --- diff --git a/examples/grid.rs b/examples/grid.rs index 99516f8..4e470fb 100644 --- a/examples/grid.rs +++ b/examples/grid.rs @@ -52,8 +52,20 @@ async fn index( s.push_str(format!("after: {}\n", grid.header_tmpl).as_str()); let mut col = zakgrid::Column::new("col name"); + s.push_str(format!("column added: {}\n", col.name()).as_str()); + col.set_title("the column title"); + s.push_str(format!("column changed title: {}\n", col.title()).as_str()); + grid.add_column(col); - s.push_str(format!("column added: {}", col.name()).as_str()); + let mut col = zakgrid::Column::new("col2 name"); + col.set_title("the second column title"); + grid.add_column(col); + + let cols = grid.columns(); + + for (i, v) in cols.iter().enumerate() { + s.push_str(format!("col {} title {}\n", i, v.title()).as_str()); + } Ok(HttpResponse::Ok().body(s)) } diff --git a/src/lib.rs b/src/lib.rs index 5e2e86c..93e0582 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -24,6 +24,14 @@ impl Column { pub fn name(&self) -> String { format!("{}", self.name) } + + pub fn set_title(&mut self, title: &str) { + self.title = String::from(title); + } + + pub fn title(&self) -> String { + format!("{}", self.title) + } } pub struct Grid { @@ -44,4 +52,12 @@ impl Grid { columns: vec![] } } + + pub fn add_column(&mut self, col: Column) { + self.columns.push(col); + } + + pub fn columns(&self) -> &Vec { + &self.columns + } }