Skip to content
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

refactor(layout): to natural reading order #681

Merged
merged 1 commit into from
Dec 9, 2023
Merged

refactor(layout): to natural reading order #681

merged 1 commit into from
Dec 9, 2023

Conversation

joshka
Copy link
Member

@joshka joshka commented Dec 9, 2023

Structs and enums at the top of the file helps show the interaction
between the types without having to find each type in between longer
impl sections.

Also moved the try_split function into the Layout impl as an associated
function and inlined the layout::split() which just called try_split.
This makes the code a bit more contained.


This is a redo of the refactor step from #641 to avoid losing code in a bad rebase.

For ease of checking that all the methods and structs are reorganized:

grep -E '^\s*(fn|pub|enum|struct|impl)' src/layout.rs | sed 's/^ *//' | sort > layout-refactor-sorted.txt
diff -u layout-main-sorted.txt layout-refactor-sorted.txt
--- layout-main-sorted.txt   2023-12-09 13:18:02
+++ layout-refactor-sorted.txt  2023-12-09 13:19:02
@@ -31,7 +31,6 @@
 fn segment_size_from_string() {
 fn segment_size_to_string() {
 fn size(&self) -> Expression {
-fn split(area: Rect, layout: &Layout) -> Rc<[Rect]> {
 fn test(area: Rect, constraints: &[Constraint], expected: &str) {
 fn test_constraint_apply() {
 fn test_split_equally_in_overconstrained_case_for_length() {
@@ -43,12 +42,12 @@
 impl AsRef<Constraint> for Constraint {
 impl Constraint {
 impl Default for Constraint {
+impl Display for Constraint {
+impl Display for Margin {
 impl Element {
 impl From<(u16, u16)> for Size {
 impl Layout {
 impl Margin {
-impl fmt::Display for Constraint {
-impl fmt::Display for Margin {
 pub const DEFAULT_CACHE_SIZE: usize = 16;
 pub const fn direction(mut self, direction: Direction) -> Layout {
 pub const fn horizontal_margin(mut self, horizontal: u16) -> Layout {

Structs and enums at the top of the file helps show the interaction
between the types without having to find each type in between longer
impl sections.

Also moved the try_split function into the Layout impl as an associated
function and inlined the `layout::split()` which just called try_split.
This makes the code a bit more contained.
Copy link

codecov bot commented Dec 9, 2023

Codecov Report

Attention: 4 lines in your changes are missing coverage. Please review.

Comparison is base (03401cd) 90.9% compared to head (45d3e23) 90.9%.

Files Patch % Lines
src/layout.rs 97.3% 4 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##            main    #681     +/-   ##
=======================================
- Coverage   90.9%   90.9%   -0.1%     
=======================================
  Files         42      42             
  Lines      12678   12677      -1     
=======================================
- Hits       11526   11525      -1     
  Misses      1152    1152             

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@joshka joshka merged commit 0576a8a into main Dec 9, 2023
33 checks passed
@joshka joshka deleted the refactor-layout branch December 9, 2023 21:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants