Remove default listview id.
@@ -7,7 +7,6 @@ use super::behaviors::MouseBehavior;
use crate::{prelude::*, utils::SelectionMode as SelMode};
static ITEMS_PANEL: &'static str = "items_panel";
-pub static LIST_VIEW: &'static str = "list_view";
/// The `ListViewState` generates the list box items and handles the selected indices.
#[derive(Default, AsAny)]
@@ -37,7 +36,7 @@ impl State for ListViewState {
let item = {
let build_context = &mut ctx.build_context();
let child = builder(build_context, i);
- let item = ListViewItem::new().build(build_context);
+ let item = ListViewItem::new().parent(entity.0).build(build_context);
let mouse_behavior = MouseBehavior::new().build(build_context);
build_context.register_shared_property::<Selector>(
@@ -122,9 +121,10 @@ impl State for ListViewItemState {
let entity = ctx.entity;
let index = ctx.index_as_child(entity).unwrap();
- let mut parent_entity = None;
+ let parent_entity: Entity = (*ctx.widget().get::<u32>("parent")).into();
+
+ let mut parent = ctx.get_widget(parent_entity);
- if let Some(parent) = &mut ctx.try_parent_from_id(LIST_VIEW) {
let selection_mode = *parent.get::<SelectionMode>("selection_mode");
// deselect item
if selected {
@@ -168,12 +168,11 @@ impl State for ListViewItemState {
.0
.insert(index);
- parent_entity = Some(parent.entity());
- }
-
- if let Some(parent) = parent_entity {
- ctx.push_event_strategy_by_entity(ChangedEvent(parent), parent, EventStrategy::Direct);
- }
+ ctx.push_event_strategy_by_entity(
+ ChangedEvent(parent_entity),
+ parent_entity,
+ EventStrategy::Direct,
+ );
}
}
@@ -322,7 +321,6 @@ impl Template for ListView {
self.name("ListView")
.style("list_view")
- .id(LIST_VIEW)
.background(colors::LYNCH_COLOR)
.border_radius(2.0)
.border_width(1.0)
