mattn / go-gtk

Go binding for GTK
http://mattn.github.com/go-gtk
BSD 3-Clause "New" or "Revised" License
2.12k stars 247 forks source link

SetDefaultSize not taken into account #400

Closed roipoussiere closed 5 years ago

roipoussiere commented 5 years ago

Here is an Hello World program:

package main

import (
        "github.com/mattn/go-gtk/gtk"
)

func main() {
        gtk.Init(nil)
        win := gtk.NewWindow(gtk.WINDOW_TOPLEVEL)

        win.Add(gtk.NewLabel("Hello World"))

        win.SetDefaultSize(600, 400)
        win.SetModal(true)
        win.SetResizable(false)
        win.SetDecorated(false)

        win.ShowAll()
        gtk.Main()
}

although I use win.SetDefaultSize(600, 400), the window is cropped to the size of the content (HelloWorld label), resulting a tiny window.

I wrote an equivalent program that uses https://github.com/gotk3/gotk3 and the window are sized correctly.

I run go 1.12.4 on Linux Manjaro/i3.

mattn commented 5 years ago

You should use window.SetSizeRequest instead (for GTK2). You can confirm this is default behavior of GTK2.

#include <gtk/gtk.h>

int
main(int argc, char* argv[]) {
  GtkWidget* window;
  GtkWidget* label;

  gtk_init(&argc, &argv);

  window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
  g_signal_connect(G_OBJECT(window), "delete-event", gtk_main_quit, window);

  label = gtk_label_new_with_mnemonic("Hello World");
  gtk_container_add(GTK_CONTAINER(window), label);

  gtk_window_set_default_size(GTK_WINDOW(window), 640, 480);
  gtk_window_set_resizable(GTK_WINDOW(window), FALSE);
  gtk_window_set_modal(GTK_WINDOW(window), TRUE);

  gtk_widget_show_all(window);

  gtk_main();
  return 0;
}