Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions packages/core/src/middleware/shift.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,33 @@ impl<Element: Clone, Window: Clone> Default for ShiftOptions<Element, Window> {
}
}

/// Enabled sides stored in [`ShiftData`].
#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)]
pub struct ShiftDataEnabled {
pub x: bool,
pub y: bool,
}

impl ShiftDataEnabled {
pub fn set_axis(mut self, axis: Axis, enabled: bool) -> Self {
match axis {
Axis::X => {
self.x = enabled;
}
Axis::Y => {
self.y = enabled;
}
}
self
}
}

/// Data stored by [`Shift`] middleware.
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct ShiftData {
pub x: f64,
pub y: f64,
pub enabled: ShiftDataEnabled,
}

/// Shift middleware.
Expand Down Expand Up @@ -215,6 +237,9 @@ impl<Element: Clone + PartialEq + 'static, Window: Clone + PartialEq + 'static>
serde_json::to_value(ShiftData {
x: limited_coords.x - x,
y: limited_coords.y - y,
enabled: ShiftDataEnabled::default()
.set_axis(main_axis, check_main_axis)
.set_axis(cross_axis, check_cross_axis),
})
.expect("Data should be valid JSON."),
),
Expand Down
22 changes: 9 additions & 13 deletions packages/core/src/middleware/size.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@ use floating_ui_utils::{get_side_axis, Alignment, Axis, Rect, Side};

use crate::{
detect_overflow::{detect_overflow, DetectOverflowOptions},
middleware::shift::{ShiftData, SHIFT_NAME},
types::{
Derivable, DerivableFn, Middleware, MiddlewareReturn, MiddlewareState,
MiddlewareWithOptions, ResetRects, ResetValue,
},
};

use super::SHIFT_NAME;

/// Name of the [`Size`] middleware.
pub const SIZE_NAME: &str = "size";

Expand Down Expand Up @@ -138,6 +137,7 @@ impl<Element: Clone + PartialEq, Window: Clone + PartialEq> Middleware<Element,
placement,
elements,
rects,
middleware_data,
platform,
..
} = state;
Expand Down Expand Up @@ -189,21 +189,17 @@ impl<Element: Clone + PartialEq, Window: Clone + PartialEq> Middleware<Element,
let overflow_available_width =
maximum_clipping_width.min(width - overflow.side(width_side));

let no_shift = state.middleware_data.get(SHIFT_NAME).is_none();
let no_shift = middleware_data.get(SHIFT_NAME).is_none();

let mut available_height = overflow_available_height;
let mut available_width = overflow_available_width;

if is_y_axis {
available_width = match alignment.is_some() || no_shift {
true => overflow_available_width.min(maximum_clipping_width),
false => maximum_clipping_width,
};
} else {
available_height = match alignment.is_some() || no_shift {
true => overflow_available_height.min(maximum_clipping_height),
false => maximum_clipping_height,
}
let data: Option<ShiftData> = middleware_data.get_as(SHIFT_NAME);
if data.as_ref().is_some_and(|data| data.enabled.x) {
available_width = maximum_clipping_width;
}
if data.as_ref().is_some_and(|data| data.enabled.y) {
available_height = maximum_clipping_height;
}

if no_shift && alignment.is_none() {
Expand Down
2 changes: 1 addition & 1 deletion upstream.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[releases]
core = "1.6.7"
core = "1.6.8"
dom = "1.6.10"
utils = "0.2.7"
vue = "1.1.4"