Skip to content

Commit 1d1ae67

Browse files
committed
Merge remote-tracking branch 'iui/master' into iui
initial step to merge masche842 features/changes into iui
2 parents eaca61a + aafd198 commit 1d1ae67

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+3895
-1982
lines changed

.gitignore

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
ui-sys/target
2-
ui-sys/Cargo.lock
1+
Cargo.lock
2+
*.swp
33
ui/target
4-
ui/Cargo.lock
5-
.DS_Store
6-
*.bk
4+
ui-sys/target
5+
iui/target
6+
target

.travis.yml

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,30 @@
11
language: rust
2-
32
rust:
4-
- stable
5-
- beta
6-
- nightly
7-
8-
env:
9-
- TEST_DIR=ui
10-
- TEST_DIR=ui-sys
11-
3+
- stable
4+
- beta
5+
- nightly
126
matrix:
137
allow_failures:
148
- rust: nightly
9+
before_install:
10+
- sudo apt-get -qq update
11+
- sudo apt-get install -y cmake
12+
- sudo apt-get install -y libgtk-3-dev
13+
script:
14+
- cd ui-sys
15+
- cargo build --verbose --tests --examples
16+
- cd ../iui
17+
- cargo build --verbose --tests --examples
18+
after_success: |
19+
[ $TRAVIS_BRANCH = master ] &&
20+
[ $TRAVIS_PULL_REQUEST = false ] &&
21+
cd $TRAVIS_BUILD_DIR/iui/ &&
22+
cargo doc &&
23+
echo "<meta http-equiv=refresh content=0;url=iui/index.html>" > target/doc/index.html &&
24+
sudo pip install ghp-import &&
25+
ghp-import -n target/doc &&
26+
git push -fq https://${GH_TOKEN}@github.com/${TRAVIS_REPO_SLUG}.git gh-pages
1527
16-
script: cd $TEST_DIR && cargo build --verbose
28+
env:
29+
global:
30+
secure: dfPG6E3lrxnbah17u8S4xJmqFMhrAKoXNxQKGSnEoP3HjZL1NrFFsGCtGbIGPGyz02sCQ3U35nmuGHjUP9SOn+oRV6oQlBx41PPHULoDfsMKojEG80Uphjhd6rCXhdTG10EeIjqK+thNvbhnKXJoSPxe7rIk+r+z4HWHjQhxQuT6i4A6AsjvLGV1UI/WxCzrRFJohnaSyd/jx4/BgBd6XXsHzBvrjYSKSDrrBfJJwqrVchLozD6wSKTaTYdK9CSVGYx8S58Kx2m1j1Hk7FuuC6tqPtOARpwlNOX83p4PUMgZln74QzPN65Y2oYx5dszjflyAf5p264ltDwMLlygDTs92kilRCrznnP1iHgtrO3+aV2jwtRtqXB16JpeYKGFMkRtd3afWZ1SaMjU7s+6tVbSvlXg88GstZPqYYw7B4qYP1BGPX6UGiYMtpqH3Tm1Ne3lX3sPQYDFaV7vkd4JoS05vuHuGU+FERJRmaMAHjz2PCEhcgwnQTzL5LFKTcfNHEFv7NkQ8zPiJ7GELg9n2KnWiRhdB4JGUu8WB1LyYP6j3CQ9NwfBj0VGiH8Urgl9fC3IJnXQW3f284vk0VxBQnSdKILHsvdo8pe6INbDu97XOhzZNIc4jLZRT08aQe5Lk+3e7nGf0CCxFNQSlP6FFN7UP9c/Qvd4M3Ys5atBAryQ=

Cargo.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[workspace]
2+
members = [
3+
"ui-sys",
4+
"ui",
5+
"iui",
6+
]

README.md

