-
Notifications
You must be signed in to change notification settings - Fork 27
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
Wide tables will clip off the right side #111
Comments
You could consider using Taffy's (https://github.com/DioxusLabs/taffy) CSS Grid support for laying out tables. It won't perfectly match the HTML table layout algorithm, but it ought to be pretty close and do a good job of sensibly distributing content to fit a space, and should also work well with nested tables. |
@nicoburns I'll definitely look into this once the glyphon pr is merged. And also see if there's other places it can be used. Thanks |
Awesome. You can probably use it for all your layout/positioning needs until you get down to the level of text/images (essentially for all the block-level HTML elements) if you want to. If you're willing to use Taffy's
|
@nicoburns tried yesterday to convert the tables to a CSS grid but implemented it in a weird way due to not knowing about MeasureFunc. Thanks heaps for that. I'll try to get a semi working PR together soon and you can help guide it the rest of the way if your willing. |
Also cloning the text for now won't be as dreadful as you'd think since the actual rendered text is kept cached, you'd just be cloning the actual string and styling (not great but not bad). |
Re: MeasureFunc. I've realised this isn't very well documented but:
Where: struct Size<T> { width: T, height: T }
Agreed. I figure that'll like be quick enough to start with, and it can be optimised later. |
@nicoburns I'm currently dealing with a bug where the spacing between grid items seems to grow relative to the size of the root node, any suggestions? |
@trimental Are you using a percentage size for the |
Heres the gist of the taffy code https://gist.github.com/trimental/0e2dcf9eeca78cd69eb9d6d077bf2717. The width of each node seems to be calculated correctly, its just the position of each node except the first per axis that grows. (Btw that code is very wip. I turned off gap to see if that fixed anything) |
I think the issue here is that you're setting the |
grid_template_columns: vec![repeat(taffy::style::GridTrackRepetition::Count(max_columns as u16), vec![auto(); max_columns]); self.headers.len() + self.rows.len()] You're also generating far too many columns here. You either want:
For rows you want:
or you can simply omit the |
@nicoburns I'm a bit confused with passing the bounds as available_space. Won't it just get turned into max_content? https://github.com/DioxusLabs/taffy/blob/5443996198f02cf5a6c6493499df3cf08394a70f/src/compute/grid/mod.rs#L168 |
So each node in the tree gets a different "available space" passed to it. You get to pass in the "available space" of the root node (in this case the grid). And that node's algorithm will choose an "available space" to pass into it's children. The line you are referencing here is the grid container computing what it will pass as available space when sizing it's children. But the grid algorithm will measure it's children multiple times with different constraints and intelligently interpolate between their "min content" and "max context" sizes (according to it's own "available space", the sizes given to tracks (rows/columns), and the sizes of other grid children, etc) so that doesn't really imply anything about the sizes that nodes will end up. If you pass in definite available space: let available_space = Size {
width: AvailableSpace::Definite(bounds.0),
height: AvailableSpace::Definite(bounds.1),
};
taffy.compute_layout(root, available_space).unwrap(); Or perhaps only constraining the width, leaving the height indefinite because we can scroll: let available_space = Size {
width: AvailableSpace::Definite(bounds.0),
height: AvailableSpace::MaxContent,
};
taffy.compute_layout(root, available_space).unwrap(); then the grid will max out at that width (wrapping text as needed) unless it contains content that can't be shrunk (for example a really long word with no line-break opportunities). |
I've put the code I've got at the moment in this branch with this commit c109c60. I'm guessing that I must be either constructing the tree wrong or handling the measure function wrong. Setting the node width length to bounds.0 seems to make it resize but just using available_size works (with a weird aligning issue though). |
@trimental What exactly is going wrong here? This commit seems to render the table in the Taffy README just fine (well, except that the "Yoga" column wraps, which it shouldn't): I have simplified the text measure func (and updated it to also use the known_dimensions as bound when set) here: https://github.com/nicoburns/inlyne/tree/taffy-table-1
This makes sense. By setting the |
I think you might want to revert back to setting grid_row and grid_column on each individual table cell. This will work better than the current setup in the case that there is a row with missing cells. |
@nicoburns if possible id like to mimic the vscode markdown viewer by wrapping lines if the window size isn't large enough to display the table. Although it does look like wrapping is occuring in your example. |
Ah, I didn't realise it wasn't wrapping properly. I think it's a bug in Taffy that the Grid doesn't properly constrain itself by the available_space parameter (or max_width) when it's the root node. Finite "available_space" on the root node is actually something that our test harness isn't setup to test currently, so I'm not entirely suprised this was missed. I will try to get that fixed (or at least investigated), but in the meantime I was able to workaround this issue by wrapping the grid in a flexbox node. I've pushed a few commits to the same branch as before:
|
Thanks. I really appreciate the time and knowledge your providing. Once this is in I'll start looking into the other areas we can use taffy. |
Repro
Rendered by GitHub
Rendered by
inlyne
table_clipping.mp4
The text was updated successfully, but these errors were encountered: