2022-04-21 16:53:28 +02:00
|
|
|
|
<!DOCTYPE html>
|
|
|
|
|
<html lang="en">
|
|
|
|
|
<head>
|
|
|
|
|
<meta charset="utf-8" />
|
|
|
|
|
<meta name="generator" content="pandoc" />
|
|
|
|
|
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
|
|
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
|
2022-11-21 14:48:20 +01:00
|
|
|
|
<title>GTK 4 tutorial</title>
|
2022-04-21 16:53:28 +02:00
|
|
|
|
<style>
|
|
|
|
|
code{white-space: pre-wrap;}
|
|
|
|
|
span.smallcaps{font-variant: small-caps;}
|
|
|
|
|
span.underline{text-decoration: underline;}
|
|
|
|
|
div.column{display: inline-block; vertical-align: top; width: 50%;}
|
|
|
|
|
div.hanging-indent{margin-left: 1.5em; text-indent: -1.5em;}
|
|
|
|
|
ul.task-list{list-style: none;}
|
|
|
|
|
pre{overflow: visible;}
|
|
|
|
|
pre > code.sourceCode { white-space: pre; position: relative; }
|
|
|
|
|
pre > code.sourceCode > span { display: inline-block; line-height: 1.25; }
|
|
|
|
|
pre > code.sourceCode > span:empty { height: 1.2em; }
|
|
|
|
|
code.sourceCode > span { color: inherit; text-decoration: inherit; }
|
|
|
|
|
div.sourceCode { margin: 1em 0; }
|
|
|
|
|
pre.sourceCode { margin: 0; }
|
|
|
|
|
@media screen {
|
|
|
|
|
div.sourceCode { overflow: auto; }
|
2022-04-17 13:54:42 +02:00
|
|
|
|
}
|
2022-04-21 16:53:28 +02:00
|
|
|
|
@media print {
|
|
|
|
|
pre > code.sourceCode { white-space: pre-wrap; }
|
|
|
|
|
pre > code.sourceCode > span { text-indent: -5em; padding-left: 5em; }
|
|
|
|
|
}
|
|
|
|
|
pre.numberSource code
|
|
|
|
|
{ counter-reset: source-line 0; }
|
|
|
|
|
pre.numberSource code > span
|
|
|
|
|
{ position: relative; left: -4em; counter-increment: source-line; }
|
|
|
|
|
pre.numberSource code > span > a:first-child::after
|
|
|
|
|
{ content: counter(source-line);
|
|
|
|
|
position: relative; left: -1em; text-align: right; vertical-align: baseline;
|
|
|
|
|
border: none; display: inline-block;
|
|
|
|
|
-webkit-touch-callout: none; -webkit-user-select: none;
|
|
|
|
|
-khtml-user-select: none; -moz-user-select: none;
|
|
|
|
|
-ms-user-select: none; user-select: none;
|
|
|
|
|
padding: 0 4px; width: 4em;
|
|
|
|
|
color: #aaaaaa;
|
|
|
|
|
}
|
|
|
|
|
pre.numberSource { margin-left: 3em; border-left: 1px solid #aaaaaa; padding-left: 4px; }
|
|
|
|
|
div.sourceCode
|
|
|
|
|
{ }
|
|
|
|
|
@media screen {
|
|
|
|
|
pre > code.sourceCode > span > a:first-child::before { text-decoration: underline; }
|
|
|
|
|
}
|
|
|
|
|
code span.al { color: #ff0000; font-weight: bold; } /* Alert */
|
|
|
|
|
code span.an { color: #60a0b0; font-weight: bold; font-style: italic; } /* Annotation */
|
|
|
|
|
code span.at { color: #7d9029; } /* Attribute */
|
|
|
|
|
code span.bn { color: #40a070; } /* BaseN */
|
|
|
|
|
code span.bu { } /* BuiltIn */
|
|
|
|
|
code span.cf { color: #007020; font-weight: bold; } /* ControlFlow */
|
|
|
|
|
code span.ch { color: #4070a0; } /* Char */
|
|
|
|
|
code span.cn { color: #880000; } /* Constant */
|
|
|
|
|
code span.co { color: #60a0b0; font-style: italic; } /* Comment */
|
|
|
|
|
code span.cv { color: #60a0b0; font-weight: bold; font-style: italic; } /* CommentVar */
|
|
|
|
|
code span.do { color: #ba2121; font-style: italic; } /* Documentation */
|
|
|
|
|
code span.dt { color: #902000; } /* DataType */
|
|
|
|
|
code span.dv { color: #40a070; } /* DecVal */
|
|
|
|
|
code span.er { color: #ff0000; font-weight: bold; } /* Error */
|
|
|
|
|
code span.ex { } /* Extension */
|
|
|
|
|
code span.fl { color: #40a070; } /* Float */
|
|
|
|
|
code span.fu { color: #06287e; } /* Function */
|
|
|
|
|
code span.im { } /* Import */
|
|
|
|
|
code span.in { color: #60a0b0; font-weight: bold; font-style: italic; } /* Information */
|
|
|
|
|
code span.kw { color: #007020; font-weight: bold; } /* Keyword */
|
|
|
|
|
code span.op { color: #666666; } /* Operator */
|
|
|
|
|
code span.ot { color: #007020; } /* Other */
|
|
|
|
|
code span.pp { color: #bc7a00; } /* Preprocessor */
|
|
|
|
|
code span.sc { color: #4070a0; } /* SpecialChar */
|
|
|
|
|
code span.ss { color: #bb6688; } /* SpecialString */
|
|
|
|
|
code span.st { color: #4070a0; } /* String */
|
|
|
|
|
code span.va { color: #19177c; } /* Variable */
|
|
|
|
|
code span.vs { color: #4070a0; } /* VerbatimString */
|
|
|
|
|
code span.wa { color: #60a0b0; font-weight: bold; font-style: italic; } /* Warning */
|
|
|
|
|
div.sourceCode { margin: 10px; padding: 16px 10px 8px 10px; border: 2px solid silver; background-color: ghostwhite; overflow-x:scroll}
|
|
|
|
|
pre:not(.sourceCode) { margin: 10px; padding: 16px 10px 8px 10px; border: 2px solid silver; background-color: ghostwhite; overflow-x:scroll}
|
|
|
|
|
table {margin-left: auto; margin-right: auto; border-collapse: collapse; border: 1px solid;}
|
|
|
|
|
th {padding: 2px 6px; border: 1px solid; background-color: ghostwhite;}
|
|
|
|
|
td {padding: 2px 6px; border: 1px solid;}
|
|
|
|
|
img {display: block; margin-left: auto; margin-right: auto;}
|
|
|
|
|
figcaption {text-align: center;}
|
|
|
|
|
</style>
|
|
|
|
|
</head>
|
|
|
|
|
<body style="padding-top: 70px;">
|
|
|
|
|
<div class="container">
|
|
|
|
|
<nav class="navbar fixed-top navbar-expand-lg navbar-dark bg-primary">
|
|
|
|
|
<div class="container-fluid">
|
|
|
|
|
<span class="navbar-brand">Gtk4 tutorial</span>
|
|
|
|
|
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
|
|
|
|
|
<span class="navbar-toggler-icon"></span>
|
|
|
|
|
</button>
|
|
|
|
|
<div class="collapse navbar-collapse" id="navbarSupportedContent">
|
|
|
|
|
<ul class="navbar-nav me-auto mb-2 mb-lg-0">
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
</ul>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</nav>
|
2022-11-21 14:48:20 +01:00
|
|
|
|
<h1 id="gtk-4-tutorial-for-beginners">GTK 4 Tutorial for beginners</h1>
|
2022-04-17 13:54:42 +02:00
|
|
|
|
<h4 id="contents-of-this-repository">Contents of this Repository</h4>
|
2022-11-21 14:48:20 +01:00
|
|
|
|
<p>This tutorial illustrates how to write C programs with the GTK 4
|
|
|
|
|
library. It focuses on beginners so the contents are limited to the
|
|
|
|
|
basics. The table of contents is at the end of this abstract.</p>
|
2022-04-17 13:54:42 +02:00
|
|
|
|
<ul>
|
2023-07-15 10:27:53 +02:00
|
|
|
|
<li>Section 3 to 23 describes the basics, with the example of a simple
|
2022-11-21 14:48:20 +01:00
|
|
|
|
editor <code>tfe</code> (Text File Editor).</li>
|
2023-07-15 10:27:53 +02:00
|
|
|
|
<li>Section 24 to 27 describes GtkDrawingArea.</li>
|
|
|
|
|
<li>Section 28 to 32 describes the list model and the list view
|
2022-11-21 14:48:20 +01:00
|
|
|
|
(GtkListView, GtkGridView and GtkColumnView). It also describes
|
|
|
|
|
GtkExpression.</li>
|
2022-04-17 13:54:42 +02:00
|
|
|
|
</ul>
|
2022-11-21 14:48:20 +01:00
|
|
|
|
<p>The latest version of the tutorial is located at <a
|
2023-04-10 09:19:44 +02:00
|
|
|
|
href="https://github.com/ToshioCP/Gtk4-tutorial">GTK4-tutorial GitHub
|
2022-12-21 14:31:33 +01:00
|
|
|
|
repository</a>. You can read it directly without download.</p>
|
2023-07-15 10:27:53 +02:00
|
|
|
|
<p>There’s a <a href="https://toshiocp.github.io/Gtk4-tutorial/">GitHub
|
|
|
|
|
Page</a> which is the HTML version of the tutorial.</p>
|
2022-11-21 14:48:20 +01:00
|
|
|
|
<h4 id="gtk-4-documentation">GTK 4 Documentation</h4>
|
2022-12-21 14:31:33 +01:00
|
|
|
|
<p>Please refer to <a href="https://docs.gtk.org/gtk4/index.html">GTK 4
|
2022-11-21 14:48:20 +01:00
|
|
|
|
API Reference</a> and <a href="https://developer.gnome.org/">GNOME
|
|
|
|
|
Developer Documentation Website</a> for further information.</p>
|
2022-12-21 14:31:33 +01:00
|
|
|
|
<p>These websites were opened in August of 2021. The old documents are
|
|
|
|
|
located at <a href="https://developer-old.gnome.org/gtk4/stable/">GTK
|
|
|
|
|
Reference Manual</a> and <a
|
|
|
|
|
href="https://developer-old.gnome.org/">GNOME Developer Center</a>.</p>
|
2022-11-21 14:48:20 +01:00
|
|
|
|
<p>If you want to know about GObject and the type system, please refer
|
|
|
|
|
to <a href="https://github.com/ToshioCP/Gobject-tutorial">GObject
|
2022-12-21 14:31:33 +01:00
|
|
|
|
tutorial</a>. GObject is the base of GTK 4, so it is important for
|
2023-07-15 10:27:53 +02:00
|
|
|
|
developers to understand it as well as GTK 4.</p>
|
2022-04-17 13:54:42 +02:00
|
|
|
|
<h4 id="contribution">Contribution</h4>
|
2022-12-21 14:31:33 +01:00
|
|
|
|
<p>This tutorial is still under development and unstable. Even though
|
2023-07-15 10:27:53 +02:00
|
|
|
|
the codes of the examples have been tested on GTK 4 (version 4.10.1),
|
2022-12-21 14:31:33 +01:00
|
|
|
|
bugs may still exist. If you find any bugs, errors or mistakes in the
|
|
|
|
|
tutorial and C examples, please let me know. You can post it to <a
|
2023-04-10 09:19:44 +02:00
|
|
|
|
href="https://github.com/ToshioCP/Gtk4-tutorial/issues">GitHub
|
2022-12-21 14:31:33 +01:00
|
|
|
|
issues</a>. You can also post updated files to <a
|
2023-04-10 09:19:44 +02:00
|
|
|
|
href="https://github.com/ToshioCP/Gtk4-tutorial/pulls">pull request</a>.
|
2022-12-21 14:31:33 +01:00
|
|
|
|
One thing you need to be careful is to correct the source files, which
|
|
|
|
|
are under the ‘src’ directory. Don’t modify the files under
|
|
|
|
|
<code>gfm</code> or <code>html</code> directories. After modifying some
|
2023-03-27 13:27:45 +02:00
|
|
|
|
source files , run <code>rake</code> to create GFM (GitHub Flavoured
|
|
|
|
|
Markdown) files and run <code>rake html</code> to create HTML files.</p>
|
2022-12-21 14:31:33 +01:00
|
|
|
|
<p>If you have a question, feel free to post it to <code>issue</code>.
|
|
|
|
|
All questions are helpful and will make this tutorial get better.</p>
|
|
|
|
|
<h4 id="how-to-get-gtk-4-tutorial-with-html-or-pdf-format">How to get
|
|
|
|
|
Gtk 4 tutorial with HTML or PDF format</h4>
|
|
|
|
|
<p>If you want to get HTML or PDF format tutorial, make them with
|
|
|
|
|
<code>rake</code> command, which is a ruby version of make. Type
|
2022-11-21 14:48:20 +01:00
|
|
|
|
<code>rake html</code> for HTML. Type <code>rake pdf</code> for PDF.
|
2022-12-21 14:31:33 +01:00
|
|
|
|
There is a document (“<a href="Readme_for_developers.html">How to build
|
|
|
|
|
GTK 4 Tutorial</a>”) for further information.</p>
|
2023-03-27 13:27:45 +02:00
|
|
|
|
<h4 id="license">License</h4>
|
2023-04-15 03:24:30 +02:00
|
|
|
|
<p>The license of this repository is written in <a
|
|
|
|
|
href="sec1.html">Section1</a>. In short,</p>
|
|
|
|
|
<ul>
|
|
|
|
|
<li>GFDL1.3 for documents</li>
|
|
|
|
|
<li>GPL3 for programs</li>
|
|
|
|
|
</ul>
|
2022-04-17 13:54:42 +02:00
|
|
|
|
<h2 id="table-of-contents">Table of contents</h2>
|
|
|
|
|
<ol type="1">
|
|
|
|
|
<li><a href="sec1.html">Prerequisite and License</a></li>
|
2023-07-15 10:27:53 +02:00
|
|
|
|
<li><a href="sec2.html">Preparation (GTK 4 installation and the download
|
|
|
|
|
of this repository)</a></li>
|
2022-04-17 13:54:42 +02:00
|
|
|
|
<li><a href="sec3.html">GtkApplication and GtkApplicationWindow</a></li>
|
|
|
|
|
<li><a href="sec4.html">Widgets (1)</a></li>
|
|
|
|
|
<li><a href="sec5.html">Widgets (2)</a></li>
|
2022-12-21 14:31:33 +01:00
|
|
|
|
<li><a href="sec6.html">Strings and memory management</a></li>
|
2022-04-17 13:54:42 +02:00
|
|
|
|
<li><a href="sec7.html">Widgets (3)</a></li>
|
2022-12-21 14:31:33 +01:00
|
|
|
|
<li><a href="sec8.html">Defining a final class</a></li>
|
|
|
|
|
<li><a href="sec9.html">GtkBuilder and UI file</a></li>
|
2022-04-17 13:54:42 +02:00
|
|
|
|
<li><a href="sec10.html">Build system</a></li>
|
2022-12-21 14:31:33 +01:00
|
|
|
|
<li><a href="sec11.html">Instance Initialization and
|
|
|
|
|
destruction</a></li>
|
2022-04-17 13:54:42 +02:00
|
|
|
|
<li><a href="sec12.html">Signals</a></li>
|
2023-07-15 10:27:53 +02:00
|
|
|
|
<li><a href="sec13.html">TfeTextView class</a></li>
|
2022-04-17 13:54:42 +02:00
|
|
|
|
<li><a href="sec14.html">Functions in GtkNotebook</a></li>
|
2023-07-15 10:27:53 +02:00
|
|
|
|
<li><a href="sec15.html">Tfe main program</a></li>
|
2022-12-21 14:31:33 +01:00
|
|
|
|
<li><a href="sec16.html">How to build tfe (text file editor)</a></li>
|
2023-07-15 10:27:53 +02:00
|
|
|
|
<li><a href="sec17.html">Menus and actions</a></li>
|
2022-04-17 13:54:42 +02:00
|
|
|
|
<li><a href="sec18.html">Stateful action</a></li>
|
|
|
|
|
<li><a href="sec19.html">Ui file for menu and action entries</a></li>
|
2023-07-15 10:27:53 +02:00
|
|
|
|
<li><a href="sec20.html">Composite widgets and alert dialog</a></li>
|
|
|
|
|
<li><a href="sec21.html">GtkFontDialogButton and Gsettings</a></li>
|
|
|
|
|
<li><a href="sec22.html">TfeWindow</a></li>
|
|
|
|
|
<li><a href="sec23.html">Pango, CSS and Application</a></li>
|
|
|
|
|
<li><a href="sec24.html">GtkDrawingArea and Cairo</a></li>
|
|
|
|
|
<li><a href="sec25.html">Periodic Events</a></li>
|
2023-07-23 04:49:22 +02:00
|
|
|
|
<li><a href="sec26.html">Custom drawing</a></li>
|
2023-07-15 10:27:53 +02:00
|
|
|
|
<li><a href="sec27.html">Tiny turtle graphics interpreter</a></li>
|
|
|
|
|
<li><a href="sec28.html">GtkListView</a></li>
|
|
|
|
|
<li><a href="sec29.html">GtkGridView and activate signal</a></li>
|
|
|
|
|
<li><a href="sec30.html">GtkExpression</a></li>
|
|
|
|
|
<li><a href="sec31.html">GtkColumnView</a></li>
|
|
|
|
|
<li><a href="sec32.html">GtkSignalListItemFactory</a></li>
|
2022-04-17 13:54:42 +02:00
|
|
|
|
</ol>
|
2022-11-21 14:48:20 +01:00
|
|
|
|
<p>This website uses <a
|
|
|
|
|
href="https://getbootstrap.jp/">Bootstrap</a>.</p>
|
2022-04-21 16:53:28 +02:00
|
|
|
|
</div>
|
|
|
|
|
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/js/bootstrap.bundle.min.js" integrity="sha384-MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM" crossorigin="anonymous"></script>
|
|
|
|
|
</body>
|
|
|
|
|
</html>
|