X-Git-Url: http://nitlanguage.org?ds=sidebyside diff --git a/lib/gtk/v3_4/gtk_core.nit b/lib/gtk/v3_4/gtk_core.nit index b9929f5..c3617f1 100644 --- a/lib/gtk/v3_4/gtk_core.nit +++ b/lib/gtk/v3_4/gtk_core.nit @@ -43,13 +43,19 @@ in "C Header" `{ `} # Initialize the GTK system -fun init_gtk `{ gtk_init(0, NULL); `} +fun gtk_init `{ gtk_init(0, NULL); `} # Hand over control to the GTK event loop -fun run_gtk `{ gtk_main(); `} +fun gtk_main `{ gtk_main(); `} + +# Run a single iteration of the main loop, block until an event is noticed +fun gtk_main_iteration: Bool `{ return gtk_main_iteration(); `} + +# Run a single iteration of the main loop, only block until an event is noticed if `blocking` +fun gtk_main_iteration_do(blocking: Bool): Bool `{ return gtk_main_iteration_do(blocking); `} # Quit the GTK event loop and clean up the system -fun quit_gtk `{ gtk_main_quit(); `} +fun gtk_main_quit `{ gtk_main_quit(); `} interface GtkCallable # return true to stop event processing, false to let it propagate @@ -86,7 +92,8 @@ extern class GtkWidget `{GtkWidget *`} return self == o; `} - fun request_size(width, height: Int) `{ + # Set the minimum dimension of this widget + fun set_size_request(width, height: Int) `{ gtk_widget_set_size_request(self, width, height); `} @@ -131,6 +138,21 @@ extern class GtkWidget `{GtkWidget *`} # Hide the widget (reverse the effects of `show`) fun hide `{ gtk_widget_hide(self); `} + + # Vertical alignement of this widget + fun valign=(value: GtkAlign) `{ gtk_widget_set_valign(self, value); `} + + # Horizontal alignement of this widget + fun halign=(value: GtkAlign) `{ gtk_widget_set_halign(self, value); `} +end + +# How a widget deals with extra space +extern class GtkAlign `{ GtkAlign `} + new fill `{ return GTK_ALIGN_FILL; `} + new start `{ return GTK_ALIGN_START; `} + new align_end `{ return GTK_ALIGN_END; `} + new center `{ return GTK_ALIGN_CENTER; `} + new baseline `{ return GTK_ALIGN_BASELINE; `} end # Base class for widgets which contain other widgets @@ -142,8 +164,9 @@ extern class GtkContainer `{GtkContainer *`} fun add(widget: GtkWidget) `{ gtk_container_add(self, widget); `} + # Remove the widget from the container - fun remove_widget(widget: GtkWidget) `{ + fun remove(widget: GtkWidget) `{ gtk_container_remove(self, widget); `} @@ -156,7 +179,6 @@ extern class GtkContainer `{GtkContainer *`} fun resize_mode=(resize_mode: GtkResizeMode) `{ gtk_container_set_resize_mode(self, resize_mode); `} - end # A container with just one child @@ -193,6 +215,11 @@ extern class GtkWindow `{GtkWindow *`} signal_connect("destroy", to_call, user_data) end + # Resize the window as if the user had done so + fun resize(width, height: Int) `{ + return gtk_window_resize(self, width, height); + `} + fun resizable: Bool `{ return gtk_window_get_resizable(self); `} @@ -290,6 +317,9 @@ extern class GtkWindow `{GtkWindow *`} fun keep_below=(setting: Bool) `{ gtk_window_set_keep_below(self, setting); `} + + # Try to convince the window manage to decorate or not this window + fun decorated=(setting: Bool) `{ gtk_window_set_decorated(self, setting); `} end # A bin with a decorative frame and optional label @@ -301,8 +331,8 @@ extern class GtkFrame `{GtkFrame *`} return (GtkFrame *)gtk_frame_new(String_to_cstring(lbl)); `} - fun frame_label: String `{ - return NativeString_to_s((char *)gtk_frame_get_label(self)); + fun frame_label: String import CString.to_s_with_copy `{ + return CString_to_s_with_copy((char *)gtk_frame_get_label(self)); `} fun frame_label=(lbl: String) import String.to_cstring `{ @@ -427,18 +457,13 @@ end extern class GtkMisc `{GtkMisc *`} super GtkWidget - fun alignment: GtkAlignment is abstract - - fun alignment=(x: Float, y: Float) `{ + fun set_alignment(x, y: Float) `{ gtk_misc_set_alignment(self, x, y); `} - fun padding: GtkAlignment is abstract - - fun padding=(x: Float, y: Float) `{ + fun set_padding(x, y: Float) `{ gtk_misc_set_padding(self, x, y); `} - end # A single line text entry field @@ -450,8 +475,8 @@ extern class GtkEntry `{GtkEntry *`} return (GtkEntry *)gtk_entry_new(); `} - fun text: String import NativeString.to_s_with_copy `{ - return NativeString_to_s_with_copy((char *)gtk_entry_get_text(self)); + fun text: String import CString.to_s_with_copy `{ + return CString_to_s_with_copy((char *)gtk_entry_get_text(self)); `} fun text=(value: String) import String.to_cstring `{ @@ -657,8 +682,8 @@ extern class GtkLabel `{GtkLabel *`} `} # Returns the text of the label - fun text: String import NativeString.to_s `{ - return NativeString_to_s((char*)gtk_label_get_text(self)); + fun text: String import CString.to_s_with_copy `{ + return CString_to_s_with_copy((char*)gtk_label_get_text(self)); `} # Sets the angle of rotation for the label. @@ -672,6 +697,24 @@ extern class GtkLabel `{GtkLabel *`} return gtk_label_get_angle(self); `} + # Set simple formatted text content from a `format` string and the `content` which is escaped + # + # ~~~nitish + # GtkLabel lbl = new GtkLabel("Non-formatted text") + # lbl.set_markup("\%s".to_cstring, + # "Italic content") + # ~~~ + fun set_markup(format, content: CString) `{ + char *formatted = g_markup_printf_escaped(format, content); + gtk_label_set_markup(self, formatted); + g_free(formatted); + `} + + # Set justification of the lines in the label relative to each other + fun justify=(value: GtkJustification) `{ gtk_label_set_justify(self, value); `} + + # Get justification of the lines in the label relative to each other + fun justify: GtkJustification `{ return gtk_label_get_justify(self); `} end # A widget displaying an image @@ -760,8 +803,8 @@ extern class GtkButton `{GtkButton *`} return (GtkButton *)gtk_button_new_from_stock(String_to_cstring(stock_id)); `} - fun text: String `{ - return NativeString_to_s((char *)gtk_button_get_label(self)); + fun text: String import CString.to_s_with_copy `{ + return CString_to_s_with_copy((char *)gtk_button_get_label(self)); `} fun text=(value: String) import String.to_cstring `{ @@ -772,6 +815,15 @@ extern class GtkButton `{GtkButton *`} signal_connect("clicked", to_call, user_data) end + # Set the image of button to the given widget + fun image=(image: GtkWidget) `{ + gtk_button_set_image(self, image); + `} + + # Get the widget that is currenty set as the image of button + fun image: GtkWidget `{ + return gtk_button_get_image(self); + `} end # A button which pops up a scale @@ -824,8 +876,8 @@ extern class GtkExpander `{GtkExpander *`} gtk_expander_set_spacing(self, pixels); `} - fun label_text: String `{ - return NativeString_to_s((char *)gtk_expander_get_label(self)); + fun label_text: String import CString.to_s_with_copy `{ + return CString_to_s_with_copy((char *)gtk_expander_get_label(self)); `} fun label_text=(lbl: String) import String.to_cstring `{ @@ -943,8 +995,8 @@ extern class GtkComboBox `{GtkComboBox *`} gtk_combo_box_set_id_column(self, id_column); `} - fun active_id: String `{ - return NativeString_to_s((char *)gtk_combo_box_get_active_id(self)); + fun active_id: String import CString.to_s_with_copy `{ + return CString_to_s_with_copy((char *)gtk_combo_box_get_active_id(self)); `} fun active_id=(id_active: String) import String.to_cstring `{ @@ -967,8 +1019,8 @@ extern class GtkComboBox `{GtkComboBox *`} gtk_combo_box_popdown(self); `} - fun title: String `{ - return NativeString_to_s((char *)gtk_combo_box_get_title(self)); + fun title: String import CString.to_s_with_copy `{ + return CString_to_s_with_copy((char *)gtk_combo_box_get_title(self)); `} fun title=(t: String) import String.to_cstring `{ @@ -1054,4 +1106,3 @@ end extern class GdkRGBA `{GdkRGBA*`} end -