-
-
Notifications
You must be signed in to change notification settings - Fork 152
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
bug: dynamic alloc of layout constraints in task details screen #614
base: main
Are you sure you want to change the base?
Conversation
Changes i've made is for accomadating loong location names, ive changed the ... to the long name, it widens the task rectangle if its longer than the default 50% and goes to the next line if its longer than we can accomadate in a single line. This fixes issue tokio-rs#523 i have attached screenshots of the same in the PR, before and after changes
@vrn21 Thanks for working on this topic! So far this PR looks good. However, with a fixed number of rows, when you go to 2 lines for the location text, the "Idle" time is getting dropped off, so that needs to be resolved too. I think that there are some hints in the original issue regarding how to approach that issue. |
Thank you for looking into this @hds and Sorry for the delay, but i'm still not sure how i'm supposed to move forward with this, i cant really determine what the height of the task_area is, before hand as in the current code, number of lines extra needed can be only computed after the each of the constraint is set. Could you help on this? |
In the code that exists, the areas are computed up front, based on the constraints provided. However, those areas aren't actually used until the If the creation of the task and waker "widgets" (that's the variable name), is performed before the area is split on constraints, then we can already compute the number of lines that each one needs and use that as input to the Does that help? |
…ask details screen I've made the logic to look whether Location is longer than a single viewable length, even before setting constraints both vertically and horizontally. This fixes issue tokio-rs#523
Sorry again for the delay, Does this work @hds? I've changed the logic to check whether locations is longer than what is viewable in a single line, before hand, assigning constraints (both vertical and horizontal) afterwards. |
This is looking good! There are a few style and layout things, but the functionality appears correct. I'll get you a proper review of this on Monday. Thanks for your work! |
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.
This is looking good, thanks! There are some changes I've suggested.
tokio-console/src/view/task.rs
Outdated
let first_line = location_lines_vector[0].clone(); | ||
location_lines_vector.remove(0); | ||
let location_vector = vec![bold(location_heading), Span::raw(first_line)]; |
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.
I think that we can use the reference here, can't we? We don't need to clone or manipulate the Vec.
let first_line = location_lines_vector[0].clone(); | |
location_lines_vector.remove(0); | |
let location_vector = vec![bold(location_heading), Span::raw(first_line)]; | |
let location_vector = vec![bold(location_heading), Span::raw(location_lines_vector[0])]; |
tokio-console/src/view/task.rs
Outdated
for line in location_lines_vector { | ||
overview.push(Line::from(Span::raw(format!(" {}", line)))); | ||
} |
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.
Then here we can use the vec slice:
for line in location_lines_vector { | |
overview.push(Line::from(Span::raw(format!(" {}", line)))); | |
} | |
for line in location_lines_vector[1..] { | |
overview.push(Line::from(Span::raw(format!(" {}", line)))); | |
} |
tokio-console/src/view/task.rs
Outdated
|
||
let location_heading = "Location: "; | ||
let location_max_width = stats_area_check[0].width as usize - 2 - location_heading.len(); // NOTE: -2 for the border | ||
let max_width_stats_area = area.width - 45; |
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.
Can we give the 45
a name? I'm guessing this is the minimum waker area needed?
tokio-console/src/view/task.rs
Outdated
.chunks(max_width_stats_area as usize) | ||
.map(|chunk| chunk.iter().collect()) | ||
.collect(); | ||
let no_of_lines_extra_required_to_accomadate_location = location_lines_vector.len() - 1; |
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.
These very long variable names don't really fit in with the style of the rest of the codebase, we probably don't need the extra variable at all.
Instead, why don't we extract out the task stats height into a variable:
let no_of_lines_extra_required_to_accomadate_location = location_lines_vector.len() - 1; | |
// Id, Name, Target, Location (multiple), total, busy, scheduled, and idle times + top/bottom borders | |
let task_stats_height = 9 + location_lines_vector.len(); |
tokio-console/src/view/task.rs
Outdated
) = if warnings.is_empty() { | ||
let chunks = Layout::default() | ||
.direction(layout::Direction::Vertical) | ||
) = if task.location().len() > location_max_width { |
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.
We definitely don't want to add another layer of if-else
statements here. I think that be specifying the task stats height outside, we can leave this like it was (just depending on the presense of warnings).
tokio-console/src/view/task.rs
Outdated
@@ -34,7 +34,6 @@ impl TaskView { | |||
pub(crate) fn update_input(&mut self, _event: input::Event) { | |||
// TODO :D | |||
} | |||
|
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.
I don't think we want to remove this line.
tokio-console/src/view/task.rs
Outdated
let location_vector = vec![bold(location_heading), Span::raw(first_line)]; | ||
overview.push(Line::from(location_vector)); | ||
for line in location_lines_vector { | ||
overview.push(Line::from(Span::raw(format!(" {}", line)))); |
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.
I think we need to add more spaces here so that the beginning of the text aligns with the first line location text.
If you leave only 4 spaces here, then the chunks for the 2nd line and onward should be bigger than the first chunk (which is also an option).
@hds i've made the changes you've told to |
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.
One point here where I think I wasn't clear regarding what I meant. And one other thing that I didn't notice before, sorry about that.
tokio-console/src/view/task.rs
Outdated
@@ -83,7 +94,7 @@ impl TaskView { | |||
// controls | |||
layout::Constraint::Length(controls.height()), | |||
// task stats | |||
layout::Constraint::Length(10), | |||
layout::Constraint::Length((10 + location_lines_vector.len() - 1) as u16), |
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.
And use that variable here:
layout::Constraint::Length((10 + location_lines_vector.len() - 1) as u16), | |
layout::Constraint::Length(task_stats_height), |
tokio-console/src/view/task.rs
Outdated
@@ -105,7 +116,7 @@ impl TaskView { | |||
// warnings (add 2 for top and bottom borders) | |||
layout::Constraint::Length(warnings.len() as u16 + 2), | |||
// task stats | |||
layout::Constraint::Length(10), | |||
layout::Constraint::Length((10 + location_lines_vector.len() - 1) as u16), |
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.
And here too:
layout::Constraint::Length((10 + location_lines_vector.len() - 1) as u16), | |
layout::Constraint::Length(task_stats_height), |
tokio-console/src/view/task.rs
Outdated
let stats_area = if location_lines_vector.len() != 1 { | ||
let area_needed_to_render_location = task.location().len() as u16; | ||
Layout::default() | ||
.direction(layout::Direction::Horizontal) | ||
.constraints( | ||
[ | ||
layout::Constraint::Min(area_needed_to_render_location + 15), //Note: 15 is the length of "| Location: |" | ||
layout::Constraint::Min(32), | ||
] | ||
.as_ref(), | ||
) | ||
.split(stats_area) | ||
} else { | ||
Layout::default() | ||
.direction(layout::Direction::Horizontal) | ||
.constraints( | ||
[ | ||
layout::Constraint::Percentage(50), | ||
layout::Constraint::Percentage(50), | ||
] | ||
.as_ref(), | ||
) | ||
.split(stats_area) | ||
}; |
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.
We can simplify this a bit by just setting different constraints:
let stats_area = if location_lines_vector.len() != 1 { | |
let area_needed_to_render_location = task.location().len() as u16; | |
Layout::default() | |
.direction(layout::Direction::Horizontal) | |
.constraints( | |
[ | |
layout::Constraint::Min(area_needed_to_render_location + 15), //Note: 15 is the length of "| Location: |" | |
layout::Constraint::Min(32), | |
] | |
.as_ref(), | |
) | |
.split(stats_area) | |
} else { | |
Layout::default() | |
.direction(layout::Direction::Horizontal) | |
.constraints( | |
[ | |
layout::Constraint::Percentage(50), | |
layout::Constraint::Percentage(50), | |
] | |
.as_ref(), | |
) | |
.split(stats_area) | |
}; | |
let stats_constraints = if location_lines_vector.len() > 1 { | |
[ | |
// 15 is the length of "| Location: |" | |
layout::Constraint::Min(area_needed_to_render_location + 15), | |
layout::Constraint::Min(32), | |
] | |
} else { | |
[ | |
layout::Constraint::Percentage(50), | |
layout::Constraint::Percentage(50), | |
] | |
}; | |
let stats_area = Layout::default() | |
.direction(layout::Direction::Horizontal) | |
.constraints(stats_constraints.as_ref()) | |
.split(stats_area); |
please refer to earlier commits to see what changes have been made
@hds i've updated the latest changes requested |
tokio-console/src/view/task.rs
Outdated
let area_needed_to_render_location = task.location().len() as u16; | ||
[ | ||
// 15 is the length of "| Location: |" | ||
layout::Constraint::Min(area_needed_to_render_location + 15), |
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.
What happens when the 2 Min
constraints add up to more than the available width?
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.
from this, i think the view would overflow according to the length the view has.
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.
I think the if
statement is incorrect then (and also back to front). In fact, I think that if instead the constraints look just like this then it might be enough (always, no if statement at all). Could you try and show some screenshots?
[
layout::Constraint::Min(location_lines_vector[0].len()),
layout::Constraint::Min(32),
]
long var names changed to shorter names Co-authored-by: Hayden Stainsby <[email protected]>
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.
What about this idea?
tokio-console/src/view/task.rs
Outdated
let area_needed_to_render_location = task.location().len() as u16; | ||
[ | ||
// 15 is the length of "| Location: |" | ||
layout::Constraint::Min(area_needed_to_render_location + 15), |
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.
I think the if
statement is incorrect then (and also back to front). In fact, I think that if instead the constraints look just like this then it might be enough (always, no if statement at all). Could you try and show some screenshots?
[
layout::Constraint::Min(location_lines_vector[0].len()),
layout::Constraint::Min(32),
]
Changes I've made is for accommodating loong location names; ive changed the .. to the long name; it widens the task rectangle if its longer than the default (50%) and goes to the next line if its longer than what we can accommodate in a single line. This fixes issue #523 have attached screenshots of the same in the PR, before and after changes
These screenshots are what was the UI before my changes.

and these are the screenshots after my changes.


