|
1 |
| -# libUI |
| 1 | +# The Improved User Interface Crate |
2 | 2 | [](https://travis-ci.org/LeoTindall/libui-rs/)
|
3 | 3 |
|
4 |
| -A Rusty user interface library that binds to platform native APIs. |
5 |
| -These are work-in-progress Rust bindings to the minimalistic native UI library [libui][libui]. |
| 4 | +`iui` is a simple, small, easy to distribute GUI library, a Rusty user interface library that binds to platform native APIs. |
| 5 | +These are work-in-progress bindings to the minimalistic native UI library [libui][libui]. |
6 | 6 |
|
7 |
| -## Building |
8 |
| -`libui` is included as a submodule. You will need CMake to build `libui` itself; |
9 |
| -after that, Cargo should be able to take care of the build process. |
| 7 | +Add this to your crate with: |
10 | 8 |
|
11 |
| -Based on work by @pcwalton |
| 9 | +``` |
| 10 | +iui = "0.1.0" |
| 11 | +``` |
12 | 12 |
|
13 |
| -[libui]: https://github.com/andlabs/libui |
| 13 | +## Example |
| 14 | + |
| 15 | +``` |
| 16 | +extern crate iui; |
| 17 | +use iui::prelude::*; |
| 18 | +use iui::controls::{VerticalBox, MultilineEntry, Button}; |
| 19 | +use std::io::prelude::*; |
| 20 | +use std::error::Error; |
| 21 | +use std::fs::File; |
| 22 | +
|
| 23 | +fn main() { |
| 24 | + // Initialize the UI |
| 25 | + let ui = UI::init().unwrap(); |
| 26 | +
|
| 27 | + // Create the input controls |
| 28 | + let entry = MultilineEntry::new(&ui); |
| 29 | + let button = Button::new(&ui, "Save Buffer"); |
| 30 | +
|
| 31 | + // Set up the application's layout |
| 32 | + let window = Window::new(&ui, "Save Buffer to File", 640, 480, WindowType::NoMenubar); |
| 33 | + let vbox = VerticalBox::new(&ui); |
| 34 | + vbox.append(&ui, entry.clone(), LayoutStrategy::Stretchy); |
| 35 | + vbox.append(&ui, button.clone(), LayoutStrategy::Compact); |
| 36 | + window.set_child(&ui, vbox); |
| 37 | + window.show(&ui); |
| 38 | +
|
| 39 | + // When the button is clicked, get the name of a file and then write the entry's contents to it. |
| 40 | + // Note the in real code you should spin off a thread to do the actual writing, do it between UI events, |
| 41 | + // or use Tokio. Even with minmal content, this method shows noticable lag. |
| 42 | + button.on_clicked(&ui, { |
| 43 | + let ui = ui.clone(); |
| 44 | + move |_| { |
| 45 | + if let Some(path) = window.save_file(&ui) { |
| 46 | + let mut file = match File::create(&path) { |
| 47 | + Err(why) => { window.modal_err(&ui, "I/O Error", &format!("Could not open file {}: {}", path.display(), why.description())); return; } |
| 48 | + Ok(f) => f |
| 49 | + }; |
| 50 | + match file.write_all(entry.value(&ui).as_bytes()) { |
| 51 | + Err(why) => { window.modal_err(&ui, "I/O Error", &format!("Could not write to file {}: {}", path.display(), why.description())); return; } |
| 52 | + Ok(_) => () |
| 53 | + }; |
| 54 | + } |
| 55 | + } |
| 56 | + }); |
14 | 57 |
|
15 |
| -# Testing Note |
| 58 | + ui.main(); |
| 59 | +} |
| 60 | +``` |
16 | 61 |
|
| 62 | +## Organization |
| 63 | + |
| 64 | +`iui` is the safe Rust wrapper, to be used by most users. |
| 65 | +`ui` is the old version of the safe wrapper. Don't use this. |
| 66 | +`ui-sys` is the raw unsafe bindings to the `libui` C code. Requires `cmake` so it can build `libui`. |
| 67 | + |
| 68 | +## Building |
| 69 | +`libui` is included as a submodule. You will need CMake to build `libui` itself. |
| 70 | + |
| 71 | +Based on work by @pcwalton. Licensed MIT. |
| 72 | + |
| 73 | +## Testing Note |
17 | 74 | Travis does not connect video devices to their testing environments, so the tests cannot be run. Therefore, the "tests" only check compilation.
|
| 75 | + |
| 76 | +[libui]: https://github.com/andlabs/libui |
0 commit comments