#x11 #api #graphics #bindings #linux #mlx #beginner

minilibx

Rust ffi绑定到Linux上X11的42个minilibx API

4个版本

0.2.1 2020年5月2日
0.2.0 2020年5月1日
0.1.1 2020年5月1日
0.1.0 2020年5月1日

#560 in 图形API

MIT 协议

28KB
607

minilibx面向Rust初学者

关于

这是对minilibX C API的Rust ffi绑定。
该API旨在让初学者学习图形开发的基础。
minilibx本身是一个X11工具的包装器,提供用于图形开发的简单库。

依赖项

  • Linux。
  • 一个编译器
  • mlx库

如何安装

首先,您需要安装以下库

  • libX11
  • libXext
  • libmlx.a(位于/usr/lib*/usr/local/lib中)

要安装libmlx,您可以执行以下操作

$ git clone [email protected]:42Paris/minilibx-linux /tmp/minilibx-linux
$ cd /tmp/minilibx-linux
$ make
$ sudo cp libmlx.a /usr/local/lib

在您的项目中

[dependencies]
minilibx = "0.2.1"

示例

extern crate minilibx;

use minilibx::{Mlx, MlxError};
use std::process;

fn main() {
    let mlx = Mlx::new().unwrap();

    let width = 1080;
    let height = 720;
    let window = mlx.new_window(width, height, "Mlx example").unwrap();

    let image = match mlx.new_image(width, height) {
        Ok(img) => img,
        Err(e) => match e {
            MlxError::Any(s) => return println!("{}", s),
            _ => return,
        },
    };

    println!("{}", image.size_line);

    window.key_hook(
        move |keycode, _| {
            // you can also check keycodes using the `xev` command on linux
            println!("{}", keycode);

            if keycode == 113 {
                process::exit(0);
            } else if keycode == 97 {
                let x = width / 2;
                let y = height / 2;
                let color = 0xffffff;
                mlx.pixel_put(&window, x, y, color);
            }
        },
        &(),
    );

    // this will loop forever
    mlx.event_loop();
}

无运行时依赖项