Merge branch 'gtk-demo-tweaks' into 'master'

Gtk demo tweaks

See merge request GNOME/gtk!2059
This commit is contained in:
Matthias Clasen 2020-06-07 12:51:34 +00:00
commit 6ff8f1b2fd
17 changed files with 81 additions and 92 deletions

View File

@ -1,7 +1,7 @@
/* Constraints/Interactive
*
* Demonstrate how constraints can be updates during
* user interaction.
* Demonstrate how constraints can be updates during user interaction.
* The vertical edge between the buttons can be dragged with the mouse.
*/
#include <glib/gi18n.h>

View File

@ -1,9 +1,8 @@
/* Cursors
*
* Demonstrates a useful set of available cursors. The cursors shown here are the ones
* defined by CSS, which we assume to be available.
*
* The example shows creating cursors by name or from an image, with or without a fallback.
* Demonstrates a useful set of available cursors. The cursors shown here are the
* ones defined by CSS, which we assume to be available. The example shows creating
* cursors by name or from an image, with or without a fallback.
*/
#include <gtk/gtk.h>

View File

@ -9,6 +9,7 @@
* display the selected item differently from the presentation
* in the popup.
*/
#include <gtk/gtk.h>
@ -242,7 +243,7 @@ do_dropdown (GtkWidget *do_widget)
window = gtk_window_new ();
gtk_window_set_display (GTK_WINDOW (window),
gtk_widget_get_display (do_widget));
gtk_window_set_title (GTK_WINDOW (window), "Drop Down");
gtk_window_set_title (GTK_WINDOW (window), "Drop Downs");
gtk_window_set_resizable (GTK_WINDOW (window), FALSE);
g_object_add_weak_pointer (G_OBJECT (window), (gpointer *)&window);

View File

@ -1,4 +1,4 @@
/* Fixed layout
/* Fixed Layout
*
* GtkFixed is a container that allows placing and transforming
* widgets manually.
@ -126,7 +126,7 @@ create_demo_window (GtkWidget *do_widget)
window = gtk_window_new ();
gtk_window_set_display (GTK_WINDOW (window), gtk_widget_get_display (do_widget));
gtk_window_set_title (GTK_WINDOW (window), "Fixed layout");
gtk_window_set_title (GTK_WINDOW (window), "Fixed Layout");
gtk_window_set_default_size (GTK_WINDOW (window), 600, 400);
g_signal_connect (window, "destroy", G_CALLBACK (close_window), NULL);

View File

@ -1,9 +1,8 @@
/* Flow Box
*
* GtkFlowBox allows flexible and responsive grids which reflow
* as needed and support sorting and filtering.
*
* The children of a GtkFlowBox are regular widgets
* as needed and support sorting and filtering. The children of
* a GtkFlowBox are regular widgets
*
* The dataset used here has 665 colors.
*/

View File

