|
6 | 6 | @kwdef struct Row
|
7 | 7 | data::Vector{Datum}
|
8 | 8 | height::Int = 1
|
| 9 | + style::Crayon = Crayon() |
9 | 10 | bottom_margin::Int = 0
|
10 | 11 | end
|
11 | 12 |
|
12 | 13 | total_height(row::Row) = row.height + row.bottom_margin
|
13 | 14 |
|
14 | 15 | @kwdef mutable struct TableState
|
15 | 16 | selected::Union{Int,Nothing} = nothing
|
| 17 | + offset::Int = 1 |
16 | 18 | end
|
17 | 19 |
|
18 | 20 | @kwdef mutable struct Table
|
|
21 | 23 | state::TableState = TableState()
|
22 | 24 | block::Union{Nothing,Block} = Block()
|
23 | 25 | style::Crayon = Crayon()
|
24 |
| - column_spacing::Int = 0 |
| 26 | + column_spacing::Int = 1 |
25 | 27 | column_widths::Vector{Int} = []
|
26 | 28 | header::Union{Row,Nothing} = nothing
|
27 |
| - highlight_symbol::Union{String,Nothing} = ">" |
| 29 | + highlight_symbol::String = ">" |
28 | 30 | highlight_style::Crayon = Crayon()
|
| 31 | + highlight_spacing::Symbol = :when_selected |
29 | 32 | end
|
30 | 33 |
|
31 | 34 |
|
@@ -88,10 +91,12 @@ function get_columns_widths(table::Table, max_width::Int)
|
88 | 91 | end
|
89 | 92 |
|
90 | 93 | function get_row_bounds(table::Table, max_height::Int)
|
91 |
| - start = 1 |
92 |
| - stop = 1 |
| 94 | + (; offset) = table.state |
| 95 | + offset = min(length(table.rows), offset) |
| 96 | + start = offset |
| 97 | + stop = offset |
93 | 98 | height = 0
|
94 |
| - for item in table.rows |
| 99 | + for item in table.rows[offset:end] |
95 | 100 | if height + item.height >= max_height
|
96 | 101 | break
|
97 | 102 | end
|
@@ -139,6 +144,7 @@ function render(table::Table, area::Rect, buf::Buffer)
|
139 | 144 | header_height = isnothing(table.header) ? 0 : (table.header.height)
|
140 | 145 | @debug "Calculate start_row stop_row"
|
141 | 146 | start_row, stop_row = get_row_bounds(table, height(area) - (header_height + 2))
|
| 147 | + table.state.offset = start_row |
142 | 148 |
|
143 | 149 | # Optionally render block around the table
|
144 | 150 | if !isnothing(table.block)
|
|
0 commit comments