Skip to content

Commit 220f712

Browse files
committed
feat: Better offset for table
1 parent c534da7 commit 220f712

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

src/widgets/table.jl

+11-5
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,15 @@ end
66
@kwdef struct Row
77
data::Vector{Datum}
88
height::Int = 1
9+
style::Crayon = Crayon()
910
bottom_margin::Int = 0
1011
end
1112

1213
total_height(row::Row) = row.height + row.bottom_margin
1314

1415
@kwdef mutable struct TableState
1516
selected::Union{Int,Nothing} = nothing
17+
offset::Int = 1
1618
end
1719

1820
@kwdef mutable struct Table
@@ -21,11 +23,12 @@ end
2123
state::TableState = TableState()
2224
block::Union{Nothing,Block} = Block()
2325
style::Crayon = Crayon()
24-
column_spacing::Int = 0
26+
column_spacing::Int = 1
2527
column_widths::Vector{Int} = []
2628
header::Union{Row,Nothing} = nothing
27-
highlight_symbol::Union{String,Nothing} = ">"
29+
highlight_symbol::String = ">"
2830
highlight_style::Crayon = Crayon()
31+
highlight_spacing::Symbol = :when_selected
2932
end
3033

3134

@@ -88,10 +91,12 @@ function get_columns_widths(table::Table, max_width::Int)
8891
end
8992

9093
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
9398
height = 0
94-
for item in table.rows
99+
for item in table.rows[offset:end]
95100
if height + item.height >= max_height
96101
break
97102
end
@@ -139,6 +144,7 @@ function render(table::Table, area::Rect, buf::Buffer)
139144
header_height = isnothing(table.header) ? 0 : (table.header.height)
140145
@debug "Calculate start_row stop_row"
141146
start_row, stop_row = get_row_bounds(table, height(area) - (header_height + 2))
147+
table.state.offset = start_row
142148

143149
# Optionally render block around the table
144150
if !isnothing(table.block)

0 commit comments

Comments
 (0)