* grub-core/gfxmenu/gui_list.c: New option scrollbar-slice.

* docs/grub.texi: Likewise.
This commit is contained in:
Vladimir Testov 2013-10-08 18:31:53 +04:00
parent dd2ed8b092
commit c582736463
3 changed files with 92 additions and 6 deletions

View file

@ -1,3 +1,8 @@
2013-10-08 Vladimir Testov <vladimir.testov@rosalab.ru>
* grub-core/gfxmenu/gui_list.c: New option `scrollbar-slice`.
* docs/grub.texi: Likewise.
2013-10-08 Vladimir Testov <vladimir.testov@rosalab.ru> 2013-10-08 Vladimir Testov <vladimir.testov@rosalab.ru>
* grub-core/gfxmenu/gui_list.c: Draw the scrollbar in a separate * grub-core/gfxmenu/gui_list.c: Draw the scrollbar in a separate

View file

@ -2079,6 +2079,19 @@ The following is a list of the components and the properties they support.
@tab The image file pattern for the scroll bar thumb (the part of the scroll @tab The image file pattern for the scroll bar thumb (the part of the scroll
bar that moves as scrolling occurs). bar that moves as scrolling occurs).
Example: ``scrollbar_thumb_*.png`` Example: ``scrollbar_thumb_*.png``
@item scrollbar_slice
@tab The menu frame styled box's slice in which the scrollbar will be
drawn. Possible values are ``west``, ``center``, ``east`` (default).
``west`` - the scrollbar will be drawn in the west slice (right-aligned).
``east`` - the scrollbar will be drawn in the east slice (left-aligned).
``center`` - the scrollbar will be drawn in the center slice.
Note: in case of ``center`` slice:
a) If the scrollbar should be drawn then boot menu entry's width is
decreased by the scrollbar's width and the scrollbar is drawn at the
right side of the center slice.
b) If the scrollbar won't be drawn then the boot menu entry's width
is the width of the center slice.
c) We don't necessary need the menu pixmap box to display the scrollbar.
@item max_items_shown @item max_items_shown
@tab The maximum number of items to show on the menu. If there are more than @tab The maximum number of items to show on the menu. If there are more than
*max_items_shown* items in the menu, the list will scroll to make all *max_items_shown* items in the menu, the list will scroll to make all

View file

