From 32480a65c257354ab8f4ff0c44c3a8240d3c5274 Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Sat, 24 May 2014 21:28:28 -0400 Subject: [PATCH] Resolved GtkEntry and GtkProgressBar resizing issues; decided from observing how they do padding that worrying about padding is counterproductive for now. --- gtkcalls_unix.go | 35 +++++++++++++++++++++++++++++++++-- todo.md | 2 +- 2 files changed, 34 insertions(+), 3 deletions(-) diff --git a/gtkcalls_unix.go b/gtkcalls_unix.go index 8c00ff1..27c5765 100644 --- a/gtkcalls_unix.go +++ b/gtkcalls_unix.go @@ -11,6 +11,26 @@ import ( ) // #include "gtk_unix.h" +// /* because cgo doesn't like ... */ +// static inline char *gtkProgressBarAllowArbitraryResize(GtkWidget *pbar) +// { +// /* min-horizontal-bar-width is a style property; we do it through CSS */ +// /* thanks tristan in irc.gimp.net/#gtk+ */ +// /* TODO find out how to make it an application default */ +// static gchar style[] = +// "* {\n" +// " -GtkProgressBar-min-horizontal-bar-width: 1;\n" +// "}\n"; +// GtkCssProvider *provider; +// GError *err = NULL; +// +// provider = gtk_css_provider_new(); +// if (gtk_css_provider_load_from_data(provider, style, -1, &err) == FALSE) +// return (char *) g_strdup(err->message); +// gtk_style_context_add_provider(gtk_widget_get_style_context(pbar), +// (GtkStyleProvider *) provider, GTK_STYLE_PROVIDER_PRIORITY_USER); +// return NULL; +// } import "C" func gtk_init() error { @@ -181,7 +201,11 @@ func gtkComboBoxLen(widget *C.GtkWidget) int { } func gtk_entry_new() *C.GtkWidget { - return C.gtk_entry_new() + e := C.gtk_entry_new() + // allows the GtkEntry to be resized with the window smaller than what it thinks the size should be + // thanks to Company in irc.gimp.net/#gtk+ + C.gtk_entry_set_width_chars(togtkentry(e), 0) + return e } func gtkPasswordEntryNew() *C.GtkWidget { @@ -231,7 +255,14 @@ func gtk_widget_get_preferred_size(widget *C.GtkWidget) (minWidth int, minHeight } func gtk_progress_bar_new() *C.GtkWidget { - return C.gtk_progress_bar_new() + p := C.gtk_progress_bar_new() + // otherwise the progress bar can't be resized smaller than some predetermined size + err := C.gtkProgressBarAllowArbitraryResize(p) + if err != nil { + defer C.g_free(C.gpointer(unsafe.Pointer(err))) + panic(fmt.Errorf("error allowing ProgressBar to be arbitrarily resized: %s", C.GoString(err))) + } + return p } func gtk_progress_bar_set_fraction(w *C.GtkWidget, percent int) { diff --git a/todo.md b/todo.md index 6d619e3..1691936 100644 --- a/todo.md +++ b/todo.md @@ -41,7 +41,7 @@ super ultra important things: - make sure the preferred size of a Listbox is the minimum size needed to display everything on all platforms (capped at the screen height, of course?) - same for Area, using the Area's size (this will be easier) - make sure the image drawn on an Area looks correct on all platforms (is not cropped incorrectly or blurred) -- when resizing a GTK+ window smaller than a certain size, the controls inside will start clipping in bizarre ways (progress bars/entry lines will just cut off; editable comboboxes will stretch slightly longer than noneditable ones; the horizontal scrollbar in Area will disappear smoothly; etc.) +- when resizing a GTK+ window smaller than a certain size, the controls inside will start clipping in bizarre ways (comboboxes will just cut off; the horizontal scrollbar in Area will disappear smoothly; etc.) - check my logs; someone in irc.gimp.net/#gtk+ answered this (or provided an answer) - see update 18 March 2014 in README - resizing seems to be completely and totally broken in the Wayland backend