Skip to content

Commit d1b1d93

Browse files
committed
This is 0.2 🎉
1 parent abae9f2 commit d1b1d93

File tree

3 files changed

+71
-49
lines changed

3 files changed

+71
-49
lines changed

README.md

Lines changed: 60 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,75 +1,87 @@
1-
# The Improved User Interface Crate
1+
# Improved User Interface
22
[![libui-rs build status](https://api.travis-ci.org/LeoTindall/libui-rs.svg?branch=master)](https://travis-ci.org/LeoTindall/libui-rs/)
3+
[![iui crates.io version badge](https://img.shields.io/crates/v/iui.svg)](https://crates.io/crates/iui/)
4+
[![issue resolution badge](https://isitmaintained.com/badge/resolution/LeoTindall/libui-rs.svg)](https://isitmaintained.com/project/LeoTindall/libui-rs)
5+
[![open issues badge](https://isitmaintained.com/badge/open/LeoTindall/libui-rs.svg)](https://isitmaintained.com/project/LeoTindall/libui-rs)
6+
![actively developed badge](https://img.shields.io/badge/maintenance-actively--developed-brightgreen.svg)
37

48
`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].
9+
These are work-in-progress bindings to the minimalistic native UI library [libui][libui] via the `ui-sys` bindings crate.
610

7-
Add this to your crate with:
11+
Add `iui` to your project with:
812

13+
```toml
14+
iui = "0.2"
915
```
10-
iui = "0.1.0"
11-
```
16+
17+
## Organization
18+
19+
`iui` is the safe Rust wrapper, to be used by most users.
20+
`ui` is the old version of the safe wrapper. Don't use this.
21+
`ui-sys` is the raw unsafe bindings to the `libui` C code. Requires `cmake` so it can build `libui`.
22+
`libui` is included as a submodule. You will need CMake to build `libui` itself.
23+
24+
Based on work by [@pcwalton](https://github.com/pcwalton/). Licensed MIT.
1225

1326
## Example
1427

1528
```
1629
extern crate iui;
1730
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;
31+
use iui::controls::{Label, Button, VerticalBox, Group};
2232
2333
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.
34+
// Initialize the UI library
35+
let ui = UI::init().expect("Couldn't initialize UI library");
36+
// Create a window into which controls can be placed
37+
let mut win = Window::new(&ui, "Test App", 200, 200, WindowType::NoMenubar);
38+
39+
// Create a vertical layout to hold the controls
40+
let mut vbox = VerticalBox::new(&ui);
41+
vbox.set_padded(&ui, true);
42+
43+
let mut group_vbox = VerticalBox::new(&ui);
44+
let mut group = Group::new(&ui, "Group");
45+
46+
// Create two buttons to place in the window
47+
let mut button = Button::new(&ui, "Button");
4248
button.on_clicked(&ui, {
49+
let ui = ui.clone();
50+
move |btn| {
51+
btn.set_text(&ui, "Clicked!");
52+
}
53+
});
54+
55+
let mut quit_button = Button::new(&ui, "Quit");
56+
quit_button.on_clicked(&ui, {
4357
let ui = ui.clone();
4458
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-
}
59+
ui.quit();
5560
}
5661
});
5762
63+
// Create a new label. Note that labels don't auto-wrap!
64+
let mut label_text = String::new();
65+
label_text.push_str("There is a ton of text in this label.\n");
66+
label_text.push_str("Pretty much every unicode character is supported.\n");
67+
label_text.push_str("🎉 用户界面 사용자 인터페이스");
68+
let label = Label::new(&ui, &label_text);
69+
70+
vbox.append(&ui, label, LayoutStrategy::Stretchy);
71+
group_vbox.append(&ui, button, LayoutStrategy::Compact);
72+
group_vbox.append(&ui, quit_button, LayoutStrategy::Compact);
73+
group.set_child(&ui, group_vbox);
74+
vbox.append(&ui, group, LayoutStrategy::Compact);
75+
76+
// Actually put the button in the window
77+
win.set_child(&ui, vbox);
78+
// Show the window
79+
win.show(&ui);
80+
// Run the application
5881
ui.main();
5982
}
6083
```
6184

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-
7385
## Testing Note
7486
Travis does not connect video devices to their testing environments, so the tests cannot be run. Therefore, the "tests" only check compilation.
7587

iui/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "iui"
3-
version = "0.1.1"
3+
version = "0.2.0"
44
authors = ["Leo Tindall <[email protected]>"]
55

66
# A short blurb about the package. This is not rendered in any format when

iui/src/lib.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,23 @@
11
//! `iui`, the `i`mproved `u`ser `i`nterface crate, provides Rust bindings to `libui`, a wrapper library for native(ish) GUI libraries
22
//! - Win32API on Windows, Cocoa on Mac OS X, and GTK+ on Linux and elsewhere. This library exposes a Rusty procedural interface to the
33
//! "Least Common Denominator" of GUI widgets. They are all available on all supported platforms.
4+
//!
5+
//! To use the library, add the following to your `Cargo.toml`:
6+
//!
7+
//! ```toml
8+
//! "iui" = "0.2"
9+
//! ```
410
//!
511
//! Most of the functionality of the crate is exposed via the [UI](struct.UI.html) RAII guard, which handles all initialization and cleanup for the
612
//! underlying library.
713
//!
814
//! After initialization, all the functionality used for creating actual UIs is in the [`controls`](controls/index.html) module.
915
//!
1016
//! Fine-grained control of the event loop is avilable via the [`EventLoop`](struct.EventLoop.html) struct.
17+
//!
18+
//! For code examples, see the [basic](https://github.com/LeoTindall/libui-rs/blob/master/iui/examples/basic.rs) and
19+
//! [advanced](https://github.com/LeoTindall/libui-rs/blob/master/iui/examples/inputs.rs) examples or the
20+
//! [file editing](https://github.com/LeoTindall/libui-rs/blob/master/iui/examples/files.rs) example.
1121
1222
#[macro_use]
1323
extern crate bitflags;

0 commit comments

Comments
 (0)