libsysprof-ui: improve duration range drawing and sizing

This disables what we draw, but it gives us a better placement for how
to go about drawing within the space.
This commit is contained in:
Christian Hergert
2019-05-15 12:19:18 -07:00
parent 938839c3cb
commit 83cf6fc55a
4 changed files with 233 additions and 45 deletions

View File

@ -23,25 +23,28 @@
#include "config.h"
#include "sysprof-cell-renderer-duration.h"
#include "sysprof-zoom-manager.h"
#define NSEC_PER_SEC (G_USEC_PER_SEC * 1000L)
typedef struct
{
gchar *text;
gint64 capture_begin_time;
gint64 capture_end_time;
gint64 begin_time;
gint64 end_time;
gint64 zoom_begin;
gint64 zoom_end;
gchar *text;
SysprofZoomManager *zoom_manager;
} SysprofCellRendererDurationPrivate;
enum {
PROP_0,
PROP_BEGIN_TIME,
PROP_CAPTURE_BEGIN_TIME,
PROP_CAPTURE_END_TIME,
PROP_END_TIME,
PROP_TEXT,
PROP_ZOOM_BEGIN,
PROP_ZOOM_END,
PROP_ZOOM_MANAGER,
N_PROPS
};
@ -71,17 +74,16 @@ sysprof_cell_renderer_duration_render (GtkCellRenderer *renderer,
g_assert (cr != NULL);
g_assert (GTK_IS_WIDGET (widget));
if (priv->end_time >= priv->begin_time)
{
if (priv->begin_time > priv->zoom_end || priv->end_time < priv->zoom_begin)
return;
}
if (priv->zoom_manager == NULL)
return;
style_context = gtk_widget_get_style_context (widget);
gtk_style_context_get_color (style_context,
gtk_style_context_get_state (style_context),
&rgba);
return;
#if 0
zoom_range = (gdouble)priv->zoom_end - (gdouble)priv->zoom_begin;
x1 = (priv->begin_time - priv->zoom_begin) / zoom_range * cell_area->width;
@ -155,6 +157,77 @@ sysprof_cell_renderer_duration_render (GtkCellRenderer *renderer,
g_object_unref (layout);
}
#endif
}
static GtkSizeRequestMode
sysprof_cell_renderer_duration_get_request_mode (GtkCellRenderer *renderer)
{
return GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH;
}
static void
sysprof_cell_renderer_duration_get_preferred_width (GtkCellRenderer *cell,
GtkWidget *widget,
gint *min_width,
gint *nat_width)
{
SysprofCellRendererDuration *self = (SysprofCellRendererDuration *)cell;
SysprofCellRendererDurationPrivate *priv = sysprof_cell_renderer_duration_get_instance_private (self);
gint width = 1;
g_assert (SYSPROF_IS_CELL_RENDERER_DURATION (self));
g_assert (GTK_IS_WIDGET (widget));
GTK_CELL_RENDERER_CLASS (sysprof_cell_renderer_duration_parent_class)->get_preferred_width (cell, widget, min_width, nat_width);
if (priv->zoom_manager && priv->capture_begin_time && priv->capture_end_time)
width = sysprof_zoom_manager_get_width_for_duration (priv->zoom_manager,
priv->capture_end_time - priv->capture_begin_time);
if (min_width)
*min_width = width;
if (nat_width)
*nat_width = width;
}
static void
sysprof_cell_renderer_duration_get_preferred_height_for_width (GtkCellRenderer *cell,
GtkWidget *widget,
gint width,
gint *min_height,
gint *nat_height)
{
PangoLayout *layout;
gint w, h;
gint ypad;
g_assert (SYSPROF_IS_CELL_RENDERER_DURATION (cell));
gtk_cell_renderer_get_padding (cell, NULL, &ypad);
layout = gtk_widget_create_pango_layout (widget, "XMZ09");
pango_layout_get_pixel_size (layout, &w, &h);
g_clear_object (&layout);
if (min_height)
*min_height = h + (ypad * 2);
if (nat_height)
*nat_height = h + (ypad * 2);
}
static void
sysprof_cell_renderer_duration_finalize (GObject *object)
{
SysprofCellRendererDuration *self = (SysprofCellRendererDuration *)object;
SysprofCellRendererDurationPrivate *priv = sysprof_cell_renderer_duration_get_instance_private (self);
g_clear_object (&priv->zoom_manager);
g_clear_pointer (&priv->text, g_free);
G_OBJECT_CLASS (sysprof_cell_renderer_duration_parent_class)->finalize (object);
}
static void
@ -172,20 +245,24 @@ sysprof_cell_renderer_duration_get_property (GObject *object,
g_value_set_int64 (value, priv->begin_time);
break;
case PROP_ZOOM_BEGIN:
g_value_set_int64 (value, priv->zoom_begin);
case PROP_CAPTURE_BEGIN_TIME:
g_value_set_int64 (value, priv->capture_begin_time);
break;
case PROP_CAPTURE_END_TIME:
g_value_set_int64 (value, priv->capture_end_time);
break;
case PROP_END_TIME:
g_value_set_int64 (value, priv->end_time);
break;
case PROP_TEXT:
g_value_set_string (value, priv->text);
break;
case PROP_ZOOM_END:
g_value_set_int64 (value, priv->zoom_end);
break;
case PROP_END_TIME:
g_value_set_int64 (value, priv->end_time);
case PROP_ZOOM_MANAGER:
g_value_set_object (value, priv->zoom_manager);
break;
default:
@ -208,8 +285,16 @@ sysprof_cell_renderer_duration_set_property (GObject *object,
priv->begin_time = g_value_get_int64 (value);
break;
case PROP_ZOOM_BEGIN:
priv->zoom_begin = g_value_get_int64 (value);
case PROP_CAPTURE_BEGIN_TIME:
priv->capture_begin_time = g_value_get_int64 (value);
break;
case PROP_CAPTURE_END_TIME:
priv->capture_end_time = g_value_get_int64 (value);
break;
case PROP_END_TIME:
priv->end_time = g_value_get_int64 (value);
break;
case PROP_TEXT:
@ -217,12 +302,8 @@ sysprof_cell_renderer_duration_set_property (GObject *object,
priv->text = g_value_dup_string (value);
break;
case PROP_ZOOM_END:
priv->zoom_end = g_value_get_int64 (value);
break;
case PROP_END_TIME:
priv->end_time = g_value_get_int64 (value);
case PROP_ZOOM_MANAGER:
g_set_object (&priv->zoom_manager, g_value_get_object (value));
break;
default:
@ -236,36 +317,52 @@ sysprof_cell_renderer_duration_class_init (SysprofCellRendererDurationClass *kla
GObjectClass *object_class = G_OBJECT_CLASS (klass);
GtkCellRendererClass *cell_class = GTK_CELL_RENDERER_CLASS (klass);
object_class->finalize = sysprof_cell_renderer_duration_finalize;
object_class->get_property = sysprof_cell_renderer_duration_get_property;
object_class->set_property = sysprof_cell_renderer_duration_set_property;
cell_class->get_preferred_height_for_width = sysprof_cell_renderer_duration_get_preferred_height_for_width;
cell_class->get_preferred_width = sysprof_cell_renderer_duration_get_preferred_width;
cell_class->get_request_mode = sysprof_cell_renderer_duration_get_request_mode;
cell_class->render = sysprof_cell_renderer_duration_render;
/* Note we do not emit ::notify() for these properties */
properties [PROP_BEGIN_TIME] =
g_param_spec_int64 ("begin-time", NULL, NULL,
G_MININT64, G_MAXINT64, 0,
(G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
(G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS));
properties [PROP_ZOOM_BEGIN] =
g_param_spec_int64 ("zoom-begin", NULL, NULL,
properties [PROP_CAPTURE_BEGIN_TIME] =
g_param_spec_int64 ("capture-begin-time", NULL, NULL,
G_MININT64, G_MAXINT64, 0,
(G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
(G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS));
properties [PROP_TEXT] =
g_param_spec_string ("text", NULL, NULL,
NULL,
(G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
properties [PROP_ZOOM_END] =
g_param_spec_int64 ("zoom-end", NULL, NULL,
properties [PROP_CAPTURE_END_TIME] =
g_param_spec_int64 ("capture-end-time", NULL, NULL,
G_MININT64, G_MAXINT64, 0,
(G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
(G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS));
properties [PROP_END_TIME] =
g_param_spec_int64 ("end-time", NULL, NULL,
G_MININT64, G_MAXINT64, 0,
(G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
(G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS));
properties [PROP_END_TIME] =
g_param_spec_int64 ("end-time", NULL, NULL,
G_MININT64, G_MAXINT64, 0,
(G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS));
properties [PROP_TEXT] =
g_param_spec_string ("text", NULL, NULL,
NULL,
(G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS));
properties [PROP_ZOOM_MANAGER] =
g_param_spec_object ("zoom-manager", NULL, NULL,
SYSPROF_TYPE_ZOOM_MANAGER,
(G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS));
g_object_class_install_properties (object_class, N_PROPS, properties);
}

View File

@ -25,24 +25,102 @@
#include "sysprof-cell-renderer-duration.h"
#include "sysprof-marks-model.h"
#include "sysprof-marks-view.h"
#include "sysprof-zoom-manager.h"
typedef struct
{
SysprofZoomManager *zoom_manager;
/* Template objects */
GtkTreeView *tree_view;
SysprofCellRendererDuration *duration_cell;
} SysprofMarksViewPrivate;
enum {
PROP_0,
PROP_ZOOM_MANAGER,
N_PROPS
};
static GParamSpec *properties [N_PROPS];
G_DEFINE_TYPE_WITH_PRIVATE (SysprofMarksView, sysprof_marks_view, GTK_TYPE_BIN)
static void
sysprof_marks_view_finalize (GObject *object)
{
SysprofMarksView *self = (SysprofMarksView *)object;
SysprofMarksViewPrivate *priv = sysprof_marks_view_get_instance_private (self);
g_clear_object (&priv->zoom_manager);
G_OBJECT_CLASS (sysprof_marks_view_parent_class)->finalize (object);
}
static void
sysprof_marks_view_get_property (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec)
{
SysprofMarksView *self = SYSPROF_MARKS_VIEW (object);
SysprofMarksViewPrivate *priv = sysprof_marks_view_get_instance_private (self);
switch (prop_id)
{
case PROP_ZOOM_MANAGER:
g_value_set_object (value, priv->zoom_manager);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
}
}
static void
sysprof_marks_view_set_property (GObject *object,
guint prop_id,
const GValue *value,
GParamSpec *pspec)
{
SysprofMarksView *self = SYSPROF_MARKS_VIEW (object);
SysprofMarksViewPrivate *priv = sysprof_marks_view_get_instance_private (self);
switch (prop_id)
{
case PROP_ZOOM_MANAGER:
g_set_object (&priv->zoom_manager, g_value_get_object (value));
g_object_set (priv->duration_cell,
"zoom-manager", priv->zoom_manager,
NULL);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
}
}
static void
sysprof_marks_view_class_init (SysprofMarksViewClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
object_class->finalize = sysprof_marks_view_finalize;
object_class->get_property = sysprof_marks_view_get_property;
object_class->set_property = sysprof_marks_view_set_property;
gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/sysprof/ui/sysprof-marks-view.ui");
gtk_widget_class_bind_template_child_private (widget_class, SysprofMarksView, tree_view);
gtk_widget_class_bind_template_child_private (widget_class, SysprofMarksView, duration_cell);
properties [PROP_ZOOM_MANAGER] =
g_param_spec_object ("zoom-manager", NULL, NULL,
SYSPROF_TYPE_ZOOM_MANAGER,
(G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
g_object_class_install_properties (object_class, N_PROPS, properties);
g_type_ensure (SYSPROF_TYPE_CELL_RENDERER_DURATION);
}
@ -66,9 +144,11 @@ sysprof_marks_view_load_cb (GObject *object,
g_autoptr(SysprofMarksModel) model = NULL;
g_autoptr(GError) error = NULL;
g_autoptr(GTask) task = user_data;
SysprofMarksView *self;
SysprofMarksViewPrivate *priv;
gint64 zoom_begin, zoom_end;
SysprofCaptureReader *reader;
SysprofMarksView *self;
gint64 capture_begin_time;
gint64 capture_end_time;
g_assert (G_IS_ASYNC_RESULT (result));
g_assert (G_IS_TASK (task));
@ -82,10 +162,16 @@ sysprof_marks_view_load_cb (GObject *object,
return;
}
sysprof_marks_model_get_range (model, &zoom_begin, &zoom_end);
reader = g_task_get_task_data (task);
g_assert (reader != NULL);
capture_begin_time = sysprof_capture_reader_get_start_time (reader);
capture_end_time = sysprof_capture_reader_get_end_time (reader);
g_object_set (priv->duration_cell,
"zoom-begin", zoom_begin,
"zoom-end", zoom_end,
"capture-begin-time", capture_begin_time,
"capture-end-time", capture_end_time,
"zoom-manager", priv->zoom_manager,
NULL);
gtk_tree_view_set_model (priv->tree_view, GTK_TREE_MODEL (model));
@ -110,6 +196,9 @@ sysprof_marks_view_load_async (SysprofMarksView *self,
task = g_task_new (self, cancellable, callback, user_data);
g_task_set_source_tag (task, sysprof_marks_view_load_async);
g_task_set_task_data (task,
sysprof_capture_reader_ref (reader),
(GDestroyNotify) sysprof_capture_reader_unref);
sysprof_marks_model_new_async (reader,
selection,

View File

@ -115,6 +115,7 @@
</child>
<child>
<object class="SysprofMarksView" id="marks_view">
<property name="zoom-manager">zoom_manager</property>
<property name="visible">true</property>
</object>
<packing>

View File

@ -64,6 +64,7 @@
<child>
<object class="SysprofCellRendererDuration" id="duration_cell">
<property name="xalign">0</property>
<property name="ypad">1</property>
</object>
<attributes>
<attribute name="text">1</attribute>