コード例 #1
0
ファイル: animated-revealing.c プロジェクト: Vasileus/gtk
int
main(int argc, char **argv)
{
  GtkWidget *window, *revealer, *grid, *widget;
  GtkCssProvider *cssprovider;
  GError *error = NULL;
  guint x, y;

  GOptionContext *context = g_option_context_new (NULL);
  g_option_context_add_main_entries (context, options, NULL);
  frame_stats_add_options (g_option_context_get_main_group (context));
  g_option_context_add_group (context,
                              gtk_get_option_group (TRUE));

  if (!g_option_context_parse (context, &argc, &argv, &error))
    {
      g_printerr ("Option parsing failed: %s\n", error->message);
      return 1;
    }

  window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  frame_stats_ensure (GTK_WINDOW (window));

  revealer = gtk_revealer_new ();
  gtk_widget_set_valign (revealer, GTK_ALIGN_START);
  gtk_revealer_set_transition_type (GTK_REVEALER (revealer), GTK_REVEALER_TRANSITION_TYPE_SLIDE_DOWN);
  gtk_revealer_set_transition_duration (GTK_REVEALER (revealer), reveal_time * 1000);
  gtk_revealer_set_reveal_child (GTK_REVEALER (revealer), TRUE);
  g_signal_connect_after (revealer, "map", G_CALLBACK (toggle_reveal), NULL);
  g_signal_connect_after (revealer, "notify::child-revealed", G_CALLBACK (toggle_reveal), NULL);
  gtk_container_add (GTK_CONTAINER (window), revealer);

  grid = gtk_grid_new ();
  gtk_container_add (GTK_CONTAINER (revealer), grid);

  cssprovider = gtk_css_provider_new ();
  gtk_css_provider_load_from_data (cssprovider, "* { padding: 2px; text-shadow: 5px 5px 2px grey; }", -1, NULL);

  for (x = 0; x < 10; x++)
    {
      for (y = 0; y < 20; y++)
        {
          widget = gtk_label_new ("Hello World");
          gtk_style_context_add_provider (gtk_widget_get_style_context (widget),
                                          GTK_STYLE_PROVIDER (cssprovider),
                                          GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
          gtk_grid_attach (GTK_GRID (grid), widget, x, y, 1, 1);
        }
    }

  gtk_widget_show_all (window);

  gtk_main ();

  return 0;
}
コード例 #2
0
static void
setup_header_bar (GtkWidget   *window,
                  VteTerminal *vtterm,
                  gboolean     show_maximized_title)
{
    /*
     * Using the default GtkHeaderBar title/subtitle widget makes the bar
     * too thick to look nice for a terminal, so set a custom widget.
     */
    GtkWidget *hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 5);
    const gchar *title = gtk_window_get_title (GTK_WINDOW (window));
    GtkWidget *label = gtk_label_new (title ? title : "dwt");
    g_object_bind_property (G_OBJECT (vtterm), "window-title",
                            G_OBJECT (label), "label",
                            G_BINDING_DEFAULT);

    GtkWidget *header = gtk_header_bar_new ();
    gtk_header_bar_set_show_close_button (GTK_HEADER_BAR (header), TRUE);
    gtk_header_bar_set_has_subtitle (GTK_HEADER_BAR (header), FALSE);
    gtk_header_bar_set_custom_title (GTK_HEADER_BAR (header), label);

    GtkWidget *button = gtk_button_new_from_icon_name ("tab-new-symbolic",
                                                       GTK_ICON_SIZE_BUTTON);
    gtk_button_set_relief (GTK_BUTTON (button), GTK_RELIEF_NONE);
    gtk_actionable_set_action_name (GTK_ACTIONABLE (button), "app.new-terminal");
    gtk_header_bar_pack_start (GTK_HEADER_BAR (header), button);

    GtkWidget *revealer = gtk_revealer_new ();
    gtk_container_add (GTK_CONTAINER (revealer),
                       gtk_image_new_from_icon_name ("software-update-urgent-symbolic",
                                                     GTK_ICON_SIZE_BUTTON));
    gtk_revealer_set_transition_duration (GTK_REVEALER (revealer), 500);
    gtk_revealer_set_transition_type (GTK_REVEALER (revealer),
                                      GTK_REVEALER_TRANSITION_TYPE_CROSSFADE);
    gtk_header_bar_pack_end (GTK_HEADER_BAR (header), revealer);

    g_signal_connect (G_OBJECT (vtterm), "bell",
                      G_CALLBACK (header_bar_term_beeped), revealer);
    g_object_bind_property (G_OBJECT (window), "urgency-hint",
                            G_OBJECT (revealer), "reveal-child",
                            G_BINDING_DEFAULT);

    gtk_window_set_titlebar (GTK_WINDOW (window), header);

    /* Hide the header bar when the window is maximized. */
    if (!show_maximized_title) {
        g_object_bind_property (G_OBJECT (window), "is-maximized",
                                G_OBJECT (header), "visible",
                                G_BINDING_INVERT_BOOLEAN);
    }
}
コード例 #3
0
static void
gtk_revealer_set_property (GObject      *object,
                           guint         property_id,
                           const GValue *value,
                           GParamSpec   *pspec)
{
  GtkRevealer *revealer = GTK_REVEALER (object);

  switch (property_id)
    {
    case PROP_TRANSITION_TYPE:
      gtk_revealer_set_transition_type (revealer, g_value_get_enum (value));
      break;
    case PROP_TRANSITION_DURATION:
      gtk_revealer_set_transition_duration (revealer, g_value_get_uint (value));
      break;
    case PROP_REVEAL_CHILD:
      gtk_revealer_set_reveal_child (revealer, g_value_get_boolean (value));
      break;
    default:
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
      break;
    }
}
コード例 #4
0
ファイル: testrevealer.c プロジェクト: 3v1n0/gtk
gint
main (gint argc,
      gchar ** argv)
{
  GtkWidget *window, *revealer, *box, *widget, *entry;

  gtk_init (&argc, &argv);

  window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  gtk_widget_set_size_request (window, 300, 300);

  box = gtk_grid_new ();
  gtk_container_add (GTK_CONTAINER (window), box);

  widget = gtk_label_new ("Some filler text to avoid\nresizing of the window");
  gtk_widget_set_margin_top (widget, 10);
  gtk_widget_set_margin_bottom (widget, 10);
  gtk_widget_set_margin_start (widget, 10);
  gtk_widget_set_margin_end (widget, 10);
  gtk_grid_attach (GTK_GRID (box), widget, 1, 1, 1, 1);

  widget = gtk_label_new ("Some filler text to avoid\nresizing of the window");
  gtk_widget_set_margin_top (widget, 10);
  gtk_widget_set_margin_bottom (widget, 10);
  gtk_widget_set_margin_start (widget, 10);
  gtk_widget_set_margin_end (widget, 10);
  gtk_grid_attach (GTK_GRID (box), widget, 3, 3, 1, 1);

  widget = gtk_toggle_button_new_with_label ("None");
  gtk_grid_attach (GTK_GRID (box), widget, 0, 0, 1, 1);
  revealer = gtk_revealer_new ();
  gtk_widget_set_halign (revealer, GTK_ALIGN_START);
  gtk_widget_set_valign (revealer, GTK_ALIGN_START);
  entry = gtk_entry_new ();
  gtk_entry_set_text (GTK_ENTRY (entry), "00000");
  gtk_container_add (GTK_CONTAINER (revealer), entry);
  g_object_bind_property (widget, "active", revealer, "reveal-child", 0);
  gtk_revealer_set_transition_type (GTK_REVEALER (revealer), GTK_REVEALER_TRANSITION_TYPE_NONE);
  gtk_revealer_set_transition_duration (GTK_REVEALER (revealer), 2000);
  gtk_grid_attach (GTK_GRID (box), revealer, 1, 0, 1, 1);

  widget = gtk_toggle_button_new_with_label ("Fade");
  gtk_grid_attach (GTK_GRID (box), widget, 4, 4, 1, 1);
  revealer = gtk_revealer_new ();
  gtk_widget_set_halign (revealer, GTK_ALIGN_END);
  gtk_widget_set_valign (revealer, GTK_ALIGN_END);
  entry = gtk_entry_new ();
  gtk_entry_set_text (GTK_ENTRY (entry), "00000");
  gtk_container_add (GTK_CONTAINER (revealer), entry);
  g_object_bind_property (widget, "active", revealer, "reveal-child", 0);
  gtk_revealer_set_transition_type (GTK_REVEALER (revealer), GTK_REVEALER_TRANSITION_TYPE_CROSSFADE);
  gtk_revealer_set_transition_duration (GTK_REVEALER (revealer), 2000);
  gtk_grid_attach (GTK_GRID (box), revealer, 3, 4, 1, 1);

  widget = gtk_toggle_button_new_with_label ("Right");
  gtk_grid_attach (GTK_GRID (box), widget, 0, 2, 1, 1);
  revealer = gtk_revealer_new ();
  gtk_widget_set_hexpand (revealer, TRUE);
  gtk_widget_set_halign (revealer, GTK_ALIGN_START);
  entry = gtk_entry_new ();
  gtk_entry_set_text (GTK_ENTRY (entry), "12345");
  gtk_container_add (GTK_CONTAINER (revealer), entry);
  g_object_bind_property (widget, "active", revealer, "reveal-child", 0);
  gtk_revealer_set_transition_type (GTK_REVEALER (revealer), GTK_REVEALER_TRANSITION_TYPE_SLIDE_RIGHT);
  gtk_revealer_set_transition_duration (GTK_REVEALER (revealer), 2000);
  gtk_grid_attach (GTK_GRID (box), revealer, 1, 2, 1, 1);

  widget = gtk_toggle_button_new_with_label ("Down");
  gtk_grid_attach (GTK_GRID (box), widget, 2, 0, 1, 1);
  revealer = gtk_revealer_new ();
  gtk_widget_set_vexpand (revealer, TRUE);
  gtk_widget_set_valign (revealer, GTK_ALIGN_START);
  entry = gtk_entry_new ();
  gtk_entry_set_text (GTK_ENTRY (entry), "23456");
  gtk_container_add (GTK_CONTAINER (revealer), entry);
  g_object_bind_property (widget, "active", revealer, "reveal-child", 0);
  gtk_revealer_set_transition_type (GTK_REVEALER (revealer), GTK_REVEALER_TRANSITION_TYPE_SLIDE_DOWN);
  gtk_revealer_set_transition_duration (GTK_REVEALER (revealer), 2000);
  gtk_grid_attach (GTK_GRID (box), revealer, 2, 1, 1, 1);

  widget = gtk_toggle_button_new_with_label ("Left");
  gtk_grid_attach (GTK_GRID (box), widget, 4, 2, 1, 1);
  revealer = gtk_revealer_new ();
  gtk_widget_set_hexpand (revealer, TRUE);
  gtk_widget_set_halign (revealer, GTK_ALIGN_END);
  entry = gtk_entry_new ();
  gtk_entry_set_text (GTK_ENTRY (entry), "34567");
  gtk_container_add (GTK_CONTAINER (revealer), entry);
  g_object_bind_property (widget, "active", revealer, "reveal-child", 0);
  gtk_revealer_set_transition_type (GTK_REVEALER (revealer), GTK_REVEALER_TRANSITION_TYPE_SLIDE_LEFT);
  gtk_revealer_set_transition_duration (GTK_REVEALER (revealer), 2000);
  gtk_grid_attach (GTK_GRID (box), revealer, 3, 2, 1, 1);

  widget = gtk_toggle_button_new_with_label ("Up");
  gtk_grid_attach (GTK_GRID (box), widget, 2, 4, 1, 1);
  revealer = gtk_revealer_new ();
  gtk_widget_set_vexpand (revealer, TRUE);
  gtk_widget_set_valign (revealer, GTK_ALIGN_END);
  entry = gtk_entry_new ();
  gtk_entry_set_text (GTK_ENTRY (entry), "45678");
  gtk_container_add (GTK_CONTAINER (revealer), entry);
  g_object_bind_property (widget, "active", revealer, "reveal-child", 0);
  gtk_revealer_set_transition_type (GTK_REVEALER (revealer), GTK_REVEALER_TRANSITION_TYPE_SLIDE_UP);
  gtk_revealer_set_transition_duration (GTK_REVEALER (revealer), 2000);
  gtk_grid_attach (GTK_GRID (box), revealer, 2, 3, 1, 1);

  gtk_widget_show_all (window);
  gtk_main ();

  gtk_widget_destroy (window);

  return 0;
}
コード例 #5
0
ファイル: infobar.cpp プロジェクト: CodeSmithyIDE/wxWidgets
bool wxInfoBar::Create(wxWindow *parent, wxWindowID winid)
{
    if ( !UseNative() )
        return wxInfoBarGeneric::Create(parent, winid);

    m_impl = new wxInfoBarGTKImpl;

    // this control is created initially hidden
    Hide();
    if ( !CreateBase(parent, winid) )
        return false;

    // create the info bar widget itself
    m_widget = gtk_info_bar_new();
    wxCHECK_MSG( m_widget, false, "failed to create GtkInfoBar" );
    g_object_ref(m_widget);

    // also create a label which will be used to show our message
    m_impl->m_label = gtk_label_new("");
    gtk_widget_show(m_impl->m_label);

    GtkWidget * const
        contentArea = gtk_info_bar_get_content_area(GTK_INFO_BAR(m_widget));
    wxCHECK_MSG( contentArea, false, "failed to get GtkInfoBar content area" );
    gtk_container_add(GTK_CONTAINER(contentArea), m_impl->m_label);

    // finish creation and connect to all the signals we're interested in
    m_parent->DoAddChild(this);

    PostCreation(wxDefaultSize);

    GTKConnectWidget("response", G_CALLBACK(wxgtk_infobar_response));
    GTKConnectWidget("close", G_CALLBACK(wxgtk_infobar_close));

    // Work around GTK+ bug https://bugzilla.gnome.org/show_bug.cgi?id=710888
    // by disabling the transition when showing it: without this, it's not
    // shown at all.
    //
    // Compile-time check is needed because GtkRevealer is new in 3.10.
#if GTK_CHECK_VERSION(3, 10, 0)
    // Run-time check is needed because the bug was introduced in 3.10 and
    // fixed in 3.22.29 (see 6b4d95e86dabfcdaa805fbf068a99e19736a39a4 and a
    // couple of previous commits in GTK+ repository).
    if ( gtk_check_version(3, 10, 0) == NULL &&
            gtk_check_version(3, 22, 29) != NULL )
    {
        GObject* const
            revealer = gtk_widget_get_template_child(GTK_WIDGET(m_widget),
                                                     GTK_TYPE_INFO_BAR,
                                                     "revealer");
        if ( revealer )
        {
            gtk_revealer_set_transition_type(GTK_REVEALER (revealer),
                                             GTK_REVEALER_TRANSITION_TYPE_NONE);
            gtk_revealer_set_transition_duration(GTK_REVEALER (revealer), 0);
        }
    }
#endif // GTK+ >= 3.10

    return true;
}