Browse Source

pstats: Add padding pixels to labels in gtk-stats

At the moment, the text runs right up to the edge of the label, which looks unsightly and inconsistent with the Windows version.
rdb 3 years ago
parent
commit
837815b553

+ 8 - 8
pandatool/src/gtk-stats/gtkStatsLabel.cxx

@@ -16,10 +16,10 @@
 #include "gtkStatsGraph.h"
 #include "convert_srgb.h"
 
-int GtkStatsLabel::_left_margin = 2;
+int GtkStatsLabel::_left_margin = 6;
 int GtkStatsLabel::_right_margin = 2;
-int GtkStatsLabel::_top_margin = 2;
-int GtkStatsLabel::_bottom_margin = 2;
+int GtkStatsLabel::_top_margin = 1;
+int GtkStatsLabel::_bottom_margin = 1;
 
 /**
  *
@@ -176,9 +176,9 @@ update_text(bool use_fullname) {
   // our widget.
   int width, height;
   pango_layout_get_pixel_size(_layout, &width, &height);
-  gtk_widget_set_size_request(_widget, width + 8, height);
-  _ideal_width = width;
-  _height = height;
+  _ideal_width = width + _left_margin + _right_margin;
+  _height = height + _top_margin + _bottom_margin;
+  gtk_widget_set_size_request(_widget, _ideal_width, _height);
 }
 
 /**
@@ -221,9 +221,9 @@ draw_callback(GtkWidget *widget, cairo_t *cr, gpointer data) {
 
   cairo_set_source_rgb(cr, fg[0], fg[1], fg[2]);
   if (self->_align_right) {
-    cairo_move_to(cr, allocation.width - width, 0);
+    cairo_move_to(cr, allocation.width - width - _right_margin, _top_margin);
   } else {
-    cairo_move_to(cr, 0, 0);
+    cairo_move_to(cr, _left_margin, _top_margin);
   }
   pango_cairo_show_layout(cr, self->_layout);
 

+ 4 - 8
pandatool/src/gtk-stats/gtkStatsLabelStack.cxx

@@ -48,16 +48,12 @@ int GtkStatsLabelStack::
 get_label_y(int label_index, GtkWidget *target_widget) const {
   nassertr(label_index >= 0 && label_index < (int)_labels.size(), 0);
 
-  GtkAllocation allocation;
-  gtk_widget_get_allocation(_widget, &allocation);
-
-  // Assume all labels have the same height.
-  int height = _labels[0]->get_height();
-  int start_y = allocation.height - height * label_index;
+  GtkStatsLabel *label = _labels[label_index];
 
   int x, y;
-  gtk_widget_translate_coordinates(_widget, target_widget,
-           0, start_y, &x, &y);
+  gtk_widget_translate_coordinates(label->get_widget(), target_widget,
+                                   0, 0, &x, &y);
+  y += label->get_height();
   return y;
 }