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.
This commit is contained in:
rdb 2022-11-30 12:32:32 +01:00
parent b0a6e498e2
commit 837815b553
2 changed files with 12 additions and 16 deletions

View File

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

View File

@ -48,16 +48,12 @@ int GtkStatsLabelStack::
get_label_y(int label_index, GtkWidget *target_widget) const { get_label_y(int label_index, GtkWidget *target_widget) const {
nassertr(label_index >= 0 && label_index < (int)_labels.size(), 0); nassertr(label_index >= 0 && label_index < (int)_labels.size(), 0);
GtkAllocation allocation; GtkStatsLabel *label = _labels[label_index];
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;
int x, y; int x, y;
gtk_widget_translate_coordinates(_widget, target_widget, gtk_widget_translate_coordinates(label->get_widget(), target_widget,
0, start_y, &x, &y); 0, 0, &x, &y);
y += label->get_height();
return y; return y;
} }