Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
button-widget: wide panels, more suitable resize limits on Widgets an…
…d arrows

Set better limits to the size taken by all BUTTON_WIDGETs when the panel is wide.
For a wide panel (example vertical panel 100px wide) a widget would, before, take a space of 100x100 (for max hardcoded icon size 48px)
Now if panel width exceeds 50px, the widgets' height stays at 50 and does not grow in height anymore.
Same behaviour applies on wide horizontal panels.
The GTK_ARROW also resizes properly for wide panel on BUTTON_WIDGETs with property "has_arrow"
  • Loading branch information
braikar authored and lukefromdc committed Oct 20, 2018
1 parent e4fc17c commit 3f351d5
Showing 1 changed file with 42 additions and 15 deletions.
57 changes: 42 additions & 15 deletions mate-panel/button-widget.c
Expand Up @@ -303,35 +303,40 @@ calc_arrow (PanelOrientation orientation,
gdouble *size)
{
GtkArrowType retval = GTK_ARROW_UP;
double scale;

scale = (orientation & PANEL_HORIZONTAL_MASK ? button_height : button_width) / 48.0;

*size = 12 * scale;
if (orientation & PANEL_HORIZONTAL_MASK) {
if (button_width > 50)
button_width = 50;
} else {
if (button_height > 50)
button_height = 50;
}

*size = (orientation & PANEL_HORIZONTAL_MASK ? button_width : button_height) / 2;
*angle = 0;

switch (orientation) {
case PANEL_ORIENTATION_TOP:
*x = scale * 3;
*y = scale * (48 - 13);
*x = (button_width - (*size)) / 2;
*y = button_height * .99 - (*size) / (3/2); // 3/2 is the approximate ratio of GTK arrows
*angle = G_PI;
retval = GTK_ARROW_DOWN;
break;
case PANEL_ORIENTATION_BOTTOM:
*x = scale * (48 - 13);
*y = scale * 1;
*x = (button_width - (*size)) / 2;
*y = button_height * .01;
*angle = 0;
retval = GTK_ARROW_UP;
break;
case PANEL_ORIENTATION_LEFT:
*x = scale * (48 - 13);
*y = scale * 3;
*x = button_width * .99 - (*size) / (3/2); // 3/2 is the approximate ratio of GTK arrows
*y = (button_height - (*size)) / 2;
*angle = G_PI / 2;
retval = GTK_ARROW_RIGHT;
break;
case PANEL_ORIENTATION_RIGHT:
*x = scale * 1;
*y = scale * 3;
*x = button_width * .01;
*y = (button_height - (*size)) / 2;
*angle = 3 * (G_PI / 2);
retval = GTK_ARROW_LEFT;
break;
Expand Down Expand Up @@ -446,9 +451,14 @@ button_widget_get_preferred_width (GtkWidget *widget,

parent = gtk_widget_get_parent (widget);

if (button_widget->priv->orientation & PANEL_HORIZONTAL_MASK)
if (button_widget->priv->orientation & PANEL_HORIZONTAL_MASK){
size = gtk_widget_get_allocated_height (parent);
else

/* should get this value (50) from gsettings, user defined value in properties of the panel (max_icon_size) OR use 48*/
if ( size > 50 )
size = 50;

} else
size = gtk_widget_get_allocated_width (parent);

*minimal_width = *natural_width = size;
Expand All @@ -467,8 +477,14 @@ button_widget_get_preferred_height (GtkWidget *widget,

if (button_widget->priv->orientation & PANEL_HORIZONTAL_MASK)
size = gtk_widget_get_allocated_height (parent);
else
else {
size = gtk_widget_get_allocated_width (parent);

/* should get this value (50) from gsettings, user defined value in properties of the panel (max_icon_size) OR use 48*/
if ( size > 50 )
size = 50;

}

*minimal_height = *natural_height = size;
}
Expand All @@ -480,6 +496,17 @@ button_widget_size_allocate (GtkWidget *widget,
ButtonWidget *button_widget = BUTTON_WIDGET (widget);
int size;

/* should get this value (50) from gsettings, user defined value in properties of the panel (max_icon_size) OR use 48?*/
if (button_widget->priv->orientation & PANEL_HORIZONTAL_MASK) {
if ( allocation->height > 50 ) {
allocation->width = 50;
}
} else {
if ( allocation->width > 50 ) {
allocation->height = 50;
}
}

GTK_WIDGET_CLASS (button_widget_parent_class)->size_allocate (widget, allocation);

if (button_widget->priv->orientation & PANEL_HORIZONTAL_MASK)
Expand Down

0 comments on commit 3f351d5

Please sign in to comment.