property action: Add state hints

We have this information in the param specs,
we might as well pass it on to give consumers
a chance to present meaningful UIs for these
actions.
This commit is contained in:
Matthias Clasen 2019-06-10 00:01:57 +00:00
parent 4e00fdea9b
commit 459c4f296a

View File

@ -158,6 +158,29 @@ g_property_action_get_state_type (GAction *action)
static GVariant *
g_property_action_get_state_hint (GAction *action)
{
GPropertyAction *paction = G_PROPERTY_ACTION (action);
if (paction->pspec->value_type == G_TYPE_INT)
{
GParamSpecInt *pspec = (GParamSpecInt *)paction->pspec;
return g_variant_new ("(ii)", pspec->minimum, pspec->maximum);
}
else if (paction->pspec->value_type == G_TYPE_UINT)
{
GParamSpecUInt *pspec = (GParamSpecUInt *)paction->pspec;
return g_variant_new ("(uu)", pspec->minimum, pspec->maximum);
}
else if (paction->pspec->value_type == G_TYPE_FLOAT)
{
GParamSpecFloat *pspec = (GParamSpecFloat *)paction->pspec;
return g_variant_new ("(dd)", (double)pspec->minimum, (double)pspec->maximum);
}
else if (paction->pspec->value_type == G_TYPE_DOUBLE)
{
GParamSpecDouble *pspec = (GParamSpecDouble *)paction->pspec;
return g_variant_new ("(dd)", pspec->minimum, pspec->maximum);
}
return NULL;
}