2013-09-08 20:39:49 +00:00
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
|
|
|
static GtkWidget *
|
|
|
|
create_level_bar (void)
|
|
|
|
{
|
2015-11-11 04:31:33 +00:00
|
|
|
GtkWidget *bar;
|
|
|
|
|
|
|
|
bar = gtk_level_bar_new ();
|
|
|
|
gtk_level_bar_set_min_value (GTK_LEVEL_BAR (bar), 0.0);
|
|
|
|
gtk_level_bar_set_max_value (GTK_LEVEL_BAR (bar), 10.0);
|
2013-09-08 20:39:49 +00:00
|
|
|
|
2015-11-11 04:31:33 +00:00
|
|
|
gtk_level_bar_add_offset_value (GTK_LEVEL_BAR (bar),
|
|
|
|
GTK_LEVEL_BAR_OFFSET_LOW, 1.0);
|
2013-09-08 20:39:49 +00:00
|
|
|
|
2015-11-11 04:31:33 +00:00
|
|
|
gtk_level_bar_add_offset_value (GTK_LEVEL_BAR (bar),
|
|
|
|
GTK_LEVEL_BAR_OFFSET_HIGH, 9.0);
|
2013-09-08 20:39:49 +00:00
|
|
|
|
2015-11-13 11:40:28 +00:00
|
|
|
gtk_level_bar_add_offset_value (GTK_LEVEL_BAR (bar),
|
|
|
|
"full", 10.0);
|
|
|
|
|
2015-11-11 04:31:33 +00:00
|
|
|
gtk_level_bar_add_offset_value (GTK_LEVEL_BAR (bar),
|
|
|
|
"my-offset", 5.0);
|
2013-09-08 20:39:49 +00:00
|
|
|
|
2015-11-11 04:31:33 +00:00
|
|
|
return bar;
|
2013-09-08 20:39:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
add_custom_css (void)
|
|
|
|
{
|
|
|
|
GtkCssProvider *provider;
|
|
|
|
const gchar data[] =
|
2015-11-13 11:40:28 +00:00
|
|
|
"levelbar block.my-offset {"
|
2015-11-11 04:31:33 +00:00
|
|
|
" background: magenta;"
|
2013-09-08 20:39:49 +00:00
|
|
|
"}";
|
|
|
|
|
|
|
|
provider = gtk_css_provider_new ();
|
2016-10-17 14:09:12 +00:00
|
|
|
gtk_css_provider_load_from_data (provider, data, -1);
|
2017-10-31 01:35:21 +00:00
|
|
|
gtk_style_context_add_provider_for_display (gdk_display_get_default (),
|
|
|
|
GTK_STYLE_PROVIDER (provider),
|
|
|
|
GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
|
2013-09-08 20:39:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
increase_level (gpointer data)
|
|
|
|
{
|
|
|
|
GtkLevelBar *bar = data;
|
|
|
|
gdouble value;
|
|
|
|
|
|
|
|
value = gtk_level_bar_get_value (bar);
|
2015-11-11 04:31:33 +00:00
|
|
|
value += 0.1;
|
|
|
|
if (value >= gtk_level_bar_get_max_value (bar))
|
|
|
|
value = gtk_level_bar_get_min_value (bar);
|
2013-09-08 20:39:49 +00:00
|
|
|
gtk_level_bar_set_value (bar, value);
|
|
|
|
|
|
|
|
return G_SOURCE_CONTINUE;
|
|
|
|
}
|
|
|
|
|
2015-11-11 04:31:33 +00:00
|
|
|
static void
|
|
|
|
toggle (GtkSwitch *sw, GParamSpec *pspec, GtkLevelBar *bar)
|
|
|
|
{
|
|
|
|
if (gtk_switch_get_active (sw))
|
|
|
|
gtk_level_bar_set_mode (bar, GTK_LEVEL_BAR_MODE_DISCRETE);
|
|
|
|
else
|
|
|
|
gtk_level_bar_set_mode (bar, GTK_LEVEL_BAR_MODE_CONTINUOUS);
|
|
|
|
}
|
|
|
|
|
2020-02-10 03:24:47 +00:00
|
|
|
static void
|
|
|
|
quit_cb (GtkWidget *widget,
|
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
gboolean *done = data;
|
|
|
|
|
|
|
|
*done = TRUE;
|
|
|
|
|
|
|
|
g_main_context_wakeup (NULL);
|
|
|
|
}
|
|
|
|
|
2013-09-08 20:39:49 +00:00
|
|
|
int
|
|
|
|
main (int argc, char *argv[])
|
|
|
|
{
|
|
|
|
GtkWidget *window;
|
2015-11-11 04:31:33 +00:00
|
|
|
GtkWidget *box;
|
2013-09-08 20:39:49 +00:00
|
|
|
GtkWidget *bar;
|
2015-11-11 04:31:33 +00:00
|
|
|
GtkWidget *box2;
|
|
|
|
GtkWidget *sw;
|
2020-02-10 03:24:47 +00:00
|
|
|
gboolean done = FALSE;
|
2013-09-08 20:39:49 +00:00
|
|
|
|
2016-12-28 13:53:22 +00:00
|
|
|
gtk_init ();
|
2013-09-08 20:39:49 +00:00
|
|
|
|
|
|
|
add_custom_css ();
|
|
|
|
|
2020-02-14 19:55:36 +00:00
|
|
|
window = gtk_window_new ();
|
2013-09-08 20:39:49 +00:00
|
|
|
gtk_window_set_default_size (GTK_WINDOW (window), 500, 100);
|
2015-11-11 04:31:33 +00:00
|
|
|
box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 10);
|
|
|
|
g_object_set (box, "margin", 20, NULL);
|
2013-09-08 20:39:49 +00:00
|
|
|
bar = create_level_bar ();
|
2015-11-11 04:31:33 +00:00
|
|
|
gtk_container_add (GTK_CONTAINER (window), box);
|
|
|
|
gtk_container_add (GTK_CONTAINER (box), bar);
|
|
|
|
box2 = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 10);
|
|
|
|
gtk_container_add (GTK_CONTAINER (box), box2);
|
|
|
|
gtk_container_add (GTK_CONTAINER (box2), gtk_label_new ("Discrete"));
|
|
|
|
sw = gtk_switch_new ();
|
|
|
|
gtk_container_add (GTK_CONTAINER (box2), sw);
|
|
|
|
g_signal_connect (sw, "notify::active", G_CALLBACK (toggle), bar);
|
|
|
|
|
2017-01-19 09:02:04 +00:00
|
|
|
gtk_widget_show (window);
|
2013-09-08 20:39:49 +00:00
|
|
|
|
2020-02-10 03:24:47 +00:00
|
|
|
g_signal_connect (window, "destroy", G_CALLBACK (quit_cb), &done);
|
2014-10-24 21:53:26 +00:00
|
|
|
|
2013-09-08 20:39:49 +00:00
|
|
|
g_timeout_add (100, increase_level, bar);
|
2020-02-10 03:24:47 +00:00
|
|
|
while (!done)
|
|
|
|
g_main_context_iteration (NULL, TRUE);
|
2013-09-08 20:39:49 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|