use super::*;
#[unsafe(no_mangle)]
pub extern "C" fn kui_env_set_window(
ptr: *mut KuiCtx,
window: u32,
custom_chrome: bool,
maximized: bool,
fullscreen: bool,
controls_w: f32,
controls_h: f32,
) {
guard((), || {
if let Some(c) = unsafe { ctx(ptr) } {
let win = &mut c.core().env.window;
win.id = WindowId(window);
win.custom_chrome = custom_chrome;
win.maximized = maximized;
win.fullscreen = fullscreen;
win.native_controls = (controls_w > 0.0 && controls_h > 0.0)
.then(|| Rect::new(0.0, 0.0, controls_w, controls_h));
}
});
}
#[unsafe(no_mangle)]
pub extern "C" fn kui_take_window_command(ptr: *mut KuiCtx, out: *mut KuiWindowCommand) -> bool {
guard(false, || {
let Some(c) = (unsafe { ctx(ptr) }) else {
return false;
};
if c.window_commands.is_empty() {
let fresh = c.core().take_window_commands();
c.window_commands.extend(fresh);
}
let Some(&cmd) = c.window_commands.front() else {
return false;
};
if !write_out(out, window_command_to_c(cmd)) {
return false;
}
c.window_commands.pop_front();
true
})
}
#[unsafe(no_mangle)]
pub extern "C" fn kui_window_declare(ptr: *mut KuiCtx, name: KuiStr, cfg: *const KuiWindowConfig) {
guard((), || {
if let Some(c) = unsafe { ctx(ptr) } {
let raw = unsafe { cfg.as_ref() };
let cfg = window_config_of(raw);
let name = kstr(name);
if let Some(k) = raw
.map(|c| c.kind)
.filter(|k| *k != KUI_WINDOW_KIND_NORMAL && *k != KUI_WINDOW_KIND_POPUP)
{
c.core().warn(kui_core::diag::unknown_window_kind(&name, k));
}
c.core().declare_window(&name, cfg);
}
});
}
#[unsafe(no_mangle)]
pub extern "C" fn kui_set_window_size(ptr: *mut KuiCtx, window: u32, w: f32, h: f32) {
guard((), || {
if let Some(c) = unsafe { ctx(ptr) } {
c.core().set_window_size(WindowId(window), Size::new(w, h));
}
});
}
#[unsafe(no_mangle)]
pub extern "C" fn kui_focus_window(ptr: *mut KuiCtx, window: u32) {
guard((), || {
if let Some(c) = unsafe { ctx(ptr) } {
c.core().focus_window(WindowId(window));
}
});
}
#[unsafe(no_mangle)]
pub extern "C" fn kui_ctx_window(ptr: *mut KuiCtx) -> u32 {
guard(0, || match unsafe { ctx(ptr) } {
Some(c) => c.core().env.window.id.0,
None => 0,
})
}
#[unsafe(no_mangle)]
pub extern "C" fn kui_ctx_window_name(ptr: *mut KuiCtx, out: *mut KuiStr) -> bool {
guard(false, || {
let Some(c) = (unsafe { ctx(ptr) }) else {
return false;
};
if out.is_null() {
return false;
}
let name = c.core().window_name();
unsafe {
*out = KuiStr {
ptr: name.as_ptr(),
len: name.len(),
};
}
c.last_window_name = Some(name);
true
})
}
#[unsafe(no_mangle)]
pub extern "C" fn kui_window_dismissed(ptr: *mut KuiCtx, id: u32, reason: u32) {
guard((), || {
if let Some(c) = unsafe { ctx(ptr) } {
let reason = match reason {
KUI_DISMISS_ESCAPE => DismissReason::Escape,
_ => DismissReason::Outside,
};
c.core().dismiss_window(WindowId(id), reason);
let evs = c.core().take_pending_events();
c.absorb(evs);
}
});
}
#[unsafe(no_mangle)]
pub extern "C" fn kui_window_closed(ptr: *mut KuiCtx, id: u32) {
guard((), || {
if let Some(c) = unsafe { ctx(ptr) } {
c.core().window_closed(WindowId(id));
let evs = c.core().take_pending_events();
c.absorb(evs);
}
});
}
#[unsafe(no_mangle)]
pub extern "C" fn kui_window_title(ptr: *mut KuiCtx, title: KuiStr) {
guard((), || {
if let Some(c) = unsafe { ctx(ptr) } {
let title = kstr(title).into_owned();
c.core().set_window_title(&title);
}
});
}
#[unsafe(no_mangle)]
pub extern "C" fn kui_window_title_get(ptr: *mut KuiCtx, out: *mut KuiStr) -> bool {
guard(false, || {
let (Some(c), Some(out)) = (unsafe { ctx(ptr) }, unsafe { out.as_mut() }) else {
return false;
};
let Some(t) = c.core().window_title() else {
return false;
};
*out = KuiStr {
ptr: t.as_ptr(),
len: t.len(),
};
true
})
}
#[unsafe(no_mangle)]
pub extern "C" fn kui_set_always_on_top(ptr: *mut KuiCtx, on_top: bool) {
guard((), || {
if let Some(c) = unsafe { ctx(ptr) } {
c.core().set_always_on_top(on_top);
}
});
}
#[unsafe(no_mangle)]
pub extern "C" fn kui_always_on_top_get(ptr: *mut KuiCtx) -> bool {
guard(false, || {
unsafe { ctx(ptr) }.is_some_and(|c| c.core().always_on_top())
})
}
#[unsafe(no_mangle)]
pub extern "C" fn kui_set_secure_input(ptr: *mut KuiCtx, on: bool) {
guard((), || {
if let Some(c) = unsafe { ctx(ptr) } {
c.core().set_secure_input(on);
}
});
}
#[unsafe(no_mangle)]
pub extern "C" fn kui_secure_input_get(ptr: *mut KuiCtx) -> bool {
guard(false, || {
unsafe { ctx(ptr) }.is_some_and(|c| c.core().secure_input())
})
}
#[unsafe(no_mangle)]
pub extern "C" fn kui_set_option_as_alt(ptr: *mut KuiCtx, option_as_alt: u32) {
guard((), || {
if let Some(c) = unsafe { ctx(ptr) } {
c.core()
.set_option_as_alt(OptionAsAlt::from_index(option_as_alt).unwrap_or_default());
}
});
}
#[unsafe(no_mangle)]
pub extern "C" fn kui_option_as_alt_get(ptr: *mut KuiCtx) -> u32 {
guard(KUI_OPTION_AS_ALT_NONE, || {
unsafe { ctx(ptr) }.map_or(KUI_OPTION_AS_ALT_NONE, |c| c.core().option_as_alt().index())
})
}
#[unsafe(no_mangle)]
pub extern "C" fn kui_set_ime_off(ptr: *mut KuiCtx, off: bool) {
guard((), || {
if let Some(c) = unsafe { ctx(ptr) } {
c.core().set_ime_off(off);
}
});
}
#[unsafe(no_mangle)]
pub extern "C" fn kui_ime_off_get(ptr: *mut KuiCtx) -> bool {
guard(false, || {
unsafe { ctx(ptr) }.is_some_and(|c| c.core().ime_off())
})
}
#[unsafe(no_mangle)]
pub extern "C" fn kui_env_set_always_on_top(ptr: *mut KuiCtx, always_on_top: bool) {
guard((), || {
if let Some(c) = unsafe { ctx(ptr) } {
c.core().env.window.always_on_top = always_on_top;
}
});
}
#[unsafe(no_mangle)]
pub extern "C" fn kui_env_set_backdrop(ptr: *mut KuiCtx, backdrop: u32) {
guard((), || {
if let Some(c) = unsafe { ctx(ptr) }
&& let Some(b) = kui_core::Backdrop::from_code(backdrop)
{
c.core().env.window.backdrop = b;
}
});
}
#[unsafe(no_mangle)]
pub extern "C" fn kui_ctx_backdrop(ptr: *mut KuiCtx) -> u32 {
guard(0, || match unsafe { ctx(ptr) } {
Some(c) => {
let b = c.core().env.window.backdrop;
kui_core::Backdrop::ALL
.iter()
.position(|x| *x == b)
.unwrap_or(0) as u32
}
None => 0,
})
}