Expose position of ui elements

This commit is contained in:
hodasemi 2024-04-21 07:41:08 +02:00
parent a50ef55ad4
commit 94d173e2bb
11 changed files with 48 additions and 0 deletions

View file

@ -136,6 +136,10 @@ impl Gridable for GuiSnippet {
fn set_layer(&self, layer: i32) -> Result<()> {
self.grid.set_layer(layer)
}
fn position_extent(&self) -> (i32, i32, u32, u32) {
self.grid.position_extent()
}
}
impl Functionality for GuiSnippet {

View file

@ -501,6 +501,10 @@ impl Gridable for Button {
Ok(())
}
fn position_extent(&self) -> (i32, i32, u32, u32) {
self.framable.position()
}
}
impl Drop for Button {

View file

@ -738,6 +738,10 @@ impl Gridable for Grid {
Ok(())
}
fn position_extent(&self) -> (i32, i32, u32, u32) {
self.framable.position()
}
}
impl Drop for Grid {

View file

@ -287,6 +287,10 @@ impl Gridable for Icon {
Ok(())
}
fn position_extent(&self) -> (i32, i32, u32, u32) {
self.framable.position()
}
}
impl Drop for Icon {

View file

@ -242,6 +242,10 @@ impl Gridable for Label {
Ok(())
}
fn position_extent(&self) -> (i32, i32, u32, u32) {
self.framable.position()
}
}
impl Drop for Label {

View file

@ -296,4 +296,8 @@ impl Gridable for MultiLineLabel {
fn set_layer(&self, layer: i32) -> Result<()> {
self.grid.set_layer(layer)
}
fn position_extent(&self) -> (i32, i32, u32, u32) {
self.grid.position_extent()
}
}

View file

@ -416,6 +416,10 @@ impl Gridable for MultiLineTextField {
self.writeable.set_ui_layer(layer);
self.grid.set_layer(layer)
}
fn position_extent(&self) -> (i32, i32, u32, u32) {
self.grid.position_extent()
}
}
impl Drop for MultiLineTextField {

View file

@ -343,6 +343,10 @@ impl Gridable for ProgressBar {
Ok(())
}
fn position_extent(&self) -> (i32, i32, u32, u32) {
self.framable.position()
}
}
impl Drop for ProgressBar {

View file

@ -293,6 +293,10 @@ impl Gridable for TextField {
Ok(())
}
fn position_extent(&self) -> (i32, i32, u32, u32) {
self.framable.position()
}
}
impl Visibility for TextField {

View file

@ -67,6 +67,8 @@ pub trait Gridable {
fn type_name(&self) -> &str;
fn set_layer(&self, layer: i32) -> Result<()>;
fn position_extent(&self) -> (i32, i32, u32, u32);
}
pub trait Visibility {

View file

@ -281,6 +281,16 @@ impl Framable {
self.bottom.load(SeqCst)
}
pub fn position(&self) -> (i32, i32, u32, u32) {
let x = self.left();
let y = self.top();
let w = self.right() - x;
let h = self.bottom() - y;
(x, y, w as u32, h as u32)
}
/// Returns `true` if `set_frame` got called, otherwise `false`
pub fn is_framed(&self) -> bool {
self.framed.load(SeqCst)