Skip to main content

makepad_example_ui_zoo/
tab_portallist.rs

1use crate::{
2    makepad_widgets::*,
3};
4
5live_design!{
6    use link::theme::*;
7    use link::shaders::*;
8    use link::widgets::*;
9    use crate::layout_templates::*;
10
11    IMG_A = dep("crate://self/resources/ducky.png")
12    IMG_PROFILE_A = dep("crate://self/resources/ducky.png")
13    COLOR_TEXT = #x8
14    COLOR_TEXT_LIGHT = #xCCC
15    COLOR_USER = #x444
16
17    Post = <View> {
18        width: Fill, height: Fit,
19        padding: { top: 10., bottom: 10.}
20
21        body = <RoundedView> {
22            width: Fill, height: Fit
23            content = <View> {
24                width: Fill, height: Fit
25                text = <P> { text: "" }
26            }
27        }
28    }
29
30    NewsFeed = {{NewsFeed}} {
31        list = <PortalList> {
32            scroll_bar: <ScrollBar> {}
33            TopSpace = <View> {height: 0.}
34            BottomSpace = <View> {height: 100.}
35
36            Post = <CachedView>{
37                flow: Down,
38                <Post> {}
39                <Hr> {}
40            }
41        }
42    }
43
44    pub DemoPortalList = <UIZooTabLayout_B> {
45        desc = {
46            <Markdown> { body: dep("crate://self/resources/portallist.md") } 
47        }
48        demos = {
49            news_feed = <NewsFeed> {}
50        }
51    }
52}
53#[derive(Live, LiveHook, Widget)]
54struct NewsFeed{
55    #[deref] view:View,
56}
57
58impl Widget for NewsFeed{
59    fn draw_walk(&mut self, cx:&mut Cx2d, scope:&mut Scope, walk:Walk)->DrawStep{
60        while let Some(item) =  self.view.draw_walk(cx, scope, walk).step(){
61            if let Some(mut list) = item.as_portal_list().borrow_mut() {
62                list.set_item_range(cx, 0, 1000);
63                while let Some(item_id) = list.next_visible_item(cx) {
64                    let template = match item_id{
65                        0 => live_id!(TopSpace),
66                        _ => live_id!(Post)
67                    };
68                    let item = list.item(cx, item_id, template);
69                    let text = match item_id % 4 {
70                        1 => format!("At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum."),
71                        2 => format!("How are you?"),
72                        3 => format!("Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet."),
73                        _ => format!("Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua."),
74                    };
75                    item.label(id!(content.text)).set_text(cx, &text);
76                    item.button(id!(likes)).set_text(cx, &format!("{}", item_id % 23));
77                    item.button(id!(comments)).set_text(cx, &format!("{}", item_id % 6));
78                    item.draw_all(cx, &mut Scope::empty());
79                }
80            }
81        }
82        DrawStep::done()
83    }
84    fn handle_event(&mut self, cx:&mut Cx, event:&Event, scope:&mut Scope){
85        self.view.handle_event(cx, event, scope)
86    }
87}