mirror of
https://github.com/zaphar/sheetsui.git
synced 2025-07-23 05:19:48 -04:00
wip: refactor cell styling into a separte method.
This commit is contained in:
parent
e9b422b2db
commit
45c081c512
@ -159,24 +159,7 @@ impl<'ws> Viewport<'ws> {
|
|||||||
.book
|
.book
|
||||||
.get_cell_addr_rendered(&Address { row: ri, col: *ci })
|
.get_cell_addr_rendered(&Address { row: ri, col: *ci })
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let mut cell = Cell::new(Text::raw(content));
|
self.compute_cell_style(ri, ci, Cell::new(Text::raw(content)))
|
||||||
if let Some((start, end)) =
|
|
||||||
&self.range_selection.map_or(None, |r| r.get_range())
|
|
||||||
{
|
|
||||||
if ri >= start.row
|
|
||||||
&& ri <= end.row
|
|
||||||
&& *ci >= start.col
|
|
||||||
&& *ci <= end.col
|
|
||||||
{
|
|
||||||
// This is a selected range
|
|
||||||
cell = cell.fg(Color::Black).bg(Color::LightBlue)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
match (self.book.location.row == ri, self.book.location.col == *ci) {
|
|
||||||
(true, true) => cell.fg(Color::White).bg(Color::Rgb(57, 61, 71)),
|
|
||||||
_ => cell,
|
|
||||||
}
|
|
||||||
.bold()
|
|
||||||
},
|
},
|
||||||
));
|
));
|
||||||
Row::new(cells)
|
Row::new(cells)
|
||||||
@ -208,6 +191,27 @@ impl<'ws> Viewport<'ws> {
|
|||||||
.column_spacing(0)
|
.column_spacing(0)
|
||||||
.flex(Flex::Start))
|
.flex(Flex::Start))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn compute_cell_style<'widget>(&self, ri: usize, ci: &usize, mut cell: Cell<'widget>) -> Cell<'widget> {
|
||||||
|
if let Some((start, end)) =
|
||||||
|
&self.range_selection.map_or(None, |r| r.get_range())
|
||||||
|
{
|
||||||
|
if ri >= start.row
|
||||||
|
&& ri <= end.row
|
||||||
|
&& *ci >= start.col
|
||||||
|
&& *ci <= end.col
|
||||||
|
{
|
||||||
|
// This is a selected range
|
||||||
|
cell = cell.fg(Color::Black).bg(Color::LightBlue)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
match (self.book.location.row == ri, self.book.location.col == *ci) {
|
||||||
|
(true, true) => cell.fg(Color::White).bg(Color::Rgb(57, 61, 71)),
|
||||||
|
// TODO(zaphar): Support ironcalc style options
|
||||||
|
_ => cell,
|
||||||
|
}
|
||||||
|
.bold()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'ws> StatefulWidget for Viewport<'ws> {
|
impl<'ws> StatefulWidget for Viewport<'ws> {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user