libsysprof-ui: add fit-width zoom helper

This commit is contained in:
Christian Hergert
2019-05-14 21:09:24 -07:00
parent 67530d595d
commit ce3e7c5f4e
2 changed files with 16 additions and 0 deletions

View File

@ -515,3 +515,15 @@ sysprof_zoom_manager_get_width_for_duration (SysprofZoomManager *self,
return (gdouble)duration / (gdouble)NSEC_PER_SEC * DEFAULT_PIXELS_PER_SEC * self->zoom;
}
gdouble
sysprof_zoom_manager_fit_zoom_for_duration (SysprofZoomManager *self,
gint64 duration,
gint width)
{
g_return_val_if_fail (SYSPROF_IS_ZOOM_MANAGER (self), 1.0);
g_return_val_if_fail (duration >= 0, 1.0);
return ((gdouble)width / DEFAULT_PIXELS_PER_SEC) /
((gdouble)duration / (gdouble)NSEC_PER_SEC);
}

View File

@ -70,5 +70,9 @@ gint sysprof_zoom_manager_get_width_for_duration (SysprofZoomMana
SYSPROF_AVAILABLE_IN_ALL
gint64 sysprof_zoom_manager_get_duration_for_width (SysprofZoomManager *self,
gint width);
SYSPROF_AVAILABLE_IN_ALL
gdouble sysprof_zoom_manager_fit_zoom_for_duration (SysprofZoomManager *self,
gint64 duration,
gint width);
G_END_DECLS