Lines changed: 92 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,95 @@
1-
# libui-rs
1+
# Improved User Interface
2+
## A cross-platform UI toolkit for Rust based on libui
3+
[![libui-rs build status](https://api.travis-ci.org/LeoTindall/libui-rs.svg?branch=master)](https://travis-ci.org/LeoTindall/libui-rs/)
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)
27

3-
[![Build Status](https://travis-ci.org/lord/libui-rs.svg?branch=master)](https://travis-ci.org/lord/libui-rs)
8+
iui: [![iui crates.io version badge](https://img.shields.io/crates/v/iui.svg)](https://crates.io/crates/iui/)
9+
[![docs.rs for iui](https://docs.rs/iui/badge.svg)](https://docs.rs/iui)
10+
ui-sys: [![ui-sys crates.io version badge](https://img.shields.io/crates/v/ui-sys.svg)](https://crates.io/crates/ui-sys/)
11+
[![docs.rs for ui-sys](https://docs.rs/ui-sys/badge.svg)](https://docs.rs/ui)
412

5-
These are work-in-progress Rust bindings to the minimalistic native UI library [libui][libui].
13+
`iui` is a simple, small, easy to distribute GUI library, a Rusty user interface library that binds to platform native APIs.
14+
These are work-in-progress bindings to the minimalistic native UI library [libui][libui] via the `ui-sys` bindings crate.
615

7-
Fork of the original Rust bindings by [Patrick Walton](https://github.com/andlabs/libui).
16+
Add `iui` to your project with:
17+
18+
```toml
19+
iui = "0.2"
20+
```
21+
22+
## Organization
23+
24+
`iui` is the safe Rust wrapper, to be used by most users.
25+
`ui` is the old version of the safe wrapper. Don't use this.
26+
`ui-sys` is the raw unsafe bindings to the `libui` C code. Requires `cmake` so it can build `libui`.
27+
`libui` is included as a submodule. You will need CMake to build `libui` itself.
28+
29+
Based on work by [@pcwalton](https://github.com/pcwalton/). Licensed MIT.
30+
31+
## Example
32+
33+
![Three example GUI applications running on Linux](themed.png)
34+
35+
```rust
36+
extern crate iui;
37+
use iui::prelude::*;
38+
use iui::controls::{Label, Button, VerticalBox, Group};
39+
40+
fn main() {
41+
// Initialize the UI library
42+
let ui = UI::init().expect("Couldn't initialize UI library");
43+
// Create a window into which controls can be placed
44+
let mut win = Window::new(&ui, "Test App", 200, 200, WindowType::NoMenubar);
45+
46+
// Create a vertical layout to hold the controls
47+
let mut vbox = VerticalBox::new(&ui);
48+
vbox.set_padded(&ui, true);
49+
50+
let mut group_vbox = VerticalBox::new(&ui);
51+
let mut group = Group::new(&ui, "Group");
52+
53+
// Create two buttons to place in the window
54+
let mut button = Button::new(&ui, "Button");
55+
button.on_clicked(&ui, {
56+
let ui = ui.clone();
57+
move |btn| {
58+
btn.set_text(&ui, "Clicked!");
59+
}
60+
});
61+
62+
let mut quit_button = Button::new(&ui, "Quit");
63+
quit_button.on_clicked(&ui, {
64+
let ui = ui.clone();
65+
move |_| {
66+
ui.quit();
67+
}
68+
});
69+
70+
// Create a new label. Note that labels don't auto-wrap!
71+
let mut label_text = String::new();
72+
label_text.push_str("There is a ton of text in this label.\n");
73+
label_text.push_str("Pretty much every unicode character is supported.\n");
74+
label_text.push_str("🎉 用户界面 사용자 인터페이스");
75+
let label = Label::new(&ui, &label_text);
76+
77+
vbox.append(&ui, label, LayoutStrategy::Stretchy);
78+
group_vbox.append(&ui, button, LayoutStrategy::Compact);
79+
group_vbox.append(&ui, quit_button, LayoutStrategy::Compact);
80+
group.set_child(&ui, group_vbox);
81+
vbox.append(&ui, group, LayoutStrategy::Compact);
82+
83+
// Actually put the button in the window
84+
win.set_child(&ui, vbox);
85+
// Show the window
86+
win.show(&ui);
87+
// Run the application
88+
ui.main();
89+
}
90+
```
91+
92+
## Testing Note
93+
Travis does not connect video devices to their testing environments, so the tests cannot be run. Therefore, the "tests" only check compilation.
94+
95+
[libui]: https://github.com/andlabs/libui

iui/Cargo.toml

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
[package]
2+
name = "iui"
3+
version = "0.2.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+
ui-sys = "0.1.1"

iui/examples/basic.rs

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
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 mut win = Window::new(&ui, "Test App", 200, 200, WindowType::NoMenubar);
10+
11+
// Create a vertical layout to hold the controls
12+
let mut vbox = VerticalBox::new(&ui);
13+
vbox.set_padded(&ui, true);
14+
15+
let mut group_vbox = VerticalBox::new(&ui);
16+
let mut group = Group::new(&ui, "Group");
17+
18+
// Create two buttons to place in the window
19+
let mut button = Button::new(&ui, "Button");
20+
button.on_clicked(&ui, {
21+
let ui = ui.clone();
22+
move |btn| {
23+
btn.set_text(&ui, "Clicked!");
24+
}
25+
});
26+
27+
let mut quit_button = Button::new(&ui, "Quit");
28+
quit_button.on_clicked(&ui, {
29+
let ui = ui.clone();
30+
move |_| {
31+
ui.quit();
32+
}
33+
});
34+
35+
// Create a new label. Note that labels don't auto-wrap!
36+
let mut label_text = String::new();
37+
label_text.push_str("There is a ton of text in this label.\n");
38+
label_text.push_str("Pretty much every unicode character is supported.\n");
39+
label_text.push_str("🎉 用户界面 사용자 인터페이스");
40+
let label = Label::new(&ui, &label_text);
41+
42+
vbox.append(&ui, label, LayoutStrategy::Stretchy);
43+
group_vbox.append(&ui, button, LayoutStrategy::Compact);
44+
group_vbox.append(&ui, quit_button, LayoutStrategy::Compact);
45+
group.set_child(&ui, group_vbox);
46+
vbox.append(&ui, group, LayoutStrategy::Compact);
47+
48+
// Actually put the button in the window
49+
win.set_child(&ui, vbox);
50+
// Show the window
51+
win.show(&ui);
52+
// Run the application
53+
ui.main();
54+
}

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 mut button = Button::new(&ui, "Save Buffer");
18+
19+
// Set up the application's layout
20+
let mut window = Window::new(&ui, "Save Buffer to File", 640, 480, WindowType::NoMenubar);
21+
let mut 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)