forked from AuroraMiddleware/gtk
applied patch from Xan Lopez to eliminate gap in painted frame for
Fri Jun 22 12:13:39 2007 Tim Janik <timj@imendio.com> * gtk/gtkframe.c (gtk_frame_paint): applied patch from Xan Lopez to eliminate gap in painted frame for yaling=0.0 or yalign=1.0. * tests/testframe.c: added test application from Xan Lopez to test xalign/yalign interactions with xthickness/ythickness. svn path=/trunk/; revision=18216
This commit is contained in:
parent
e7525262bd
commit
9d21e46190
@ -1,3 +1,11 @@
|
|||||||
|
Fri Jun 22 12:13:39 2007 Tim Janik <timj@imendio.com>
|
||||||
|
|
||||||
|
* gtk/gtkframe.c (gtk_frame_paint): applied patch from Xan Lopez
|
||||||
|
to eliminate gap in painted frame for yaling=0.0 or yalign=1.0.
|
||||||
|
|
||||||
|
* tests/testframe.c: added test application from Xan Lopez to
|
||||||
|
test xalign/yalign interactions with xthickness/ythickness.
|
||||||
|
|
||||||
Fri Jun 22 00:34:34 2007 Tim Janik <timj@gtk.org>
|
Fri Jun 22 00:34:34 2007 Tim Janik <timj@gtk.org>
|
||||||
|
|
||||||
* gdk/x11/gdkdisplay-x11.c (gdk_x11_display_get_xdisplay): applied
|
* gdk/x11/gdkdisplay-x11.c (gdk_x11_display_get_xdisplay): applied
|
||||||
|
@ -425,7 +425,9 @@ gtk_frame_get_label_widget (GtkFrame *frame)
|
|||||||
* of the widget. A value of 0.0 represents left alignment;
|
* of the widget. A value of 0.0 represents left alignment;
|
||||||
* 1.0 represents right alignment.
|
* 1.0 represents right alignment.
|
||||||
* @yalign: The y alignment of the label. A value of 0.0 aligns under
|
* @yalign: The y alignment of the label. A value of 0.0 aligns under
|
||||||
* the frame; 1.0 aligns above the frame.
|
* the frame; 1.0 aligns above the frame. If the values are exactly
|
||||||
|
* 0.0 or 1.0 the gap in the frame won't be painted because the label
|
||||||
|
* will be completely above or below the frame.
|
||||||
*
|
*
|
||||||
* Sets the alignment of the frame widget's label. The
|
* Sets the alignment of the frame widget's label. The
|
||||||
* default values for a newly created frame are 0.0 and 0.5.
|
* default values for a newly created frame are 0.0 and 0.5.
|
||||||
@ -553,20 +555,26 @@ gtk_frame_paint (GtkWidget *widget,
|
|||||||
else
|
else
|
||||||
xalign = 1 - frame->label_xalign;
|
xalign = 1 - frame->label_xalign;
|
||||||
|
|
||||||
height_extra = MAX (0, child_requisition.height - widget->style->ythickness);
|
height_extra = MAX (0, child_requisition.height - widget->style->ythickness)
|
||||||
height_extra *= (1 - frame->label_yalign);
|
- frame->label_yalign * child_requisition.height;
|
||||||
y -= height_extra;
|
y -= height_extra;
|
||||||
height += height_extra;
|
height += height_extra;
|
||||||
|
|
||||||
x2 = widget->style->xthickness + (frame->child_allocation.width - child_requisition.width - 2 * LABEL_PAD - 2 * LABEL_SIDE_PAD) * xalign + LABEL_SIDE_PAD;
|
x2 = widget->style->xthickness + (frame->child_allocation.width - child_requisition.width - 2 * LABEL_PAD - 2 * LABEL_SIDE_PAD) * xalign + LABEL_SIDE_PAD;
|
||||||
|
|
||||||
|
|
||||||
gtk_paint_shadow_gap (widget->style, widget->window,
|
/* If the label is completely over or under the frame we can omit the gap */
|
||||||
widget->state, frame->shadow_type,
|
if (frame->label_yalign == 0.0 || frame->label_yalign == 1.0)
|
||||||
area, widget, "frame",
|
gtk_paint_shadow (widget->style, widget->window,
|
||||||
x, y, width, height,
|
widget->state, frame->shadow_type,
|
||||||
GTK_POS_TOP,
|
area, widget, "frame",
|
||||||
x2, child_requisition.width + 2 * LABEL_PAD);
|
x, y, width, height);
|
||||||
|
else
|
||||||
|
gtk_paint_shadow_gap (widget->style, widget->window,
|
||||||
|
widget->state, frame->shadow_type,
|
||||||
|
area, widget, "frame",
|
||||||
|
x, y, width, height,
|
||||||
|
GTK_POS_TOP,
|
||||||
|
x2, child_requisition.width + 2 * LABEL_PAD);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
gtk_paint_shadow (widget->style, widget->window,
|
gtk_paint_shadow (widget->style, widget->window,
|
||||||
@ -604,7 +612,7 @@ gtk_frame_size_request (GtkWidget *widget,
|
|||||||
|
|
||||||
requisition->width = child_requisition.width + 2 * LABEL_PAD + 2 * LABEL_SIDE_PAD;
|
requisition->width = child_requisition.width + 2 * LABEL_PAD + 2 * LABEL_SIDE_PAD;
|
||||||
requisition->height =
|
requisition->height =
|
||||||
MAX (0, child_requisition.height - GTK_WIDGET (widget)->style->ythickness);
|
MAX (0, child_requisition.height - widget->style->ythickness);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -45,6 +45,7 @@ noinst_PROGRAMS = \
|
|||||||
testentrycompletion \
|
testentrycompletion \
|
||||||
testfilechooser \
|
testfilechooser \
|
||||||
testfilechooserbutton \
|
testfilechooserbutton \
|
||||||
|
testframe \
|
||||||
testgtk \
|
testgtk \
|
||||||
testiconview \
|
testiconview \
|
||||||
testicontheme \
|
testicontheme \
|
||||||
@ -99,6 +100,7 @@ testiconview_DEPENDENCIES = $(TEST_DEPS)
|
|||||||
testaccel_DEPENDENCIES = $(TEST_DEPS)
|
testaccel_DEPENDENCIES = $(TEST_DEPS)
|
||||||
testassistant_DEPENDENCIES = $(TEST_DEPS)
|
testassistant_DEPENDENCIES = $(TEST_DEPS)
|
||||||
testbbox_DEPENDENCIES = $(TEST_DEPS)
|
testbbox_DEPENDENCIES = $(TEST_DEPS)
|
||||||
|
testframe_DEPENDENCIES = $(TEST_DEPS)
|
||||||
testcairo_DEPENDENCIES = $(TEST_DEPS)
|
testcairo_DEPENDENCIES = $(TEST_DEPS)
|
||||||
testcalendar_DEPENDENCIES = $(TEST_DEPS)
|
testcalendar_DEPENDENCIES = $(TEST_DEPS)
|
||||||
testcombo_DEPENDENCIES = $(TEST_DEPS)
|
testcombo_DEPENDENCIES = $(TEST_DEPS)
|
||||||
@ -153,6 +155,7 @@ print_editor_LDADD = $(LDADDS)
|
|||||||
testaccel_LDADD = $(LDADDS)
|
testaccel_LDADD = $(LDADDS)
|
||||||
testassistant_LDADD = $(LDADDS)
|
testassistant_LDADD = $(LDADDS)
|
||||||
testbbox_LDADD = $(LDADDS)
|
testbbox_LDADD = $(LDADDS)
|
||||||
|
testframe_LDADD = $(LDADDS)
|
||||||
testcairo_LDADD = $(LDADDS)
|
testcairo_LDADD = $(LDADDS)
|
||||||
testcalendar_LDADD = $(LDADDS)
|
testcalendar_LDADD = $(LDADDS)
|
||||||
testcombo_LDADD = $(LDADDS)
|
testcombo_LDADD = $(LDADDS)
|
||||||
@ -276,6 +279,9 @@ testactions_SOURCES = \
|
|||||||
testbbox_SOURCES = \
|
testbbox_SOURCES = \
|
||||||
testbbox.c
|
testbbox.c
|
||||||
|
|
||||||
|
testframe_SOURCES = \
|
||||||
|
testframe.c
|
||||||
|
|
||||||
testiconview_SOURCES = \
|
testiconview_SOURCES = \
|
||||||
testiconview.c \
|
testiconview.c \
|
||||||
prop-editor.c
|
prop-editor.c
|
||||||
|
146
tests/testframe.c
Normal file
146
tests/testframe.c
Normal file
@ -0,0 +1,146 @@
|
|||||||
|
/* testframe.c
|
||||||
|
* Copyright (C) 2007 Xan López <xan@gnome.org>
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Library General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library 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
|
||||||
|
* Library General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Library General Public
|
||||||
|
* License along with this library; if not, write to the
|
||||||
|
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||||
|
* Boston, MA 02111-1307, USA.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <gtk/gtk.h>
|
||||||
|
#include <math.h>
|
||||||
|
|
||||||
|
static void
|
||||||
|
spin_ythickness_cb (GtkSpinButton *spin, gpointer user_data)
|
||||||
|
{
|
||||||
|
GtkWidget *frame = user_data;
|
||||||
|
GtkRcStyle *rcstyle;
|
||||||
|
|
||||||
|
rcstyle = gtk_rc_style_new ();
|
||||||
|
rcstyle->xthickness = GTK_WIDGET (frame)->style->xthickness;
|
||||||
|
rcstyle->ythickness = gtk_spin_button_get_value (spin);
|
||||||
|
gtk_widget_modify_style (frame, rcstyle);
|
||||||
|
gtk_rc_style_unref (rcstyle);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
spin_xthickness_cb (GtkSpinButton *spin, gpointer user_data)
|
||||||
|
{
|
||||||
|
GtkWidget *frame = user_data;
|
||||||
|
GtkRcStyle *rcstyle;
|
||||||
|
|
||||||
|
rcstyle = gtk_rc_style_new ();
|
||||||
|
rcstyle->xthickness = gtk_spin_button_get_value (spin);
|
||||||
|
rcstyle->ythickness = GTK_WIDGET (frame)->style->ythickness;
|
||||||
|
gtk_widget_modify_style (frame, rcstyle);
|
||||||
|
|
||||||
|
gtk_rc_style_unref (rcstyle);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Function to normalize rounding errors in FP arithmetic to
|
||||||
|
our desired limits */
|
||||||
|
|
||||||
|
#define EPSILON 1e-10
|
||||||
|
|
||||||
|
static gdouble
|
||||||
|
double_normalize (gdouble n)
|
||||||
|
{
|
||||||
|
if (fabs (1.0 - n) < EPSILON)
|
||||||
|
n = 1.0;
|
||||||
|
else if (n < EPSILON)
|
||||||
|
n = 0.0;
|
||||||
|
|
||||||
|
return n;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
spin_xalign_cb (GtkSpinButton *spin, GtkFrame *frame)
|
||||||
|
{
|
||||||
|
gdouble xalign = double_normalize (gtk_spin_button_get_value (spin));
|
||||||
|
gtk_frame_set_label_align (frame, xalign, frame->label_yalign);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
spin_yalign_cb (GtkSpinButton *spin, GtkFrame *frame)
|
||||||
|
{
|
||||||
|
gdouble yalign = double_normalize (gtk_spin_button_get_value (spin));
|
||||||
|
gtk_frame_set_label_align (frame, frame->label_xalign, yalign);
|
||||||
|
}
|
||||||
|
|
||||||
|
int main (int argc, char **argv)
|
||||||
|
{
|
||||||
|
GtkWidget *window, *frame, *xthickness_spin, *ythickness_spin, *vbox;
|
||||||
|
GtkWidget *xalign_spin, *yalign_spin, *button, *table, *label;
|
||||||
|
|
||||||
|
gtk_init (&argc, &argv);
|
||||||
|
|
||||||
|
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
|
||||||
|
gtk_container_set_border_width (GTK_CONTAINER (window), 5);
|
||||||
|
gtk_window_set_default_size (GTK_WINDOW (window), 300, 300);
|
||||||
|
|
||||||
|
g_signal_connect (G_OBJECT (window), "delete-event", gtk_main_quit, NULL);
|
||||||
|
|
||||||
|
vbox = gtk_vbox_new (FALSE, 5);
|
||||||
|
gtk_container_add (GTK_CONTAINER (window), vbox);
|
||||||
|
|
||||||
|
frame = gtk_frame_new ("Testing");
|
||||||
|
gtk_box_pack_start (GTK_BOX (vbox), frame, TRUE, TRUE, 0);
|
||||||
|
|
||||||
|
button = gtk_button_new_with_label ("Hello!");
|
||||||
|
gtk_container_add (GTK_CONTAINER (frame), button);
|
||||||
|
|
||||||
|
table = gtk_table_new (4, 2, FALSE);
|
||||||
|
gtk_box_pack_start (GTK_BOX (vbox), table, FALSE, FALSE, 0);
|
||||||
|
|
||||||
|
/* Spin to control xthickness */
|
||||||
|
label = gtk_label_new ("xthickness: ");
|
||||||
|
gtk_table_attach_defaults (GTK_TABLE (table), label, 0, 1, 0, 1);
|
||||||
|
|
||||||
|
xthickness_spin = gtk_spin_button_new_with_range (0, 250, 1);
|
||||||
|
g_signal_connect (G_OBJECT (xthickness_spin), "value-changed", G_CALLBACK (spin_xthickness_cb), frame);
|
||||||
|
gtk_spin_button_set_value (GTK_SPIN_BUTTON (xthickness_spin), frame->style->xthickness);
|
||||||
|
gtk_table_attach_defaults (GTK_TABLE (table), xthickness_spin, 1, 2, 0, 1);
|
||||||
|
|
||||||
|
/* Spin to control ythickness */
|
||||||
|
label = gtk_label_new ("ythickness: ");
|
||||||
|
gtk_table_attach_defaults (GTK_TABLE (table), label, 0, 1, 1, 2);
|
||||||
|
|
||||||
|
ythickness_spin = gtk_spin_button_new_with_range (0, 250, 1);
|
||||||
|
g_signal_connect (G_OBJECT (ythickness_spin), "value-changed", G_CALLBACK (spin_ythickness_cb), frame);
|
||||||
|
gtk_spin_button_set_value (GTK_SPIN_BUTTON (ythickness_spin), frame->style->ythickness);
|
||||||
|
gtk_table_attach_defaults (GTK_TABLE (table), ythickness_spin, 1, 2, 1, 2);
|
||||||
|
|
||||||
|
/* Spin to control label xalign */
|
||||||
|
label = gtk_label_new ("xalign: ");
|
||||||
|
gtk_table_attach_defaults (GTK_TABLE (table), label, 0, 1, 2, 3);
|
||||||
|
|
||||||
|
xalign_spin = gtk_spin_button_new_with_range (0.0, 1.0, 0.1);
|
||||||
|
g_signal_connect (G_OBJECT (xalign_spin), "value-changed", G_CALLBACK (spin_xalign_cb), frame);
|
||||||
|
gtk_spin_button_set_value (GTK_SPIN_BUTTON (xalign_spin), GTK_FRAME (frame)->label_xalign);
|
||||||
|
gtk_table_attach_defaults (GTK_TABLE (table), xalign_spin, 1, 2, 2, 3);
|
||||||
|
|
||||||
|
/* Spin to control label yalign */
|
||||||
|
label = gtk_label_new ("yalign: ");
|
||||||
|
gtk_table_attach_defaults (GTK_TABLE (table), label, 0, 1, 3, 4);
|
||||||
|
|
||||||
|
yalign_spin = gtk_spin_button_new_with_range (0.0, 1.0, 0.1);
|
||||||
|
g_signal_connect (G_OBJECT (yalign_spin), "value-changed", G_CALLBACK (spin_yalign_cb), frame);
|
||||||
|
gtk_spin_button_set_value (GTK_SPIN_BUTTON (yalign_spin), GTK_FRAME (frame)->label_yalign);
|
||||||
|
gtk_table_attach_defaults (GTK_TABLE (table), yalign_spin, 1, 2, 3, 4);
|
||||||
|
|
||||||
|
gtk_widget_show_all (window);
|
||||||
|
|
||||||
|
gtk_main ();
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user