diff --git a/src/sysprof/style.css b/src/sysprof/style.css index 86b7b79d..946ab248 100644 --- a/src/sysprof/style.css +++ b/src/sysprof/style.css @@ -83,3 +83,7 @@ timescrubber timecode { flamegraph { font-size: 11px; } + +timespanlayer { + font-size: 10px; +} diff --git a/src/sysprof/sysprof-marks-section.c b/src/sysprof/sysprof-marks-section.c index 9ee2af91..57e52581 100644 --- a/src/sysprof/sysprof-marks-section.c +++ b/src/sysprof/sysprof-marks-section.c @@ -42,6 +42,25 @@ struct _SysprofMarksSection G_DEFINE_FINAL_TYPE (SysprofMarksSection, sysprof_marks_section, SYSPROF_TYPE_SECTION) +static char * +format_mark_label (gpointer unused, + SysprofDocumentMark *mark) +{ + const char *message; + const char *name; + + if (mark == NULL) + return NULL; + + name = sysprof_document_mark_get_name (mark); + message = sysprof_document_mark_get_message (mark); + + if (name && *name && message && *message) + return g_strdup_printf ("%s – %s", name, message); + else + return g_strdup_printf ("%s", name); +} + static char * format_number (gpointer unused, guint number) @@ -74,6 +93,7 @@ sysprof_marks_section_class_init (SysprofMarksSectionClass *klass) gtk_widget_class_bind_template_child (widget_class, SysprofMarksSection, mark_table); gtk_widget_class_bind_template_child (widget_class, SysprofMarksSection, median_column); gtk_widget_class_bind_template_child (widget_class, SysprofMarksSection, summary_column_view); + gtk_widget_class_bind_template_callback (widget_class, format_mark_label); gtk_widget_class_bind_template_callback (widget_class, format_number); g_type_ensure (SYSPROF_TYPE_CHART); diff --git a/src/sysprof/sysprof-marks-section.ui b/src/sysprof/sysprof-marks-section.ui index 2dbe40b3..48a927e8 100644 --- a/src/sysprof/sysprof-marks-section.ui +++ b/src/sysprof/sysprof-marks-section.ui @@ -175,9 +175,9 @@ - + - + diff --git a/src/sysprof/sysprof-time-series.c b/src/sysprof/sysprof-time-series.c index 1b8b1c9b..3935bb90 100644 --- a/src/sysprof/sysprof-time-series.c +++ b/src/sysprof/sysprof-time-series.c @@ -330,7 +330,6 @@ sysprof_time_series_dup_label (SysprofTimeSeries *self, if (!(item = g_list_model_get_item (model, position))) return NULL; - g_value_init (&value, G_TYPE_STRING); gtk_expression_evaluate (self->label_expression, item, &value); return g_value_dup_string (&value); } diff --git a/src/sysprof/sysprof-time-span-layer.c b/src/sysprof/sysprof-time-span-layer.c index 7c0884c1..6ffd228b 100644 --- a/src/sysprof/sysprof-time-span-layer.c +++ b/src/sysprof/sysprof-time-span-layer.c @@ -216,12 +216,28 @@ sysprof_time_span_layer_snapshot (GtkWidget *widget, gtk_snapshot_append_color (snapshot, color, &rect); } - if (rect.size.width > 20) + if (label != NULL) { + gboolean rect_fits_text; + int right_empty_space; + int label_width; - if (label != NULL) + pango_layout_set_text (layout, label, -1); + pango_layout_set_alignment (layout, PANGO_ALIGN_LEFT); + + pango_layout_get_pixel_size (layout, &label_width, NULL); + + /* If it fits 75% of the text inside the rect, it's enough and + * won't look too busy. + */ + rect_fits_text = ((rect.size.width - 6) / (float) label_width) > 0.75; + right_empty_space = width - (rect.origin.x + rect.size.width) - 6; + + /* Draw inside the rect if the label fits, or if there's not more + * space outside the rect. + */ + if (rect_fits_text || (rect.size.width - 6) > right_empty_space) { - pango_layout_set_text (layout, label, -1); pango_layout_set_width (layout, (rect.size.width - 6) * PANGO_SCALE); gtk_snapshot_save (snapshot); @@ -229,6 +245,15 @@ sysprof_time_span_layer_snapshot (GtkWidget *widget, gtk_snapshot_append_layout (snapshot, layout, label_color); gtk_snapshot_restore (snapshot); } + else if (n_values == 1 && right_empty_space > 20) + { + pango_layout_set_width (layout, right_empty_space * PANGO_SCALE); + + gtk_snapshot_save (snapshot); + gtk_snapshot_translate (snapshot, &GRAPHENE_POINT_INIT (rect.origin.x + rect.size.width + 3, layout_y)); + gtk_snapshot_append_layout (snapshot, layout, label_color); + gtk_snapshot_restore (snapshot); + } } } } @@ -472,6 +497,8 @@ sysprof_time_span_layer_class_init (SysprofTimeSpanLayerClass *klass) (G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS)); g_object_class_install_properties (object_class, N_PROPS, properties); + + gtk_widget_class_set_css_name (widget_class, "timespanlayer"); } static void