View Source ElementTui.FocusStream (ElementTui v0.5.1)

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

Link to this function

focus_by(orig_state, func)

View Source
Create a new FocusStream from a list or stream of elements.
Link to this function

next(focus_stream, opts \\ [])

View Source

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)
Link to this function

prev(focus_stream, opts \\ [])

View Source

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)