View Source ElementTui.FocusStream (ElementTui v0.5.0)
Module to handle a list/stream of elements, while keeping one in focus. This module makes it easier to implement a scrollable (horizontal or vertical box).
Examples
fs = FocusStream.new([1, 2, 3, 4, 5, 6])
# Select next element
fs = FocusStream.next(fs, bound: true)
# Focus the third element
fs = FocusStream.focus_by(fs, fn x -> x == 3 end)
# Select previous element
fs = FocusStream.prev(fs, bound: true)
# Turn into a vertical box, containing all the elements and printing a bar in front of the focussed element to highlight it
FocusStream.map(fs, fn el, focussed ->
case focussed do
true -> Element.text("┃ " <> inspect(el))
false -> Element.text(" " <> inspect(el))
end
end)
|> Element.vbox()
Summary
Functions
Create a new FocusStream from a list or stream of elements.
Select the next element in the FocusStream.
Select the previous element in the FocusStream.
Functions
Create a new FocusStream from a list or stream of elements.
Select the next element in the FocusStream.
Pass the bound: true
option to include a bound check. Currently the default is no bound check, but that might change in the future.
Examples
fs = FocusStream.new([1, 2, 3, 4, 5, 6])
# Select next element
fs = FocusStream.next(fs, bound: true)
Select the previous element in the FocusStream.
Pass the bound: true
option to include a bound check. Currently the default is no bound check, but that might change in the future.
Examples
fs = FocusStream.new([1, 2, 3, 4, 5, 6])
# Focus the third element
fs = FocusStream.focus_by(fs, fn x -> x == 3 end)
fs = FocusStream.prev(fs, bound: true)