summaryrefslogtreecommitdiffstats
path: root/source
diff options
context:
space:
mode:
authorQuentin Glidic <sardemff7+git@sardemff7.net>2017-05-30 12:41:44 +0200
committerQuentin Glidic <sardemff7+git@sardemff7.net>2017-05-30 13:45:19 +0200
commit823a45f711b4d999bbf7cebf4fbcb5113b35b000 (patch)
tree3731d4e3c9ab3a6dc90d5fcd758986b76d26af0f /source
parent685d4f0e13bee9a23c647e637e2f7194353be501 (diff)
scrollbar: Rework scrollbar_scroll_get_line to work on relative y
Signed-off-by: Quentin Glidic <sardemff7+git@sardemff7.net>
Diffstat (limited to 'source')
-rw-r--r--source/widgets/scrollbar.c32
1 files changed, 18 insertions, 14 deletions
diff --git a/source/widgets/scrollbar.c b/source/widgets/scrollbar.c
index b21066f7..f7d54877 100644
--- a/source/widgets/scrollbar.c
+++ b/source/widgets/scrollbar.c
@@ -46,22 +46,26 @@ static int scrollbar_get_desired_height ( widget *wid )
// TODO
// This should behave more like a real scrollbar.
-unsigned int scrollbar_scroll ( const scrollbar *sb, int y )
+guint scrollbar_scroll_get_line ( const scrollbar *sb, int y )
{
- if ( sb != NULL ) {
- if ( y >= sb->widget.y && y <= ( sb->widget.y + sb->widget.h ) ) {
- short r = ( sb->length * sb->widget.h ) / ( (double) ( sb->length + sb->pos_length ) );
- short handle = sb->widget.h - r;
- double sec = ( ( r ) / (double) ( sb->length - 1 ) );
- short half_handle = handle / 2;
- y -= sb->widget.y + half_handle;
- y = MIN ( MAX ( 0, y ), sb->widget.h - 2 * half_handle );
-
- unsigned int sel = ( ( y ) / sec );
- return MIN ( sel, sb->length - 1 );
- }
+ y -= sb->widget.border.top.distance;
+ if ( y < 0 ) {
+ return 0;
+ }
+
+ if ( y > sb->widget.h ) {
+ return sb->length - 1;
}
- return 0;
+
+ short r = ( sb->length * sb->widget.h ) / ( (double) ( sb->length + sb->pos_length ) );
+ short handle = sb->widget.h - r;
+ double sec = ( ( r ) / (double) ( sb->length - 1 ) );
+ short half_handle = handle / 2;
+ y -= half_handle;
+ y = MIN ( MAX ( 0, y ), sb->widget.h - 2 * half_handle );
+
+ unsigned int sel = ( ( y ) / sec );
+ return MIN ( sel, sb->length - 1 );
}
static gboolean scrollbar_trigger_action ( widget *wid, MouseBindingMouseDefaultAction action, G_GNUC_UNUSED gint x, gint y, G_GNUC_UNUSED void *user_data )