yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
implot_support.cc
Go to the documentation of this file.
2
6
7namespace yaze {
8namespace gui {
9namespace plotting {
10namespace {
11
12ImVec4 WithAlpha(const ImVec4& color, float alpha) {
13 return ImVec4(color.x, color.y, color.z, color.w * alpha);
14}
15
16ImVec2 ScaledSpacing(float multiplier) {
17 const float spacing = LayoutHelpers::GetStandardSpacing();
18 return ImVec2(spacing * multiplier, spacing * multiplier);
19}
20
21ImPlotStyle BuildBaseStyle(const Theme& theme,
22 const PlotStyleConfig& config) {
23 ImPlotStyle style;
24 style.LineWeight = config.line_weight;
25 style.MarkerSize = config.marker_size;
26 style.MarkerWeight = config.marker_weight;
27 style.FillAlpha = config.fill_alpha;
28 style.DigitalBitHeight = ImGui::GetFontSize() * 0.85f;
29 style.DigitalBitGap = ImGui::GetStyle().ItemSpacing.y * 0.5f;
30 style.PlotBorderSize = 1.0f;
31 style.MinorAlpha = config.grid_alpha;
32 style.MajorTickLen = ImVec2(6.0f, 6.0f);
33 style.MinorTickLen = ImVec2(3.0f, 3.0f);
34 style.MajorTickSize = ImVec2(1.0f, 1.0f);
35 style.MinorTickSize = ImVec2(1.0f, 1.0f);
36 style.MajorGridSize = ImVec2(1.0f, 1.0f);
37 style.MinorGridSize = ImVec2(1.0f, 1.0f);
38 style.PlotPadding = ScaledSpacing(1.5f);
39 style.LabelPadding = ScaledSpacing(0.75f);
40 style.LegendPadding = ScaledSpacing(1.0f);
41 style.LegendInnerPadding = ScaledSpacing(0.5f);
42 style.LegendSpacing = ImVec2(LayoutHelpers::GetStandardSpacing(),
44 style.MousePosPadding = ScaledSpacing(1.0f);
45 style.AnnotationPadding = ScaledSpacing(0.35f);
46 style.FitPadding = ImVec2(0.05f, 0.05f);
47 style.PlotDefaultSize = ImVec2(420, 280);
48 style.PlotMinSize = ImVec2(220, 160);
49 style.UseISO8601 = config.use_iso_8601;
50 style.Use24HourClock = config.use_24h_clock;
51 style.UseLocalTime = true;
52
53 style.Colors[ImPlotCol_Line] =
55 style.Colors[ImPlotCol_Fill] =
57 style.Colors[ImPlotCol_MarkerOutline] =
59 style.Colors[ImPlotCol_MarkerFill] =
61 style.Colors[ImPlotCol_ErrorBar] =
63 style.Colors[ImPlotCol_FrameBg] =
65 style.Colors[ImPlotCol_PlotBg] =
67 style.Colors[ImPlotCol_PlotBorder] =
69 style.Colors[ImPlotCol_LegendBg] =
71 style.Colors[ImPlotCol_LegendBorder] =
73 style.Colors[ImPlotCol_LegendText] =
75 style.Colors[ImPlotCol_TitleText] =
77 style.Colors[ImPlotCol_InlayText] =
79 style.Colors[ImPlotCol_AxisText] =
81 style.Colors[ImPlotCol_AxisGrid] =
83 style.Colors[ImPlotCol_AxisTick] =
85 style.Colors[ImPlotCol_AxisBg] =
87 style.Colors[ImPlotCol_AxisBgHovered] =
89 style.Colors[ImPlotCol_AxisBgActive] =
91 style.Colors[ImPlotCol_Selection] =
93 style.Colors[ImPlotCol_Crosshairs] =
95
96 return style;
97}
98
99} // namespace
100
102 if (ImPlot::GetCurrentContext() == nullptr) {
103 ImPlot::CreateContext();
104 }
105}
106
107ImPlotStyle BuildStyleFromTheme(const Theme& theme,
108 const PlotStyleConfig& config) {
110 return BuildBaseStyle(theme, config);
111}
112
114 const PlotStyleConfig& config)
115 : previous_style_() {
117 previous_style_ = ImPlot::GetStyle();
118 ImPlot::GetStyle() = BuildBaseStyle(theme, config);
119}
120
122
126 ImPlot::BeginPlot(config.id.c_str(), config.size, config.flags);
127 if (should_end_) {
128 ImPlot::SetupAxes(config.x_label, config.y_label, config.x_axis_flags,
129 config.y_axis_flags);
130 }
131}
132
134 if (should_end_) {
135 ImPlot::EndPlot();
136 }
137}
138
139} // namespace plotting
140} // namespace gui
141} // namespace yaze
static float GetStandardSpacing()
PlotGuard(const PlotConfig &config)
PlotStyleScope(const Theme &theme, const PlotStyleConfig &config={})
ImPlotStyle BuildBaseStyle(const Theme &theme, const PlotStyleConfig &config)
ImVec4 WithAlpha(const ImVec4 &color, float alpha)
ImPlotStyle BuildStyleFromTheme(const Theme &theme, const PlotStyleConfig &config)
ImVec4 ConvertColorToImVec4(const Color &color)
Definition color.h:23
Comprehensive theme structure for YAZE.