1use std::sync::Arc;
3
4use crate::{view::View, Library};
5
6pub struct Overlay {
14 lib: Arc<Library>,
15 internal: ul_sys::ULOverlay,
16
17 view: View,
18}
19
20impl Overlay {
21 pub(crate) unsafe fn create(
24 lib: Arc<Library>,
25 window: ul_sys::ULWindow,
26 width: u32,
27 height: u32,
28 x: i32,
29 y: i32,
30 ) -> Option<Self> {
31 let internal_overlay = lib.appcore().ulCreateOverlay(window, width, height, x, y);
32
33 if internal_overlay.is_null() {
34 return None;
35 }
36
37 let raw_view = lib.appcore().ulOverlayGetView(internal_overlay);
38 let view = View::from_raw(lib.clone(), raw_view)?;
40 Some(Self {
41 lib,
42 internal: internal_overlay,
43 view,
44 })
45 }
46
47 pub(crate) unsafe fn create_with_view(
50 lib: Arc<Library>,
51 window_raw: ul_sys::ULWindow,
52 view: View,
53 x: i32,
54 y: i32,
55 ) -> Option<Self> {
56 let internal = lib
57 .appcore()
58 .ulCreateOverlayWithView(window_raw, view.to_ul(), x, y);
59 if internal.is_null() {
60 return None;
61 }
62
63 Some(Self {
64 lib,
65 internal,
66 view,
67 })
68 }
69}
70
71impl Overlay {
72 pub fn view(&self) -> &View {
74 &self.view
75 }
76
77 pub fn width(&self) -> u32 {
79 unsafe { self.lib.appcore().ulOverlayGetWidth(self.internal) }
80 }
81
82 pub fn height(&self) -> u32 {
84 unsafe { self.lib.appcore().ulOverlayGetHeight(self.internal) }
85 }
86
87 pub fn x(&self) -> i32 {
89 unsafe { self.lib.appcore().ulOverlayGetX(self.internal) }
90 }
91
92 pub fn y(&self) -> i32 {
94 unsafe { self.lib.appcore().ulOverlayGetY(self.internal) }
95 }
96
97 pub fn is_hidden(&self) -> bool {
99 unsafe { self.lib.appcore().ulOverlayIsHidden(self.internal) }
100 }
101
102 pub fn show(&self) {
104 unsafe { self.lib.appcore().ulOverlayShow(self.internal) }
105 }
106
107 pub fn hide(&self) {
109 unsafe { self.lib.appcore().ulOverlayHide(self.internal) }
110 }
111
112 pub fn has_focus(&self) -> bool {
114 unsafe { self.lib.appcore().ulOverlayHasFocus(self.internal) }
115 }
116
117 pub fn focus(&self) {
119 unsafe { self.lib.appcore().ulOverlayFocus(self.internal) }
120 }
121
122 pub fn unfocus(&self) {
124 unsafe { self.lib.appcore().ulOverlayUnfocus(self.internal) }
125 }
126
127 pub fn move_to(&self, x: i32, y: i32) {
129 unsafe { self.lib.appcore().ulOverlayMoveTo(self.internal, x, y) }
130 }
131
132 pub fn resize(&self, width: u32, height: u32) {
135 unsafe {
136 self.lib
137 .appcore()
138 .ulOverlayResize(self.internal, width, height)
139 }
140 }
141
142 }
146
147impl Drop for Overlay {
148 fn drop(&mut self) {
149 unsafe {
150 self.lib.appcore().ulDestroyOverlay(self.internal);
151 }
152 }
153}