clay_layout/elements/
custom.rs1use core::{ffi::c_void, ptr};
2
3use crate::{bindings::*, mem, DataRef, TypedConfig};
4
5use super::ElementConfigType;
6
7#[derive(Debug, Copy, Clone)]
8pub struct Custom {
9 pub data: *mut c_void,
10}
11
12impl Custom {
13 pub fn new() -> Self {
14 Self::default()
15 }
16
17 pub fn data(&mut self, data: DataRef) -> &mut Self {
19 self.data = data.ptr as *mut c_void;
20 self
21 }
22
23 pub fn end(&self) -> TypedConfig {
24 let memory = unsafe { Clay__StoreCustomElementConfig((*self).into()) };
25
26 TypedConfig {
27 config_memory: memory as _,
28 id: mem::zeroed_init(),
29 config_type: ElementConfigType::Image as _,
30 }
31 }
32}
33
34impl Default for Custom {
35 fn default() -> Self {
36 Self {
37 data: ptr::null_mut(),
38 }
39 }
40}
41
42impl From<Clay_CustomElementConfig> for Custom {
43 fn from(value: Clay_CustomElementConfig) -> Self {
44 Self {
45 data: value.customData,
46 }
47 }
48}
49
50impl From<Custom> for Clay_CustomElementConfig {
51 fn from(value: Custom) -> Self {
52 Self {
53 customData: value.data,
54 }
55 }
56}