Skip to content

Commit a1d8972

Browse files
committed
Add functions to handle event loop manually
* main_steps * main_step
1 parent 7b1126d commit a1d8972

File tree

4 files changed

+23
-4
lines changed

4 files changed

+23
-4
lines changed

ui-sys/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ extern {
2424
pub fn uiUninit();
2525
pub fn uiFreeInitError(err: *const c_char);
2626

27+
pub fn uiMainSteps();
28+
pub fn uiMainStep(wait: c_int) -> c_int;
2729
pub fn uiMain();
2830
pub fn uiQuit();
2931

ui/Cargo.toml

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

66
[dependencies]

ui/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ pub use controls::{Combobox, Control, DateTimePicker, Entry, FontButton, Group,
1414
pub use controls::{MultilineEntry, ProgressBar, RadioButtons, Separator, Slider, Spinbox, Tab};
1515
pub use ffi_utils::Text;
1616
pub use menus::{Menu, MenuItem};
17-
pub use ui::{InitError, InitOptions, init, main, msg_box, msg_box_error, on_should_quit};
17+
pub use ui::{InitError, InitOptions, init, main_steps, main_step, main, msg_box, msg_box_error, on_should_quit};
1818
pub use ui::{open_file, queue_main, quit, save_file, uninit};
1919
pub use windows::Window;
2020
pub use image::Image;

ui/src/ui.rs

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! General functions.
22
33
use ffi_utils::{self, Text};
4-
use libc::{c_char, c_void};
4+
use libc::{c_char, c_int, c_void};
55
use std::fmt::{self, Debug, Formatter};
66
use std::ffi::{CStr, CString};
77
use std::mem;
@@ -13,7 +13,7 @@ use windows::Window;
1313
pub struct InitOptions;
1414

1515
#[inline]
16-
pub fn init(_: InitOptions) -> Result<(),InitError> {
16+
pub fn init(_: InitOptions) -> Result<(), InitError> {
1717
unsafe {
1818
let mut init_options = uiInitOptions {
1919
Size: mem::size_of::<uiInitOptions>(),
@@ -39,6 +39,23 @@ pub fn uninit() {
3939
}
4040
}
4141

42+
/// start manual control over event loop
43+
#[inline]
44+
pub fn main_steps() {
45+
unsafe {
46+
ui_sys::uiMainSteps()
47+
}
48+
}
49+
50+
/// advance event loop
51+
#[inline]
52+
pub fn main_step(wait: bool) -> bool {
53+
unsafe {
54+
ui_sys::uiMainStep(if wait { 1 } else { 0 }) > 0
55+
}
56+
}
57+
58+
/// call to start event loop handled by libui
4259
#[inline]
4360
pub fn main() {
4461
unsafe {

0 commit comments

Comments
 (0)