use crate::tokens::DESIGN_TOKENS;
use egui::Color32;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub enum TooltipMode {
#[default]
Floating,
Tracking,
Magnifier,
}
impl std::fmt::Display for TooltipMode {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
TooltipMode::Floating => write!(f, "Floating"),
TooltipMode::Tracking => write!(f, "Tracking"),
TooltipMode::Magnifier => write!(f, "Magnifier"),
}
}
}
#[derive(Debug, Clone)]
pub struct TooltipOptions {
pub enabled: bool,
pub mode: TooltipMode,
pub show_ohlc: bool,
pub show_volume: bool,
pub show_change: bool,
pub show_time: bool,
pub show_indicators: bool,
pub magnifier_zoom: f32,
pub magnifier_size: f32,
pub background_color: Color32,
pub text_color: Color32,
pub border_color_bullish: Color32,
pub border_color_bearish: Color32,
pub font_size: f32,
pub price_precision: usize,
pub tracking_bar_height: f32,
pub tracking_bar_background: Color32,
}
impl Default for TooltipOptions {
fn default() -> Self {
Self {
enabled: true,
mode: TooltipMode::Floating,
show_ohlc: true,
show_volume: true,
show_change: true,
show_time: true,
show_indicators: true,
magnifier_zoom: 2.0,
magnifier_size: 120.0,
background_color: DESIGN_TOKENS.semantic.extended.chart_tooltip_bg,
text_color: DESIGN_TOKENS.semantic.extended.chart_text,
border_color_bullish: DESIGN_TOKENS.semantic.extended.bullish,
border_color_bearish: DESIGN_TOKENS.semantic.extended.bearish,
font_size: 11.0,
price_precision: 8,
tracking_bar_height: 24.0,
tracking_bar_background: DESIGN_TOKENS.semantic.chart.bg,
}
}
}
impl TooltipOptions {
pub fn floating() -> Self {
Self {
mode: TooltipMode::Floating,
..Default::default()
}
}
pub fn tracking() -> Self {
Self {
mode: TooltipMode::Tracking,
..Default::default()
}
}
pub fn magnifier() -> Self {
Self {
mode: TooltipMode::Magnifier,
..Default::default()
}
}
pub fn magnifier_with_zoom(zoom: f32) -> Self {
Self {
mode: TooltipMode::Magnifier,
magnifier_zoom: zoom,
..Default::default()
}
}
pub fn with_mode(mut self, mode: TooltipMode) -> Self {
self.mode = mode;
self
}
pub fn with_enabled(mut self, enabled: bool) -> Self {
self.enabled = enabled;
self
}
pub fn with_ohlc(mut self, show: bool) -> Self {
self.show_ohlc = show;
self
}
pub fn with_volume(mut self, show: bool) -> Self {
self.show_volume = show;
self
}
pub fn with_change(mut self, show: bool) -> Self {
self.show_change = show;
self
}
pub fn with_magnifier_zoom(mut self, zoom: f32) -> Self {
self.magnifier_zoom = zoom;
self
}
pub fn with_magnifier_size(mut self, size: f32) -> Self {
self.magnifier_size = size;
self
}
pub fn with_precision(mut self, precision: usize) -> Self {
self.price_precision = precision;
self
}
}