Skip to content

Commit c67507a

Browse files
committed
Cargo fmt
1 parent 073b749 commit c67507a

File tree

5 files changed

+119
-100
lines changed

5 files changed

+119
-100
lines changed

src/compute/flexbox.rs

Lines changed: 33 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
use core::f32;
55

66
use crate::compute::compute_node_layout;
7+
use crate::debug::NODE_LOGGER;
78
use crate::geometry::{Point, Rect, Size};
89
use crate::layout::{AvailableSpace, Cache, Layout, RunMode, SizingMode};
910
use crate::math::MaybeMath;
@@ -13,7 +14,6 @@ use crate::style::{AlignContent, AlignSelf, Dimension, Display, FlexWrap, Justif
1314
use crate::style::{FlexDirection, FlexboxLayout};
1415
use crate::sys::{abs, round, Vec};
1516
use crate::tree::LayoutTree;
16-
use crate::debug::NODE_LOGGER;
1717

1818
/// The intermediate results of a flexbox calculation for a single item
1919
struct FlexItem {
@@ -123,7 +123,9 @@ pub fn compute(
123123
// Pull these out earlier to avoid borrowing issues
124124
let min_size = style.min_size.maybe_resolve(known_dimensions);
125125
let max_size = style.max_size.maybe_resolve(known_dimensions);
126-
let clamped_style_size = style.size.maybe_resolve(known_dimensions)
126+
let clamped_style_size = style
127+
.size
128+
.maybe_resolve(known_dimensions)
127129
.zip_map(min_size, |size, min| size.maybe_max(min))
128130
.zip_map(max_size, |size, max| size.maybe_min(max));
129131

@@ -136,7 +138,7 @@ pub fn compute(
136138
known_dimensions.zip_map(clamped_style_size, |known, style| known.or(style)),
137139
available_space,
138140
RunMode::ComputeSize,
139-
cache_slot == 0,//true,
141+
cache_slot == 0, //true,
140142
);
141143

142144
let clamped_first_pass_size = first_pass
@@ -149,7 +151,7 @@ pub fn compute(
149151
known_dimensions.zip_map(clamped_first_pass_size, |known, first_pass| known.or(first_pass.into())),
150152
available_space,
151153
RunMode::PeformLayout,
152-
cache_slot == 0,//true,
154+
cache_slot == 0, //true,
153155
)
154156
} else {
155157
// NODE_LOGGER.log("FLEX: single-pass");
@@ -159,7 +161,7 @@ pub fn compute(
159161
known_dimensions.zip_map(clamped_style_size, |known, style| known.or(style)),
160162
available_space,
161163
RunMode::PeformLayout,
162-
cache_slot == 0,//true,
164+
cache_slot == 0, //true,
163165
)
164166
}
165167

@@ -673,11 +675,19 @@ fn determine_flex_base_size(
673675
// The following logic was developed not from the spec but by trail and error looking into how
674676
// webkit handled various scenarios. Can probably be solved better by passing in
675677
// min-content max-content constraints from the top
676-
let min_main = compute_node_layout(tree, child.node, Size::NONE, available_space, RunMode::ComputeSize, SizingMode::ContentSize, 1)
677-
.main(constants.dir)
678-
.maybe_max(child.min_size.main(constants.dir))
679-
.maybe_min(child.size.main(constants.dir))
680-
.into();
678+
let min_main = compute_node_layout(
679+
tree,
680+
child.node,
681+
Size::NONE,
682+
available_space,
683+
RunMode::ComputeSize,
684+
SizingMode::ContentSize,
685+
1,
686+
)
687+
.main(constants.dir)
688+
.maybe_max(child.min_size.main(constants.dir))
689+
.maybe_min(child.size.main(constants.dir))
690+
.into();
681691

682692
child.hypothetical_inner_size.set_main(
683693
constants.dir,
@@ -929,11 +939,19 @@ fn resolve_flexible_lengths(
929939
// min-content max-content constraints from the top. Need to figure out correct thing to do here as
930940
// just piling on more conditionals.
931941
let min_main = if constants.is_row && !tree.needs_measure(child.node) {
932-
compute_node_layout(tree, child.node, Size::NONE, available_space, RunMode::ComputeSize, SizingMode::ContentSize, 1)
933-
.width
934-
.maybe_min(child.size.width)
935-
.maybe_max(child.min_size.width)
936-
.into()
942+
compute_node_layout(
943+
tree,
944+
child.node,
945+
Size::NONE,
946+
available_space,
947+
RunMode::ComputeSize,
948+
SizingMode::ContentSize,
949+
1,
950+
)
951+
.width
952+
.maybe_min(child.size.width)
953+
.maybe_max(child.min_size.width)
954+
.into()
937955
} else {
938956
child.min_size.main(constants.dir)
939957
};

src/compute/leaf.rs

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,11 @@ pub(crate) fn compute(
2828
let node_min_size = Size::NONE;
2929
let node_max_size = Size::NONE;
3030
(node_size, node_min_size, node_max_size)
31-
},
31+
}
3232
SizingMode::InherentSize => {
3333
let style_size = style.size.maybe_resolve(available_space.as_options());
34-
let node_size = style_size.zip_map(known_dimensions, |style_size, known_dimensions| known_dimensions.or(style_size));
34+
let node_size =
35+
style_size.zip_map(known_dimensions, |style_size, known_dimensions| known_dimensions.or(style_size));
3536
let node_min_size = style.min_size.maybe_resolve(available_space.as_options());
3637
let node_max_size = style.max_size.maybe_resolve(available_space.as_options());
3738
(node_size, node_min_size, node_max_size)
@@ -94,20 +95,17 @@ pub(crate) fn compute(
9495
};
9596
}
9697

97-
fn maybe_clamp(size: Size<Option<f32>>, min_size: Size<Option<f32>>, max_size: Size<Option<f32>>, sizing_mode: SizingMode) -> Size<Option<f32>> {
98+
fn maybe_clamp(
99+
size: Size<Option<f32>>,
100+
min_size: Size<Option<f32>>,
101+
max_size: Size<Option<f32>>,
102+
sizing_mode: SizingMode,
103+
) -> Size<Option<f32>> {
98104
match sizing_mode {
99105
SizingMode::ContentSize => size,
100-
SizingMode::InherentSize => {
101-
Size {
102-
width: size.
103-
width
104-
.maybe_max(min_size.width)
105-
.maybe_min(max_size.width),
106-
height:size
107-
.height
108-
.maybe_max(min_size.height)
109-
.maybe_min(max_size.height),
110-
}
111-
}
106+
SizingMode::InherentSize => Size {
107+
width: size.width.maybe_max(min_size.width).maybe_min(max_size.width),
108+
height: size.height.maybe_max(min_size.height).maybe_min(max_size.height),
109+
},
112110
}
113111
}

src/compute/mod.rs

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@ pub(crate) mod flexbox;
22
pub(crate) mod leaf;
33

44
use core::sync::atomic::AtomicU16;
5-
use std::env::consts;
65
use slotmap::Key;
6+
use std::env::consts;
77

8+
use crate::debug::NODE_LOGGER;
89
use crate::error::TaffyError;
910
use crate::geometry::{Point, Size};
1011
use crate::layout::{AvailableSpace, Cache, Layout, RunMode, SizingMode};
@@ -14,7 +15,6 @@ use crate::resolve::MaybeResolve;
1415
use crate::style::Display;
1516
use crate::sys::round;
1617
use crate::tree::LayoutTree;
17-
use crate::debug::NODE_LOGGER;
1818

1919
/// Updates the stored layout of the provided `node` and its children
2020
pub fn compute_layout(
@@ -23,7 +23,15 @@ pub fn compute_layout(
2323
available_space: Size<AvailableSpace>,
2424
) -> Result<(), TaffyError> {
2525
// Recursively compute node layout
26-
let size = compute_node_layout(tree, root, Size::NONE, available_space, RunMode::PeformLayout, SizingMode::InherentSize, 0);
26+
let size = compute_node_layout(
27+
tree,
28+
root,
29+
Size::NONE,
30+
available_space,
31+
RunMode::PeformLayout,
32+
SizingMode::InherentSize,
33+
0,
34+
);
2735

2836
let layout = Layout { order: 0, size, location: Point::ZERO };
2937
*tree.layout_mut(root) = layout;
@@ -49,11 +57,12 @@ fn compute_node_layout(
4957

5058
// NODE_LOGGER.push_node(node);
5159
// println!("");
52-
5360

5461
// First we check if we have a cached result for the given input
5562
let cache_run_mode = if tree.children(node).is_empty() { RunMode::PeformLayout } else { run_mode };
56-
if let Some(cached_size) = compute_from_cache(tree, node, known_dimensions, available_space, cache_run_mode, sizing_mode) {
63+
if let Some(cached_size) =
64+
compute_from_cache(tree, node, known_dimensions, available_space, cache_run_mode, sizing_mode)
65+
{
5766
// NODE_LOGGER.debug_llog("CACHE", cached_size);
5867
// NODE_LOGGER.debug_llog("run_mode", run_mode);
5968
// NODE_LOGGER.debug_llog("sizing_mode", sizing_mode);
@@ -101,13 +110,13 @@ fn compute_node_layout(
101110
// println!("match {:?}", tree.style(node).display);
102111
match tree.style(node).display {
103112
Display::Flex => {
104-
// NODE_LOGGER.log("Algo: flexbox");
105-
self::flexbox::compute(tree, node, known_dimensions, available_space, run_mode, cache_slot)
106-
},
113+
// NODE_LOGGER.log("Algo: flexbox");
114+
self::flexbox::compute(tree, node, known_dimensions, available_space, run_mode, cache_slot)
115+
}
107116
Display::None => {
108-
// NODE_LOGGER.log("Algo: none");
109-
Size { width: 0.0, height: 0.0 }
110-
},
117+
// NODE_LOGGER.log("Algo: none");
118+
Size { width: 0.0, height: 0.0 }
119+
}
111120
}
112121
};
113122

@@ -136,14 +145,13 @@ fn compute_from_cache(
136145
let entry = tree.cache_mut(node, idx);
137146
// NODE_LOGGER.debug_llog("cache_entry", &entry);
138147
if let Some(entry) = entry {
139-
140148
// Cached ComputeSize results are not valid if we are running in PerformLayout mode
141149
if entry.run_mode == RunMode::ComputeSize && run_mode == RunMode::PeformLayout {
142150
return None;
143151
}
144152

145153
// if known_dimensions.width == entry.known_dimensions.width
146-
// && known_dimensions.height == entry.known_dimensions.height
154+
// && known_dimensions.height == entry.known_dimensions.height
147155
if (known_dimensions.width == entry.known_dimensions.width || known_dimensions.width == Some(entry.cached_size.width))
148156
&& (known_dimensions.height == entry.known_dimensions.height || known_dimensions.height == Some(entry.cached_size.height))
149157
// && entry.available_space.width.is_roughly_equal(available_space.width)
@@ -158,8 +166,8 @@ fn compute_from_cache(
158166
|| entry.available_space.height.is_roughly_equal(available_space.height)
159167
|| (sizing_mode == SizingMode::ContentSize && available_space.height.is_definite() && available_space.height.unwrap() >= entry.cached_size.height)
160168
)
161-
// && (entry.available_space.width.is_roughly_equal(available_space.width) || (available_space.width.is_definite() && available_space.width.unwrap() >= entry.cached_size.width))
162-
// && (entry.available_space.height.is_roughly_equal(available_space.height) || (available_space.height.is_definite() && available_space.height.unwrap() >= entry.cached_size.height))
169+
// && (entry.available_space.width.is_roughly_equal(available_space.width) || (available_space.width.is_definite() && available_space.width.unwrap() >= entry.cached_size.width))
170+
// && (entry.available_space.height.is_roughly_equal(available_space.height) || (available_space.height.is_definite() && available_space.height.unwrap() >= entry.cached_size.height))
163171
{
164172
return Some(entry.cached_size);
165173
}

src/debug.rs

Lines changed: 48 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use core::fmt::{Debug, Display, Write};
2-
use core::sync::atomic::{Ordering, AtomicUsize};
3-
use std::sync::{Mutex, Arc};
2+
use core::sync::atomic::{AtomicUsize, Ordering};
43
use slotmap::Key;
4+
use std::sync::{Arc, Mutex};
55

66
use crate::node::Node;
77
use crate::tree::LayoutTree;
@@ -21,76 +21,71 @@ fn print_node(tree: &impl LayoutTree, node: Node, level: usize) {
2121
leftpad = level * 4,
2222
key = node.data(),
2323
x = layout.location.x,
24-
y = layout.location.y,
24+
y = layout.location.y,
2525
width = layout.size.width,
2626
height = layout.size.height,
2727
);
2828

2929
// Recurse into children
3030
for child in tree.children(node) {
31-
print_node(tree, *child, level + 1)
31+
print_node(tree, *child, level + 1)
3232
}
3333
}
3434

35-
36-
37-
pub (crate) struct DebugLogger {
38-
stack: Mutex<Vec<String>>,
35+
pub(crate) struct DebugLogger {
36+
stack: Mutex<Vec<String>>,
3937
}
4038

41-
static EMPTY_STRING : String = String::new();
39+
static EMPTY_STRING: String = String::new();
4240

4341
impl DebugLogger {
44-
45-
pub (crate) const fn new() -> Self {
46-
Self {
47-
stack: Mutex::new(Vec::new())
42+
pub(crate) const fn new() -> Self {
43+
Self { stack: Mutex::new(Vec::new()) }
4844
}
49-
}
5045

51-
pub (crate) fn push_node(&self, new_key: impl Key) {
52-
let mut stack = self.stack.lock().unwrap();
53-
let mut key_string = String::new();
54-
write!(&mut key_string, "{:?}", new_key.data()).unwrap();
55-
stack.push(key_string);
56-
}
46+
pub(crate) fn push_node(&self, new_key: impl Key) {
47+
let mut stack = self.stack.lock().unwrap();
48+
let mut key_string = String::new();
49+
write!(&mut key_string, "{:?}", new_key.data()).unwrap();
50+
stack.push(key_string);
51+
}
5752

58-
pub (crate) fn pop_node(&self) {
59-
let mut stack = self.stack.lock().unwrap();
60-
stack.pop();
61-
}
53+
pub(crate) fn pop_node(&self) {
54+
let mut stack = self.stack.lock().unwrap();
55+
stack.pop();
56+
}
6257

63-
pub (crate) fn log(&self, message: impl Display) {
64-
let stack = self.stack.lock().unwrap();
65-
let key = stack.last().unwrap_or(&EMPTY_STRING);
66-
let level = stack.len() * 4;
67-
let space = " ";
68-
println!("{space:level$}{key}: {message}");
69-
}
58+
pub(crate) fn log(&self, message: impl Display) {
59+
let stack = self.stack.lock().unwrap();
60+
let key = stack.last().unwrap_or(&EMPTY_STRING);
61+
let level = stack.len() * 4;
62+
let space = " ";
63+
println!("{space:level$}{key}: {message}");
64+
}
7065

71-
pub (crate) fn llog(&self, label: &str, message: impl Display) {
72-
let stack = self.stack.lock().unwrap();
73-
let key = stack.last().unwrap_or(&EMPTY_STRING);
74-
let level = stack.len() * 4;
75-
let space = " ";
76-
println!("{space:level$}{key}: {label} {message}");
77-
}
66+
pub(crate) fn llog(&self, label: &str, message: impl Display) {
67+
let stack = self.stack.lock().unwrap();
68+
let key = stack.last().unwrap_or(&EMPTY_STRING);
69+
let level = stack.len() * 4;
70+
let space = " ";
71+
println!("{space:level$}{key}: {label} {message}");
72+
}
7873

79-
pub (crate) fn debug_log(&self, message: impl Debug) {
80-
let stack = self.stack.lock().unwrap();
81-
let key = stack.last().unwrap_or(&EMPTY_STRING);
82-
let level = stack.len() * 4;
83-
let space = " ";
84-
println!("{space:level$}{key}: {message:?}");
85-
}
74+
pub(crate) fn debug_log(&self, message: impl Debug) {
75+
let stack = self.stack.lock().unwrap();
76+
let key = stack.last().unwrap_or(&EMPTY_STRING);
77+
let level = stack.len() * 4;
78+
let space = " ";
79+
println!("{space:level$}{key}: {message:?}");
80+
}
8681

87-
pub (crate) fn debug_llog(&self, label: &str, message: impl Debug) {
88-
let stack = self.stack.lock().unwrap();
89-
let key = stack.last().unwrap_or(&EMPTY_STRING);
90-
let level = stack.len() * 4;
91-
let space = " ";
92-
println!("{space:level$}{key}: {label} {message:?}");
93-
}
82+
pub(crate) fn debug_llog(&self, label: &str, message: impl Debug) {
83+
let stack = self.stack.lock().unwrap();
84+
let key = stack.last().unwrap_or(&EMPTY_STRING);
85+
let level = stack.len() * 4;
86+
let space = " ";
87+
println!("{space:level$}{key}: {label} {message:?}");
88+
}
9489
}
9590

96-
pub (crate) static NODE_LOGGER : DebugLogger = DebugLogger::new();
91+
pub(crate) static NODE_LOGGER: DebugLogger = DebugLogger::new();

src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ extern crate alloc;
1818
#[cfg(feature = "serde")]
1919
extern crate serde;
2020

21+
#[doc(hidden)]
22+
pub mod debug;
2123
pub mod error;
2224
pub mod geometry;
2325
pub mod layout;
@@ -26,8 +28,6 @@ pub mod node;
2628
pub mod prelude;
2729
pub mod style;
2830
pub mod tree;
29-
#[doc(hidden)]
30-
pub mod debug;
3131

3232
#[cfg(feature = "random")]
3333
pub mod randomizable;

0 commit comments

Comments
 (0)