Auto-fix clippy::collapsible_if violations (#36428)
Release Notes: - N/A
This commit is contained in:
+109
-120
@@ -286,21 +286,20 @@ impl Interactivity {
|
||||
{
|
||||
self.mouse_move_listeners
|
||||
.push(Box::new(move |event, phase, hitbox, window, cx| {
|
||||
if phase == DispatchPhase::Capture {
|
||||
if let Some(drag) = &cx.active_drag {
|
||||
if drag.value.as_ref().type_id() == TypeId::of::<T>() {
|
||||
(listener)(
|
||||
&DragMoveEvent {
|
||||
event: event.clone(),
|
||||
bounds: hitbox.bounds,
|
||||
drag: PhantomData,
|
||||
dragged_item: Arc::clone(&drag.value),
|
||||
},
|
||||
window,
|
||||
cx,
|
||||
);
|
||||
}
|
||||
}
|
||||
if phase == DispatchPhase::Capture
|
||||
&& let Some(drag) = &cx.active_drag
|
||||
&& drag.value.as_ref().type_id() == TypeId::of::<T>()
|
||||
{
|
||||
(listener)(
|
||||
&DragMoveEvent {
|
||||
event: event.clone(),
|
||||
bounds: hitbox.bounds,
|
||||
drag: PhantomData,
|
||||
dragged_item: Arc::clone(&drag.value),
|
||||
},
|
||||
window,
|
||||
cx,
|
||||
);
|
||||
}
|
||||
}));
|
||||
}
|
||||
@@ -1514,15 +1513,14 @@ impl Interactivity {
|
||||
let mut element_state =
|
||||
element_state.map(|element_state| element_state.unwrap_or_default());
|
||||
|
||||
if let Some(element_state) = element_state.as_ref() {
|
||||
if cx.has_active_drag() {
|
||||
if let Some(pending_mouse_down) = element_state.pending_mouse_down.as_ref()
|
||||
{
|
||||
*pending_mouse_down.borrow_mut() = None;
|
||||
}
|
||||
if let Some(clicked_state) = element_state.clicked_state.as_ref() {
|
||||
*clicked_state.borrow_mut() = ElementClickedState::default();
|
||||
}
|
||||
if let Some(element_state) = element_state.as_ref()
|
||||
&& cx.has_active_drag()
|
||||
{
|
||||
if let Some(pending_mouse_down) = element_state.pending_mouse_down.as_ref() {
|
||||
*pending_mouse_down.borrow_mut() = None;
|
||||
}
|
||||
if let Some(clicked_state) = element_state.clicked_state.as_ref() {
|
||||
*clicked_state.borrow_mut() = ElementClickedState::default();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1530,35 +1528,35 @@ impl Interactivity {
|
||||
// If there's an explicit focus handle we're tracking, use that. Otherwise
|
||||
// create a new handle and store it in the element state, which lives for as
|
||||
// as frames contain an element with this id.
|
||||
if self.focusable && self.tracked_focus_handle.is_none() {
|
||||
if let Some(element_state) = element_state.as_mut() {
|
||||
let mut handle = element_state
|
||||
.focus_handle
|
||||
.get_or_insert_with(|| cx.focus_handle())
|
||||
.clone()
|
||||
.tab_stop(false);
|
||||
if self.focusable
|
||||
&& self.tracked_focus_handle.is_none()
|
||||
&& let Some(element_state) = element_state.as_mut()
|
||||
{
|
||||
let mut handle = element_state
|
||||
.focus_handle
|
||||
.get_or_insert_with(|| cx.focus_handle())
|
||||
.clone()
|
||||
.tab_stop(false);
|
||||
|
||||
if let Some(index) = self.tab_index {
|
||||
handle = handle.tab_index(index).tab_stop(true);
|
||||
}
|
||||
|
||||
self.tracked_focus_handle = Some(handle);
|
||||
if let Some(index) = self.tab_index {
|
||||
handle = handle.tab_index(index).tab_stop(true);
|
||||
}
|
||||
|
||||
self.tracked_focus_handle = Some(handle);
|
||||
}
|
||||
|
||||
if let Some(scroll_handle) = self.tracked_scroll_handle.as_ref() {
|
||||
self.scroll_offset = Some(scroll_handle.0.borrow().offset.clone());
|
||||
} else if self.base_style.overflow.x == Some(Overflow::Scroll)
|
||||
|| self.base_style.overflow.y == Some(Overflow::Scroll)
|
||||
} else if (self.base_style.overflow.x == Some(Overflow::Scroll)
|
||||
|| self.base_style.overflow.y == Some(Overflow::Scroll))
|
||||
&& let Some(element_state) = element_state.as_mut()
|
||||
{
|
||||
if let Some(element_state) = element_state.as_mut() {
|
||||
self.scroll_offset = Some(
|
||||
element_state
|
||||
.scroll_offset
|
||||
.get_or_insert_with(Rc::default)
|
||||
.clone(),
|
||||
);
|
||||
}
|
||||
self.scroll_offset = Some(
|
||||
element_state
|
||||
.scroll_offset
|
||||
.get_or_insert_with(Rc::default)
|
||||
.clone(),
|
||||
);
|
||||
}
|
||||
|
||||
let style = self.compute_style_internal(None, element_state.as_mut(), window, cx);
|
||||
@@ -2031,26 +2029,27 @@ impl Interactivity {
|
||||
let hitbox = hitbox.clone();
|
||||
window.on_mouse_event({
|
||||
move |_: &MouseUpEvent, phase, window, cx| {
|
||||
if let Some(drag) = &cx.active_drag {
|
||||
if phase == DispatchPhase::Bubble && hitbox.is_hovered(window) {
|
||||
let drag_state_type = drag.value.as_ref().type_id();
|
||||
for (drop_state_type, listener) in &drop_listeners {
|
||||
if *drop_state_type == drag_state_type {
|
||||
let drag = cx
|
||||
.active_drag
|
||||
.take()
|
||||
.expect("checked for type drag state type above");
|
||||
if let Some(drag) = &cx.active_drag
|
||||
&& phase == DispatchPhase::Bubble
|
||||
&& hitbox.is_hovered(window)
|
||||
{
|
||||
let drag_state_type = drag.value.as_ref().type_id();
|
||||
for (drop_state_type, listener) in &drop_listeners {
|
||||
if *drop_state_type == drag_state_type {
|
||||
let drag = cx
|
||||
.active_drag
|
||||
.take()
|
||||
.expect("checked for type drag state type above");
|
||||
|
||||
let mut can_drop = true;
|
||||
if let Some(predicate) = &can_drop_predicate {
|
||||
can_drop = predicate(drag.value.as_ref(), window, cx);
|
||||
}
|
||||
let mut can_drop = true;
|
||||
if let Some(predicate) = &can_drop_predicate {
|
||||
can_drop = predicate(drag.value.as_ref(), window, cx);
|
||||
}
|
||||
|
||||
if can_drop {
|
||||
listener(drag.value.as_ref(), window, cx);
|
||||
window.refresh();
|
||||
cx.stop_propagation();
|
||||
}
|
||||
if can_drop {
|
||||
listener(drag.value.as_ref(), window, cx);
|
||||
window.refresh();
|
||||
cx.stop_propagation();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2094,31 +2093,24 @@ impl Interactivity {
|
||||
}
|
||||
|
||||
let mut pending_mouse_down = pending_mouse_down.borrow_mut();
|
||||
if let Some(mouse_down) = pending_mouse_down.clone() {
|
||||
if !cx.has_active_drag()
|
||||
&& (event.position - mouse_down.position).magnitude()
|
||||
> DRAG_THRESHOLD
|
||||
{
|
||||
if let Some((drag_value, drag_listener)) = drag_listener.take() {
|
||||
*clicked_state.borrow_mut() = ElementClickedState::default();
|
||||
let cursor_offset = event.position - hitbox.origin;
|
||||
let drag = (drag_listener)(
|
||||
drag_value.as_ref(),
|
||||
cursor_offset,
|
||||
window,
|
||||
cx,
|
||||
);
|
||||
cx.active_drag = Some(AnyDrag {
|
||||
view: drag,
|
||||
value: drag_value,
|
||||
cursor_offset,
|
||||
cursor_style: drag_cursor_style,
|
||||
});
|
||||
pending_mouse_down.take();
|
||||
window.refresh();
|
||||
cx.stop_propagation();
|
||||
}
|
||||
}
|
||||
if let Some(mouse_down) = pending_mouse_down.clone()
|
||||
&& !cx.has_active_drag()
|
||||
&& (event.position - mouse_down.position).magnitude() > DRAG_THRESHOLD
|
||||
&& let Some((drag_value, drag_listener)) = drag_listener.take()
|
||||
{
|
||||
*clicked_state.borrow_mut() = ElementClickedState::default();
|
||||
let cursor_offset = event.position - hitbox.origin;
|
||||
let drag =
|
||||
(drag_listener)(drag_value.as_ref(), cursor_offset, window, cx);
|
||||
cx.active_drag = Some(AnyDrag {
|
||||
view: drag,
|
||||
value: drag_value,
|
||||
cursor_offset,
|
||||
cursor_style: drag_cursor_style,
|
||||
});
|
||||
pending_mouse_down.take();
|
||||
window.refresh();
|
||||
cx.stop_propagation();
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -2428,33 +2420,32 @@ impl Interactivity {
|
||||
style.refine(&self.base_style);
|
||||
|
||||
if let Some(focus_handle) = self.tracked_focus_handle.as_ref() {
|
||||
if let Some(in_focus_style) = self.in_focus_style.as_ref() {
|
||||
if focus_handle.within_focused(window, cx) {
|
||||
style.refine(in_focus_style);
|
||||
}
|
||||
if let Some(in_focus_style) = self.in_focus_style.as_ref()
|
||||
&& focus_handle.within_focused(window, cx)
|
||||
{
|
||||
style.refine(in_focus_style);
|
||||
}
|
||||
|
||||
if let Some(focus_style) = self.focus_style.as_ref() {
|
||||
if focus_handle.is_focused(window) {
|
||||
style.refine(focus_style);
|
||||
}
|
||||
if let Some(focus_style) = self.focus_style.as_ref()
|
||||
&& focus_handle.is_focused(window)
|
||||
{
|
||||
style.refine(focus_style);
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(hitbox) = hitbox {
|
||||
if !cx.has_active_drag() {
|
||||
if let Some(group_hover) = self.group_hover_style.as_ref() {
|
||||
if let Some(group_hitbox_id) = GroupHitboxes::get(&group_hover.group, cx) {
|
||||
if group_hitbox_id.is_hovered(window) {
|
||||
style.refine(&group_hover.style);
|
||||
}
|
||||
}
|
||||
if let Some(group_hover) = self.group_hover_style.as_ref()
|
||||
&& let Some(group_hitbox_id) = GroupHitboxes::get(&group_hover.group, cx)
|
||||
&& group_hitbox_id.is_hovered(window)
|
||||
{
|
||||
style.refine(&group_hover.style);
|
||||
}
|
||||
|
||||
if let Some(hover_style) = self.hover_style.as_ref() {
|
||||
if hitbox.is_hovered(window) {
|
||||
style.refine(hover_style);
|
||||
}
|
||||
if let Some(hover_style) = self.hover_style.as_ref()
|
||||
&& hitbox.is_hovered(window)
|
||||
{
|
||||
style.refine(hover_style);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2468,12 +2459,10 @@ impl Interactivity {
|
||||
for (state_type, group_drag_style) in &self.group_drag_over_styles {
|
||||
if let Some(group_hitbox_id) =
|
||||
GroupHitboxes::get(&group_drag_style.group, cx)
|
||||
&& *state_type == drag.value.as_ref().type_id()
|
||||
&& group_hitbox_id.is_hovered(window)
|
||||
{
|
||||
if *state_type == drag.value.as_ref().type_id()
|
||||
&& group_hitbox_id.is_hovered(window)
|
||||
{
|
||||
style.refine(&group_drag_style.style);
|
||||
}
|
||||
style.refine(&group_drag_style.style);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2495,16 +2484,16 @@ impl Interactivity {
|
||||
.clicked_state
|
||||
.get_or_insert_with(Default::default)
|
||||
.borrow();
|
||||
if clicked_state.group {
|
||||
if let Some(group) = self.group_active_style.as_ref() {
|
||||
style.refine(&group.style)
|
||||
}
|
||||
if clicked_state.group
|
||||
&& let Some(group) = self.group_active_style.as_ref()
|
||||
{
|
||||
style.refine(&group.style)
|
||||
}
|
||||
|
||||
if let Some(active_style) = self.active_style.as_ref() {
|
||||
if clicked_state.element {
|
||||
style.refine(active_style)
|
||||
}
|
||||
if let Some(active_style) = self.active_style.as_ref()
|
||||
&& clicked_state.element
|
||||
{
|
||||
style.refine(active_style)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -297,10 +297,10 @@ impl RetainAllImageCache {
|
||||
/// Remove the image from the cache by the given source.
|
||||
pub fn remove(&mut self, source: &Resource, window: &mut Window, cx: &mut App) {
|
||||
let hash = hash(source);
|
||||
if let Some(mut item) = self.0.remove(&hash) {
|
||||
if let Some(Ok(image)) = item.get() {
|
||||
cx.drop_image(image, Some(window));
|
||||
}
|
||||
if let Some(mut item) = self.0.remove(&hash)
|
||||
&& let Some(Ok(image)) = item.get()
|
||||
{
|
||||
cx.drop_image(image, Some(window));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -379,13 +379,12 @@ impl Element for Img {
|
||||
None => {
|
||||
if let Some(state) = &mut state {
|
||||
if let Some((started_loading, _)) = state.started_loading {
|
||||
if started_loading.elapsed() > LOADING_DELAY {
|
||||
if let Some(loading) = self.style.loading.as_ref() {
|
||||
let mut element = loading();
|
||||
replacement_id =
|
||||
Some(element.request_layout(window, cx));
|
||||
layout_state.replacement = Some(element);
|
||||
}
|
||||
if started_loading.elapsed() > LOADING_DELAY
|
||||
&& let Some(loading) = self.style.loading.as_ref()
|
||||
{
|
||||
let mut element = loading();
|
||||
replacement_id = Some(element.request_layout(window, cx));
|
||||
layout_state.replacement = Some(element);
|
||||
}
|
||||
} else {
|
||||
let current_view = window.current_view();
|
||||
|
||||
@@ -732,46 +732,44 @@ impl StateInner {
|
||||
item.element.prepaint_at(item_origin, window, cx);
|
||||
});
|
||||
|
||||
if let Some(autoscroll_bounds) = window.take_autoscroll() {
|
||||
if autoscroll {
|
||||
if autoscroll_bounds.top() < bounds.top() {
|
||||
return Err(ListOffset {
|
||||
item_ix: item.index,
|
||||
offset_in_item: autoscroll_bounds.top() - item_origin.y,
|
||||
});
|
||||
} else if autoscroll_bounds.bottom() > bounds.bottom() {
|
||||
let mut cursor = self.items.cursor::<Count>(&());
|
||||
cursor.seek(&Count(item.index), Bias::Right);
|
||||
let mut height = bounds.size.height - padding.top - padding.bottom;
|
||||
if let Some(autoscroll_bounds) = window.take_autoscroll()
|
||||
&& autoscroll
|
||||
{
|
||||
if autoscroll_bounds.top() < bounds.top() {
|
||||
return Err(ListOffset {
|
||||
item_ix: item.index,
|
||||
offset_in_item: autoscroll_bounds.top() - item_origin.y,
|
||||
});
|
||||
} else if autoscroll_bounds.bottom() > bounds.bottom() {
|
||||
let mut cursor = self.items.cursor::<Count>(&());
|
||||
cursor.seek(&Count(item.index), Bias::Right);
|
||||
let mut height = bounds.size.height - padding.top - padding.bottom;
|
||||
|
||||
// Account for the height of the element down until the autoscroll bottom.
|
||||
height -= autoscroll_bounds.bottom() - item_origin.y;
|
||||
// Account for the height of the element down until the autoscroll bottom.
|
||||
height -= autoscroll_bounds.bottom() - item_origin.y;
|
||||
|
||||
// Keep decreasing the scroll top until we fill all the available space.
|
||||
while height > Pixels::ZERO {
|
||||
cursor.prev();
|
||||
let Some(item) = cursor.item() else { break };
|
||||
// Keep decreasing the scroll top until we fill all the available space.
|
||||
while height > Pixels::ZERO {
|
||||
cursor.prev();
|
||||
let Some(item) = cursor.item() else { break };
|
||||
|
||||
let size = item.size().unwrap_or_else(|| {
|
||||
let mut item = render_item(cursor.start().0, window, cx);
|
||||
let item_available_size = size(
|
||||
bounds.size.width.into(),
|
||||
AvailableSpace::MinContent,
|
||||
);
|
||||
item.layout_as_root(item_available_size, window, cx)
|
||||
});
|
||||
height -= size.height;
|
||||
}
|
||||
|
||||
return Err(ListOffset {
|
||||
item_ix: cursor.start().0,
|
||||
offset_in_item: if height < Pixels::ZERO {
|
||||
-height
|
||||
} else {
|
||||
Pixels::ZERO
|
||||
},
|
||||
let size = item.size().unwrap_or_else(|| {
|
||||
let mut item = render_item(cursor.start().0, window, cx);
|
||||
let item_available_size =
|
||||
size(bounds.size.width.into(), AvailableSpace::MinContent);
|
||||
item.layout_as_root(item_available_size, window, cx)
|
||||
});
|
||||
height -= size.height;
|
||||
}
|
||||
|
||||
return Err(ListOffset {
|
||||
item_ix: cursor.start().0,
|
||||
offset_in_item: if height < Pixels::ZERO {
|
||||
-height
|
||||
} else {
|
||||
Pixels::ZERO
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -356,12 +356,11 @@ impl TextLayout {
|
||||
(None, "".into())
|
||||
};
|
||||
|
||||
if let Some(text_layout) = element_state.0.borrow().as_ref() {
|
||||
if text_layout.size.is_some()
|
||||
&& (wrap_width.is_none() || wrap_width == text_layout.wrap_width)
|
||||
{
|
||||
return text_layout.size.unwrap();
|
||||
}
|
||||
if let Some(text_layout) = element_state.0.borrow().as_ref()
|
||||
&& text_layout.size.is_some()
|
||||
&& (wrap_width.is_none() || wrap_width == text_layout.wrap_width)
|
||||
{
|
||||
return text_layout.size.unwrap();
|
||||
}
|
||||
|
||||
let mut line_wrapper = cx.text_system().line_wrapper(text_style.font(), font_size);
|
||||
@@ -763,14 +762,13 @@ impl Element for InteractiveText {
|
||||
let mut interactive_state = interactive_state.unwrap_or_default();
|
||||
if let Some(click_listener) = self.click_listener.take() {
|
||||
let mouse_position = window.mouse_position();
|
||||
if let Ok(ix) = text_layout.index_for_position(mouse_position) {
|
||||
if self
|
||||
if let Ok(ix) = text_layout.index_for_position(mouse_position)
|
||||
&& self
|
||||
.clickable_ranges
|
||||
.iter()
|
||||
.any(|range| range.contains(&ix))
|
||||
{
|
||||
window.set_cursor_style(crate::CursorStyle::PointingHand, hitbox)
|
||||
}
|
||||
{
|
||||
window.set_cursor_style(crate::CursorStyle::PointingHand, hitbox)
|
||||
}
|
||||
|
||||
let text_layout = text_layout.clone();
|
||||
@@ -803,13 +801,13 @@ impl Element for InteractiveText {
|
||||
} else {
|
||||
let hitbox = hitbox.clone();
|
||||
window.on_mouse_event(move |event: &MouseDownEvent, phase, window, _| {
|
||||
if phase == DispatchPhase::Bubble && hitbox.is_hovered(window) {
|
||||
if let Ok(mouse_down_index) =
|
||||
if phase == DispatchPhase::Bubble
|
||||
&& hitbox.is_hovered(window)
|
||||
&& let Ok(mouse_down_index) =
|
||||
text_layout.index_for_position(event.position)
|
||||
{
|
||||
mouse_down.set(Some(mouse_down_index));
|
||||
window.refresh();
|
||||
}
|
||||
{
|
||||
mouse_down.set(Some(mouse_down_index));
|
||||
window.refresh();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user