~delthas/senpai-dev

allow scrolling topic left and right v1 PROPOSED

aoife cassidy: 1
 allow scrolling topic left and right

 3 files changed, 33 insertions(+), 4 deletions(-)
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~delthas/senpai-dev/patches/56465/mbox | git am -3
Learn more about email & git

[PATCH v1] allow scrolling topic left and right Export this patch

---
haven't managed to make clickable links work while scrolling too far,
would appreciate guidance on what would be the right course of action.

 app.go        |  6 ++++++
 ui/buffers.go | 13 ++++++++++---
 ui/ui.go      | 18 +++++++++++++++++-
 3 files changed, 33 insertions(+), 4 deletions(-)

diff --git a/app.go b/app.go
index b00c563..3e8cf40 100644
--- a/app.go
+++ b/app.go
@@ -603,6 +603,8 @@ func (app *App) handleMouseEvent(ev vaxis.Mouse) {
				app.win.ScrollChannelUpBy(4)
			} else if x > w-app.win.MemberWidth() {
				app.win.ScrollMemberUpBy(4)
			} else if y == 0 {
				app.win.ScrollTopicLeftBy(4)
			} else {
				app.win.ScrollUpBy(4)
			}
@@ -612,6 +614,8 @@ func (app *App) handleMouseEvent(ev vaxis.Mouse) {
				app.win.ScrollChannelDownBy(4)
			} else if x > w-app.win.MemberWidth() {
				app.win.ScrollMemberDownBy(4)
			} else if y == 0 {
				app.win.ScrollTopicRightBy(4)
			} else {
				app.win.ScrollDownBy(4)
			}
@@ -657,11 +661,13 @@ func (app *App) handleMouseEvent(ev vaxis.Mouse) {
			if i := app.win.VerticalBufferOffset(y); i == app.win.ClickedBuffer() {
				app.win.GoToBufferNo(i)
				app.clearBufferCommand()
				app.win.ResetTopicOffset()
			}
		} else if app.win.ChannelWidth() == 0 && y == h-1 {
			if i := app.win.HorizontalBufferOffset(x); i >= 0 && i == app.win.ClickedBuffer() {
				app.win.GoToBufferNo(i)
				app.clearBufferCommand()
				app.win.ResetTopicOffset()
			}
		} else if x > w-app.win.MemberWidth() {
			if i := y - 2 + app.win.MemberOffset(); i >= 0 && i == app.win.ClickedMember() {
diff --git a/ui/buffers.go b/ui/buffers.go
index cb21267..e34a98e 100644
--- a/ui/buffers.go
+++ b/ui/buffers.go
@@ -962,7 +962,7 @@ func (bs *BufferList) DrawHorizontalBufferList(vx *Vaxis, x0, y0, width int, off
	}
}

func (bs *BufferList) DrawTimeline(ui *UI, x0, y0, nickColWidth int) {
func (bs *BufferList) DrawTimeline(ui *UI, x0, y0, nickColWidth int, topicOffset *int) {
	vx := ui.vx
	clearArea(vx, x0, y0, bs.tlInnerWidth+nickColWidth+9, bs.tlHeight+2)

@@ -974,6 +974,13 @@ func (bs *BufferList) DrawTimeline(ui *UI, x0, y0, nickColWidth int) {
		}
	}

	if x0+len(b.topic.string)-*topicOffset < bs.tlInnerWidth+nickColWidth {
		*topicOffset = x0 + len(b.topic.string) - (bs.tlInnerWidth + nickColWidth)
		if *topicOffset < 0 {
			*topicOffset = 0
		}
	}

	xTopic := x0
	{
		// TODO: factorize this (same code for drawing timeline)
@@ -981,8 +988,8 @@ func (bs *BufferList) DrawTimeline(ui *UI, x0, y0, nickColWidth int) {
		var st vaxis.Style
		nextStyles := b.topic.styles

		i := 0
		sr := []rune(b.topic.string)
		i := *topicOffset
		sr := []rune(b.topic.string[*topicOffset:])
		for len(sr) > 0 {
			if 0 < len(nextStyles) && nextStyles[0].Start == i {
				st = nextStyles[0].Style
diff --git a/ui/ui.go b/ui/ui.go
index f4e788a..8dddfc4 100644
--- a/ui/ui.go
+++ b/ui/ui.go
@@ -63,6 +63,7 @@ type UI struct {
	channelOffset int
	memberClicked int
	memberOffset  int
	topicOffset   int

	channelWidth int
	memberWidth  int
@@ -350,6 +351,21 @@ func (ui *UI) ScrollMemberDownBy(n int) {
	ui.memberOffset += n
}

func (ui *UI) ScrollTopicLeftBy(n int) {
	ui.topicOffset -= n
	if ui.topicOffset < 0 {
		ui.topicOffset = 0
	}
}

func (ui *UI) ScrollTopicRightBy(n int) {
	ui.topicOffset += n
}

func (ui *UI) ResetTopicOffset() {
	ui.topicOffset = 0
}

func (ui *UI) LinesAboveOffset() int {
	return ui.bs.LinesAboveOffset()
}
@@ -650,7 +666,7 @@ func (ui *UI) Draw(members []irc.Member) {

	w, h := ui.vx.window.Size()

	ui.bs.DrawTimeline(ui, ui.channelWidth, 0, ui.config.NickColWidth)
	ui.bs.DrawTimeline(ui, ui.channelWidth, 0, ui.config.NickColWidth, &ui.topicOffset)
	if ui.channelWidth == 0 {
		ui.bs.DrawHorizontalBufferList(ui.vx, 0, h-1, w-ui.memberWidth, &ui.channelOffset)
	} else {

base-commit: b24c37f5ca93337da7255556cabf85ba10ef347f
-- 
2.45.2