Add info icon to icon

This commit is contained in:
hodasemi 2024-05-17 14:16:30 +02:00
parent 34b569b59b
commit 5eec536a27

View file

@ -1,4 +1,7 @@
use crate::{builder::validator::iconinfo::IconInfo, prelude::*}; use crate::{
builder::validator::iconinfo::IconInfo, guihandler::gui::iconizable::IconizablePositioning,
prelude::*,
};
use anyhow::Result; use anyhow::Result;
use utilities::prelude::*; use utilities::prelude::*;
use vulkan_rs::prelude::*; use vulkan_rs::prelude::*;
@ -84,11 +87,24 @@ impl IconBuilder {
textable_wrapper.set_text(&text, false)?; textable_wrapper.set_text(&text, false)?;
} }
let info_icon = IconizableWrapper::new(
framable.clone(),
None,
Some(IconizablePositioning {
left: 1.2,
right: 0.0,
top: 1.2,
bottom: 0.0,
}),
0,
)?;
Ok(Arc::new(Icon { Ok(Arc::new(Icon {
framable, framable,
background, background,
iconizable_wrapper, iconizable_wrapper,
textable_wrapper, textable_wrapper,
info_icon,
visible: AtomicBool::new(false), visible: AtomicBool::new(false),
})) }))
@ -100,6 +116,7 @@ pub struct Icon {
background: RwLock<Option<FillType>>, background: RwLock<Option<FillType>>,
iconizable_wrapper: IconizableWrapper, iconizable_wrapper: IconizableWrapper,
textable_wrapper: TextableWrapper, textable_wrapper: TextableWrapper,
info_icon: IconizableWrapper,
visible: AtomicBool, visible: AtomicBool,
} }
@ -149,6 +166,14 @@ impl Icon {
self.textable_wrapper.set_text_color(color) self.textable_wrapper.set_text_color(color)
} }
pub fn set_info_icon(&self, button: &Arc<Image>) -> Result<()> {
self.info_icon.set_icon(button, self.visible())
}
pub fn clear_info_icon(&self) -> Result<()> {
self.info_icon.clear_icon(self.visible())
}
pub fn try_from(icon_info: &IconInfo, gui_handler: &Arc<GuiHandler>) -> Result<Arc<Self>> { pub fn try_from(icon_info: &IconInfo, gui_handler: &Arc<GuiHandler>) -> Result<Arc<Self>> {
let mut icon_builder = Icon::builder().set_text_color(icon_info.text_color); let mut icon_builder = Icon::builder().set_text_color(icon_info.text_color);
@ -196,6 +221,7 @@ impl Icon {
self.iconizable_wrapper.disable()?; self.iconizable_wrapper.disable()?;
self.textable_wrapper.disable()?; self.textable_wrapper.disable()?;
self.info_icon.disable()?;
if let Some(background) = self.background.read().unwrap().as_ref() { if let Some(background) = self.background.read().unwrap().as_ref() {
background.disable()?; background.disable()?;
@ -233,6 +259,7 @@ impl Visibility for Icon {
self.iconizable_wrapper.enable()?; self.iconizable_wrapper.enable()?;
self.textable_wrapper.enable()?; self.textable_wrapper.enable()?;
self.info_icon.enable()?;
if let Some(background) = self.background.read().unwrap().as_ref() { if let Some(background) = self.background.read().unwrap().as_ref() {
background.enable()?; background.enable()?;
@ -260,6 +287,7 @@ impl Gridable for Icon {
self.iconizable_wrapper.update_frame()?; self.iconizable_wrapper.update_frame()?;
self.textable_wrapper.update()?; self.textable_wrapper.update()?;
self.info_icon.update_frame()?;
if let Some(background) = self.background.read().unwrap().as_ref() { if let Some(background) = self.background.read().unwrap().as_ref() {
background.update_frame()?; background.update_frame()?;
@ -280,6 +308,7 @@ impl Gridable for Icon {
self.framable.set_ui_layer(layer); self.framable.set_ui_layer(layer);
self.iconizable_wrapper.set_ui_layer(layer)?; self.iconizable_wrapper.set_ui_layer(layer)?;
self.textable_wrapper.set_ui_layer(layer)?; self.textable_wrapper.set_ui_layer(layer)?;
self.info_icon.set_ui_layer(layer)?;
if let Some(background) = self.background.read().unwrap().as_ref() { if let Some(background) = self.background.read().unwrap().as_ref() {
background.set_ui_layer(layer); background.set_ui_layer(layer);