Skip to contentSkip to conversation

fix centering the text in selected item

PATCH In review Vladimir Testov 1 participant 1 message Apr 11, 2013

lore
Share & tools
lore
#0 lore raw

PATCH 4/11 fix centering the text in selected item

if the font size of the selected item differs from text size in ordinary item then it will be misaligned (see sreenshots)

Signature · 4 lines
With best regards,
_______________________________
Vladimir Testov, ROSA Laboratory.
www.rosalab.ru
grub-core/gfxmenu/gui_list.c +16 -3
diff -Naur grub-new4/grub-core/gfxmenu/gui_list.c grub-new5/grub-core/gfxmenu/gui_list.c
@@ -263,6 +263,8 @@
 
   int string_left_offset = sel_leftpad + self->icon_width + icon_text_space;
   int string_top_offset = (item_height - (ascent + descent)) / 2 + ascent;
+  int selected_top_offset;
+  int top_offset;
 
   grub_video_rect_t svpsave, sviewport;
   sviewport.x = string_left_offset;
@@ -273,9 +275,18 @@
   grub_video_color_t color, item_color, selected_item_color;
   item_font = self->item_font;
   if (self->selected_item_font)
-    selected_item_font = self->selected_item_font;
+    {
+      selected_item_font = self->selected_item_font;
+      int sel_ascent = grub_font_get_ascent (self->selected_item_font);
+      int sel_descent = grub_font_get_descent (self->selected_item_font);
+      selected_top_offset = (item_height - (sel_ascent + sel_descent)) / 2 
+                            + sel_ascent;
+    }
   else
-    selected_item_font = item_font;
+    {
+      selected_item_font = item_font;
+      selected_top_offset = string_top_offset;
+    }
   item_color = grub_video_map_rgba_color (self->item_color);
   if (self->selected_item_color_set)
     selected_item_color = grub_video_map_rgba_color (self->selected_item_color);
@@ -295,11 +306,13 @@
                         item_top - sel_toppad);
           font = selected_item_font;
           color = selected_item_color;
+          top_offset = selected_top_offset;
         }
       else
         {
           font = item_font;
           color = item_color;
+          top_offset = string_top_offset;
         }
 
       icon = get_item_icon (self, menu_index);
@@ -327,7 +340,7 @@
                                  font,
                                  color,
                                  0,
-                                 string_top_offset);
+                                 top_offset);
           grub_gui_restore_viewport (&svpsave);
         }
       item_top += item_height + item_vspace;