From captaindeng12138 at gmail.com Tue Mar 5 05:51:02 2024 From: captaindeng12138 at gmail.com (Kyle DENG) Date: Tue, 5 Mar 2024 11:51:02 +0000 Subject: [giraffe-user] Label/TextView in giraffe library Message-ID: Hello, I hope to create a Label/TextView here and can setText or getText at any time. But I can't find the relevant interface documentation and can query how to implement it. val textEntry = Entry.new () val () = Grid.attach grid (textEntry, 0, 0, 5, 1) fun activate app () = let open Gtk (* create a new window, and set its title *) val window = ApplicationWindow.new app val () = Window.setTitle window "Window" val () = Container.setBorderWidth window 10 (* Here we construct the container that is going pack our buttons *) val grid = Grid.new () (* Pack the container in the window *) val () = Container.add window grid (* val textEntry = Label.new (SOME "Input: ") *) val textEntry = Entry.new () val () = Grid.attach grid (textEntry, 0, 0, 5, 1) val () = Widget.showAll window in () end I want to know how to create a Label/TextView and be able to setText or getText at any time. Thanks. -------------- next part -------------- An HTML attachment was scrubbed... URL: From phil.clayton at veonix.com Tue Mar 5 06:43:37 2024 From: phil.clayton at veonix.com (Phil Clayton) Date: Tue, 5 Mar 2024 12:43:37 +0000 Subject: [giraffe-user] Label/TextView in giraffe library In-Reply-To: References: Message-ID: <08927b53-ab5d-8d9a-5f60-9a3841df4792@veonix.com> Hi, On 05/03/2024 11:51, Kyle DENG wrote: > I hope to create a Label/TextView here and can setText or getText at any > time. But I can't find the relevant interface documentation and can > query how to implement it. The GTK documentation can be found at https://docs.gtk.org/gtk3/ The original GTK documentation, which some find more readable is at https://developer-old.gnome.org/gtk3/ There is not currently SML-specific documentation but you can look at the SML signatures in your Giraffe Library installation. For the Gtk namespace we have structure Gtk : GTK and the signatures in ${GIRAFFEHOME}/lib/sml/gtk-3.0/ define the SML interface, e.g. GTK-sig.sml GTK_LABEL-sig.sml The general form of the SML interface for a library is described here: https://giraffelibrary.org/ug-index.html#sml-interface > |val textEntry = Entry.new () val () = Grid.attach grid (textEntry, 0, > 0, 5, 1)| Note that these are not in the scope of `open Gtk` so would produce a compiler error about `Entry` and `Grid` being unknown. You could write e.g. `Gtk.Entry.new` but you likely want to declare these inside `activate` anyway. At the top-level, SML would keep a reference to these objects, which you don't want. > |fun activate app () = let open Gtk (* create a new window, and set its > title *) val window = ApplicationWindow.new app val () = Window.setTitle > window "Window" val () = Container.setBorderWidth window 10 (* Here we > construct the container that is going pack our buttons *) val grid = > Grid.new () (* Pack the container in the window *) val () = > Container.add window grid (* val textEntry = Label.new (SOME "Input: ") > *) val textEntry = Entry.new () val () = Grid.attach grid (textEntry, 0, > 0, 5, 1) val () = Widget.showAll window in () end | > > I want to know how to create a Label/TextView and be able to setText or > getText at any time. You can see the SML interface for these classes in GTK_LABEL-sig.sml GTK_TEXT_VIEW-sig.sml and GtkEntry is in GTK_ENTRY-sig.sml For example, the following copies the text entry to the output label (and stdout) when the update button is pressed: fun activate app () = let open Gtk (* create a new window, and set its title *) val window = ApplicationWindow.new app val () = Window.setTitle window "Window" val () = Container.setBorderWidth window 10 (* Here we construct the container that is going pack our buttons *) val grid = Grid.new () (* Pack the container in the window *) val () = Container.add window grid val inputLabel = Label.new (SOME "Input: ") val inputEntry = Entry.new () val () = Grid.attach grid (inputLabel, 0, 0, 1, 1) val () = Grid.attach grid (inputEntry, 1, 0, 5, 1) val updateButton = Button.newWithLabel "Update" val outputLabel = Label.new NONE val () = Grid.attach grid (updateButton, 6, 0, 1, 1) val () = Grid.attach grid (outputLabel, 7, 0, 1, 1) fun onUpdate () = let val text = Entry.getText inputEntry val () = Label.setText outputLabel text val () = List.app print [text, "\n"] in () end val _ = Signal.connect updateButton (Button.clickedSig, onUpdate) val () = Widget.showAll window in () end From captaindeng12138 at gmail.com Fri Mar 29 04:58:28 2024 From: captaindeng12138 at gmail.com (Kyle DENG) Date: Fri, 29 Mar 2024 09:58:28 +0000 Subject: [giraffe-user] Source code of Giraffe Library Message-ID: Hello, If I want to learn about some source code of Giraffe Library, which website I can find it please let me know Thanks. -------------- next part -------------- An HTML attachment was scrubbed... URL: From captaindeng12138 at gmail.com Fri Mar 29 05:03:23 2024 From: captaindeng12138 at gmail.com (Kyle DENG) Date: Fri, 29 Mar 2024 10:03:23 +0000 Subject: [giraffe-user] Question abotu Gtk programs Message-ID: Hello, Can Gtk be used to write Poly/ML GUI programs? Because I saw that the introduction of gtk files is compiled using C language. Or is it that Poly/ML GUI programs can only be written using Giraffe Library? Thanks. -------------- next part -------------- An HTML attachment was scrubbed... URL: From phil.clayton at veonix.com Fri Mar 29 19:20:03 2024 From: phil.clayton at veonix.com (Phil Clayton) Date: Sat, 30 Mar 2024 00:20:03 +0000 Subject: [giraffe-user] Question abotu Gtk programs In-Reply-To: References: Message-ID: On 29/03/2024 10:03, Kyle DENG wrote: > Can Gtk be used to write Poly/ML GUI programs? Because I saw that the > introduction of gtk files is compiled using C language. GTK is a C library and, like any C library, its functions can be called from Poly/ML by creating bindings in SML to the C functions. Giraffe Library provides such bindings to GTK's (introspectable) C functions but also much more on top of this to provide a coherent GTK API in SML. > Or is it that Poly/ML GUI programs can only be written using Giraffe > Library? In practice, you need Giraffe Library or something equivalent (but I am not aware of any alternative for GTK). If you tried to use GTK directly from Poly/ML you would very likely end up creating functionality that is already provided by Giraffe Library, and it would take a very long time to write even a simple program! Phil From phil.clayton at veonix.com Fri Mar 29 19:23:16 2024 From: phil.clayton at veonix.com (Phil Clayton) Date: Sat, 30 Mar 2024 00:23:16 +0000 Subject: [giraffe-user] Source code of Giraffe Library In-Reply-To: References: Message-ID: <318d566f-55d7-da17-09a0-d32b50c6f8fe@veonix.com> On 29/03/2024 09:58, Kyle DENG wrote: > If I want to learn about some source code of Giraffe Library, which > website I can find it please let me know The source code is available on GitHub: https://github.com/giraffelibrary/giraffe