~gioverse/chat

cddbe8d31e5ba5998db727a1939b38a21fcbf141 — vkoshelev 4 months ago bc1dd00
fix ScrollToEnd behavior
2 files changed, 15 insertions(+), 3 deletions(-)

M example/kitchen/ui/row-tracker.go
M example/kitchen/ui/ui.go
M example/kitchen/ui/row-tracker.go => example/kitchen/ui/row-tracker.go +13 -2
@@ 29,7 29,8 @@ type RowTracker struct {
	Generator     *gen.Generator
	// MaxLoads specifies the number of elements a given load in either
	// direction can return.
	MaxLoads int
	MaxLoads    int
	ScrollToEnd bool
}

// NewExampleData constructs a RowTracker populated with the provided


@@ 117,7 118,17 @@ func (r *RowTracker) Load(dir list.Direction, relativeTo list.Serial) (loaded []
		// If loading relative to nothing, likely the chat interface is empty.
		// We should load the most recent messages first in this case, regardless
		// of the direction parameter.
		return r.Rows[numRows-min(r.MaxLoads, numRows):], numRows > r.MaxLoads
		if r.ScrollToEnd {
			return r.Rows[numRows-min(r.MaxLoads, numRows):], numRows > r.MaxLoads
		} else {
			var res int
			if numRows < r.MaxLoads {
				res = numRows
			} else {
				res = r.MaxLoads
			}
			return r.Rows[:res], numRows > r.MaxLoads
		}
	}
	idx := r.SerialToIndex[relativeTo]
	if dir == list.After {

M example/kitchen/ui/ui.go => example/kitchen/ui/ui.go +2 -1
@@ 168,6 168,7 @@ func NewUI(invalidator func(), conf Config) *UI {
		rt := NewExampleData(users, local, g, 100)
		rt.SimulateLatency = conf.Latency
		rt.MaxLoads = conf.LoadSize
		rt.ScrollToEnd = false
		lm := list.NewManager(conf.BufferSize,
			list.Hooks{
				// Define an allocator function that can instaniate the appropriate


@@ 224,7 225,7 @@ func NewUI(invalidator func(), conf Config) *UI {

	ui.Rooms.Select(0)
	for ii := range ui.Rooms.List {
		ui.Rooms.List[ii].List.ScrollToEnd = true
		ui.Rooms.List[ii].List.ScrollToEnd = ui.Rooms.List[ii].Messages.ScrollToEnd
		ui.Rooms.List[ii].List.Axis = layout.Vertical
	}