ltk

Socket-based GUI for X11 (WIP)
git clone git://lumidify.org/ltk.git (fast, but not encrypted)
git clone https://lumidify.org/git/ltk.git (encrypted, but very slow)
Log | Files | Refs | README | LICENSE

commit 1e8ddcfae89e504b4106c3cc213b1e81e9ebca7d
parent c25f7ed3099b6026f5e0c169e30a8a28719d5633
Author: lumidify <nobody@lumidify.org>
Date:   Sat, 23 Jan 2021 16:42:31 +0100

Make scrollbar simpler so it works somewhat at least because I don't want to fight with it at the moment

Diffstat:
Mscrollbar.c | 39+++++++++++++++++++++++++++++++--------
1 file changed, 31 insertions(+), 8 deletions(-)

diff --git a/scrollbar.c b/scrollbar.c @@ -159,18 +159,40 @@ ltk_scrollbar_draw(ltk_scrollbar *scrollbar, ltk_rect clip) { } static int -ltk_scrollbar_mouse_press(ltk_scrollbar *scrollbar, XEvent event) { - if (event.xbutton.button != 1) - return 1; - scrollbar->last_mouse_x = scrollbar->widget.rect.x; - scrollbar->last_mouse_y = scrollbar->widget.rect.y; - scrollbar->cur_pos = 0; - ltk_scrollbar_motion_notify(scrollbar, event); - return 1; +ltk_scrollbar_mouse_press(ltk_scrollbar *sc, XEvent event) { + int max_pos; + double rel_pos; + if (event.xbutton.button != 1 && event.xbutton.button != 3) + return 0; + if (sc->orient == LTK_HORIZONTAL) { + rel_pos = (event.xbutton.x - sc->widget.rect.x) / (double)sc->widget.rect.w; + max_pos = sc->virtual_size > sc->widget.rect.w ? sc->virtual_size - sc->widget.rect.w : 0; + } else { + rel_pos = (event.xbutton.y - sc->widget.rect.y) / (double)sc->widget.rect.h; + max_pos = sc->virtual_size > sc->widget.rect.h ? sc->virtual_size - sc->widget.rect.h : 0; + } + /* On right click, move the scrollbar left/up by 30% of the total size times how far + away the click is from the right/bottom. + On left click, move the scrollbar right/down by 30% of the total size times how far + away the click is from the left/top. */ + if (event.xbutton.button == 1) { + sc->cur_pos += rel_pos * sc->virtual_size * 0.3; + } else if (event.xbutton.button == 3) { + sc->cur_pos -= (1 - rel_pos) * sc->virtual_size * 0.3; + } + + if (sc->cur_pos < 0) + sc->cur_pos = 0; + else if (sc->cur_pos > max_pos) + sc->cur_pos = max_pos; + sc->callback(sc->callback_data); + return 0; } +/* FIXME: Make this scrollbar more "traditional" */ static int ltk_scrollbar_motion_notify(ltk_scrollbar *sc, XEvent event) { + /* double scale; int delta, max_pos; if (sc->widget.state != LTK_PRESSED) @@ -193,6 +215,7 @@ ltk_scrollbar_motion_notify(ltk_scrollbar *sc, XEvent event) { sc->last_mouse_y = event.xbutton.y; if (delta > 0) sc->callback(sc->callback_data); + */ return 1; }