-
Notifications
You must be signed in to change notification settings - Fork 77
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Support for BorderChar on Table level #259
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @assemmarwan
Thanks for contribution,
I think you misunderstood the issue a bit.
(As well as I did with the example in the issue :))
The idea is that you target a specific line in a table being not dependent on row/column.
For example you want to set a char at 3rd horizontal line, it might be a 3rd row (with offset 0) or it may be a 2nd (with offset 1) or even 1st row (with offset 3).
It'd need to create a new public function/struct like
BorderChar::horizontal_exact(3, ':', Offset::End(0))
// or
ExactLine::horizontal(3, BorderChar::horizontal(':', Offset::End(0)))
I'd go with the 1st interface as it less general, though ExactLine
sounds interesting for some cases but not exactly here.
The implementation is relatively simple as well.
You'd need to calculate the needed exact row/column based on relative offset and index.
- iterate over rows/columns
- Use
Table::get_width_ctrl
,Table::get_height_ctrl
to get row/column height/width - Check if you belong to the corresponding row/column
- If you do then iterate over row/column to find a cell by
Offset
in a similar way.
Ohhh, I think I got you. I agree with you to use If you don't mind share a sample table output when |
@zhiburt Do I keep the misunderstood feature 😅 ? Or should I discard it? |
I guess it's better be discarded as we can do exactly this by. Modify::new(Segment::all()).with(BorderChar ... )
original table
To be honest I got stuck thinking about:
Let me know what you think. |
Nice. I will revert my changes 👍🏻
Thanks for the explanation 😃
For the sake of consistency with the current implementation, I would say not to allow it. But if we were to allow it, how would we achieve that with current implementation? Because all offsets start without the external border (intersection) always. If you would point me to how it's done please.
I think to remain consistent with the original BorderChar::vertical_exact(2, '$', Offset::Start(3)) Also to achieve this:
We can do it by: BorderChar::horizontal_exact(1, '$', Offset::Start(10)) |
Then actually we could achieve it by So I would try to do it my way?
You'd need to call So yes I tend to believe it's possible to do.
|
Alright, so I'll work on it such that:
|
I have noticed that the functions Lines 293 to 313 in 64d6808
What do you recommend that I use to determine the target position of the character? |
I've forgot about it. (it actually a subject to change in the future).
What do you mean?
|
@zhiburt Would you please assist about how to tell whether a cell has borders. This is assuming I have the border. is this way valid? let mut border = table.get_config_mut()
.get_border((0, 0), (count_rows, count_cols));
let has_border = border.top.is_some(); |
Yes
PS: Maybe its worth to improve the documentation of papergrid a bit 😞 |
Accidentally I needed to experiment with this; And I've got some work in progress patchwork. (surely it requires some tests and refactorings) I'd say it's quite bad from performance perspective but it seems to work (I didn't test it well, just have a few runs). impl<R> tabled::TableOption<R> for SetHorizontalChar
where
R: Records,
{
fn change(&mut self, table: &mut tabled::Table<R>) {
let shape = table.shape();
let is_last_line = self.line == (shape.0 * 2);
let mut row = self.line;
if is_last_line {
row = self.line - 1;
}
let mut evaluator = tabled::papergrid::width::WidthEstimator::default();
evaluator.estimate(table.get_records(), table.get_config());
let widths: Vec<_> = evaluator.into();
let mut i = 0;
for column in 0..shape.1 {
let has_vertical = table.get_config().has_vertical(column, shape.1);
if has_vertical {
if self.position == i {
let mut border = table.get_config().get_border((row, column), shape);
if is_last_line {
border.left_bottom_corner = Some(self.c1);
} else {
border.left_top_corner = Some(self.c1);
}
table.get_config_mut().set_border((row, column), border);
return;
}
i += 1;
}
let width = widths[column];
if self.position < i + width {
let offset = self.position + 1 - i;
// let offset = width - offset;
table.get_config_mut().override_horizontal_border(
(self.line, column),
self.c2,
tabled::papergrid::Offset::Begin(offset),
);
return;
}
i += width;
}
let has_vertical = table.get_config().has_vertical(shape.1, shape.1);
if self.position == i && has_vertical {
let mut border = table.get_config().get_border((row, shape.1), shape);
if is_last_line {
border.left_bottom_corner = Some(self.c1);
} else {
border.left_top_corner = Some(self.c1);
}
table.get_config_mut().set_border((row, shape.1), border);
}
}
} |
Add support for
BorderChar
on Table Level as mentioned in the issue: #239ToDo List