Skip to content

Commit d2ec856

Browse files
committed
Fix warnings and document functions
Signed-off-by: Nico Burns <[email protected]>
1 parent 6e8bf01 commit d2ec856

File tree

5 files changed

+57
-53
lines changed

5 files changed

+57
-53
lines changed

src/compute/block.rs

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -79,19 +79,28 @@ impl BlockContext<'_> {
7979
}
8080
}
8181

82+
/// Set the width of the overall Block Formatting Context. This is used to resolve positions
83+
/// that are relative to the right of the context such as right-floated boxes.
84+
///
85+
/// Sub-blocks within a Block Formatting Context should use the `Self::sub_context` method to create
86+
/// a sub-`BlockContext` with `insets` instead.
8287
pub fn set_width(&mut self, available_space: AvailableSpace) {
8388
self.bfc.float_context.set_width(available_space);
8489
}
8590

91+
/// Returns whether this block is the root block of it's Block Formatting Context
8692
pub fn is_bfc_root(&self) -> bool {
8793
self.is_root
8894
}
8995

96+
/// Set the x-axis content-box insets of the `BlockContext`. These are the difference between the border-box
97+
/// and the content-box of the box (padding + border + scrollbar_gutter).
9098
pub fn apply_content_box_inset(&mut self, content_box_x_insets: [f32; 2]) {
9199
self.content_box_insets[0] = self.insets[0] + content_box_x_insets[0];
92100
self.content_box_insets[1] = self.insets[1] + content_box_x_insets[1];
93101
}
94102

103+
/// Position a floated box with the context
95104
pub fn place_floated_box(
96105
&mut self,
97106
floated_box: Size<f32>,
@@ -114,6 +123,7 @@ impl BlockContext<'_> {
114123
pos
115124
}
116125

126+
/// Search a space suitable for laying out non-floated content into
117127
pub fn find_content_slot(&self, min_y: f32, clear: Clear, after: Option<usize>) -> ContentSlot {
118128
let mut slot =
119129
self.bfc.float_context.find_content_slot(min_y + self.y_offset, self.content_box_insets, clear, after);
@@ -126,9 +136,9 @@ impl BlockContext<'_> {
126136
self.float_content_contribution = self.float_content_contribution.max(child_contribution);
127137
}
128138

129-
fn floated_content_width_contribution(&self) -> f32 {
130-
self.bfc.float_context.content_width()
131-
}
139+
// fn floated_content_width_contribution(&self) -> f32 {
140+
// self.bfc.float_context.content_width()
141+
// }
132142

