egui_charts/chart/rendering/
context.rs1use egui::{Color32, Painter, Rect};
2
3pub use crate::chart::coords::ChartMapping;
5
6pub struct RenderContext<'a> {
8 pub painter: &'a Painter,
10 pub rect: Rect,
12}
13
14impl<'a> RenderContext<'a> {
15 pub fn new(painter: &'a Painter, rect: Rect) -> Self {
17 Self { painter, rect }
18 }
19}
20
21#[derive(Debug, Copy, Clone)]
23pub struct StyleColors {
24 pub bullish: Color32,
25 pub bearish: Color32,
26 pub text: Color32,
27 pub bullish_border: Option<Color32>,
29 pub bearish_border: Option<Color32>,
31 pub bullish_wick: Option<Color32>,
33 pub bearish_wick: Option<Color32>,
35 pub candle_border_width: f32,
37}
38
39impl StyleColors {
40 pub fn bar_color(&self, is_bullish: bool) -> Color32 {
42 if is_bullish {
43 self.bullish
44 } else {
45 self.bearish
46 }
47 }
48
49 pub fn wick_color(&self, is_bullish: bool) -> Color32 {
52 if is_bullish {
53 self.bullish_wick
54 .or(self.bullish_border)
55 .unwrap_or(self.bullish)
56 } else {
57 self.bearish_wick
58 .or(self.bearish_border)
59 .unwrap_or(self.bearish)
60 }
61 }
62
63 pub fn border_color(&self, is_bullish: bool) -> Color32 {
66 if is_bullish {
67 self.bullish_border.unwrap_or(self.bullish)
68 } else {
69 self.bearish_border.unwrap_or(self.bearish)
70 }
71 }
72
73 pub fn has_border(&self) -> bool {
75 self.candle_border_width > 0.0
76 }
77}
78
79#[derive(Debug, Copy, Clone)]
81pub struct BarRenderParams {
82 pub x: f32,
83 pub width: f32,
84 pub wick_width: f32,
85}
86
87impl BarRenderParams {
88 pub fn new(x: f32, width: f32, wick_width: f32) -> Self {
89 Self {
90 x,
91 width,
92 wick_width,
93 }
94 }
95}