Updated because [7/11] patch has been updated.

On Friday, July 19, 2013 05:41:38 PM Vladimir Testov wrote:
> scrollbar_slice = "east" \ "center" \ "west"
> 
> Typically, the scrollbar is drawn in the east slice.
> 
> Now we can decide where we would like it to be drawn.
> 
> "east", default value, works the same way as it was before.
> 
> "west" scrollbar is drawn to the left from the entry list, in the west
> slice.
> 
> "center" scrollbar is drawn in the center slice of the boot menu. That way
> we don't need to make special east slice of the menu decoration box
> (menu_pixmap_style). moreover, we no longer need to use menu_pixmap_style if
> we would like to see the scrollbar in the theme we are making. If there is
> no need to draw the scrollbar then item's width is maximal. If we need to
> draw the scrollbar then item's width will be decreased so the scrollbar
> will be drawn on the free space.
> 
> --
> With best regards,
> _______________________________
> Vladimir Testov, ROSA Laboratory.
> www.rosalab.ru
-- 
With best regards,
_______________________________
Vladimir Testov, ROSA Laboratory.
www.rosalab.ru
diff -Naur grub-new7/grub-core/gfxmenu/gui_list.c grub-new8/grub-core/gfxmenu/gui_list.c
--- grub-new7/grub-core/gfxmenu/gui_list.c	2013-07-19 19:49:41.875854896 +0400
+++ grub-new8/grub-core/gfxmenu/gui_list.c	2013-07-19 19:52:28.168444172 +0400
@@ -25,6 +25,12 @@
 #include <grub/gfxwidgets.h>
 #include <grub/color.h>
 
+enum scrollbar_slices {
+  SCROLLBAR_SLICE_WEST,
+  SCROLLBAR_SLICE_CENTER,
+  SCROLLBAR_SLICE_EAST
+};
+
 struct grub_gui_list_impl
 {
   struct grub_gui_list list;
@@ -59,6 +65,7 @@
   int scrollbar_thumb_top_offset;
   int scrollbar_thumb_bottom_offset;
   int scrollbar_width;
+  int scrollbar_slice;
 
   int first_shown_index;
 
@@ -136,6 +143,9 @@
   return (self->menu_box != 0 && self->selected_item_box != 0);
 }
 
+static void
+list_get_minimal_size (void *vself, unsigned *width, unsigned *height);
+
 static int
 check_scrollbar (list_impl_t self)
 {
@@ -198,6 +208,18 @@
               self->draw_scrollbar = 0;
               return 0;
             }
+
+          /* Checks for scrollbar_slice option.  */
+          if (self->scrollbar_slice == SCROLLBAR_SLICE_CENTER)
+            {
+              unsigned min_menu_width, min_menu_height;
+              list_get_minimal_size (self, &min_menu_width, &min_menu_height);
+              if ((int) min_menu_width + self->scrollbar_width > (int) self->bounds.width)
+                {
+                  self->draw_scrollbar = 0;
+                  return 0;
+                }
+            }
         }
     }
 
@@ -333,7 +355,7 @@
 			   oviewport.width - 2 * boxpad,
 			   oviewport.height - 2 * boxpad);
 
-  int cwidth = oviewport.width - 2 * boxpad - 2;
+  int cwidth = oviewport.width - 2 * boxpad;
   if (selbox->get_border_width)
     cwidth -= selbox->get_border_width (selbox);
   selbox->set_content_size (selbox, cwidth, item_height);
@@ -435,11 +457,12 @@
     int box_top_pad = box->get_top_pad (box);
     int box_right_pad = box->get_right_pad (box);
     int box_bottom_pad = box->get_bottom_pad (box);
-    grub_video_rect_t vpsave2, content_rect;
+    grub_video_rect_t vpsave2, content_rect, scrollbar_rect;
     int num_shown_items = get_num_shown_items (self);
     int drawing_scrollbar = (self->draw_scrollbar
 			     && (num_shown_items < self->view->menu->size)
 			     && check_scrollbar (self));
+    int scrollbar_width = self->scrollbar_width;
 
     content_rect.x = box_left_pad;
     content_rect.y = box_top_pad;
@@ -448,6 +471,36 @@
 
     box->set_content_size (box, content_rect.width, content_rect.height);
 
+    scrollbar_rect.width = scrollbar_width;
+    scrollbar_rect.y = content_rect.y;
+    scrollbar_rect.height = content_rect.height;
+    switch (self->scrollbar_slice)
+      {
+        case SCROLLBAR_SLICE_WEST:
+          content_rect.x += 2;
+          content_rect.width -= 2;
+          scrollbar_rect.x = box_left_pad - scrollbar_width;
+          if (scrollbar_width > box_left_pad)
+            {
+              scrollbar_rect.x = 0;
+              scrollbar_rect.width = box_left_pad;
+            }
+          break;
+        case SCROLLBAR_SLICE_CENTER:
+          content_rect.width -= 2;
+          if (drawing_scrollbar)
+            content_rect.width -= scrollbar_width;
+          scrollbar_rect.x = self->bounds.width - box_right_pad
+                             - scrollbar_width;
+          break;
+        case SCROLLBAR_SLICE_EAST:
+          content_rect.width -= 2;
+          scrollbar_rect.x = self->bounds.width - box_right_pad;
+          if (scrollbar_width > box_right_pad)
+            scrollbar_rect.width = box_right_pad;
+          break;
+      }
+
     box->draw (box, 0, 0);
 
     grub_gui_set_viewport (&content_rect, &vpsave2);
@@ -456,16 +509,12 @@
 
     if (drawing_scrollbar)
       {
-        /* Draw the scrollbar in the east slice. */
-        content_rect.x = self->bounds.width - box_right_pad;
-        content_rect.width = box_right_pad;
-
-        grub_gui_set_viewport (&content_rect, &vpsave2);
+        grub_gui_set_viewport (&scrollbar_rect, &vpsave2);
         draw_scrollbar (self,
                         self->first_shown_index, num_shown_items,
                         0, self->view->menu->size,
-                        self->scrollbar_width,
-                        content_rect.height);
+                        scrollbar_width,
+                        scrollbar_rect.height);
         grub_gui_restore_viewport (&vpsave2);
       }
   }
@@ -659,6 +708,15 @@
     {
       self->scrollbar_width = grub_strtoul (value, 0, 10);
     }
+  else if (grub_strcmp (name, "scrollbar_slice") == 0)
+    {
+      if (grub_strcmp (value, "west") == 0)
+        self->scrollbar_slice = SCROLLBAR_SLICE_WEST;
+      else if (grub_strcmp (value, "center") == 0)
+        self->scrollbar_slice = SCROLLBAR_SLICE_CENTER;
+      else if (grub_strcmp (value, "east") == 0)
+        self->scrollbar_slice = SCROLLBAR_SLICE_EAST;
+    }
   else if (grub_strcmp (name, "scrollbar") == 0)
     {
       self->draw_scrollbar = grub_strcmp (value, "false") != 0;
@@ -766,6 +824,7 @@
   self->scrollbar_thumb_top_offset = 0;
   self->scrollbar_thumb_bottom_offset = 0;
   self->scrollbar_width = 16;
+  self->scrollbar_slice = SCROLLBAR_SLICE_EAST;
 
   self->first_shown_index = 0;
 
_______________________________________________
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel

Reply via email to