1 Star 0 Fork 0

天上的八哥/getting-started-gtk-rs

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
4年前
Loading...
README
LGPL-3.0

简介

这个是GTK4.0教程的Rust实现。

为了重复利用/target文件夹(单次编译一般在1个G左右),请跳到对应的提交查看。

由于最后部分将会用到教程中的代码,因此许可证必须与教程代码一致,即LGPL 2.0及之后版本。

勘误

依赖文件(Config.toml)中的sledchrono被错误添加。它们与这个项目无关,可以删除。

Basics 基础

51fb97ad

对应教程Basics部分

建立了一个200*200的空窗体。

Hello, World 你好,世界

8efeca27

对应教程Hello, World部分

建立一个写着"Hello, World"的按钮,按下后会打印出"Hello World"并关闭窗体。

Packing 布局

581707d6

对应教程Packing部分

建立一个包含三个按钮的窗体并布局。

Custom Drawing 绘画

95cfd0d5

对应教程Custom Drawing部分

建立一个带绘画区域的窗体。按住左键绘制,按右键或改变窗体大小消除图案。

根据gtk-rs官方教程,静态指针改为Rc<RefCell<T>>

Building user interfaces 创建交互界面

f255231

对应教程Building user interfaces部分

通过导入XML定义的界面文件来生成窗体。

由于cargo不具备类似maven或gradle的资源文件管理功能,我将XML文件直接当作字符串放入程序中。

Building application 创建应用

对应教程Building application部分

创建一个应用。

鉴于不想折腾桌面文件、图标、GSettings设置、资源文件等,内容将会有较大程度的精简。想要了解如何使用Meson打包系统,建议参考官方模板

A trivial application 一个简单的应用

e0a6d74

对应教程A trivial application部分

创建一个只有窗体的简单的应用。

省略了桌面文件及图标。

Populating the window 填充窗体

c0f9978

对应教程Populating the window部分

通过ui文件定义窗体的大小、标题、布局。

如上所述,ui文件直接作为字符串放入代码避免打包问题。

Opening files 打开文件

dc67f3d

对应教程Opening files部分

添加查看文件功能,可打开多个文件。参数在启动时传递。

例:cargo run -- README.md LICENSE .gitignore

A menu 菜单

5b66db6

对应教程A Menu部分

添加一个包含退出菜单项的菜单,及退出快捷键组合。

A preference dialog 偏好设置

7fd5e85

对应教程A preference dialog部分

添加一个可设置字体的对话框。

设置GSettings文件

运行时需安装org.gtk.exampleapp.gschema.xml

标准设置

$ sudo install -D org.gtk.example.gschema.xml /usr/share/glib-2.0/schemas/
$ sudo glib-compile-schemas /usr/share/glib-2.0/schemas/

这个命令将会把org.gtk.example.gschema.xml文件复制到惯例目录中并编译,之后只需正常使用cargo run即可运行。

非标准安装

$ glib-compile-schemas .
$ GSETTINGS_SCHEMA_DIR=. cargo run --README.md

以上是不移动org.gtk.example.gschema.xml的例子,直接在当前文件中编译,无需root权限,但是运行时需指定放置GSettings Schema的文件夹。

Adding a search bar 添加搜索栏

f98f046

对应教程Adding a search bar部分

添加一个搜索栏。

我没有在gtk-rs中找到对应template_bind_callback的方法,因此没有采用这种方式,而是手动添加信号。

Adding a side bar 添加侧边栏

2206285

对应教程Adding a side bar部分

添加一个侧边栏。统计所有单词后生成每个单词对应的按钮,用于跳转到该位置。

鉴于Rust有自己的集合,我没有采用GTK的集合。

Properties 属性

2045e10

对应教程Properties部分

利用属性控制行数的显示与否。

总结

教程到这里就结束了。希望这个仓库对你有帮助。

