module Long_list:sig
..end
Handle large lists by not displaying all elements at once.
Very quickly, displaying a list of layouts (for instance, listing files in a
directory) can run the computer out of memory if it tries to keep in memory
the textures of all entries of the list. In these cases you need to use a
Long_list
.
See for instance Example #34 that displays a list of 1 million entries.
Long_lists may contain any type of Layout. They don't need to be all of the
same dimension. Instead of providing the list of layouts, one must give a
function generate
such that the layout given by generate i
is the i-eth
element of the list.
type
t
val create : ?name:string ->
w:int ->
h:int ->
length:int ->
?first:int ->
generate:(int -> Layout.t) ->
?height_fn:(int -> int option) ->
?cleanup:(Layout.t -> unit) ->
?max_memory:int ->
?linear:bool ->
?scrollbar_width:int -> ?scale_width:bool -> unit -> t
Create a long list through the function generate
which maps any index i
to the ieth element (layout) of the list. If specified (which is
not a good idea), the max_memory
should be at least twice the area (in
physical pixels) of the visible part of the list. If the number of
elements is large (typically 100000 or more, this depends on your CPU),
its is highly advisable to provide a height_fn
, which to an index i
gives the height (in logical pixels) of the ieth entry. If some
heights are not known in advance, it's ok to return None
. For instance,
if all entries have the same height, say 30 pixels, one can define
let height_fn _ = Some 30
val create_layout : ?name:string ->
w:int ->
h:int ->
length:int ->
?first:int ->
generate:(int -> Layout.t) ->
?height_fn:(int -> int option) ->
?cleanup:(Layout.t -> unit) ->
?max_memory:int ->
?linear:bool ->
?scrollbar_width:int -> ?scale_width:bool -> unit -> Layout.t
Similar to create
but only returns the layout. Equivalent to calling
Long_list.get_layout
to the result of create
.
val get_layout : t -> Layout.t
val get_scroll : t -> float
Return the scroll percentage of the Long list, between 0 and 1. A value of 0 means no scroll: the first row is visible. The value 1 means that the scrollbar is fully downwards, the last row is visible.
val set_scroll : t -> float -> unit