mirror of
https://gitlab.gnome.org/GNOME/gtk.git
synced 2025-01-14 06:10:21 +00:00
testtooltips: Add static tooltip
Just a widget class emulating the tooltip look by calling itself "tooltip" in the css node tree and adding the .background style class.
This commit is contained in:
parent
ae5d3a20a8
commit
35670a1ee6
@ -23,6 +23,38 @@
|
|||||||
|
|
||||||
#include <gtk/gtk.h>
|
#include <gtk/gtk.h>
|
||||||
|
|
||||||
|
typedef struct _MyTooltip MyTooltip;
|
||||||
|
typedef struct _MyTooltipClass MyTooltipClass;
|
||||||
|
|
||||||
|
|
||||||
|
struct _MyTooltip
|
||||||
|
{
|
||||||
|
GtkBin parent_instance;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct _MyTooltipClass
|
||||||
|
{
|
||||||
|
GtkBinClass parent_class;
|
||||||
|
};
|
||||||
|
|
||||||
|
G_DEFINE_TYPE (MyTooltip, my_tooltip, GTK_TYPE_BIN)
|
||||||
|
|
||||||
|
static void
|
||||||
|
my_tooltip_init (MyTooltip *tt)
|
||||||
|
{
|
||||||
|
GtkWidget *label = gtk_label_new ("Some text in a tooltip");
|
||||||
|
|
||||||
|
gtk_container_add (GTK_CONTAINER (tt), label);
|
||||||
|
|
||||||
|
gtk_style_context_add_class (gtk_widget_get_style_context (GTK_WIDGET (tt)), "background");
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
my_tooltip_class_init (MyTooltipClass *tt_class)
|
||||||
|
{
|
||||||
|
gtk_widget_class_set_css_name (GTK_WIDGET_CLASS (tt_class), "tooltip");
|
||||||
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
query_tooltip_cb (GtkWidget *widget,
|
query_tooltip_cb (GtkWidget *widget,
|
||||||
gint x,
|
gint x,
|
||||||
@ -248,6 +280,7 @@ main (int argc, char *argv[])
|
|||||||
GtkWidget *drawing_area;
|
GtkWidget *drawing_area;
|
||||||
GtkWidget *button;
|
GtkWidget *button;
|
||||||
GtkWidget *label;
|
GtkWidget *label;
|
||||||
|
GtkWidget *tooltip;
|
||||||
|
|
||||||
GtkWidget *tooltip_window;
|
GtkWidget *tooltip_window;
|
||||||
GtkWidget *tooltip_button;
|
GtkWidget *tooltip_button;
|
||||||
@ -272,6 +305,13 @@ main (int argc, char *argv[])
|
|||||||
box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 3);
|
box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 3);
|
||||||
gtk_container_add (GTK_CONTAINER (window), box);
|
gtk_container_add (GTK_CONTAINER (window), box);
|
||||||
|
|
||||||
|
tooltip = g_object_new (my_tooltip_get_type (), NULL);
|
||||||
|
gtk_widget_set_margin_top (tooltip, 20);
|
||||||
|
gtk_widget_set_margin_bottom (tooltip, 20);
|
||||||
|
gtk_widget_set_halign (tooltip, GTK_ALIGN_CENTER);
|
||||||
|
gtk_container_add (GTK_CONTAINER (box), tooltip);
|
||||||
|
|
||||||
|
|
||||||
/* A check button using the tooltip-markup property */
|
/* A check button using the tooltip-markup property */
|
||||||
button = gtk_check_button_new_with_label ("This one uses the tooltip-markup property");
|
button = gtk_check_button_new_with_label ("This one uses the tooltip-markup property");
|
||||||
gtk_widget_set_tooltip_text (button, "Hello, I am a static tooltip.");
|
gtk_widget_set_tooltip_text (button, "Hello, I am a static tooltip.");
|
||||||
|
Loading…
Reference in New Issue
Block a user