Skip to content

Commit 1c5a200

Browse files
committed
Merge iui for 0.1.0
2 parents 5ddc1ff + 96cb829 commit 1c5a200

File tree

24 files changed

+1638
-50
lines changed

24 files changed

+1638
-50
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@ Cargo.lock
22
*.swp
33
ui/target
44
ui-sys/target
5+
iui/target
56

.travis.yml

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,28 @@
11
language: rust
22
rust:
3-
- stable
4-
- beta
5-
- nightly
3+
- stable
4+
- beta
5+
- nightly
66
matrix:
77
allow_failures:
8-
- rust: nightly
8+
- rust: nightly
99
before_install:
10-
- sudo apt-get -qq update
11-
- sudo apt-get install -y cmake
12-
- sudo apt-get install -y libgtk-3-dev
10+
- sudo apt-get -qq update
11+
- sudo apt-get install -y cmake
12+
- sudo apt-get install -y libgtk-3-dev
1313
script:
14-
- cd ui-sys
15-
- cargo build --verbose --tests --examples
16-
- cd ../ui
17-
- cargo build --verbose --tests --examples
14+
- cd ui-sys
15+
- cargo build --verbose --tests --examples
16+
- cd ../ui
17+
- cargo build --verbose --tests --examples
18+
- cd ../iui
19+
- cargo build --verbose --tests --examples
1820
after_success: |
1921
[ $TRAVIS_BRANCH = master ] &&
2022
[ $TRAVIS_PULL_REQUEST = false ] &&
21-
cd $TRAVIS_BUILD_DIR/ui/ &&
23+
cd $TRAVIS_BUILD_DIR/iui/ &&
2224
cargo doc &&
23-
echo "<meta http-equiv=refresh content=0;url=ui/index.html>" > target/doc/index.html &&
25+
echo "<meta http-equiv=refresh content=0;url=iui/index.html>" > target/doc/index.html &&
2426
sudo pip install ghp-import &&
2527
ghp-import -n target/doc &&
2628
git push -fq https://${GH_TOKEN}@github.com/${TRAVIS_REPO_SLUG}.git gh-pages

README.md