@ -3,10 +3,9 @@
* This demo displays the time in different timezones.
*
* The goal is to show how to set up expressions that track changes
* in objects and make them update widgets.
*
* For that, we create a GtkClock object that updates its time every
* second and then use various ways to display that time.
* in objects and make them update widgets. For that, we create a
* GtkClock object that updates its time every second and then use
* various ways to display that time.
*
* Typically, this will be done using GtkBuilder .ui files with the
* help of the <binding> tag, but this demo shows the code that runs
@ -41,7 +40,8 @@ enum {
/* This function returns the current time in the clock's timezone.
* Note that this returns a new object every time, so we need to
* remember to unref it after use. */
* remember to unref it after use.
*/
static GDateTime *
gtk_clock_get_time (GtkClock *clock)
{
@ -51,10 +51,11 @@ gtk_clock_get_time (GtkClock *clock)
return g_date_time_new_now_local ();
}
/* Here, we implement the functionality required by the GdkPaintable interface.
* This way we have a trivial way to display an analog clock.
* It also allows demonstrating how to directly use objects in the listview
* later by making this object do something interesting. */
/* Here, we implement the functionality required by the GdkPaintable
* interface. This way we have a trivial way to display an analog clock.
* It also allows demonstrating how to directly use objects in the
* listview later by making this object do something interesting.
*/
static void
gtk_clock_snapshot (GdkPaintable *paintable,
GdkSnapshot *snapshot,
@ -68,26 +69,31 @@ gtk_clock_snapshot (GdkPaintable *paintable,
#define BLACK ((GdkRGBA) { 0, 0, 0, 1 })
/* save/restore() is necessary so we can undo the transforms we start
* out with. */
* out with.
*/
gtk_snapshot_save (snapshot);
/* First, we move the (0, 0) point to the center of the area so
* we can draw everything relative to it. */
* we can draw everything relative to it.
*/
gtk_snapshot_translate (snapshot, &GRAPHENE_POINT_INIT (width / 2, height / 2));
/* Next we scale it, so that we can pretend that the clock is
* 100px in size. That way, we don't need to do any complicated
* math later.
* We use MIN() here so that we use the smaller dimension for sizing.
* That way we don't overdraw but keep the aspect ratio. */
* math later. We use MIN() here so that we use the smaller
* dimension for sizing. That way we don't overdraw but keep
* the aspect ratio.
*/
gtk_snapshot_scale (snapshot, MIN (width, height) / 100.0, MIN (width, height) / 100.0);
/* Now we have a circle with diameter 100px (and radius 50px) that
* has its (0, 0) point at the center.
* Let's draw a simple clock into it. */
/* Now we have a circle with diameter 100px (and radius 50px) that
* has its (0, 0) point at the center. Let's draw a simple clock into it.
*/
time = gtk_clock_get_time (self);
/* First, draw a circle. This is a neat little trick to draw a circle
* without requiring Cairo. */
* without requiring Cairo.
*/
gsk_rounded_rect_init_from_rect (&outline, &GRAPHENE_RECT_INIT(-50, -50, 100, 100), 50);
gtk_snapshot_append_border (snapshot,
&outline,
@ -95,9 +101,11 @@ gtk_clock_snapshot (GdkPaintable *paintable,
(GdkRGBA [4]) { BLACK, BLACK, BLACK, BLACK });
/* Next, draw the hour hand.
* We do this using tranforms again: Instead of computing where the angle points
* to, we just rotate everything and then draw the hand as if if was :00.
* We don't even need to care about am/pm here because rotations just work. */
* We do this using tranforms again: Instead of computing where the angle
* points to, we just rotate everything and then draw the hand as if it
* was :00. We don't even need to care about am/pm here because rotations
* just work.
*/
gtk_snapshot_save (snapshot);
gtk_snapshot_rotate (snapshot, 30 * g_date_time_get_hour (time) + 0.5 * g_date_time_get_minute (time));
gsk_rounded_rect_init_from_rect (&outline, &GRAPHENE_RECT_INIT(-2, -23, 4, 25), 2);
@ -107,7 +115,8 @@ gtk_clock_snapshot (GdkPaintable *paintable,
gtk_snapshot_restore (snapshot);
/* And the same as above for the minute hand. Just make this one longer
* so people can tell the hands apart. */
* so people can tell the hands apart.
*/
gtk_snapshot_save (snapshot);
gtk_snapshot_rotate (snapshot, 6 * g_date_time_get_minute (time));
gsk_rounded_rect_init_from_rect (&outline, &GRAPHENE_RECT_INIT(-2, -43, 4, 45), 2);
@ -125,8 +134,9 @@ gtk_clock_snapshot (GdkPaintable *paintable,
gtk_snapshot_pop (snapshot);
gtk_snapshot_restore (snapshot);
/* And finally, don't forget to restore the initial save() that we did for
* the initial transformations. */
/* And finally, don't forget to restore the initial save() that
* we did for the initial transformations.
*/
gtk_snapshot_restore (snapshot);
g_date_time_unref (time);
@ -145,10 +155,9 @@ gtk_clock_get_intrinsic_height (GdkPaintable *paintable)
return 100;
}
/* Initialize the paintable interface. This way we turn our clock objects
* into objects that can be drawn.
* There are more functions to this interface to define desired size,
* but this is enough.
/* Initialize the paintable interface. This way we turn our clocks
* into objects that can be drawn. There are more functions to this
* interface to define desired size, but this is enough.
*/
static void
gtk_clock_paintable_init (GdkPaintableInterface *iface)
@ -158,8 +167,9 @@ gtk_clock_paintable_init (GdkPaintableInterface *iface)
iface->get_intrinsic_height = gtk_clock_get_intrinsic_height;
}
/* Finally, we define the type. The important part is adding the paintable
* interface, so GTK knows that this object can indeed be drawm.
/* Finally, we define the type. The important part is adding the
* paintable interface, so GTK knows that this object can indeed
* be drawn.
*/
G_DEFINE_TYPE_WITH_CODE (GtkClock, gtk_clock, G_TYPE_OBJECT,
G_IMPLEMENT_INTERFACE (GDK_TYPE_PAINTABLE,
@ -221,11 +231,14 @@ gtk_clock_set_property (GObject *object,
/* This is the list of all the ticking clocks */
static GSList *ticking_clocks = NULL;
/* This is the id of the timeout source that is updating all ticking clocks */
/* This is the ID of the timeout source that is updating all
* ticking clocks.
*/
static guint ticking_clock_id = 0;
/* Every second, this function is called to tell everybody that the
* clocks are ticking.
/* Every second, this function is called to tell everybody that
* the clocks are ticking.
*/
static gboolean
gtk_clock_tick (gpointer unused)
@ -240,6 +253,7 @@ gtk_clock_tick (gpointer unused)
* so notify about that.
*/
g_object_notify_by_pspec (G_OBJECT (clock), properties[PROP_TIME]);
/* We will also draw the hands of the clock differently.
* So notify about that, too.
*/
@ -343,6 +357,9 @@ create_clocks_model (void)
clock = gtk_clock_new ("San Francisco", g_time_zone_new ("America/Los_Angeles"));
g_list_store_append (result, clock);
g_object_unref (clock);
clock = gtk_clock_new ("Xalapa", g_time_zone_new ("America/Mexico_City"));
g_list_store_append (result, clock);
g_object_unref (clock);
clock = gtk_clock_new ("Boston", g_time_zone_new ("America/New_York"));
g_list_store_append (result, clock);
g_object_unref (clock);

View File

@ -6,7 +6,7 @@
* and sort the data in various ways. The controls for
* this are implemented using GtkDropDown.
*
* The dataset used here has 9283 items.
* The dataset used here has 9283 items.
*/
#include <gtk/gtk.h>

View File

@ -11,7 +11,7 @@
* A GtkNoSelectionModel is used to make sure no item in the list can be
* selected. All other interactions with the items is still possible.
*
* The dataset used here has 70000 items.
* The dataset used here has 70000 items.
*/
#include <gtk/gtk.h>

View File

@ -599,7 +599,7 @@ display_image (const char *resource)
{
GtkWidget *sw, *image;
image = gtk_image_new_from_resource (resource);
image = gtk_picture_new_for_resource (resource);
gtk_widget_set_halign (image, GTK_ALIGN_CENTER);
gtk_widget_set_valign (image, GTK_ALIGN_CENTER);
sw = gtk_scrolled_window_new (NULL, NULL);
@ -1040,7 +1040,7 @@ activate (GApplication *app)
listmodel = create_demo_model ();
treemodel = gtk_tree_list_model_new (FALSE,
G_LIST_MODEL (listmodel),
FALSE,
TRUE,
get_child_model,
NULL,
NULL);

View File

@ -5,7 +5,7 @@ Text <span color="gray">c<span color="green">o</span>l<span color="tomato">o</sp
Colorful <span underline="low" underline-color="blue"><span underline="double" underline-color="red">under</span>lines</span> and <span background="pink"><span underline="error">mo</span><span underline="error" underline-color="green">re</span></span>
Colorful <span strikethrough="true" strikethrough-color="magenta">strikethroughs</span>
Colorful <span strikethrough="true" strikethrough-color="magenta">strikethroughs</span> and <span overline="single" overline_color="green">overlines</span>
Superscripts and subscripts: 𝜀<span rise="-6000" size="x-small" font_desc="italic">0</span> = 𝜔<span rise="8000" size="smaller">𝜔<span rise="14000" size="smaller">𝜔<span rise="20000">.<span rise="23000">.<span rise="26000">.</span></span></span></span></span>

View File

@ -1,4 +1,4 @@
/* Sliding puzzle
/* Sliding Puzzle
*
* This demo demonstrates how to use gestures and paintables to create a
* small sliding puzzle game.

View File

@ -96,8 +96,7 @@ change_theme (GtkWidget *widget,
GdkFrameClock *frame_clock,
gpointer data)
{
GtkBuilder *builder = data;
GtkWidget *label;
GtkWidget *label = data;
Theme next = themes[theme++ % G_N_ELEMENTS (themes)];
char *name;
@ -110,7 +109,6 @@ change_theme (GtkWidget *widget,
gtk_window_set_title (GTK_WINDOW (widget), name);
g_free (name);
label = GTK_WIDGET (gtk_builder_get_object (builder, "fps"));
if (frame_clock)
{
char *fps;
@ -198,6 +196,7 @@ do_themes (GtkWidget *do_widget)
GtkBuilder *builder;
GtkWidget *header;
GtkWidget *button;
GtkWidget *label;
GtkGesture *gesture;
builder = gtk_builder_new_from_resource ("/themes/themes.ui");
@ -207,13 +206,17 @@ do_themes (GtkWidget *do_widget)
gtk_widget_get_display (do_widget));
header = GTK_WIDGET (gtk_builder_get_object (builder, "header"));
label = GTK_WIDGET (gtk_builder_get_object (builder, "fps"));
gesture = gtk_gesture_click_new ();
g_signal_connect (gesture, "pressed", G_CALLBACK (clicked), builder);
g_signal_connect (gesture, "pressed", G_CALLBACK (clicked), label);
gtk_widget_add_controller (header, GTK_EVENT_CONTROLLER (gesture));
button = GTK_WIDGET (gtk_builder_get_object (builder, "toggle"));
g_signal_connect (button, "notify::active", G_CALLBACK (toggle_cycle), builder);
g_signal_connect (button, "notify::active", G_CALLBACK (toggle_cycle), label);
gtk_widget_realize (window);
g_object_unref (builder);
}
if (!gtk_widget_get_visible (window))

View File

@ -1527,7 +1527,6 @@ get_layout (GtkCellRendererText *celltext,
uline = PANGO_UNDERLINE_DOUBLE;
break;
#if PANGO_VERSION_CHECK(1,45,0)
case PANGO_UNDERLINE_SINGLE_LINE:
uline = PANGO_UNDERLINE_DOUBLE_LINE;
break;
@ -1535,7 +1534,6 @@ get_layout (GtkCellRendererText *celltext,
case PANGO_UNDERLINE_DOUBLE_LINE:
case PANGO_UNDERLINE_ERROR_LINE:
break;
#endif
case PANGO_UNDERLINE_DOUBLE:
case PANGO_UNDERLINE_LOW:

View File

@ -1241,7 +1241,6 @@ attribute_from_text (GtkBuilder *builder,
if (gtk_builder_value_from_string_type (builder, G_TYPE_INT, value, &val, error))
attribute = pango_attr_background_alpha_new ((guint16)g_value_get_int (&val));
break;
#if PANGO_VERSION_CHECK(1,44,0)
case PANGO_ATTR_ALLOW_BREAKS:
if (gtk_builder_value_from_string_type (builder, G_TYPE_BOOLEAN, value, &val, error))
attribute = pango_attr_allow_breaks_new (g_value_get_boolean (&val));
@ -1254,8 +1253,6 @@ attribute_from_text (GtkBuilder *builder,
if (gtk_builder_value_from_string_type (builder, G_TYPE_BOOLEAN, value, &val, error))
attribute = pango_attr_insert_hyphens_new (g_value_get_boolean (&val));
break;
#endif
#if PANGO_VERSION_CHECK(1,45,0)
case PANGO_ATTR_OVERLINE:
if (gtk_builder_value_from_string_type (builder, PANGO_TYPE_OVERLINE, value, &val, NULL))
attribute = pango_attr_overline_new (g_value_get_enum (&val));
@ -1269,7 +1266,6 @@ attribute_from_text (GtkBuilder *builder,
color->blue * 65535);
}
break;
#endif
case PANGO_ATTR_INVALID:
default:
break;

View File

@ -4772,7 +4772,6 @@ get_tag_for_attributes (PangoAttrIterator *iter)
g_object_set (tag, "underline-rgba", &rgba, NULL);
}
#if PANGO_VERSION_CHECK(1,45,0)
attr = pango_attr_iterator_get (iter, PANGO_ATTR_OVERLINE);
if (attr)
g_object_set (tag, "overline", ((PangoAttrInt*)attr)->value, NULL);
@ -4790,7 +4789,6 @@ get_tag_for_attributes (PangoAttrIterator *iter)
rgba.alpha = 1.;
g_object_set (tag, "overline-rgba", &rgba, NULL);
}
#endif
attr = pango_attr_iterator_get (iter, PANGO_ATTR_STRIKETHROUGH);
if (attr)

View File

@ -1597,7 +1597,6 @@ add_generic_attrs (GtkTextLayout *layout,
pango_attr_list_insert (attrs, attr);
}
#if PANGO_VERSION_CHECK(1,45,0)
if (appearance->overline != PANGO_OVERLINE_NONE)
{
attr = pango_attr_overline_new (appearance->overline);
@ -1619,7 +1618,6 @@ add_generic_attrs (GtkTextLayout *layout,
pango_attr_list_insert (attrs, attr);
}
#endif
if (appearance->strikethrough)
{
@ -2140,7 +2138,6 @@ add_preedit_attrs (GtkTextLayout *layout,
gdk_rgba_free (appearance.underline_rgba);
appearance.underline_rgba = gdk_rgba_copy (&rgba);
break;
#if PANGO_VERSION_CHECK(1,45,0)
case PANGO_ATTR_OVERLINE:
appearance.overline = ((PangoAttrInt *)attr)->value;
break;
@ -2150,7 +2147,6 @@ add_preedit_attrs (GtkTextLayout *layout,
gdk_rgba_free (appearance.overline_rgba);
appearance.overline_rgba = gdk_rgba_copy (&rgba);
break;
#endif
case PANGO_ATTR_STRIKETHROUGH:
appearance.strikethrough = ((PangoAttrInt *)attr)->value;
break;

View File

@ -117,10 +117,8 @@ enum {
PROP_RIGHT_MARGIN,
PROP_UNDERLINE,
PROP_UNDERLINE_RGBA,
#if PANGO_VERSION_CHECK(1,45,0)
PROP_OVERLINE,
PROP_OVERLINE_RGBA,
#endif
PROP_RISE,
PROP_BACKGROUND_FULL_HEIGHT,
PROP_LANGUAGE,
@ -161,10 +159,8 @@ enum {
PROP_RIGHT_MARGIN_SET,
PROP_UNDERLINE_SET,
PROP_UNDERLINE_RGBA_SET,
#if PANGO_VERSION_CHECK(1,45,0)
PROP_OVERLINE_SET,
PROP_OVERLINE_RGBA_SET,
#endif
PROP_RISE_SET,
PROP_BACKGROUND_FULL_HEIGHT_SET,
PROP_LANGUAGE_SET,
@ -514,7 +510,6 @@ gtk_text_tag_class_init (GtkTextTagClass *klass)
GDK_TYPE_RGBA,
GTK_PARAM_READWRITE));
#if PANGO_VERSION_CHECK(1,45,0)
g_object_class_install_property (object_class,
PROP_OVERLINE,
g_param_spec_enum ("overline",
@ -531,7 +526,6 @@ gtk_text_tag_class_init (GtkTextTagClass *klass)
P_("Color of overline for this text"),
GDK_TYPE_RGBA,
GTK_PARAM_READWRITE));
#endif
/**
* GtkTextTag:strikethrough-rgba:
@ -793,7 +787,6 @@ gtk_text_tag_class_init (GtkTextTagClass *klass)
P_("Underline RGBA set"),
P_("Whether this tag affects underlining color"));
#if PANGO_VERSION_CHECK(1,45,0)
ADD_SET_PROP ("overline-set", PROP_OVERLINE_SET,
P_("Overline set"),
P_("Whether this tag affects overlining"));
@ -801,7 +794,6 @@ gtk_text_tag_class_init (GtkTextTagClass *klass)
ADD_SET_PROP ("overline-rgba-set", PROP_OVERLINE_RGBA_SET,
P_("Overline RGBA set"),
P_("Whether this tag affects overlining color"));
#endif
/**
* GtkTextTag:strikethrough-rgba-set:
@ -929,7 +921,6 @@ set_underline_rgba (GtkTextTag *tag,
}
}
#if PANGO_VERSION_CHECK(1,45,0)
static void
set_overline_rgba (GtkTextTag *tag,
const GdkRGBA *rgba)
@ -959,7 +950,6 @@ set_overline_rgba (GtkTextTag *tag,
}
}
}
#endif
static void
set_strikethrough_rgba (GtkTextTag *tag,
@ -1485,7 +1475,6 @@ gtk_text_tag_set_property (GObject *object,
}
break;
#if PANGO_VERSION_CHECK(1,45,0)
case PROP_OVERLINE:
priv->overline_set = TRUE;
priv->values->appearance.overline = g_value_get_enum (value);
@ -1498,7 +1487,6 @@ gtk_text_tag_set_property (GObject *object,
set_overline_rgba (text_tag, color);
}
break;
#endif
case PROP_RISE:
priv->rise_set = TRUE;
@ -1702,7 +1690,6 @@ gtk_text_tag_set_property (GObject *object,
priv->underline_rgba_set = g_value_get_boolean (value);
break;
#if PANGO_VERSION_CHECK(1,45,0)
case PROP_OVERLINE_SET:
priv->overline_set = g_value_get_boolean (value);
break;
@ -1710,7 +1697,6 @@ gtk_text_tag_set_property (GObject *object,
case PROP_OVERLINE_RGBA_SET:
priv->overline_rgba_set = g_value_get_boolean (value);
break;
#endif
case PROP_RISE_SET:
priv->rise_set = g_value_get_boolean (value);
@ -1913,7 +1899,6 @@ gtk_text_tag_get_property (GObject *object,
g_value_set_boxed (value, priv->values->appearance.underline_rgba);
break;
#if PANGO_VERSION_CHECK(1,45,0)
case PROP_OVERLINE:
g_value_set_enum (value, priv->values->appearance.overline);
break;
@ -1922,7 +1907,6 @@ gtk_text_tag_get_property (GObject *object,
if (priv->overline_rgba_set)
g_value_set_boxed (value, priv->values->appearance.overline_rgba);
break;
#endif
case PROP_RISE:
g_value_set_int (value, priv->values->appearance.rise);
@ -2056,7 +2040,6 @@ gtk_text_tag_get_property (GObject *object,
g_value_set_boolean (value, priv->underline_rgba_set);
break;
#if PANGO_VERSION_CHECK(1,45,0)
case PROP_OVERLINE_SET:
g_value_set_boolean (value, priv->overline_set);
break;
@ -2064,7 +2047,6 @@ gtk_text_tag_get_property (GObject *object,
case PROP_OVERLINE_RGBA_SET:
g_value_set_boolean (value, priv->overline_rgba_set);
break;
#endif
case PROP_RISE_SET:
g_value_set_boolean (value, priv->rise_set);