Skip to contentSkip to conversation

[7/?] grub-core/gfxmenu/gui_list.c - scrollbar thumb offsets

PATCH In review Vladimir Testov 1 participant 2 messages Jul 18, 2013 – Jul 19, 2013

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 [7/?] grub-core/gfxmenu/gui_list.c - scrollbar thumb offsets

New options
scrollbar_thumb_top_offset
scrollbar_thumb_bottom_offset

With these two options we can make scrollbar thumb with round edges so it will fit to the scrollbar frame. See screenshots.

offset is a number of pixels to indent from the edge of the center slice of the scrollbar's frame.
positive value means we move to the bottom
negative value means we move to the top

in the example given (see screenshots)
scrollbar_thumb_top_offset = -5
scrollbar_thumb_bottom_offset = 5

Sanity checks are present.

Signature · 4 lines
With best regards,
_______________________________
Vladimir Testov, ROSA Laboratory.
www.rosalab.ru
grub-core/gfxmenu/gui_list.c +43 -7
diff -Naur grub-new6/grub-core/gfxmenu/gui_list.c grub-new7/grub-core/gfxmenu/gui_list.c
@@ -56,6 +56,8 @@
   char *scrollbar_thumb_pattern;
   grub_gfxmenu_box_t scrollbar_frame;
   grub_gfxmenu_box_t scrollbar_thumb;
+  int scrollbar_thumb_top_offset;
+  int scrollbar_thumb_bottom_offset;
   int scrollbar_width;
 
   int first_shown_index;
@@ -149,22 +151,26 @@
 
       self->need_to_recreate_scrollbar = 0;
 
+
       /* Sanity checks. */
       if (self->scrollbar_frame != 0 && self->scrollbar_thumb != 0)
         {
           grub_gfxmenu_box_t box = self->menu_box;
           grub_gfxmenu_box_t frame = self->scrollbar_frame;
           grub_gfxmenu_box_t thumb = self->scrollbar_thumb;
-          int box_vertical_pad = (box->get_top_pad (box)
-                                  + box->get_bottom_pad (box));
+
+          int box_top_pad = box->get_top_pad (box);
+          int box_bottom_pad = box->get_bottom_pad (box);
+          int box_vertical_pad = box_top_pad + box_bottom_pad;
+          int frame_top_pad = frame->get_top_pad (frame);
+          int frame_bottom_pad = frame->get_bottom_pad (frame);
+          int frame_vertical_pad = frame_top_pad + frame_bottom_pad;
           int frame_horizontal_pad = (frame->get_left_pad (frame)
                                       + frame->get_right_pad (frame));
-          int frame_vertical_pad = (frame->get_top_pad (frame)
-                                    + frame->get_bottom_pad (frame));
+          int thumb_vertical_pad = (thumb->get_top_pad (thumb)
+                                + thumb->get_bottom_pad (thumb));
           int thumb_horizontal_pad = (thumb->get_left_pad (thumb)
                                       + thumb->get_right_pad (thumb));
-          int thumb_vertical_pad = (thumb->get_top_pad (thumb)
-                                    + thumb->get_bottom_pad (thumb));
           int scrollbar_height = self->bounds.height - box_vertical_pad;
 
           if (self->scrollbar_width < frame_horizontal_pad
@@ -174,6 +180,22 @@
               self->draw_scrollbar = 0;
               return 0;
             }
+
+          /* Check offsets.  */
+          /* Offset from the top of the scrollbar viewport. */
+          int thumb_top = frame_top_pad
+                          + self->scrollbar_thumb_top_offset;
+          /* Offset from the bottom of the scrollbar viewport. */
+          int thumb_bottom = - frame_bottom_pad
+                             + self->scrollbar_thumb_bottom_offset;
+
+          int real_height = scrollbar_height - thumb_top + thumb_bottom;
+          if (thumb_top < 0 || thumb_bottom > 0
+              || real_height < thumb_vertical_pad)
+            {
+              self->scrollbar_thumb_top_offset = 0;
+              self->scrollbar_thumb_bottom_offset = 0;
+            }
         }
     }
 