@ -25,6 +25,12 @@
#include <grub/gfxwidgets.h> #include <grub/gfxwidgets.h>
#include <grub/color.h> #include <grub/color.h>
enum scrollbar_slice_mode {
SCROLLBAR_SLICE_WEST,
SCROLLBAR_SLICE_CENTER,
SCROLLBAR_SLICE_EAST
};
struct grub_gui_list_impl struct grub_gui_list_impl
{ {
struct grub_gui_list list; struct grub_gui_list list;
@ -54,6 +60,7 @@ struct grub_gui_list_impl
grub_gfxmenu_box_t scrollbar_frame; grub_gfxmenu_box_t scrollbar_frame;
grub_gfxmenu_box_t scrollbar_thumb; grub_gfxmenu_box_t scrollbar_thumb;
int scrollbar_width; int scrollbar_width;
enum scrollbar_slice_mode scrollbar_slice;
int first_shown_index; int first_shown_index;
@ -254,7 +261,7 @@ draw_menu (list_impl_t self, int num_shown_items)
oviewport.width - 2 * boxpad, oviewport.width - 2 * boxpad,
oviewport.height - 2 * boxpad); oviewport.height - 2 * boxpad);
int cwidth = oviewport.width - 2 * boxpad - 2; int cwidth = oviewport.width - 2 * boxpad;
if (selbox->get_border_width) if (selbox->get_border_width)
cwidth -= selbox->get_border_width (selbox); cwidth -= selbox->get_border_width (selbox);
selbox->set_content_size (selbox, cwidth, item_height); selbox->set_content_size (selbox, cwidth, item_height);
@ -355,6 +362,7 @@ list_paint (void *vself, const grub_video_rect_t *region)
int drawing_scrollbar = (self->draw_scrollbar int drawing_scrollbar = (self->draw_scrollbar
&& (num_shown_items < self->view->menu->size) && (num_shown_items < self->view->menu->size)
&& check_scrollbar (self)); && check_scrollbar (self));
int scrollbar_width = self->scrollbar_width;
content_rect.x = box_left_pad; content_rect.x = box_left_pad;
content_rect.y = box_top_pad; content_rect.y = box_top_pad;
@ -365,21 +373,58 @@ list_paint (void *vself, const grub_video_rect_t *region)
box->draw (box, 0, 0); box->draw (box, 0, 0);
switch (self->scrollbar_slice)
{
case SCROLLBAR_SLICE_WEST:
content_rect.x += 2;
content_rect.width -= 2;
break;
case SCROLLBAR_SLICE_CENTER:
if (drawing_scrollbar)
content_rect.width -= scrollbar_width + 2;
break;
case SCROLLBAR_SLICE_EAST:
content_rect.width -= 2;
break;
}
grub_gui_set_viewport (&content_rect, &vpsave2); grub_gui_set_viewport (&content_rect, &vpsave2);
draw_menu (self, num_shown_items); draw_menu (self, num_shown_items);
grub_gui_restore_viewport (&vpsave2); grub_gui_restore_viewport (&vpsave2);
if (drawing_scrollbar) if (drawing_scrollbar)
{ {
/* Draw the scrollbar in the east slice. */ content_rect.width = scrollbar_width;
switch (self->scrollbar_slice)
{
case SCROLLBAR_SLICE_WEST:
if (box_left_pad > scrollbar_width)
{
content_rect.x = box_left_pad - scrollbar_width;
content_rect.width = scrollbar_width;
}
else
{
content_rect.x = 0;
content_rect.width = box_left_pad;
}
break;
case SCROLLBAR_SLICE_CENTER:
content_rect.x = self->bounds.width - box_right_pad
- scrollbar_width;
content_rect.width = scrollbar_width;
break;
case SCROLLBAR_SLICE_EAST:
content_rect.x = self->bounds.width - box_right_pad; content_rect.x = self->bounds.width - box_right_pad;
content_rect.width = box_right_pad; content_rect.width = box_right_pad;
break;
}
grub_gui_set_viewport (&content_rect, &vpsave2); grub_gui_set_viewport (&content_rect, &vpsave2);
draw_scrollbar (self, draw_scrollbar (self,
self->first_shown_index, num_shown_items, self->first_shown_index, num_shown_items,
0, self->view->menu->size, 0, self->view->menu->size,
self->scrollbar_width, scrollbar_width,
content_rect.height); content_rect.height);
grub_gui_restore_viewport (&vpsave2); grub_gui_restore_viewport (&vpsave2);
} }
@ -448,9 +493,22 @@ list_get_minimal_size (void *vself, unsigned *width, unsigned *height)
*width = width_s; *width = width_s;
*width += 2 * boxpad + box_left_pad + box_right_pad *width += 2 * boxpad + box_left_pad + box_right_pad
+ sel_left_pad + sel_right_pad + 2 + sel_left_pad + sel_right_pad
+ self->item_icon_space + self->icon_width; + self->item_icon_space + self->icon_width;
switch (self->scrollbar_slice)
{
case SCROLLBAR_SLICE_WEST:
*width += 2;
break;
case SCROLLBAR_SLICE_CENTER:
*width += self->scrollbar_width + 2;
break;
case SCROLLBAR_SLICE_EAST:
*width += 2;
break;
}
/* Set the menu box height to fit the items. */ /* Set the menu box height to fit the items. */
*height = (item_height * num_items *height = (item_height * num_items
+ item_vspace * (num_items - 1) + item_vspace * (num_items - 1)
@ -578,6 +636,15 @@ list_set_property (void *vself, const char *name, const char *value)
{ {
self->scrollbar_width = grub_strtol (value, 0, 10); self->scrollbar_width = grub_strtol (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) else if (grub_strcmp (name, "scrollbar") == 0)
{ {
self->draw_scrollbar = grub_strcmp (value, "false") != 0; self->draw_scrollbar = grub_strcmp (value, "false") != 0;
@ -679,6 +746,7 @@ grub_gui_list_new (void)
self->scrollbar_frame_pattern = 0; self->scrollbar_frame_pattern = 0;
self->scrollbar_thumb_pattern = 0; self->scrollbar_thumb_pattern = 0;
self->scrollbar_width = 16; self->scrollbar_width = 16;
self->scrollbar_slice = SCROLLBAR_SLICE_EAST;
self->first_shown_index = 0; self->first_shown_index = 0;