Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make demo a bit more mobile friendly #44

Merged
merged 1 commit into from
Sep 10, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 46 additions & 21 deletions demo/src/plot_demo.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
use std::f64::consts::TAU;
use std::ops::RangeInclusive;

use egui::{remap, vec2, Color32, ComboBox, NumExt, Pos2, Response, Stroke, TextWrapMode, Vec2b};
use egui::{
remap, vec2, Color32, ComboBox, NumExt, Pos2, Response, ScrollArea, Stroke, TextWrapMode, Vec2b,
};

use egui_plot::{
Arrows, AxisHints, Bar, BarChart, BoxElem, BoxPlot, BoxSpread, CoordinatesFormatter, Corner,
Expand Down Expand Up @@ -63,7 +65,7 @@ impl PlotDemo {
ui.add(crate::egui_github_link_file!());
});
ui.separator();
ui.horizontal(|ui| {
ui.horizontal_wrapped(|ui| {
ui.selectable_value(&mut self.open_panel, Panel::Lines, "Lines");
ui.selectable_value(&mut self.open_panel, Panel::Markers, "Markers");
ui.selectable_value(&mut self.open_panel, Panel::Legend, "Legend");
Expand Down Expand Up @@ -254,7 +256,9 @@ impl LineDemo {

impl LineDemo {
fn ui(&mut self, ui: &mut egui::Ui) -> Response {
self.options_ui(ui);
ScrollArea::horizontal().show(ui, |ui| {
self.options_ui(ui);
});

if self.animate {
ui.ctx().request_repaint();
Expand Down Expand Up @@ -392,8 +396,27 @@ impl LegendDemo {
}

fn ui(&mut self, ui: &mut egui::Ui) -> Response {
ScrollArea::horizontal().show(ui, |ui| {
self.settings_ui(ui);
});

let Self { config } = self;
let legend_plot = Plot::new("legend_demo")
.legend(config.clone())
.data_aspect(1.0);
legend_plot
.show(ui, |plot_ui| {
plot_ui.line(Self::line_with_slope(0.5).name("lines"));
plot_ui.line(Self::line_with_slope(1.0).name("lines"));
plot_ui.line(Self::line_with_slope(2.0).name("lines"));
plot_ui.line(Self::sin().name("sin(x)"));
plot_ui.line(Self::cos().name("cos(x)"));
})
.response
}

fn settings_ui(&mut self, ui: &mut egui::Ui) {
let Self { config } = self;
egui::Grid::new("settings").show(ui, |ui| {
ui.label("Text style:");
ui.horizontal(|ui| {
Expand All @@ -420,18 +443,6 @@ impl LegendDemo {
);
ui.end_row();
});
let legend_plot = Plot::new("legend_demo")
.legend(config.clone())
.data_aspect(1.0);
legend_plot
.show(ui, |plot_ui| {
plot_ui.line(Self::line_with_slope(0.5).name("lines"));
plot_ui.line(Self::line_with_slope(1.0).name("lines"));
plot_ui.line(Self::line_with_slope(2.0).name("lines"));
plot_ui.line(Self::sin().name("sin(x)"));
plot_ui.line(Self::cos().name("cos(x)"));
})
.response
}
}

Expand Down Expand Up @@ -642,6 +653,13 @@ impl LinkedAxesDemo {
ui.checkbox(&mut self.link_cursor_y, "Y");
});

ScrollArea::horizontal()
.show(ui, |ui| self.plots_ui(ui))
.inner
}

fn plots_ui(&self, ui: &mut egui::Ui) -> Response {
ui.style_mut().wrap_mode = Some(TextWrapMode::Extend);
let link_group_id = ui.id().with("linked_demo");
ui.horizontal(|ui| {
Plot::new("left-top")
Expand Down Expand Up @@ -877,6 +895,17 @@ impl Default for ChartsDemo {

impl ChartsDemo {
fn ui(&mut self, ui: &mut egui::Ui) -> Response {
ScrollArea::horizontal().show(ui, |ui| {
self.options_ui(ui);
});
match self.chart {
Chart::GaussBars => self.bar_gauss(ui),
Chart::StackedBars => self.bar_stacked(ui),
Chart::BoxPlot => self.box_plot(ui),
}
}

fn options_ui(&mut self, ui: &mut egui::Ui) -> Response {
ui.horizontal(|ui| {
ui.vertical(|ui| {
ui.label("Type:");
Expand Down Expand Up @@ -912,12 +941,8 @@ impl ChartsDemo {
});
});
});
});
match self.chart {
Chart::GaussBars => self.bar_gauss(ui),
Chart::StackedBars => self.bar_stacked(ui),
Chart::BoxPlot => self.box_plot(ui),
}
})
.response
}

fn bar_gauss(&self, ui: &mut egui::Ui) -> Response {
Expand Down
Loading