@@ -250,11 +272,13 @@
                             + thumb->get_bottom_pad (thumb));
   int thumb_horizontal_pad = (thumb->get_left_pad (thumb)
                               + thumb->get_right_pad (thumb));
-  int tracktop = frame->get_top_pad (frame);
+  int tracktop = frame->get_top_pad (frame) + self->scrollbar_thumb_top_offset;
   int tracklen = scrollbar_height - frame_vertical_pad;
   frame->set_content_size (frame,
                            scrollbar_width - frame_horizontal_pad,
                            tracklen);
+  tracklen += - self->scrollbar_thumb_top_offset
+                  + self->scrollbar_thumb_bottom_offset;
   int thumby;
   int thumbheight = tracklen * extent / (max - min) + 1;
   if (thumbheight >= thumb_vertical_pad)
@@ -619,6 +643,16 @@
       grub_free (self->scrollbar_thumb_pattern);
       self->scrollbar_thumb_pattern = value ? grub_strdup (value) : 0;
     }
+  else if (grub_strcmp (name, "scrollbar_thumb_top_offset") == 0)
+    {
+      self->need_to_recreate_scrollbar = 1;
+      self->scrollbar_thumb_top_offset = grub_strtol (value, 0, 10);
+    }
+  else if (grub_strcmp (name, "scrollbar_thumb_bottom_offset") == 0)
+    {
+      self->need_to_recreate_scrollbar = 1;
+      self->scrollbar_thumb_bottom_offset = grub_strtol (value, 0, 10);
+    }
   else if (grub_strcmp (name, "scrollbar_width") == 0)
     {
       self->scrollbar_width = grub_strtoul (value, 0, 10);
@@ -727,6 +761,8 @@
   self->scrollbar_thumb = 0;
   self->scrollbar_frame_pattern = 0;
   self->scrollbar_thumb_pattern = 0;
+  self->scrollbar_thumb_top_offset = 0;
+  self->scrollbar_thumb_bottom_offset = 0;
   self->scrollbar_width = 16;
 
   self->first_shown_index = 0;
#1 lore raw

Sanity checks fixed. Rare case with too big scrollbar frame was incorrectly handled.

Quoted 23 lines · Vladimir Testov

New options
scrollbar_thumb_top_offset
scrollbar_thumb_bottom_offset

With these two options we can make scrollbar thumb with round edges so it will fit to the scrollbar frame. See screenshots.

offset is a number of pixels to indent from the edge of the center slice of the scrollbar's frame.
positive value means we move to the bottom
negative value means we move to the top

in the example given (see screenshots)
scrollbar_thumb_top_offset = -5
scrollbar_thumb_bottom_offset = 5

Sanity checks are present.

--
With best regards,
_______________________________
Vladimir Testov, ROSA Laboratory.
www.rosalab.ru

Signature · 4 lines
With best regards,
_______________________________
Vladimir Testov, ROSA Laboratory.
www.rosalab.ru
grub-core/gfxmenu/gui_list.c +46 -8
diff -Naur grub-new6/grub-core/gfxmenu/gui_list.c grub-new7/grub-core/gfxmenu/gui_list.c
@@ -56,6 +56,8 @@
   char *scrollbar_thumb_pattern;
   grub_gfxmenu_box_t scrollbar_frame;
   grub_gfxmenu_box_t scrollbar_thumb;
+  int scrollbar_thumb_top_offset;
+  int scrollbar_thumb_bottom_offset;
   int scrollbar_width;
 
   int first_shown_index;
@@ -149,27 +151,49 @@
 
       self->need_to_recreate_scrollbar = 0;
 
+
       /* Sanity checks. */
       if (self->scrollbar_frame != 0 && self->scrollbar_thumb != 0)
         {
           grub_gfxmenu_box_t box = self->menu_box;
           grub_gfxmenu_box_t frame = self->scrollbar_frame;
           grub_gfxmenu_box_t thumb = self->scrollbar_thumb;
-          int box_vertical_pad = (box->get_top_pad (box)
-                                  + box->get_bottom_pad (box));
+
+          int box_top_pad = box->get_top_pad (box);
+          int box_bottom_pad = box->get_bottom_pad (box);
+          int box_vertical_pad = box_top_pad + box_bottom_pad;
+          int frame_top_pad = frame->get_top_pad (frame);
+          int frame_bottom_pad = frame->get_bottom_pad (frame);
+          int frame_vertical_pad = frame_top_pad + frame_bottom_pad;
           int frame_horizontal_pad = (frame->get_left_pad (frame)
                                       + frame->get_right_pad (frame));
-          int frame_vertical_pad = (frame->get_top_pad (frame)
-                                    + frame->get_bottom_pad (frame));
+          int thumb_vertical_pad = (thumb->get_top_pad (thumb)
+                                + thumb->get_bottom_pad (thumb));
           int thumb_horizontal_pad = (thumb->get_left_pad (thumb)
                                       + thumb->get_right_pad (thumb));
-          int thumb_vertical_pad = (thumb->get_top_pad (thumb)
-                                    + thumb->get_bottom_pad (thumb));
           int scrollbar_height = self->bounds.height - box_vertical_pad;
 
+          /* Offset from the top of the scrollbar viewport. */
+          int thumb_top = frame_top_pad
+                          + self->scrollbar_thumb_top_offset;
+          /* Offset from the bottom of the scrollbar viewport. */
+          int thumb_bottom = - frame_bottom_pad
+                             + self->scrollbar_thumb_bottom_offset;
+
+          /* Check offset sanity.  */
+          int real_height = scrollbar_height - thumb_top + thumb_bottom;
+          if (thumb_top < 0 || thumb_bottom > 0
+              || real_height < thumb_vertical_pad)
+            {
+              self->scrollbar_thumb_top_offset = 0;
+              self->scrollbar_thumb_bottom_offset = 0;
+              real_height = scrollbar_height - frame_vertical_pad;
+            }
+
+          /* Sanity checks themselves. */
           if (self->scrollbar_width < frame_horizontal_pad
                                       + thumb_horizontal_pad
-              || scrollbar_height < frame_vertical_pad + thumb_vertical_pad)
+              || real_height < thumb_vertical_pad)
             {
               self->draw_scrollbar = 0;
               return 0;
@@ -250,11 +274,13 @@
                             + thumb->get_bottom_pad (thumb));
   int thumb_horizontal_pad = (thumb->get_left_pad (thumb)
                               + thumb->get_right_pad (thumb));
-  int tracktop = frame->get_top_pad (frame);
+  int tracktop = frame->get_top_pad (frame) + self->scrollbar_thumb_top_offset;
   int tracklen = scrollbar_height - frame_vertical_pad;
   frame->set_content_size (frame,
                            scrollbar_width - frame_horizontal_pad,
                            tracklen);
+  tracklen += - self->scrollbar_thumb_top_offset
+                  + self->scrollbar_thumb_bottom_offset;
   int thumby;
   int thumbheight = tracklen * extent / (max - min) + 1;
   if (thumbheight >= thumb_vertical_pad)
@@ -619,6 +645,16 @@
       grub_free (self->scrollbar_thumb_pattern);
       self->scrollbar_thumb_pattern = value ? grub_strdup (value) : 0;
     }
+  else if (grub_strcmp (name, "scrollbar_thumb_top_offset") == 0)
+    {
+      self->need_to_recreate_scrollbar = 1;
+      self->scrollbar_thumb_top_offset = grub_strtol (value, 0, 10);
+    }
+  else if (grub_strcmp (name, "scrollbar_thumb_bottom_offset") == 0)
+    {
+      self->need_to_recreate_scrollbar = 1;
+      self->scrollbar_thumb_bottom_offset = grub_strtol (value, 0, 10);
+    }
   else if (grub_strcmp (name, "scrollbar_width") == 0)
     {
       self->scrollbar_width = grub_strtoul (value, 0, 10);
@@ -727,6 +763,8 @@
   self->scrollbar_thumb = 0;
   self->scrollbar_frame_pattern = 0;
   self->scrollbar_thumb_pattern = 0;
+  self->scrollbar_thumb_top_offset = 0;
+  self->scrollbar_thumb_bottom_offset = 0;
   self->scrollbar_width = 16;
 
   self->first_shown_index = 0;