red / REP

Red Enhancement Process
BSD 3-Clause "New" or "Revised" License
11 stars 4 forks source link

WISH: on-scroll for text-list and API to control it #152

Open GiuseppeChillemi opened 1 year ago

GiuseppeChillemi commented 1 year ago

VID does not have a multi-column text-list. You can connect multiple single text-lists and propagate the on-change event but you end up in a problem: they will go out of sync. To solve the problem you can try to position to 1 and then to the requested position but it is kludgy. I have tried with this tecnique and the result is not good. Also you CAN'T use the scroller as you do not have an on-scroll actor so using it you will lose the row syncing.

Here is the code I have created

Red [
    title: "Multi Text List"
]

l: copy []
list-size: 3
list-name: 'one

;--- Creates a list with multiple columns

repeat idx 50 [
    append l compose [(rejoin ["a" idx]) (rejoin ["b" idx]) (rejoin ["c" idx])]
]

select-everywhere: func [
    "Select the same element on all lists"
    face [object!] "The current face"
    id [word! string!] "The id of the list"
    position [integer!] "The position to select"
] [
    ;--- This is needed for syncing
    foreach-face/with face/parent [face/selected: 1] [attempt [face/extra/list-id = id]]

    ;--- This repositions everywhere
    foreach-face/with face/parent [face/selected: position] [attempt [face/extra/list-id = id]]
]

make-list-view: func [
    "Create a navigable list made of multiple text-lists"
    data [block! object!] "The table as flat"
    col-ln [integer!] "The lenght of columns"
    list-id [word! string!] "The name of the list"
    /local
    template
    row
    list-body
] [
    ;The basic template for the list
    template: [
        style clist: text-list data "" on-change [select-everywhere face face/extra/list-id face/selected]
    ]

    ;Init of the list body
    ;
    list-body: copy template

    ;The text-list that manages a column
    ;
    row: [clist data "" with [extra: make object! [list-id: quote (list-id) data: l column: (col-num) original-data: data] data: extract/index l (col-ln) extra/column]] 

    ;Creating the code that manages alla the columns
    ;
    repeat col-num col-ln [
        append list-body compose/deep copy row

    ]

    ;Returning the list VID code
    ;
    list-body
]

view make-list-view l list-size list-name

My request is for an on-scroll actor and expose the API elements to get/set the position of the list like the first/last visible row number, number of rows on screen.

Some screen-capture and discussion is here.

Thank you in advance