User Tools

Site Tools


programming:gtk4

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
programming:gtk4 [2022/03/20 18:36]
nanodano created
programming:gtk4 [2022/03/21 05:19] (current)
nanodano
Line 58: Line 58:
  
 # Documentation will now be in docs/ # Documentation will now be in docs/
-Examples will be in examples/+For example: gtk-4.6.1/docs/reference/gtk/gtk4/index.html 
 + 
 +# There are examples in source under examples/ directory 
  
 # Install to prefix (use `sudo` if doing system install) # Install to prefix (use `sudo` if doing system install)
Line 69: Line 71:
 ===== Documentation ===== ===== Documentation =====
  
-  * Online API documentation: [[https://docs.gtk.org/gtk4/index.html]] 
-  * Offline API documentation, if you built from source with docs, will be in the ''docs'' directory. For example, ''gtk-4.6.1/docs/reference/gtk/gtk4/index.html'' 
-  * Example code is in the source code directory under ''examples/'' 
  
 +**Offline**
 +
 +There is example code in the ''examples/'' directory of the source. If you built from source and included the docs with the build, there will also be nice HTML pages in the ''docs/'' directory.
 +
 +    * API documentation - ''index.html'' - e.g. ''gtk-4.6.1/docs/reference/gtk/gtk4/index.html''
 +    * Widget gallery: ''visual_index.html'' - e.g. ''gtk-4.6.1/docs/reference/gtk/gtk4/visual_index.html''
 +    * Example code: ''examples/'' directory - e.g. ''gtk-4.6.1/examples/''
 +
 +**Online**
 +
 +    * API documentation: [[https://docs.gtk.org/gtk4/index.html]]
 +    * Widget gallery: [[https://docs.gtk.org/gtk4/visual_index.html]]
 +    * Example code: [[https://gitlab.gnome.org/GNOME/gtk/-/tree/main/examples]]
  
 ===== Hello world ===== ===== Hello world =====
Line 109: Line 121:
   g_signal_connect (app, "activate", G_CALLBACK (on_activate), NULL);   g_signal_connect (app, "activate", G_CALLBACK (on_activate), NULL);
   return g_application_run (G_APPLICATION (app), argc, argv);   return g_application_run (G_APPLICATION (app), argc, argv);
 +}
 +</code>
 +
 +===== gtkmm (C++) =====
 +
 +You can use [[http://www.gtkmm.org/en/|gtkmm]] to write C++ code instead of C. On their wiki they have  [[https://developer-old.gnome.org/gtkmm-tutorial/stable/|tutorials]] and [[https://developer-old.gnome.org/gtkmm-tutorial/stable/sec-install-unix-and-linux.html.en|build instructions]] for the [[https://download.gnome.org/sources/gtkmm/|source code]].
 +
 +You might need some other dependencies like:
 +
 +  * sigc++-3.0
 +  * gtk4
 +  * glibmm-2.68
 +  * cairomm-1.16
 +  * pangomm-2.48
 +
 +
 +To build from source:
 +
 +
 +<code bash>
 +# Install mm-common
 +sudo apt install mm-common
 +
 +# Build and install libsigc++3
 +# https://github.com/libsigcplusplus/libsigcplusplus
 +wget https://github.com/libsigcplusplus/libsigcplusplus/releases/download/3.2.0/libsigc++-3.2.0.tar.xz
 +tar xzf libsigc++-3.2.0
 +cd libsigc++-3.2.0
 +cmake .
 +./autogen.sh --prefix=/usr/local --enable-static
 +make
 +sudo make install
 +
 +# glibmm
 +# https://gitlab.gnome.org/GNOME/glibmm
 +wget https://gitlab.gnome.org/GNOME/glibmm/-/archive/2.70.0/glibmm-2.70.0.tar.gz
 +tar xzf glibmm-2.70.0.tar.gz
 +cd glibmm-2.70.0
 +./autogen.sh --prefix=/usr/local --enable-static
 +make
 +sudo make install
 +
 +# cairomm
 +# https://www.cairographics.org/releases/
 +wget https://www.cairographics.org/releases/cairomm-1.16.1.tar.xz
 +tar xBf cairomm-1.16.1.tar.xz
 +cd cairomm-1.16.1
 +./autogen.sh --prefix=/usr/local --enable-static
 +make
 +sudo make install
 +
 +# pangomm
 +# https://gitlab.gnome.org/GNOME/pangomm
 +wget https://gitlab.gnome.org/GNOME/pangomm/-/archive/2.50.0/pangomm-2.50.0.tar.gz
 +tar xzf pangomm-2.50.0.tar.gz
 +cd pangomm-2.50.0
 +./autogen.sh --prefix=/usr/local --enable-static
 +make
 +sudo make install
 +
 +
 +# gtkmm
 +wget https://download.gnome.org/sources/gtkmm/4.6/gtkmm-4.6.0.tar.xz
 +tar xBf gtkmm-4.6.0.tar.xz
 +cd gtkmm-4.6.0
 +./autogen.sh --prefix=/usr/local --enable-static
 +make
 +sudo make install
 +
 +</code>
 +
 +
 +
 +When compiling, use ''-std=c++20'' flag. When running, you may need to set LD_LIBRARY_PATH if you installed to a special prefix. Maybe able to add ''-static'' if you built all libs with ''--enable-static' configuration and a ''.a'' file is in the lib dir.
 +
 +<code bash>
 +# Compile app with gtk4
 +g++ main.cpp `pkg-config gtkmm-4.0 --cflags --libs` -std=c++20
 +
 +# Set path for shared library when running
 +LD_LIBRARY_PATH=/usr/local/lib ./a.out
 +</code>
 +
 +Here is a gtkmm hello world:
 +
 +<code cpp main.cpp>
 +// gtkmm4 example
 +
 +// Compile with:
 +// g++ main.cpp `pkg-config gtkmm-4.0 --cflags --libs` -std=c++20
 +
 +// Run with
 +// LD_LIBRARY_PATH=/usr/local/lib ./a.out
 +#include <gtkmm.h>
 +
 +class MyWindow : public Gtk::Window
 +{
 +public:
 +  MyWindow();
 +};
 +
 +MyWindow::MyWindow()
 +{
 +  set_title("Basic application");
 +  set_default_size(200, 200);
 +}
 +
 +int main(int argc, char* argv[])
 +{
 +  auto app = Gtk::Application::create("org.gtkmm.examples.base");
 +
 +  return app->make_window_and_run<MyWindow>(argc, argv);
 } }
 </code> </code>
programming/gtk4.1647801369.txt.gz · Last modified: 2022/03/20 18:36 by nanodano