mirror of
https://github.com/varun-r-mallya/sysprof.git
synced 2025-12-31 20:36:25 +00:00
libsysprof-ui: add simplified time label
This handles the resizing of the numbers better to avoid jitter of the positioning.
This commit is contained in:
@ -25,6 +25,7 @@
|
|||||||
<file preprocess="xml-stripblanks">ui/sysprof-profiler-menu-button.ui</file>
|
<file preprocess="xml-stripblanks">ui/sysprof-profiler-menu-button.ui</file>
|
||||||
<file preprocess="xml-stripblanks">ui/sysprof-recording-state-view.ui</file>
|
<file preprocess="xml-stripblanks">ui/sysprof-recording-state-view.ui</file>
|
||||||
<file preprocess="xml-stripblanks">ui/sysprof-tab.ui</file>
|
<file preprocess="xml-stripblanks">ui/sysprof-tab.ui</file>
|
||||||
|
<file preprocess="xml-stripblanks">ui/sysprof-time-label.ui</file>
|
||||||
<file preprocess="xml-stripblanks">ui/sysprof-visualizer-view.ui</file>
|
<file preprocess="xml-stripblanks">ui/sysprof-visualizer-view.ui</file>
|
||||||
</gresource>
|
</gresource>
|
||||||
</gresources>
|
</gresources>
|
||||||
|
|||||||
@ -42,6 +42,7 @@ libsysprof_ui_private_sources = [
|
|||||||
'sysprof-environ-variable.c',
|
'sysprof-environ-variable.c',
|
||||||
'sysprof-environ.c',
|
'sysprof-environ.c',
|
||||||
'sysprof-tab.c',
|
'sysprof-tab.c',
|
||||||
|
'sysprof-time-label.c',
|
||||||
'sysprof-theme-manager.c',
|
'sysprof-theme-manager.c',
|
||||||
'../stackstash.c',
|
'../stackstash.c',
|
||||||
]
|
]
|
||||||
|
|||||||
@ -21,13 +21,14 @@
|
|||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
#include "sysprof-recording-state-view.h"
|
#include "sysprof-recording-state-view.h"
|
||||||
|
#include "sysprof-time-label.h"
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
SysprofProfiler *profiler;
|
SysprofProfiler *profiler;
|
||||||
GtkLabel *elapsed;
|
SysprofTimeLabel *elapsed;
|
||||||
GtkLabel *samples;
|
GtkLabel *samples;
|
||||||
gulong notify_elapsed_handler;
|
gulong notify_elapsed_handler;
|
||||||
} SysprofRecordingStateViewPrivate;
|
} SysprofRecordingStateViewPrivate;
|
||||||
|
|
||||||
G_DEFINE_TYPE_WITH_PRIVATE (SysprofRecordingStateView, sysprof_recording_state_view, GTK_TYPE_BIN)
|
G_DEFINE_TYPE_WITH_PRIVATE (SysprofRecordingStateView, sysprof_recording_state_view, GTK_TYPE_BIN)
|
||||||
@ -55,9 +56,6 @@ sysprof_recording_state_view_notify_elapsed (SysprofRecordingStateView *self,
|
|||||||
g_autofree gchar *str = NULL;
|
g_autofree gchar *str = NULL;
|
||||||
SysprofCaptureWriter *writer;
|
SysprofCaptureWriter *writer;
|
||||||
gint64 elapsed;
|
gint64 elapsed;
|
||||||
guint hours;
|
|
||||||
guint minutes;
|
|
||||||
guint seconds;
|
|
||||||
|
|
||||||
g_assert (SYSPROF_IS_RECORDING_STATE_VIEW (self));
|
g_assert (SYSPROF_IS_RECORDING_STATE_VIEW (self));
|
||||||
g_assert (SYSPROF_IS_PROFILER (profiler));
|
g_assert (SYSPROF_IS_PROFILER (profiler));
|
||||||
@ -78,20 +76,7 @@ sysprof_recording_state_view_notify_elapsed (SysprofRecordingStateView *self,
|
|||||||
}
|
}
|
||||||
|
|
||||||
elapsed = (gint64)sysprof_profiler_get_elapsed (profiler);
|
elapsed = (gint64)sysprof_profiler_get_elapsed (profiler);
|
||||||
|
sysprof_time_label_set_duration (priv->elapsed, elapsed);
|
||||||
hours = elapsed / (60 * 60);
|
|
||||||
if (hours > 0)
|
|
||||||
minutes = (elapsed % (hours * 60 * 60)) / 60;
|
|
||||||
else
|
|
||||||
minutes = elapsed / 60;
|
|
||||||
seconds = elapsed % 60;
|
|
||||||
|
|
||||||
if (hours == 0)
|
|
||||||
str = g_strdup_printf ("%02u:%02u", minutes, seconds);
|
|
||||||
else
|
|
||||||
str = g_strdup_printf ("%02u:%02u:%02u", hours, minutes, seconds);
|
|
||||||
|
|
||||||
gtk_label_set_label (priv->elapsed, str);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -168,10 +153,11 @@ sysprof_recording_state_view_class_init (SysprofRecordingStateViewClass *klass)
|
|||||||
|
|
||||||
g_object_class_install_properties (object_class, N_PROPS, properties);
|
g_object_class_install_properties (object_class, N_PROPS, properties);
|
||||||
|
|
||||||
gtk_widget_class_set_template_from_resource (widget_class,
|
gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/sysprof/ui/sysprof-recording-state-view.ui");
|
||||||
"/org/gnome/sysprof/ui/sysprof-recording-state-view.ui");
|
|
||||||
gtk_widget_class_bind_template_child_private (widget_class, SysprofRecordingStateView, elapsed);
|
gtk_widget_class_bind_template_child_private (widget_class, SysprofRecordingStateView, elapsed);
|
||||||
gtk_widget_class_bind_template_child_private (widget_class, SysprofRecordingStateView, samples);
|
gtk_widget_class_bind_template_child_private (widget_class, SysprofRecordingStateView, samples);
|
||||||
|
|
||||||
|
g_type_ensure (SYSPROF_TYPE_TIME_LABEL);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -189,7 +175,7 @@ sysprof_recording_state_view_set_profiler (SysprofRecordingStateView *self,
|
|||||||
g_assert (SYSPROF_IS_RECORDING_STATE_VIEW (self));
|
g_assert (SYSPROF_IS_RECORDING_STATE_VIEW (self));
|
||||||
g_assert (!profiler || SYSPROF_IS_PROFILER (profiler));
|
g_assert (!profiler || SYSPROF_IS_PROFILER (profiler));
|
||||||
|
|
||||||
gtk_label_set_label (priv->elapsed, "00:00");
|
sysprof_time_label_set_duration (priv->elapsed, 0);
|
||||||
|
|
||||||
if (profiler != priv->profiler)
|
if (profiler != priv->profiler)
|
||||||
{
|
{
|
||||||
@ -199,8 +185,6 @@ sysprof_recording_state_view_set_profiler (SysprofRecordingStateView *self,
|
|||||||
g_clear_object (&priv->profiler);
|
g_clear_object (&priv->profiler);
|
||||||
}
|
}
|
||||||
|
|
||||||
gtk_label_set_label (priv->elapsed, "00:00");
|
|
||||||
|
|
||||||
if (profiler != NULL)
|
if (profiler != NULL)
|
||||||
{
|
{
|
||||||
priv->profiler = g_object_ref (profiler);
|
priv->profiler = g_object_ref (profiler);
|
||||||
|
|||||||
103
src/libsysprof-ui/sysprof-time-label.c
Normal file
103
src/libsysprof-ui/sysprof-time-label.c
Normal file
@ -0,0 +1,103 @@
|
|||||||
|
/* sysprof-time-label.c
|
||||||
|
*
|
||||||
|
* Copyright 2019 Christian Hergert <chergert@redhat.com>
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define G_LOG_DOMAIN "sysprof-time-label"
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
|
|
||||||
|
#include "sysprof-time-label.h"
|
||||||
|
|
||||||
|
#define NSEC_PER_SEC (G_USEC_PER_SEC * 1000L)
|
||||||
|
|
||||||
|
struct _SysprofTimeLabel
|
||||||
|
{
|
||||||
|
GtkBox parent;
|
||||||
|
|
||||||
|
GtkLabel *minutes;
|
||||||
|
GtkLabel *seconds;
|
||||||
|
};
|
||||||
|
|
||||||
|
G_DEFINE_TYPE (SysprofTimeLabel, sysprof_time_label, GTK_TYPE_BOX)
|
||||||
|
|
||||||
|
static void
|
||||||
|
sysprof_time_label_class_init (SysprofTimeLabelClass *klass)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
sysprof_time_label_init (SysprofTimeLabel *self)
|
||||||
|
{
|
||||||
|
PangoAttrList *attrs = pango_attr_list_new ();
|
||||||
|
GtkWidget *sep;
|
||||||
|
|
||||||
|
pango_attr_list_insert (attrs, pango_attr_scale_new (4));
|
||||||
|
pango_attr_list_insert (attrs, pango_attr_weight_new (PANGO_WEIGHT_BOLD));
|
||||||
|
|
||||||
|
gtk_box_set_spacing (GTK_BOX (self), 3);
|
||||||
|
|
||||||
|
self->minutes = g_object_new (GTK_TYPE_LABEL,
|
||||||
|
"attributes", attrs,
|
||||||
|
"visible", TRUE,
|
||||||
|
"xalign", 1.0f,
|
||||||
|
NULL);
|
||||||
|
gtk_container_add_with_properties (GTK_CONTAINER (self), GTK_WIDGET (self->minutes),
|
||||||
|
"pack-type", GTK_PACK_START,
|
||||||
|
"expand", TRUE,
|
||||||
|
"fill", TRUE,
|
||||||
|
NULL);
|
||||||
|
|
||||||
|
sep = g_object_new (GTK_TYPE_LABEL,
|
||||||
|
"attributes", attrs,
|
||||||
|
"visible", TRUE,
|
||||||
|
"label", ":",
|
||||||
|
NULL);
|
||||||
|
gtk_box_set_center_widget (GTK_BOX (self), sep);
|
||||||
|
|
||||||
|
self->seconds = g_object_new (GTK_TYPE_LABEL,
|
||||||
|
"attributes", attrs,
|
||||||
|
"visible", TRUE,
|
||||||
|
"xalign", 0.0f,
|
||||||
|
NULL);
|
||||||
|
gtk_container_add_with_properties (GTK_CONTAINER (self), GTK_WIDGET (self->seconds),
|
||||||
|
"pack-type", GTK_PACK_END,
|
||||||
|
"expand", TRUE,
|
||||||
|
"fill", TRUE,
|
||||||
|
NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
sysprof_time_label_set_duration (SysprofTimeLabel *self,
|
||||||
|
guint duration)
|
||||||
|
{
|
||||||
|
gchar minstr[12];
|
||||||
|
gchar secstr[12];
|
||||||
|
gint min, sec;
|
||||||
|
|
||||||
|
g_return_if_fail (SYSPROF_IS_TIME_LABEL (self));
|
||||||
|
|
||||||
|
min = duration / 60;
|
||||||
|
sec = duration % 60;
|
||||||
|
|
||||||
|
g_snprintf (minstr, sizeof minstr, "%02d", min);
|
||||||
|
g_snprintf (secstr, sizeof secstr, "%02d", sec);
|
||||||
|
|
||||||
|
gtk_label_set_label (self->minutes, minstr);
|
||||||
|
gtk_label_set_label (self->seconds, secstr);
|
||||||
|
}
|
||||||
34
src/libsysprof-ui/sysprof-time-label.h
Normal file
34
src/libsysprof-ui/sysprof-time-label.h
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
/* sysprof-time-label.h
|
||||||
|
*
|
||||||
|
* Copyright 2019 Christian Hergert <chergert@redhat.com>
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <gtk/gtk.h>
|
||||||
|
|
||||||
|
G_BEGIN_DECLS
|
||||||
|
|
||||||
|
#define SYSPROF_TYPE_TIME_LABEL (sysprof_time_label_get_type())
|
||||||
|
|
||||||
|
G_DECLARE_FINAL_TYPE (SysprofTimeLabel, sysprof_time_label, SYSPROF, TIME_LABEL, GtkBox)
|
||||||
|
|
||||||
|
void sysprof_time_label_set_duration (SysprofTimeLabel *self,
|
||||||
|
guint duration);
|
||||||
|
|
||||||
|
G_END_DECLS
|
||||||
@ -20,17 +20,11 @@
|
|||||||
</object>
|
</object>
|
||||||
</child>
|
</child>
|
||||||
<child>
|
<child>
|
||||||
<object class="GtkLabel" id="elapsed">
|
<object class="SysprofTimeLabel" id="elapsed">
|
||||||
<property name="label" translatable="yes">00:00</property>
|
|
||||||
<property name="visible">true</property>
|
<property name="visible">true</property>
|
||||||
<style>
|
<style>
|
||||||
<class name="dim-label"/>
|
<class name="dim-label"/>
|
||||||
</style>
|
</style>
|
||||||
<attributes>
|
|
||||||
<attribute name="scale" value="4"/>
|
|
||||||
<attribute name="weight" value="bold"/>
|
|
||||||
<attribute name="font-features" value="font-feature-settings: 'tnum'"/>
|
|
||||||
</attributes>
|
|
||||||
</object>
|
</object>
|
||||||
</child>
|
</child>
|
||||||
<child>
|
<child>
|
||||||
|
|||||||
50
src/libsysprof-ui/ui/sysprof-time-label.ui
Normal file
50
src/libsysprof-ui/ui/sysprof-time-label.ui
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!-- Generated with glade 3.22.0 -->
|
||||||
|
<interface>
|
||||||
|
<requires lib="gtk+" version="3.0"/>
|
||||||
|
<template class="SysprofTimeLabel" parent="GtkBox">
|
||||||
|
<property name="can_focus">False</property>
|
||||||
|
<property name="spacing">2</property>
|
||||||
|
<child type="center">
|
||||||
|
<object class="GtkLabel">
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="can_focus">False</property>
|
||||||
|
<property name="label">:</property>
|
||||||
|
</object>
|
||||||
|
<packing>
|
||||||
|
<property name="expand">False</property>
|
||||||
|
<property name="fill">True</property>
|
||||||
|
<property name="position">3</property>
|
||||||
|
</packing>
|
||||||
|
</child>
|
||||||
|
<child>
|
||||||
|
<object class="GtkLabel" id="minute">
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="can_focus">False</property>
|
||||||
|
<property name="label" translatable="yes">00</property>
|
||||||
|
<property name="width_chars">2</property>
|
||||||
|
<property name="xalign">1</property>
|
||||||
|
</object>
|
||||||
|
<packing>
|
||||||
|
<property name="expand">True</property>
|
||||||
|
<property name="fill">True</property>
|
||||||
|
<property name="position">2</property>
|
||||||
|
</packing>
|
||||||
|
</child>
|
||||||
|
<child>
|
||||||
|
<object class="GtkLabel" id="second">
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="can_focus">False</property>
|
||||||
|
<property name="label" translatable="yes">00</property>
|
||||||
|
<property name="width_chars">2</property>
|
||||||
|
<property name="xalign">0</property>
|
||||||
|
</object>
|
||||||
|
<packing>
|
||||||
|
<property name="expand">True</property>
|
||||||
|
<property name="fill">True</property>
|
||||||
|
<property name="pack_type">end</property>
|
||||||
|
<property name="position">4</property>
|
||||||
|
</packing>
|
||||||
|
</child>
|
||||||
|
</template>
|
||||||
|
</interface>
|
||||||
Reference in New Issue
Block a user