GTK4-RS 项目教程
gtk4-rsRust bindings of GTK 4项目地址:https://gitcode.com/gh_mirrors/gt/gtk4-rs
1. 项目的目录结构及介绍
GTK4-RS 项目的目录结构如下:
/crate
├── Gir.toml
├── README.md
├── src
│ └── auto
├── sys
└── tests
- Gir.toml: 用于生成自动代码的配置文件。
- README.md: 项目的基本介绍和详细信息。
- src: 包含源代码的目录,其中
auto
子目录包含自动生成的代码。 - sys: 包含与 C API 一一对应的绑定。
- tests: 包含测试文件。
2. 项目的启动文件介绍
项目的启动文件通常是 main.rs
,位于 src
目录下。以下是一个简单的启动文件示例:
use gtk4 as gtk;
use gtk::prelude::*;
use gtk::{glib, Application, ApplicationWindow, Button};
fn main() -> glib::ExitCode {
let application = Application::builder()
.application_id("com.example.FirstGtkApp")
.build();
application.connect_activate(|app| {
let window = ApplicationWindow::builder()
.application(app)
.title("First GTK Program")
.default_width(350)
.default_height(70)
.build();
let button = Button::with_label("Click me");
button.connect_clicked(|_| {
eprintln!("Clicked");
});
window.set_child(Some(&button));
window.present();
});
application.run()
}
3. 项目的配置文件介绍
项目的配置文件主要是 Gir.toml
,用于配置自动代码生成器 gir
。以下是一个简单的 Gir.toml
示例:
[options]
library = "Gtk4"
version = "4.0"
min_cfg_version = "4.0"
target_path = "."
- library: 指定要绑定的库。
- version: 指定库的版本。
- min_cfg_version: 指定最低配置版本。
- target_path: 指定生成文件的目标路径。
以上是 GTK4-RS 项目的基本教程,涵盖了项目的目录结构、启动文件和配置文件的介绍。希望这些信息对您有所帮助。
gtk4-rsRust bindings of GTK 4项目地址:https://gitcode.com/gh_mirrors/gt/gtk4-rs