Lines changed: 68 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,76 @@
1-
# libUI
1+
# The Improved User Interface Crate
22
[![libui-rs build status](https://api.travis-ci.org/LeoTindall/libui-rs.svg?branch=master)](https://travis-ci.org/LeoTindall/libui-rs/)
33

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].
66

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:
108

11-
Based on work by @pcwalton
9+
```
10+
iui = "0.1.0"
11+
```
1212

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+
});
1457
15-
# Testing Note
58+
ui.main();
59+
}
60+
```
1661

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
1774
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

iui/Cargo.toml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
[package]
2+
name = "iui"
3+
version = "0.1.0"
4+
authors = ["Leo Tindall <[email protected]>"]
5+
6+
# A short blurb about the package. This is not rendered in any format when
7+
# uploaded to crates.io (aka this is not markdown).
8+
description = "Simple, small, easy to distribute GUI bindings."
9+
10+
# These URLs point to more information about the package. These are
11+
# intended to be webviews of the relevant data, not necessarily compatible
12+
# with VCS tools and the like.
13+
documentation = "https://docs.rs/iui/"
14+
repository = "https://github.com/LeoTindall/libui-rs"
15+
16+
# This points to a file under the package root (relative to this `Cargo.toml`).
17+
# The contents of this file are stored and indexed in the registry.
18+
# crates.io will render this file and place the result on the crate's page.
19+
readme = "../README.md"
20+
21+
# This is a list of up to five keywords that describe this crate. Keywords
22+
# are searchable on crates.io, and you may choose any words that would
23+
# help someone find this crate.
24+
keywords = ["windows", "gtk", "gui", "user interface", "macos"]
25+
26+
# This is a list of up to five categories where this crate would fit.
27+
# Categories are a fixed list available at crates.io/category_slugs, and
28+
# they must match exactly.
29+
categories = ["gui", "os::macos-apis", "os::unix-apis", "os::windows-apis"]
30+
license = "MIT"
31+
32+
[badges]
33+
# Travis CI: `repository` in format "<user>/<project>" is required.
34+
# `branch` is optional; default is `master`
35+
travis-ci = { repository = "LeoTindall/libui-rs", branch = "master" }
36+
37+
# Is it maintained resolution time: `repository` is required.
38+
is-it-maintained-issue-resolution = { repository = "LeoTindall/libui-rs" }
39+
40+
# Is it maintained percentage of open issues: `repository` is required.
41+
is-it-maintained-open-issues = { repository = "LeoTindall/libui-rs" }
42+
43+
maintenance = { status = "actively-developed" }
44+
45+
[dependencies]
46+
bitflags = "0.7"
47+
libc = "0.2"
48+
failure = "0.1.1"
49+
50+
[dependencies.ui-sys]
51+
path = "../ui-sys"

iui/examples/basic.rs

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
extern crate iui;
2+
use iui::prelude::*;
3+
use iui::controls::{Label, Button, VerticalBox, Group};
4+
5+
fn main() {
6+
// Initialize the UI library
7+
let ui = UI::init().expect("Couldn't initialize UI library");
8+
// Create a window into which controls can be placed
9+
let win = Window::new(&ui, "Test App", 200, 200, WindowType::NoMenubar);
10+
11+
// Create a vertical layout to hold the controls
12+
let vbox = VerticalBox::new(&ui);
13+
vbox.set_padded(&ui, true);
14+
15+
let group_vbox = VerticalBox::new(&ui);
16+
let group = Group::new(&ui, "Group");
17+
18+
// Create two buttons to place in the window
19+
let button = Button::new(&ui, "Button");
20+
let quit_button = Button::new(&ui, "Quit");
21+
22+
// Create a new label. Note that labels don't auto-wrap!
23+
let mut label_text = String::new();
24+
label_text.push_str("There is a ton of text in this label.\n");
25+
label_text.push_str("Pretty much every unicode character is supported.\n");
26+
label_text.push_str("🎉 用户界面 사용자 인터페이스");
27+
let label = Label::new(&ui, &label_text);
28+
29+
vbox.append(&ui, label, LayoutStrategy::Stretchy);
30+
group_vbox.append(&ui, button, LayoutStrategy::Compact);
31+
group_vbox.append(&ui, quit_button, LayoutStrategy::Compact);
32+
group.set_child(&ui, group_vbox);
33+
vbox.append(&ui, group, LayoutStrategy::Compact);
34+
35+
// Actually put the button in the window
36+
win.set_child(&ui, vbox);
37+
// Show the window
38+
win.show(&ui);
39+
// Run the application
40+
ui.main();
41+
}

iui/examples/files.rs

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
//! Demonstrates the use of the Window::save_file() call to get a filename via a friendly GUI,
2+
//! and the Window::modal_err() call to display modal dialog boxes.
3+
4+
extern crate iui;
5+
use iui::prelude::*;
6+
use iui::controls::{VerticalBox, MultilineEntry, Button};
7+
use std::io::prelude::*;
8+
use std::error::Error;
9+
use std::fs::File;
10+
11+
fn main() {
12+
// Initialize the UI
13+
let ui = UI::init().unwrap();
14+
15+
// Create the input controls
16+
let entry = MultilineEntry::new(&ui);
17+
let button = Button::new(&ui, "Save Buffer");
18+
19+
// Set up the application's layout
20+
let window = Window::new(&ui, "Save Buffer to File", 640, 480, WindowType::NoMenubar);
21+
let vbox = VerticalBox::new(&ui);
22+
vbox.append(&ui, entry.clone(), LayoutStrategy::Stretchy);
23+
vbox.append(&ui, button.clone(), LayoutStrategy::Compact);
24+
window.set_child(&ui, vbox);
25+
window.show(&ui);
26+
27+
// When the button is clicked, get the name of a file and then write the entry's contents to it.
28+
// Note the in real code you should spin off a thread to do the actual writing, do it between UI events,
29+
// or use Tokio. Even with minmal content, this method shows noticable lag.
30+
button.on_clicked(&ui, {
31+
let ui = ui.clone();
32+
move |_| {
33+
if let Some(path) = window.save_file(&ui) {
34+
let mut file = match File::create(&path) {
35+
Err(why) => { window.modal_err(&ui, "I/O Error", &format!("Could not open file {}: {}", path.display(), why.description())); return; }
36+
Ok(f) => f
37+
};
38+
match file.write_all(entry.value(&ui).as_bytes()) {
39+
Err(why) => { window.modal_err(&ui, "I/O Error", &format!("Could not write to file {}: {}", path.display(), why.description())); return; }
40+
Ok(_) => ()
41+
};
42+
}
43+
}
44+
});
45+
46+
ui.main();
47+
48+
}

0 commit comments

Comments
 (0)