Commit 1faaea01 authored by Alexander Mikhaylenko's avatar Alexander Mikhaylenko
Browse files

title-bar: Respect CSS min-width and min-height

parent 34b8172b
......@@ -164,6 +164,106 @@ hdy_title_bar_draw (GtkWidget *widget,
return GTK_WIDGET_CLASS (hdy_title_bar_parent_class)->draw (widget, cr);
}
/* This private method is prefixed by the class name because it will be a
* virtual method in GTK 4.
*/
static void
hdy_title_bar_measure (GtkWidget *widget,
GtkOrientation orientation,
gint for_size,
gint *minimum,
gint *natural,
gint *minimum_baseline,
gint *natural_baseline)
{
GtkWidget *child;
gint parent_min, parent_nat;
gint css_width, css_height, css_min;
child = gtk_bin_get_child (GTK_BIN (widget));
gtk_style_context_get (gtk_widget_get_style_context (widget),
gtk_widget_get_state_flags (widget),
"min-width", &css_width,
"min-height", &css_height,
NULL);
if (orientation == GTK_ORIENTATION_HORIZONTAL)
css_min = css_width;
else
css_min = css_height;
if (child)
if (orientation == GTK_ORIENTATION_HORIZONTAL)
if (for_size != 1)
gtk_widget_get_preferred_width_for_height (child,
MAX (for_size, css_height),
&parent_min, &parent_nat);
else
gtk_widget_get_preferred_width (child, &parent_min, &parent_nat);
else
if (for_size != 1)
gtk_widget_get_preferred_height_for_width (child,
MAX (for_size, css_width),
&parent_min, &parent_nat);
else
gtk_widget_get_preferred_height (child, &parent_min, &parent_nat);
else {
parent_min = 0;
parent_nat = 0;
}
if (minimum)
*natural = MAX (parent_min, css_min);
if (minimum)
*natural = MAX (parent_nat, css_min);
if (minimum_baseline)
*minimum_baseline = -1;
if (natural_baseline)
*natural_baseline = -1;
}
static void
hdy_title_bar_get_preferred_width (GtkWidget *widget,
gint *minimum,
gint *natural)
{
hdy_title_bar_measure (widget, GTK_ORIENTATION_HORIZONTAL, -1,
minimum, natural, NULL, NULL);
}
static void
hdy_title_bar_get_preferred_width_for_height (GtkWidget *widget,
gint height,
gint *minimum,
gint *natural)
{
hdy_title_bar_measure (widget, GTK_ORIENTATION_HORIZONTAL, height,
minimum, natural, NULL, NULL);
}
static void
hdy_title_bar_get_preferred_height (GtkWidget *widget,
gint *minimum,
gint *natural)
{
hdy_title_bar_measure (widget, GTK_ORIENTATION_VERTICAL, -1,
minimum, natural, NULL, NULL);
}
static void
hdy_title_bar_get_preferred_height_for_width (GtkWidget *widget,
gint width,
gint *minimum,
gint *natural)
{
hdy_title_bar_measure (widget, GTK_ORIENTATION_VERTICAL, width,
minimum, natural, NULL, NULL);
}
static void
hdy_title_bar_size_allocate (GtkWidget *widget,
GtkAllocation *allocation)
......@@ -192,6 +292,10 @@ hdy_title_bar_class_init (HdyTitleBarClass *klass)
object_class->set_property = hdy_title_bar_set_property;
widget_class->draw = hdy_title_bar_draw;
widget_class->get_preferred_width = hdy_title_bar_get_preferred_width;
widget_class->get_preferred_width_for_height = hdy_title_bar_get_preferred_width_for_height;
widget_class->get_preferred_height = hdy_title_bar_get_preferred_height;
widget_class->get_preferred_height_for_width = hdy_title_bar_get_preferred_height_for_width;
widget_class->size_allocate = hdy_title_bar_size_allocate;
/**
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment