-
Notifications
You must be signed in to change notification settings - Fork 68
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
Use percentages for relative heights of panels #67
Conversation
To avoid cutting off panels altogether use percentages for the various panels instead of fixed heights for all but process panel. By default the process panel occupies 10% more space than other non-zero ones.
This reverts commit e91a90a.
I had tried using percentages before for arranging these panels, but I wasn't able to come to a good layout. I'll take a look at this and your other PR probably this weekend. Thank you for the contributions! |
So a few comments -
|
I see, but the same issue can be seen with the original code too (see screenshot using original build). The tui library must be trying to fit everything in given constraints and there must be some "residues" which are not being redistributed. Will have to take a look at its code.
Makes sense. Will need changes to the tui library.
Cannot reproduce this problem. Do you see this with Mac or Linux or both? I don't see how this PR can effect that behaviour.
Yeah, that's a bit of a problem. This is also the case when one starts with zero size on command-line with and without this change. Pressing TAB actually lands up in that invisible section in both cases but there is no visual feedback though one can expand it back. Can make the change to avoid going down to zero size but the problem with zero size on command-line remains (visually the issue is that pressing TAB lands up in that invisible area with no visual feedback to the user and 'e' does expand it). The command-line issue should be tracked with a separate bug where the fix should be to make the section completely disappear rather than being invisible. |
I tried reproducing this on the original code for a while and I wasn't able to do it. What screen dimensions did you use?
I was thinking we could do this in zenith but still providing the specific heights to TUI but figuring what they should be using the percentages and some rules. So for example if we had the CPU section at 20% - screen height was 43 Characters - (43 * .2) = 8.6. From here we could round to nearest even integer to come up with specific section size (8).
Did my testing on Ubuntu.
Yes, I have to admit this was a bit of laziness on my part ;). |
issue #71, mentioned in #67 (comment)
- use an ordered vector to track the geometry of each section (height for now) instead of using separate variables for each section - convert the height percentages into lengths before applying as constraints - catch terminal resize event and recalculate the lengths as per percentages - apply the constraints that non-process sections should have even number of rows, each section should be at least size 2, process section should have at least size 4; this is after accounting for all other section heights
@bvaisvil I have updated the commit as per the comments. In addition have changed to use an "ordered" vector of sections with their heights instead of separate variables. The vector contains only the sections that are non-zero in size. Additionally it does not depend on a fixed order of sections rather the code will now follow whatever order of sections (from top to bottom) appear in the vector. In future it will be much easier to have vertical splits etc which I think will be required if sensors is added, for example, due to lack of real estate even now. The code to remove sections if zero in size has been updated to only render as per what appears in the vector. Conversion of percentages to actual heights is a bit more code than desirable due to constraints like each section must be have at least size 2, process section should have at least size 4 etc. It should be fairly straightforward though. Additionally when a section is resized (e/m), then other section sizes are proportionally reduced. Of course, this is only in terms of percentages while the translation to rows may or may not show up when those values are converted to integers (or even numbers) and user may need to press multiple times and that may reduce multiple sections at once. I think this is for the best since the alternative of picking up a random section to reduce the size can cause unexpected sections to shrink (from user's pov). Please check how it looks and review the code. I have played with sizes and e/m quite a bit, and overall I think it now does about the best it can within the constraints even under extreme (e.g. keep pressing 'e' continuously for one section then other and so on). |
Really like how this works, thanks for reworking it! I have noticed an issue, however. When shrinking the window, at some point there is a subtraction with overflow panic: process_index = section_index as i32;
// floor to nearest integer and set constraint as Min
process_height = max_section_height.min(required_height.floor().max(4.0) as u16);
max_section_height -= process_height - 4; // <-- this line panics
constraints.push(Constraint::Min(process_height)); These were the dimensions I was using to cause the crash:
|
use i32 in calculations and cast to u16 at the last moment where required after ensuring that the i32's are all positive (>= 2 for heights in this case)
Fixed. Using i32's for calculation now and convert to u16 at the last point (heights all ensured to be >=2 by then). |
also added some more function comments
- pass a flag to check if process table had to "borrow" from others to keep its minimum size and abort size change due to e/m keys if that is the case - some other cleanups
To avoid cutting off panels altogether, use percentages for the various panels
instead of fixed heights (for all but process panel).
By default the process panel occupies 10% more space than other non-zero ones.
See the comparison in the two attached screenshots for before and after the patch in my default terminal having a size of 140x40.
These screenshots compare maximized terminal windows for before and after where the two are similar.