GNU LESSER GENERAL PUBLIC LICENSE Version 3, 29 June 2007 Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/> Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. This version of the GNU Lesser General Public License incorporates the terms and conditions of version 3 of the GNU General Public License, supplemented by the additional permissions listed below. 0. Additional Definitions. As used herein, "this License" refers to version 3 of the GNU Lesser General Public License, and the "GNU GPL" refers to version 3 of the GNU General Public License. "The Library" refers to a covered work governed by this License, other than an Application or a Combined Work as defined below. An "Application" is any work that makes use of an interface provided by the Library, but which is not otherwise based on the Library. Defining a subclass of a class defined by the Library is deemed a mode of using an interface provided by the Library. A "Combined Work" is a work produced by combining or linking an Application with the Library. The particular version of the Library with which the Combined Work was made is also called the "Linked Version". The "Minimal Corresponding Source" for a Combined Work means the Corresponding Source for the Combined Work, excluding any source code for portions of the Combined Work that, considered in isolation, are based on the Application, and not on the Linked Version. The "Corresponding Application Code" for a Combined Work means the object code and/or source code for the Application, including any data and utility programs needed for reproducing the Combined Work from the Application, but excluding the System Libraries of the Combined Work. 1. Exception to Section 3 of the GNU GPL. You may convey a covered work under sections 3 and 4 of this License without being bound by section 3 of the GNU GPL. 2. Conveying Modified Versions. If you modify a copy of the Library, and, in your modifications, a facility refers to a function or data to be supplied by an Application that uses the facility (other than as an argument passed when the facility is invoked), then you may convey a copy of the modified version: a) under this License, provided that you make a good faith effort to ensure that, in the event an Application does not supply the function or data, the facility still operates, and performs whatever part of its purpose remains meaningful, or b) under the GNU GPL, with none of the additional permissions of this License applicable to that copy. 3. Object Code Incorporating Material from Library Header Files. The object code form of an Application may incorporate material from a header file that is part of the Library. You may convey such object code under terms of your choice, provided that, if the incorporated material is not limited to numerical parameters, data structure layouts and accessors, or small macros, inline functions and templates (ten or fewer lines in length), you do both of the following: a) Give prominent notice with each copy of the object code that the Library is used in it and that the Library and its use are covered by this License. b) Accompany the object code with a copy of the GNU GPL and this license document. 4. Combined Works. You may convey a Combined Work under terms of your choice that, taken together, effectively do not restrict modification of the portions of the Library contained in the Combined Work and reverse engineering for debugging such modifications, if you also do each of the following: a) Give prominent notice with each copy of the Combined Work that the Library is used in it and that the Library and its use are covered by this License. b) Accompany the Combined Work with a copy of the GNU GPL and this license document. c) For a Combined Work that displays copyright notices during execution, include the copyright notice for the Library among these notices, as well as a reference directing the user to the copies of the GNU GPL and this license document. d) Do one of the following: 0) Convey the Minimal Corresponding Source under the terms of this License, and the Corresponding Application Code in a form suitable for, and under terms that permit, the user to recombine or relink the Application with a modified version of the Linked Version to produce a modified Combined Work, in the manner specified by section 6 of the GNU GPL for conveying Corresponding Source. 1) Use a suitable shared library mechanism for linking with the Library. A suitable mechanism is one that (a) uses at run time a copy of the Library already present on the user's computer system, and (b) will operate properly with a modified version of the Library that is interface-compatible with the Linked Version. e) Provide Installation Information, but only if you would otherwise be required to provide such information under section 6 of the GNU GPL, and only to the extent that such information is necessary to install and execute a modified version of the Combined Work produced by recombining or relinking the Application with a modified version of the Linked Version. (If you use option 4d0, the Installation Information must accompany the Minimal Corresponding Source and Corresponding Application Code. If you use option 4d1, you must provide the Installation Information in the manner specified by section 6 of the GNU GPL for conveying Corresponding Source.) 5. Combined Libraries. You may place library facilities that are a work based on the Library side by side in a single library together with other library facilities that are not Applications and are not covered by this License, and convey such a combined library under terms of your choice, if you do both of the following: a) Accompany the combined library with a copy of the same work based on the Library, uncombined with any other library facilities, conveyed under the terms of this License. b) Give prominent notice with the combined library that part of it is a work based on the Library, and explaining where to find the accompanying uncombined form of the same work. 6. Revised Versions of the GNU Lesser General Public License. The Free Software Foundation may publish revised and/or new versions of the GNU Lesser General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Library as you received it specifies that a certain numbered version of the GNU Lesser General Public License "or any later version" applies to it, you have the option of following the terms and conditions either of that published version or of any later version published by the Free Software Foundation. If the Library as you received it does not specify a version number of the GNU Lesser General Public License, you may choose any version of the GNU Lesser General Public License ever published by the Free Software Foundation. If the Library as you received it specifies that a proxy can decide whether future versions of the GNU Lesser General Public License shall apply, that proxy's public statement of acceptance of any version is permanent authorization for you to choose that version for the Library.

简介

用rust实现Getting start with gtk中的例子 展开 收起
README
LGPL-3.0
取消

发行版

暂无发行版

贡献者 (1)

全部

语言

近期动态

接近4年前推送了新的提交到 master 分支,795b2ce...7cf8677
接近4年前推送了新的提交到 master 分支,fc2bfb6...795b2ce
接近4年前推送了新的提交到 master 分支,0a2f34a...fc2bfb6
接近4年前推送了新的提交到 master 分支,9990868...0a2f34a
接近4年前推送了新的提交到 master 分支,d7cd85e...9990868
加载更多
不能加载更多了
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/peter-jerry-ye/getting-started-gtk-rs.git
git@gitee.com:peter-jerry-ye/getting-started-gtk-rs.git
peter-jerry-ye
getting-started-gtk-rs
getting-started-gtk-rs
master

搜索帮助