bug: fix empty widget in layout

This commit is contained in:
ClementTsang 2020-04-27 16:00:16 -04:00
parent 8e4f6a3a02
commit 15dba2e6cf
2 changed files with 127 additions and 108 deletions

View File

@ -9,11 +9,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Features ### Features
- [#58](https://github.com/ClementTsang/bottom/issues/58): I/O stats per process - [#58](https://github.com/ClementTsang/bottom/issues/58): I/O stats per process.
- [#55](https://github.com/ClementTsang/bottom/issues/55): Battery monitoring widget - [#55](https://github.com/ClementTsang/bottom/issues/55): Battery monitoring widget.
- [#114](https://github.com/ClementTsang/bottom/pull/114): Process state per process - [#114](https://github.com/ClementTsang/bottom/pull/114): Process state per process.
### Changes ### Changes
@ -49,6 +49,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Fixed bug where a single empty row as a layout would crash without a proper warning. - Fixed bug where a single empty row as a layout would crash without a proper warning.
The behaviour now errors out with a more helpful message. The behaviour now errors out with a more helpful message.
- Fixed bug where empty widgets in layout would cause widget movement to not work properly when moving vertically.
### Development changes ### Development changes
- Switch to stateful widget style for tables. - Switch to stateful widget style for tables.

View File

@ -322,15 +322,14 @@ impl BottomLayout {
widget.up_neighbour = Some(current_best_widget_id); widget.up_neighbour = Some(current_best_widget_id);
} }
} }
} else if let Some(next_row_up) = layout_mapping } else {
.range( let mut up_range = layout_mapping.range(
..( ..(
row_height_percentage_start, row_height_percentage_start,
row_height_percentage_start, row_height_percentage_start,
), ),
) );
.next_back() while let Some(next_row_up) = up_range.next_back() {
{
let mut current_best_distance = 0; let mut current_best_distance = 0;
let mut current_best_widget_id = widget.widget_id; let mut current_best_widget_id = widget.widget_id;
let (target_start_width, target_end_width) = let (target_start_width, target_end_width) =
@ -348,7 +347,10 @@ impl BottomLayout {
/ 100, / 100,
) )
} else { } else {
(col_width_percentage_start, col_width_percentage_end) (
col_width_percentage_start,
col_width_percentage_end,
)
}; };
for col_position in &(next_row_up.1).1 { for col_position in &(next_row_up.1).1 {
@ -361,10 +363,12 @@ impl BottomLayout {
candidate_col_end - candidate_col_start; candidate_col_end - candidate_col_start;
for candidate_widget in &(next_col_row.1).1 { for candidate_widget in &(next_col_row.1).1 {
let candidate_start = candidate_col_start let candidate_start = candidate_col_start
+ (candidate_widget.0).0 * candidate_difference + (candidate_widget.0).0
* candidate_difference
/ 100; / 100;
let candidate_end = candidate_col_start let candidate_end = candidate_col_start
+ (candidate_widget.0).1 * candidate_difference + (candidate_widget.0).1
* candidate_difference
/ 100; / 100;
if is_intersecting( if is_intersecting(
@ -376,7 +380,9 @@ impl BottomLayout {
(candidate_start, candidate_end), (candidate_start, candidate_end),
); );
if current_best_distance < candidate_distance { if current_best_distance
< candidate_distance
{
current_best_distance = current_best_distance =
candidate_distance + 1; candidate_distance + 1;
current_best_widget_id = current_best_widget_id =
@ -389,6 +395,8 @@ impl BottomLayout {
if current_best_distance > 0 { if current_best_distance > 0 {
widget.up_neighbour = Some(current_best_widget_id); widget.up_neighbour = Some(current_best_widget_id);
break;
}
} }
} }
@ -430,15 +438,14 @@ impl BottomLayout {
widget.down_neighbour = Some(current_best_widget_id); widget.down_neighbour = Some(current_best_widget_id);
} }
} }
} else if let Some(next_row_down) = layout_mapping } else {
.range( let mut down_range = layout_mapping.range(
( (
row_height_percentage_start + 1, row_height_percentage_start + 1,
row_height_percentage_start + 1, row_height_percentage_start + 1,
).., )..,
) );
.next() while let Some(next_row_down) = down_range.next() {
{
let mut current_best_distance = 0; let mut current_best_distance = 0;
let mut current_best_widget_id = widget.widget_id; let mut current_best_widget_id = widget.widget_id;
let (target_start_width, target_end_width) = let (target_start_width, target_end_width) =
@ -456,11 +463,15 @@ impl BottomLayout {
/ 100, / 100,
) )
} else { } else {
(col_width_percentage_start, col_width_percentage_end) (
col_width_percentage_start,
col_width_percentage_end,
)
}; };
for col_position in &(next_row_down.1).1 { for col_position in &(next_row_down.1).1 {
if let Some(next_col_row) = (col_position.1).1.iter().next() if let Some(next_col_row) =
(col_position.1).1.iter().next()
{ {
let (candidate_col_start, candidate_col_end) = let (candidate_col_start, candidate_col_end) =
((col_position.0).0, (col_position.0).1); ((col_position.0).0, (col_position.0).1);
@ -468,10 +479,12 @@ impl BottomLayout {
candidate_col_end - candidate_col_start; candidate_col_end - candidate_col_start;
for candidate_widget in &(next_col_row.1).1 { for candidate_widget in &(next_col_row.1).1 {
let candidate_start = candidate_col_start let candidate_start = candidate_col_start
+ (candidate_widget.0).0 * candidate_difference + (candidate_widget.0).0
* candidate_difference
/ 100; / 100;
let candidate_end = candidate_col_start let candidate_end = candidate_col_start
+ (candidate_widget.0).1 * candidate_difference + (candidate_widget.0).1
* candidate_difference
/ 100; / 100;
if is_intersecting( if is_intersecting(
@ -483,7 +496,9 @@ impl BottomLayout {
(candidate_start, candidate_end), (candidate_start, candidate_end),
); );
if current_best_distance < candidate_distance { if current_best_distance
< candidate_distance
{
current_best_distance = current_best_distance =
candidate_distance + 1; candidate_distance + 1;
current_best_widget_id = current_best_widget_id =
@ -496,6 +511,8 @@ impl BottomLayout {
if current_best_distance > 0 { if current_best_distance > 0 {
widget.down_neighbour = Some(current_best_widget_id); widget.down_neighbour = Some(current_best_widget_id);
break;
}
} }
} }
} }