#[allow(unused_imports)]
use super::*;
#[cfg(feature = "image_processing")]
const ICON_SIZE_MEDIUM: f32 = 30.;
pub mod embedded_icons {
pub const DEFAULT_LINK: &str = "__default_link";
pub const CONFLUENCE_VIRTUOS: &str = "confluence";
pub const CONFLUENCE_CLIENT: &str = "client_confluence";
pub const ZOOM_VIRTUOS: &str = "zoom";
pub const ZOOM_WOOKIEE: &str = "wookiee_zoom";
pub const ZOOM_CLIENT: &str = "client_zoom";
pub const SHOTGRID: &str = "shotgrid";
pub const HANSOFT: &str = "hansoft";
pub const MS_TEAMS: &str = "ms_teams";
pub const P4V: &str = "p4v";
pub const JIRA: &str = "jira";
pub const LFX: &str = "lfx";
pub const MEDIA_SHUTTLE: &str = "media_shuttle";
pub const TRANSLATE: &str = "translate";
pub const LUCID_CHART: &str = "lucid_chart";
pub const PIPELINE: &str = "pipeline";
pub const PROJECT_PORTAL: &str = "project_portal";
pub const ADD_LINK: &str = "add_new_link";
pub const NO_PROJ_THUMB: &str = "no_proj_thumb";
pub const DUMMY_PROFILE: &str = "dummy_profile";
pub const ASSET_REVEAL_DIR: &str = "asset_reveal_dir";
pub const REVEAL_BRIEF_DIR: &str = "reveal_brief_dir";
pub const OPEN_BRIEF_DOC: &str = "open_brief_doc";
pub const NEXT_STAGE: &str = "next_stage";
pub const CATEGORY_CREATOR: &str = "category_creator";
pub const ASSET_GENESIS: &str = "asset_genesis";
pub const STAFF_GENESIS: &str = "staff_genesis";
pub const QMS_NOTIFIER: &str = "qms_notifier";
pub const DEFECT_TRACKING: &str = "defect_tracking";
pub const PROGRESS_REVIEW: &str = "progress_review";
pub const NOTICE_MASTER: &str = "notice_master";
pub const PREFERENCES: &str = "preferences";
pub const TOOL_WINDOWS: &str = "tool_windows";
pub const MAYA: &str = "maya";
pub const _3DS_MAX: &str = "3ds_max";
pub const BLENDER: &str = "blender";
pub const HOUDINI: &str = "houdini";
pub const ZBRUSH: &str = "zbrush";
pub const SUBSTANCE_PAINTER: &str = "substance_painter";
pub const MARI: &str = "mari";
pub const UNREAL: &str = "unreal";
pub const UNITY: &str = "unity";
pub const HUNTER: &str = "hunter";
}
#[cfg(feature = "image_processing")]
static ICON_BOOK_INSTANCE: OnceCell<IconCel> = OnceCell::new();
#[cfg(feature = "image_processing")]
#[derive(Debug)]
pub struct IconCel {
icon: IconBook,
}
#[cfg(feature = "image_processing")]
impl IconCel {
pub fn icon_book() -> &'static IconBook {
&ICON_BOOK_INSTANCE
.get()
.expect("IconCel is not initialized")
.icon
}
pub fn init() -> AnyResult<()> {
let icon_cel = IconCel {
icon: IconBook::new()?,
};
match ICON_BOOK_INSTANCE.set(icon_cel) {
Ok(_) => {
info!("Initialized IconCel");
Ok(())
}
Err(_e) => Err(anyhow!("Failed to assign IconCel again")),
}
}
}
#[cfg(feature = "image_processing")]
struct EmbeddedIcon {
img: RetainedImage,
public: bool,
}
#[cfg(feature = "image_processing")]
impl EmbeddedIcon {
fn from_bytes(bytes: &[u8], public: bool) -> AnyResult<Self> {
Ok(Self {
img: pixel::retained_image_from_bytes(bytes)?,
public,
})
}
}
#[cfg(feature = "image_processing")]
pub struct IconBook(HashMap<String, EmbeddedIcon>);
#[cfg(feature = "image_processing")]
impl fmt::Debug for IconBook {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_tuple("IconBook")
.field(
&self
.0
.iter()
.map(|(k, v)| format!("{}, {}", k, v.img.debug_name()))
.collect::<Vec<String>>(),
)
.finish()
}
}
#[cfg(feature = "image_processing")]
impl IconBook {
pub fn get_included(&self, key: &str) -> &RetainedImage {
&self.0.get(key).unwrap().img
}
pub fn get_or_default(&self, key: &str) -> &RetainedImage {
match self.0.get(key) {
Some(icon) => &icon.img,
None => self.get_included(embedded_icons::DEFAULT_LINK),
}
}
pub fn select_public_icon_key_ui(&self, key: &mut String, ui: &mut egui::Ui) {
egui::ComboBox::from_label("Icon")
.selected_text(key.as_str())
.show_ui(ui, |ui| {
egui::Grid::new("icon_book").show(ui, |ui| {
for (i, (k, icon)) in self.0.iter().filter(|(_, v)| v.public).enumerate() {
let button = ImageButton::new(
icon.img.texture_id(ui.ctx()),
[ICON_SIZE_MEDIUM, ICON_SIZE_MEDIUM],
);
if button
.ui(ui)
.on_hover_text(format!("Change icon to {}", k))
.clicked()
{
*key = k.to_owned();
};
if (i + 1) % 3 == 0 {
ui.end_row();
};
}
});
});
}
pub fn new() -> AnyResult<Self> {
let mut map = HashMap::<String, EmbeddedIcon>::new();
map.insert(
embedded_icons::DEFAULT_LINK.into(),
EmbeddedIcon::from_bytes(
&include_bytes!("../../../../_icons/baseline_link_white_48dp.png").to_vec(),
true,
)?,
);
map.insert(
embedded_icons::CONFLUENCE_VIRTUOS.into(),
EmbeddedIcon::from_bytes(
&include_bytes!("../../../../_icons/confluence-virtuos-logo-256x256.png").to_vec(),
true,
)?,
);
map.insert(
embedded_icons::CONFLUENCE_CLIENT.into(),
EmbeddedIcon::from_bytes(
&include_bytes!("../../../../_icons/confluence-client-logo-256x256.png").to_vec(),
true,
)?,
);
map.insert(
embedded_icons::ZOOM_VIRTUOS.into(),
EmbeddedIcon::from_bytes(
&include_bytes!("../../../../_icons/zoom-virtuos-logo-256x256.png").to_vec(),
true,
)?,
);
map.insert(
embedded_icons::ZOOM_WOOKIEE.into(),
EmbeddedIcon::from_bytes(
&include_bytes!("../../../../_icons/zoom-wookiee-logo-256x256.png").to_vec(),
true,
)?,
);
map.insert(
embedded_icons::ZOOM_CLIENT.into(),
EmbeddedIcon::from_bytes(
&include_bytes!("../../../../_icons/zoom-client-logo-256x256.png").to_vec(),
true,
)?,
);
map.insert(
embedded_icons::SHOTGRID.into(),
EmbeddedIcon::from_bytes(
&include_bytes!("../../../../_icons/shotgrid-logo-256x256.png").to_vec(),
true,
)?,
);
map.insert(
embedded_icons::HANSOFT.into(),
EmbeddedIcon::from_bytes(
&include_bytes!("../../../../_icons/hansoft-logo-256x256.png").to_vec(),
true,
)?,
);
map.insert(
embedded_icons::MS_TEAMS.into(),
EmbeddedIcon::from_bytes(
&include_bytes!("../../../../_icons/microsoft-teams-logo-256x256.png").to_vec(),
true,
)?,
);
map.insert(
embedded_icons::P4V.into(),
EmbeddedIcon::from_bytes(
&include_bytes!("../../../../_icons/p4v-logo-256x256.png").to_vec(),
true,
)?,
);
map.insert(
embedded_icons::JIRA.into(),
EmbeddedIcon::from_bytes(
&include_bytes!("../../../../_icons/offsite-jira-logo-256x256.png").to_vec(),
true,
)?,
);
map.insert(
embedded_icons::LFX.into(),
EmbeddedIcon::from_bytes(
&include_bytes!("../../../../_icons/offsite-lfx-logo-256x256.png").to_vec(),
true,
)?,
);
map.insert(
embedded_icons::MEDIA_SHUTTLE.into(),
EmbeddedIcon::from_bytes(
&include_bytes!("../../../../_icons/offsite-media-shuttle-logo-256x256.png")
.to_vec(),
true,
)?,
);
map.insert(
embedded_icons::TRANSLATE.into(),
EmbeddedIcon::from_bytes(
&include_bytes!("../../../../_icons/offsite-translate-256x256.png").to_vec(),
true,
)?,
);
map.insert(
embedded_icons::LUCID_CHART.into(),
EmbeddedIcon::from_bytes(
&include_bytes!("../../../../_icons/process-lucidchart-logo-256x256.png").to_vec(),
true,
)?,
);
map.insert(
embedded_icons::PIPELINE.into(),
EmbeddedIcon::from_bytes(
&include_bytes!("../../../../_icons/process-pipeline-256x256.png").to_vec(),
true,
)?,
);
map.insert(
embedded_icons::PROJECT_PORTAL.into(),
EmbeddedIcon::from_bytes(
&include_bytes!("../../../../_icons/project-portal-256x256.png").to_vec(),
true,
)?,
);
map.insert(
embedded_icons::ADD_LINK.into(),
EmbeddedIcon::from_bytes(
&include_bytes!("../../../../_icons/add-link-256x256.png").to_vec(),
false,
)?,
);
map.insert(
embedded_icons::NO_PROJ_THUMB.into(),
EmbeddedIcon::from_bytes(
&include_bytes!("../../../../_icons/baseline_broken_image_white_48dp.png").to_vec(),
false,
)?,
);
map.insert(
embedded_icons::DUMMY_PROFILE.into(),
EmbeddedIcon::from_bytes(
&include_bytes!("../../../../_icons/round_account_circle_white_48dp.png").to_vec(),
false,
)?,
);
map.insert(
embedded_icons::ASSET_REVEAL_DIR.into(),
EmbeddedIcon::from_bytes(
&include_bytes!("../../../../_icons/asset-reveal-dir-256x256.png").to_vec(),
false,
)?,
);
map.insert(
embedded_icons::REVEAL_BRIEF_DIR.into(),
EmbeddedIcon::from_bytes(
&include_bytes!("../../../../_icons/asset-reveal-brief-dir-256x256.png").to_vec(),
false,
)?,
);
map.insert(
embedded_icons::OPEN_BRIEF_DOC.into(),
EmbeddedIcon::from_bytes(
&include_bytes!("../../../../_icons/open-brief-doc-256x256.png").to_vec(),
false,
)?,
);
map.insert(
embedded_icons::NEXT_STAGE.into(),
EmbeddedIcon::from_bytes(
&include_bytes!("../../../../_icons/baseline_arrow_forward_ios_white_48dp.png")
.to_vec(),
false,
)?,
);
map.insert(
embedded_icons::CATEGORY_CREATOR.into(),
EmbeddedIcon::from_bytes(
&include_bytes!("../../../../_icons/system-category-creator-256x256.png").to_vec(),
false,
)?,
);
map.insert(
embedded_icons::ASSET_GENESIS.into(),
EmbeddedIcon::from_bytes(
&include_bytes!("../../../../_icons/system-asset-genesis-256x256.png").to_vec(),
false,
)?,
);
map.insert(
embedded_icons::STAFF_GENESIS.into(),
EmbeddedIcon::from_bytes(
&include_bytes!("../../../../_icons/system-staff-genesis-256x256.png").to_vec(),
false,
)?,
);
map.insert(
embedded_icons::QMS_NOTIFIER.into(),
EmbeddedIcon::from_bytes(
&include_bytes!("../../../../_icons/system-qms-notifier-256x256.png").to_vec(),
false,
)?,
);
map.insert(
embedded_icons::DEFECT_TRACKING.into(),
EmbeddedIcon::from_bytes(
&include_bytes!("../../../../_icons/system-defect-tracking-256x256.png").to_vec(),
false,
)?,
);
map.insert(
embedded_icons::PROGRESS_REVIEW.into(),
EmbeddedIcon::from_bytes(
&include_bytes!("../../../../_icons/system-progress-review-256x256.png").to_vec(),
false,
)?,
);
map.insert(
embedded_icons::NOTICE_MASTER.into(),
EmbeddedIcon::from_bytes(
&include_bytes!("../../../../_icons/system-notice-master-256x256.png").to_vec(),
false,
)?,
);
map.insert(
embedded_icons::PREFERENCES.into(),
EmbeddedIcon::from_bytes(
&include_bytes!("../../../../_icons/system-preferences-256x256.png").to_vec(),
false,
)?,
);
map.insert(
embedded_icons::TOOL_WINDOWS.into(),
EmbeddedIcon::from_bytes(
&include_bytes!("../../../../_icons/baseline_view_list_white_48dp.png").to_vec(),
false,
)?,
);
map.insert(
embedded_icons::MAYA.into(),
EmbeddedIcon::from_bytes(
&include_bytes!("../../../../_icons/software-maya-logo-256x256.png").to_vec(),
false,
)?,
);
map.insert(
embedded_icons::_3DS_MAX.into(),
EmbeddedIcon::from_bytes(
&include_bytes!("../../../../_icons/software-3ds-max-logo-256x256.jpg").to_vec(),
false,
)?,
);
map.insert(
embedded_icons::BLENDER.into(),
EmbeddedIcon::from_bytes(
&include_bytes!("../../../../_icons/software-blender-logo-256x256.png").to_vec(),
false,
)?,
);
map.insert(
embedded_icons::HOUDINI.into(),
EmbeddedIcon::from_bytes(
&include_bytes!("../../../../_icons/software-houdini-logo-256x256.png").to_vec(),
false,
)?,
);
map.insert(
embedded_icons::ZBRUSH.into(),
EmbeddedIcon::from_bytes(
&include_bytes!("../../../../_icons/software-zbrush-logo-256x256.png").to_vec(),
false,
)?,
);
map.insert(
embedded_icons::SUBSTANCE_PAINTER.into(),
EmbeddedIcon::from_bytes(
&include_bytes!("../../../../_icons/software-substance-painter-logo-256x256.png")
.to_vec(),
false,
)?,
);
map.insert(
embedded_icons::MARI.into(),
EmbeddedIcon::from_bytes(
&include_bytes!("../../../../_icons/software-mari-logo-256x256.png").to_vec(),
false,
)?,
);
map.insert(
embedded_icons::UNREAL.into(),
EmbeddedIcon::from_bytes(
&include_bytes!("../../../../_icons/software-unreal-logo-256x256.jpg").to_vec(),
false,
)?,
);
map.insert(
embedded_icons::UNITY.into(),
EmbeddedIcon::from_bytes(
&include_bytes!("../../../../_icons/software-unity-logo2-256x256.jpg").to_vec(),
false,
)?,
);
map.insert(
embedded_icons::HUNTER.into(),
EmbeddedIcon::from_bytes(
&include_bytes!("../../../../_icons/hunter-tutorial-256x256.png").to_vec(),
false,
)?,
);
Ok(Self(map))
}
}
#[cfg(test)]
mod tests {
#[test]
#[cfg(feature = "image_processing")]
fn load_icons() {
use super::*;
match IconBook::new() {
Ok(_) => {}
Err(e) => {
panic!("{}", e);
}
}
}
}