Skip to content

Commit 5fd2b24

Browse files
committed
Add simple window autosave function (darwin only)
1 parent 122c39b commit 5fd2b24

File tree

3 files changed

+10
-0
lines changed

3 files changed

+10
-0
lines changed

ui-sys/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ extern {
8888
pub fn uiWindowSetChild(w: *mut uiWindow, child: *mut uiControl);
8989
pub fn uiWindowMargined(w: *mut uiWindow) -> c_int;
9090
pub fn uiWindowSetMargined(w: *mut uiWindow, margined: c_int);
91+
pub fn uiWindowSetAutosave(w: *mut uiWindow, name: *const c_char);
9192
pub fn uiNewWindow(title: *const c_char, width: c_int, height: c_int, hasMenubar: c_int)
9293
-> *mut uiWindow;
9394
}

ui/examples/image.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ impl AreaHandler for ImageAreaHandler {
2525
fn run() {
2626
let mainwin = Window::new("ui Control Gallery", 640, 480, true);
2727
mainwin.set_margined(true);
28+
mainwin.set_autosave("libui-rs_image-example_main-window");
2829
mainwin.on_closing(Box::new(|_| {
2930
ui::quit();
3031
false

ui/src/windows.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,14 @@ impl Window {
8484
}
8585
}
8686

87+
pub fn set_autosave(&self, name: &str) {
88+
ffi_utils::ensure_initialized();
89+
unsafe {
90+
let c_string = CString::new(name.as_bytes().to_vec()).unwrap();
91+
ui_sys::uiWindowSetAutosave(self.ui_window, c_string.as_ptr())
92+
}
93+
}
94+
8795
#[inline]
8896
pub fn new(title: &str, width: c_int, height: c_int, has_menubar: bool) -> Window {
8997
ffi_utils::ensure_initialized();

0 commit comments

Comments
 (0)