interpreter: Replace ComponentPositions with a simple Vec<LogicalRect>

... now that the Vec is the only member of `ComponentPosiitons`.
This commit is contained in:
Tobias Hunger 2024-03-20 12:34:00 +01:00 committed by Tobias Hunger
parent fd9e234197
commit b7d2a30b81
4 changed files with 15 additions and 24 deletions

View file

@ -1202,7 +1202,7 @@ impl ComponentInstance {
&self,
path: &Path,
offset: u32,
) -> crate::highlight::ComponentPositions {
) -> Vec<i_slint_core::lengths::LogicalRect> {
crate::highlight::component_positions(&self.inner, path, offset)
}

View file

@ -12,22 +12,15 @@ use std::path::Path;
use std::rc::Rc;
use vtable::VRc;
/// Positions of the Element in the UI
#[derive(Default)]
pub struct ComponentPositions {
/// The geometry information of all occurrences of this element in the UI
pub geometries: Vec<i_slint_core::lengths::LogicalRect>,
}
fn collect_highlight_data(
component: &DynamicComponentVRc,
elements: &[std::rc::Weak<RefCell<Element>>],
) -> ComponentPositions {
) -> Vec<i_slint_core::lengths::LogicalRect> {
let component_instance = VRc::downgrade(component);
let component_instance = component_instance.upgrade().unwrap();
generativity::make_guard!(guard);
let c = component_instance.unerase(guard);
let mut values = ComponentPositions::default();
let mut values = Vec::new();
for element in elements.iter().filter_map(|e| e.upgrade()) {
if let Some(repeater_path) = repeater_path(&element) {
fill_highlight_data(&repeater_path, &element, &c, &c, &mut values);
@ -40,7 +33,7 @@ pub(crate) fn component_positions(
component_instance: &DynamicComponentVRc,
path: &Path,
offset: u32,
) -> ComponentPositions {
) -> Vec<i_slint_core::lengths::LogicalRect> {
generativity::make_guard!(guard);
let c = component_instance.unerase(guard);
@ -58,11 +51,11 @@ pub(crate) fn element_position(
generativity::make_guard!(guard);
let c = component_instance.unerase(guard);
let mut values = ComponentPositions::default();
let mut values = Vec::new();
if let Some(repeater_path) = repeater_path(element) {
fill_highlight_data(&repeater_path, element, &c, &c, &mut values);
}
values.geometries
values
}
pub(crate) fn element_at_source_code_position(
@ -81,7 +74,7 @@ fn fill_highlight_data(
element: &ElementRc,
component_instance: &ItemTreeBox,
root_component_instance: &ItemTreeBox,
values: &mut ComponentPositions,
values: &mut Vec<i_slint_core::lengths::LogicalRect>,
) {
if let [first, rest @ ..] = repeater_path {
generativity::make_guard!(guard);
@ -115,7 +108,7 @@ fn fill_highlight_data(
let origin = item_rc.map_to_item_tree(geometry.origin, &root_vrc);
let size = geometry.size;
values.geometries.push(LogicalRect { origin, size });
values.push(LogicalRect { origin, size });
}
}

View file

@ -11,7 +11,6 @@ use i_slint_core::component_factory::FactoryContext;
use i_slint_core::lengths::{LogicalLength, LogicalPoint};
use i_slint_core::model::VecModel;
use lsp_types::Url;
use slint_interpreter::highlight::ComponentPositions;
use slint_interpreter::{ComponentDefinition, ComponentHandle, ComponentInstance};
use std::cell::RefCell;
use std::collections::{HashMap, HashSet};
@ -607,7 +606,7 @@ fn set_selections(
is_layout: bool,
is_moveable: bool,
is_resizable: bool,
positions: ComponentPositions,
positions: &[i_slint_core::lengths::LogicalRect],
) {
let Some(ui) = ui else {
return;
@ -625,7 +624,6 @@ fn set_selections(
};
let values = positions
.geometries
.iter()
.enumerate()
.map(|(i, g)| ui::Selection {
@ -647,7 +645,7 @@ fn set_selections(
fn set_selected_element(
selection: Option<element_selection::ElementSelection>,
positions: slint_interpreter::highlight::ComponentPositions,
positions: &[i_slint_core::lengths::LogicalRect],
notify_editor_about_selection_after_update: bool,
) {
let (is_layout, is_in_layout) = selection

View file

@ -7,7 +7,7 @@ use i_slint_compiler::diagnostics::SourceFile;
use i_slint_compiler::object_tree::{Component, ElementRc};
use i_slint_core::lengths::{LogicalLength, LogicalPoint};
use rowan::TextRange;
use slint_interpreter::{highlight::ComponentPositions, ComponentInstance};
use slint_interpreter::ComponentInstance;
use crate::common::ElementRcNode;
@ -84,7 +84,7 @@ fn element_covers_point(
}
pub fn unselect_element() {
super::set_selected_element(None, ComponentPositions::default(), false);
super::set_selected_element(None, &[], false);
}
pub fn select_element_at_source_code_position(
@ -119,13 +119,13 @@ fn select_element_at_source_code_position_impl(
let instance_index = position
.and_then(|p| {
positions.geometries.iter().enumerate().find_map(|(i, g)| g.contains(p).then_some(i))
positions.iter().enumerate().find_map(|(i, g)| g.contains(p).then_some(i))
})
.unwrap_or_default();
super::set_selected_element(
Some(ElementSelection { path, offset, instance_index, is_layout }),
positions,
&positions,
notify_editor_about_selection_after_update,
);
}
@ -423,5 +423,5 @@ pub fn reselect_element() {
};
let positions = component_instance.component_positions(&selected.path, selected.offset);
super::set_selected_element(Some(selected), positions, false);
super::set_selected_element(Some(selected), &positions, false);
}