MyStudio IDE: I'm building an IDE with Rust+GTK!
Background:
In my journey for learning Rust, I've started a side project called MyStudio IDE which is, as the name implies, an IDE built on Rust.
Shoutout to Andreas Kling and his Serenity OS project for inspiration.
This project is meant as a learning experience. If you're hoping for something like VS Code, I'm sorry to disappoint you.
Let's build a Hello world GTK program with Rust!
Prerequisites:
Terminology:
crate:
An external library that contains modules and provides some functionality.
The Rust lang's official package registry. It's NPM for Rust.
cargo:
Cargo is a CLI tool to work with Rust projects. A beginner's analogy to this would be JS Angular's ng
CLI tool.
Project Setup:
I create a new project by running:
cargo new my-studio
You should see output similar to:
~/projects: cargo new my-studio
Created binary (application) `my-studio` package
By default, cargo provides us with a hello world. Let's run it.
~/projects: cd my-studio
~/projects/my-studio: cargo run
This will take time. Please be patient...
After sometime, you'll see something like this:
Compiling my-studio v0.1.0 (/home/user/projects/my-studio)
Finished dev [unoptimized + debuginfo] target(s) in 0.80s
Running `target/debug/my-studio`
Hello, world!
Cool! Let's move on.
GTK + Rust
Let's add the gtk-rs crate to Cargo.toml at the project root. So, Cargo.toml is like package.json for Rust.
Cargo.toml
[package]
name = "my-studio"
version = "0.1.0"
edition = "2018"
[dependencies]
gtk-rs="0.14.2" # <-- Include it here
At the time of writing, 0.14.2 is the latest version of the crate. Please check crates.io for new releases.
Hello World
This code is borrowed from gtk-rs
repo on GitHub.
Link
use gtk::prelude::*;
fn build_ui(application: >k::Application) {
let window = gtk::ApplicationWindow::new(application);
window.set_title("First GTK+ Program");
window.set_border_width(10);
window.set_position(gtk::WindowPosition::Center);
window.set_default_size(350, 70);
let button = gtk::Button::with_label("Click me!");
window.add(&button);
window.show_all();
}
fn main() {
let application =
gtk::Application::new(Some("com.github.gtk-rs.examples.basic"), Default::default());
application.connect_activate(build_ui);
application.run();
}
Output:
Hope you liked it! Feel free to @ me on Twitter on your thoughts on this. Bye :)