Skip to content

Commit

Permalink
Update list_view.rs
Browse files Browse the repository at this point in the history
  • Loading branch information
namse authored Aug 2, 2024
1 parent 4f9c245 commit bdb11b9
Showing 1 changed file with 19 additions and 14 deletions.
33 changes: 19 additions & 14 deletions namui/namui-prebuilt/src/list_view.rs
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
use crate::scroll_view::{self};
use namui::*;
use std::borrow::Cow;

pub struct AutoListView<'a, Items, C>
pub struct AutoListView<Items, Key, C>
where
C: Component,
Items: ExactSizeIterator<Item = (Cow<'a, str>, C)>,
Key: Into<AddKey>,
Items: ExactSizeIterator<Item = (Key, C)>,
{
pub height: Px,
pub scroll_bar_width: Px,
pub item_wh: Wh<Px>,
pub items: Items,
}

impl<'a, Items, C> Component for AutoListView<'a, Items, C>
impl<Items, Key, C> Component for AutoListView<Items, Key, C>
where
C: Component,
Items: ExactSizeIterator<Item = (Cow<'a, str>, C)>,
Key: Into<AddKey>,
Items: ExactSizeIterator<Item = (Key, C)>,
{
fn render(self, ctx: &RenderCtx) {
let Self {
Expand All @@ -38,10 +39,11 @@ where
}
}

pub struct ListView<'a, Items, C>
pub struct ListView<Items, Key, C>
where
C: Component,
Items: ExactSizeIterator<Item = (Cow<'a, str>, C)>,
Key: Into<AddKey>,
Items: ExactSizeIterator<Item = (Key, C)>,
{
pub height: Px,
pub scroll_bar_width: Px,
Expand All @@ -51,10 +53,11 @@ where
pub set_scroll_y: SetState<Px>,
}

impl<'a, Items, C> Component for ListView<'a, Items, C>
impl<Items, Key, C> Component for ListView<Items, Key, C>
where
C: Component,
Items: ExactSizeIterator<Item = (Cow<'a, str>, C)>,
Key: Into<AddKey>,
Items: ExactSizeIterator<Item = (Key, C)>,
{
fn render(self, ctx: &RenderCtx) {
let Self {
Expand All @@ -81,21 +84,23 @@ where
}
}

struct ListViewInner<'a, Items, C>
struct ListViewInner<Items, Key, C>
where
C: Component,
Items: ExactSizeIterator<Item = (Cow<'a, str>, C)>,
Key: Into<AddKey>,
Items: ExactSizeIterator<Item = (Key, C)>,
{
height: Px,
item_wh: Wh<Px>,
items: Items,
scroll_y: Px,
}

impl<'a, Items, C> Component for ListViewInner<'a, Items, C>
impl<Items, Key, C> Component for ListViewInner<Items, Key, C>
where
C: Component,
Items: ExactSizeIterator<Item = (Cow<'a, str>, C)>,
Key: Into<AddKey>,
Items: ExactSizeIterator<Item = (Key, C)>,
{
fn render(self, ctx: &RenderCtx) {
let Self {
Expand Down Expand Up @@ -150,7 +155,7 @@ where

ctx.compose(|ctx| {
for (index, (key, visible_item)) in visible_items.into_iter().enumerate() {
ctx.compose_with_key(key.as_ref(), |ctx| {
ctx.compose_with_key(key, |ctx| {
ctx.translate((0.px(), item_wh.height * (index + visible_item_start_index)))
.add(visible_item);
});
Expand Down

0 comments on commit bdb11b9

Please sign in to comment.