use egui::{Color32, Label, Response, RichText, Ui, Widget};
use egui_cha::ViewCtx;
pub mod icons {
pub const HOUSE: &str = "\u{e2c2}";
pub const ARROW_LEFT: &str = "\u{e058}";
pub const ARROW_RIGHT: &str = "\u{e06c}";
pub const PLUS: &str = "\u{e3d4}";
pub const MINUS: &str = "\u{e32a}";
pub const X: &str = "\u{e4f6}";
pub const CHECK: &str = "\u{e182}";
pub const GEAR: &str = "\u{e270}";
pub const INFO: &str = "\u{e2ce}";
pub const WARNING: &str = "\u{e4e0}";
pub const HASH: &str = "\u{e2a2}";
pub const USER: &str = "\u{e4c2}";
pub const FLOPPY_DISK: &str = "\u{e248}";
pub const TRASH: &str = "\u{e4a6}";
pub const PENCIL_SIMPLE: &str = "\u{e3b4}";
pub const FOLDER_SIMPLE: &str = "\u{e25a}";
pub const FILE: &str = "\u{e230}";
pub const MAGNIFYING_GLASS: &str = "\u{e30c}";
pub const ARROWS_CLOCKWISE: &str = "\u{e094}";
pub const PLAY: &str = "\u{e3d0}";
pub const PAUSE: &str = "\u{e39e}";
pub const STOP: &str = "\u{e46c}";
pub const RECORD: &str = "\u{e3f0}";
pub const COPY: &str = "\u{e1ca}";
pub const DOWNLOAD_SIMPLE: &str = "\u{e20c}";
pub const UPLOAD_SIMPLE: &str = "\u{e4c0}";
pub const LINK_SIMPLE: &str = "\u{e2e6}";
pub const EYE: &str = "\u{e220}";
pub const EYE_SLASH: &str = "\u{e222}";
pub const FIRE: &str = "\u{e242}";
pub const BUG: &str = "\u{e5f4}";
pub const WRENCH: &str = "\u{e5d4}";
pub const X_CIRCLE: &str = "\u{e4f8}";
pub const SKULL: &str = "\u{e916}";
pub const CARET_UP: &str = "\u{e13c}";
pub const CARET_DOWN: &str = "\u{e136}";
pub const LOCK: &str = "\u{e2ec}";
pub const LOCK_OPEN: &str = "\u{e2ee}";
pub const CORNERS_OUT: &str = "\u{e1ce}"; pub const CORNERS_IN: &str = "\u{e1cc}";
pub const STACK: &str = "\u{e45e}";
pub const SLIDERS_HORIZONTAL: &str = "\u{e450}";
pub const IMAGE: &str = "\u{e2c4}";
pub const MONITOR_PLAY: &str = "\u{e338}";
pub const GRID_FOUR: &str = "\u{e296}";
pub const ARROWS_OUT_LINE_HORIZONTAL: &str = "\u{e534}";
pub const ARROWS_OUT_LINE_VERTICAL: &str = "\u{e536}";
pub const SQUARES_FOUR: &str = "\u{e464}";
pub const BROOM: &str = "\u{ec54}";
pub const MAGNIFYING_GLASS_PLUS: &str = "\u{e310}";
pub const FRAME_CORNERS: &str = "\u{e626}";
pub const LOCK_KEY: &str = "\u{e2fe}"; }
pub struct Icon {
icon_char: &'static str,
size: f32,
color: Option<Color32>,
}
impl Icon {
pub fn new(icon_char: &'static str) -> Self {
Self {
icon_char,
size: 16.0,
color: None,
}
}
pub fn house() -> Self {
Self::new(icons::HOUSE)
}
pub fn arrow_left() -> Self {
Self::new(icons::ARROW_LEFT)
}
pub fn arrow_right() -> Self {
Self::new(icons::ARROW_RIGHT)
}
pub fn plus() -> Self {
Self::new(icons::PLUS)
}
pub fn minus() -> Self {
Self::new(icons::MINUS)
}
pub fn x() -> Self {
Self::new(icons::X)
}
pub fn check() -> Self {
Self::new(icons::CHECK)
}
pub fn gear() -> Self {
Self::new(icons::GEAR)
}
pub fn info() -> Self {
Self::new(icons::INFO)
}
pub fn warning() -> Self {
Self::new(icons::WARNING)
}
pub fn hash() -> Self {
Self::new(icons::HASH)
}
pub fn user() -> Self {
Self::new(icons::USER)
}
pub fn play() -> Self {
Self::new(icons::PLAY)
}
pub fn pause() -> Self {
Self::new(icons::PAUSE)
}
pub fn stop() -> Self {
Self::new(icons::STOP)
}
pub fn record() -> Self {
Self::new(icons::RECORD)
}
pub fn fire() -> Self {
Self::new(icons::FIRE)
}
pub fn bug() -> Self {
Self::new(icons::BUG)
}
pub fn wrench() -> Self {
Self::new(icons::WRENCH)
}
pub fn x_circle() -> Self {
Self::new(icons::X_CIRCLE)
}
pub fn caret_up() -> Self {
Self::new(icons::CARET_UP)
}
pub fn caret_down() -> Self {
Self::new(icons::CARET_DOWN)
}
pub fn lock() -> Self {
Self::new(icons::LOCK)
}
pub fn lock_open() -> Self {
Self::new(icons::LOCK_OPEN)
}
pub fn corners_out() -> Self {
Self::new(icons::CORNERS_OUT)
}
pub fn corners_in() -> Self {
Self::new(icons::CORNERS_IN)
}
pub fn stack() -> Self {
Self::new(icons::STACK)
}
pub fn sliders_horizontal() -> Self {
Self::new(icons::SLIDERS_HORIZONTAL)
}
pub fn image() -> Self {
Self::new(icons::IMAGE)
}
pub fn monitor_play() -> Self {
Self::new(icons::MONITOR_PLAY)
}
pub fn size(mut self, size: f32) -> Self {
self.size = size;
self
}
pub fn color(mut self, color: Color32) -> Self {
self.color = Some(color);
self
}
pub fn show(self, ui: &mut Ui) -> Response {
ui.add(self)
}
pub fn show_ctx<Msg>(self, ctx: &mut ViewCtx<Msg>) -> Response {
ctx.ui.add(self)
}
}
impl Widget for Icon {
fn ui(self, ui: &mut Ui) -> Response {
let mut text = RichText::new(self.icon_char)
.size(self.size)
.family(egui::FontFamily::Name("icons".into()));
if let Some(color) = self.color {
text = text.color(color);
}
ui.add(Label::new(text).selectable(false))
}
}