1use super::*;
2
3impl Ui {
4 pub(super) fn assert_finite_f32(caller: &str, name: &str, value: f32) {
5 assert!(value.is_finite(), "{caller} {name} must be finite");
6 }
7
8 pub(super) fn assert_finite_vec2(caller: &str, name: &str, value: [f32; 2]) {
9 assert!(
10 value[0].is_finite() && value[1].is_finite(),
11 "{caller} {name} must contain finite values"
12 );
13 }
14
15 pub(crate) fn new() -> Self {
19 Ui {
20 buffer: UnsafeCell::new(UiBuffer::new(1024)),
21 }
22 }
23
24 #[doc(alias = "GetIO")]
26 pub fn io(&self) -> &crate::io::Io {
27 unsafe {
28 let io = sys::igGetIO_Nil();
29 if io.is_null() {
30 panic!("Ui::io() requires an active ImGui context");
31 }
32 &*(io as *const crate::io::Io)
33 }
34 }
35
36 pub(crate) fn scratch_txt(&self, txt: impl AsRef<str>) -> *const std::os::raw::c_char {
38 unsafe {
39 let handle = &mut *self.buffer.get();
40 handle.scratch_txt(txt)
41 }
42 }
43
44 pub(crate) fn scratch_txt_two(
46 &self,
47 txt_0: impl AsRef<str>,
48 txt_1: impl AsRef<str>,
49 ) -> (*const std::os::raw::c_char, *const std::os::raw::c_char) {
50 unsafe {
51 let handle = &mut *self.buffer.get();
52 handle.scratch_txt_two(txt_0, txt_1)
53 }
54 }
55
56 pub(crate) fn scratch_txt_with_opt(
58 &self,
59 txt_0: impl AsRef<str>,
60 txt_1: Option<impl AsRef<str>>,
61 ) -> (*const std::os::raw::c_char, *const std::os::raw::c_char) {
62 unsafe {
63 let handle = &mut *self.buffer.get();
64 handle.scratch_txt_with_opt(txt_0, txt_1)
65 }
66 }
67
68 pub(crate) fn scratch_buffer(&self) -> &UnsafeCell<UiBuffer> {
70 &self.buffer
71 }
72
73 #[doc(alias = "GetID")]
78 pub fn get_id(&self, label: &str) -> Id {
79 unsafe { Id::from(sys::igGetID_Str(self.scratch_txt(label))) }
80 }
81}