delete use of the chlorine crate

This commit is contained in:
Lokathor 2024-12-27 11:25:02 -07:00 committed by Jonathan Spira
parent 8445334450
commit 4d56a476b6
7 changed files with 746 additions and 723 deletions

View File

@ -26,7 +26,6 @@ exclude = [
]
[dependencies]
chlorine = "1.0.7"
mint = "0.5.6"
cfg-if = "1"

File diff suppressed because it is too large Load Diff

View File

@ -1,24 +1,4 @@
#![no_std]
// We use `chlorine` over (the more well known) `cty` right now since `cty`
// doesn't fully match std::os::raw (leading to issues like
// https://github.com/japaric/cty/issues/18). Chlorine *does* match std::os::raw
// (and libc), but has a longer and more confusing name, so we just alias it.
// Also, this makes it easier to switch to something else/back easier, if we
// decide to.
//
// Note that with the exception of bugs like the above, which crate we use (cty,
// chlorine, libc, std::os::raw, ...) shouldn't matter to end user code¹, since
// these are type aliases that should all be equivalent. This means that we're
// free to switch back iff the bug is fixed, and users are free to use whichever
// they prefer regardless of what we chose.
//
// (TODO: using extern crate for this is a hack, we probably should replace this
// with `use chlorine as cty` in the binding files eventually, but lets punt on
// it for a bit)
//
// ¹ The exception to this is that `std::os::raw` isn't there for `no_std`, and
// `libc` has potentially undesirable linking impacts on windows.
pub extern crate chlorine as cty;
cfg_if::cfg_if! {
if #[cfg(feature = "wasm")] {

View File

@ -304,7 +304,7 @@ where
sys::igInputTextWithHint(
label,
hint,
ptr as *mut sys::cty::c_char,
ptr as *mut core::ffi::c_char,
capacity,
self.flags.bits() as i32,
Some(callback::<T>),
@ -315,7 +315,7 @@ where
sys::igInputText(
label,
ptr as *mut sys::cty::c_char,
ptr as *mut core::ffi::c_char,
capacity,
self.flags.bits() as i32,
Some(callback::<T>),
@ -461,7 +461,7 @@ impl<'ui, 'p, T: InputTextCallbackHandler, L: AsRef<str>> InputTextMultiline<'ui
let o = unsafe {
sys::igInputTextMultiline(
self.ui.scratch_txt(self.label),
ptr as *mut sys::cty::c_char,
ptr as *mut core::ffi::c_char,
capacity,
self.size.into(),
self.flags.bits() as i32,

View File

@ -236,7 +236,7 @@ impl Ui {
}
/// Internal method to push a single text to our scratch buffer.
fn scratch_txt(&self, txt: impl AsRef<str>) -> *const sys::cty::c_char {
fn scratch_txt(&self, txt: impl AsRef<str>) -> *const core::ffi::c_char {
unsafe {
let handle = &mut *self.buffer.get();
handle.scratch_txt(txt)
@ -244,7 +244,7 @@ impl Ui {
}
/// Internal method to push an option text to our scratch buffer.
fn scratch_txt_opt(&self, txt: Option<impl AsRef<str>>) -> *const sys::cty::c_char {
fn scratch_txt_opt(&self, txt: Option<impl AsRef<str>>) -> *const core::ffi::c_char {
unsafe {
let handle = &mut *self.buffer.get();
handle.scratch_txt_opt(txt)
@ -255,7 +255,7 @@ impl Ui {
&self,
txt_0: impl AsRef<str>,
txt_1: impl AsRef<str>,
) -> (*const sys::cty::c_char, *const sys::cty::c_char) {
) -> (*const core::ffi::c_char, *const core::ffi::c_char) {
unsafe {
let handle = &mut *self.buffer.get();
handle.scratch_txt_two(txt_0, txt_1)
@ -266,7 +266,7 @@ impl Ui {
&self,
txt_0: impl AsRef<str>,
txt_1: Option<impl AsRef<str>>,
) -> (*const sys::cty::c_char, *const sys::cty::c_char) {
) -> (*const core::ffi::c_char, *const core::ffi::c_char) {
unsafe {
let handle = &mut *self.buffer.get();
handle.scratch_txt_with_opt(txt_0, txt_1)
@ -418,7 +418,7 @@ impl Ui {
/// Create [`Id`] from a pointer
pub fn new_id_ptr<T>(&self, input: &T) -> Id {
let p = input as *const T as *const sys::cty::c_void;
let p = input as *const T as *const core::ffi::c_void;
let value = unsafe { sys::igGetID_Ptr(p) };
Id(value)
}

View File

@ -22,7 +22,7 @@ impl UiBuffer {
}
/// Internal method to push a single text to our scratch buffer.
pub fn scratch_txt(&mut self, txt: impl AsRef<str>) -> *const sys::cty::c_char {
pub fn scratch_txt(&mut self, txt: impl AsRef<str>) -> *const core::ffi::c_char {
self.refresh_buffer();
let start_of_substr = self.push(txt);
@ -30,7 +30,7 @@ impl UiBuffer {
}
/// Internal method to push an option text to our scratch buffer.
pub fn scratch_txt_opt(&mut self, txt: Option<impl AsRef<str>>) -> *const sys::cty::c_char {
pub fn scratch_txt_opt(&mut self, txt: Option<impl AsRef<str>>) -> *const core::ffi::c_char {
match txt {
Some(v) => self.scratch_txt(v),
None => ptr::null(),
@ -42,7 +42,7 @@ impl UiBuffer {
&mut self,
txt_0: impl AsRef<str>,
txt_1: impl AsRef<str>,
) -> (*const sys::cty::c_char, *const sys::cty::c_char) {
) -> (*const core::ffi::c_char, *const core::ffi::c_char) {
self.refresh_buffer();
let first_offset = self.push(txt_0);
@ -56,7 +56,7 @@ impl UiBuffer {
&mut self,
txt_0: impl AsRef<str>,
txt_1: Option<impl AsRef<str>>,
) -> (*const sys::cty::c_char, *const sys::cty::c_char) {
) -> (*const core::ffi::c_char, *const core::ffi::c_char) {
match txt_1 {
Some(value) => self.scratch_txt_two(txt_0, value),
None => (self.scratch_txt(txt_0), ptr::null()),
@ -76,7 +76,7 @@ impl UiBuffer {
/// # Safety
/// This can return a pointer to undefined data if given a `pos >= self.buffer.len()`.
/// This is marked as unsafe to reflect that.
pub unsafe fn offset(&self, pos: usize) -> *const sys::cty::c_char {
pub unsafe fn offset(&self, pos: usize) -> *const core::ffi::c_char {
self.buffer.as_ptr().add(pos) as *const _
}

View File

@ -22,7 +22,7 @@ impl TextFilter {
let ptr = filter.as_mut_ptr();
Self {
id: label,
raw: unsafe { sys::ImGuiTextFilter_ImGuiTextFilter(ptr as *mut sys::cty::c_char) },
raw: unsafe { sys::ImGuiTextFilter_ImGuiTextFilter(ptr as *mut core::ffi::c_char) },
}
}
@ -51,7 +51,7 @@ impl TextFilter {
let mut id = self.id.clone();
id.push('\0');
let ptr = id.as_mut_ptr();
sys::ImGuiTextFilter_Draw(self.raw, ptr as *mut sys::cty::c_char, size);
sys::ImGuiTextFilter_Draw(self.raw, ptr as *mut core::ffi::c_char, size);
}
}
@ -68,7 +68,7 @@ impl TextFilter {
buf.push('\0');
let ptr = buf.as_mut_ptr();
unsafe {
sys::ImGuiTextFilter_PassFilter(self.raw, ptr as *mut sys::cty::c_char, ptr::null())
sys::ImGuiTextFilter_PassFilter(self.raw, ptr as *mut core::ffi::c_char, ptr::null())
}
}
@ -81,8 +81,8 @@ impl TextFilter {
unsafe {
sys::ImGuiTextFilter_PassFilter(
self.raw,
b_ptr as *mut sys::cty::c_char,
e_ptr as *mut sys::cty::c_char,
b_ptr as *mut core::ffi::c_char,
e_ptr as *mut core::ffi::c_char,
)
}
}