133143
fn floated_content_height_contribution(&self) -> f32 {
134144
self.float_content_contribution
@@ -200,13 +210,6 @@ struct BlockItem {
200210
can_be_collapsed_through: bool,
201211
}
202212

203-
#[cfg(feature = "float_layout")]
204-
impl BlockItem {
205-
fn is_floated(&self) -> bool {
206-
matches!(self.float, Float::Left | Float::Right)
207-
}
208-
}
209-
210213
/// Computes the layout of [`LayoutPartialTree`] according to the block layout algorithm
211214
pub fn compute_block_layout(
212215
tree: &mut impl LayoutBlockContainer,

src/compute/float.rs

Lines changed: 35 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -47,39 +47,43 @@ pub struct FloatContext {
4747
/// to be laid out into
4848
#[derive(Debug, Clone, Copy, Default)]
4949
pub struct ContentSlot {
50+
/// The id of the segment that the slot starts in
5051
pub segment_id: Option<usize>,
52+
/// The x position of the start of the slot
5153
pub x: f32,
54+
/// The y position of the start of the slot
5255
pub y: f32,
56+
/// The width of the slot
5357
pub width: f32,
58+
/// The height of the slot
5459
pub height: f32,
5560
}
5661

57-
/// A floated box to place within the context
58-
#[derive(Debug, Clone, Copy, Default)]
59-
pub struct FloatedBox {
60-
/// A user defined ID for the box
61-
// pub(crate) id: u64,
62-
pub(crate) width: f32,
63-
pub(crate) height: f32,
64-
}
62+
// /// A floated box to place within the context
63+
// #[derive(Debug, Clone, Copy, Default)]
64+
// pub struct FloatedBox {
65+
// /// The width of the box
66+
// pub(crate) width: f32,
67+
// /// The height of the box
68+
// pub(crate) height: f32,
69+
// }
6570

6671
/// A floated box
6772
#[derive(Debug, Clone, Default)]
6873
struct PlacedFloatedBox {
6974
/// A user defined ID for the box
7075
// id: u64,
76+
/// The width of the box
7177
width: f32,
78+
/// The height of the box
7279
height: f32,
73-
/// Distance from the edge of the container that the box is floated towards
80+
/// Horizontal distance from the edge of the container that the box is floated towards
7481
/// (distance from the left for left floats, from the right for right floats)
7582
x_inset: f32,
83+
/// Vertical distance from top edge of the container
7684
y: f32,
7785
}
7886

79-
impl PlacedFloatedBox {
80-
const DEFAULT: Self = Self { /*id: 0, */ width: 0.0, height: 0.0, x_inset: 0.0, y: 0.0 };
81-
}
82-
8387
impl FloatContext {
8488
/// Create a new empty `FloatContext`
8589
pub fn new(available_space: AvailableSpace) -> Self {
@@ -156,6 +160,7 @@ impl FloatContext {
156160
}
157161
}
158162

163+
/// Search a space suitable for laying out non-floated content into
159164
pub fn find_content_slot(
160165
&self,
161166
min_y: f32,
@@ -166,34 +171,23 @@ impl FloatContext {
166171
self.placer.find_content_slot(min_y, containing_block_insets, clear, after)
167172
}
168173

169-
pub(crate) fn content_width(&self) -> f32 {
170-
match self.available_space {
171-
AvailableSpace::Definite(width) => width,
172-
AvailableSpace::MinContent => {
173-
let left_max =
174-
self.left_floats.iter().map(|float| float.x_inset).max_by(|a, b| a.total_cmp(b)).unwrap_or(0.0);
175-
let right_max =
176-
self.right_floats.iter().map(|float| float.x_inset).max_by(|a, b| a.total_cmp(b)).unwrap_or(0.0);
177-
left_max.max(right_max)
178-
}
179-
AvailableSpace::MaxContent => {
180-
let left_max = self.left_floats.last().map(|float| float.x_inset).unwrap_or(0.0);
181-
let right_max = self.right_floats.last().map(|float| float.x_inset).unwrap_or(0.0);
182-
left_max + right_max
183-
}
184-
}
185-
}
186-
187-
pub(crate) fn content_height(&self) -> f32 {
188-
self.placer.segments.last().map(|seg| seg.y.end).unwrap_or(0.0)
189-
}
190-
191-
fn get_float_list(&self, float_direction: FloatDirection) -> &[PlacedFloatedBox] {
192-
match float_direction {
193-
FloatDirection::Left => &self.left_floats,
194-
FloatDirection::Right => &self.right_floats,
195-
}
196-
}
174+
// pub(crate) fn content_width(&self) -> f32 {
175+
// match self.available_space {
176+
// AvailableSpace::Definite(width) => width,
177+
// AvailableSpace::MinContent => {
178+
// let left_max =
179+
// self.left_floats.iter().map(|float| float.x_inset).max_by(|a, b| a.total_cmp(b)).unwrap_or(0.0);
180+
// let right_max =
181+
// self.right_floats.iter().map(|float| float.x_inset).max_by(|a, b| a.total_cmp(b)).unwrap_or(0.0);
182+
// left_max.max(right_max)
183+
// }
184+
// AvailableSpace::MaxContent => {
185+
// let left_max = self.left_floats.last().map(|float| float.x_inset).unwrap_or(0.0);
186+
// let right_max = self.right_floats.last().map(|float| float.x_inset).unwrap_or(0.0);
187+
// left_max + right_max
188+
// }
189+
// }
190+
// }
197191
}
198192

199193
#[derive(Debug, Clone)]

src/compute/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ pub use self::flexbox::compute_flexbox_layout;
4848
pub use self::grid::compute_grid_layout;
4949

5050
#[cfg(feature = "float_layout")]
51-
pub use self::float::{ContentSlot, FloatContext, FloatedBox};
51+
pub use self::float::{ContentSlot, FloatContext};
5252

5353
use crate::geometry::{Line, Point, Size};
5454
use crate::style::{AvailableSpace, CoreStyle, Overflow};

src/style/float.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,26 @@ pub enum Float {
1515
None,
1616
}
1717

18+
/// Whether a box that is definitely floated is floated to the left
19+
/// of to the right.
20+
///
21+
/// This type is only used in the low-level parts of the
1822
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
1923
#[repr(u8)]
2024
pub enum FloatDirection {
25+
/// The box is floated to the left
2126
Left = 0,
27+
/// The box is floated to the right
2228
Right = 1,
2329
}
2430

2531
impl Float {
32+
/// Whether the box is floated
2633
pub fn is_floated(self) -> bool {
2734
matches!(self, Self::Left | Self::Right)
2835
}
2936

37+
/// Converts [`Float`] into `Option<FloatDirection>`ca
3038
pub fn float_direction(&self) -> Option<FloatDirection> {
3139
match self {
3240
Float::Left => Some(FloatDirection::Left),

src/tree/taffy_tree.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ use crate::util::sys::{new_vec_with_capacity, ChildrenVec, Vec};
2020
use crate::compute::{
2121
compute_cached_layout, compute_hidden_layout, compute_leaf_layout, compute_root_layout, round_layout,
2222
};
23-
use crate::BlockFormattingContext;
2423
use crate::CacheTree;
2524

2625
#[cfg(feature = "block_layout")]

0 commit comments

Comments
 (0)