Use same convention for size as in imgui-rs

This commit is contained in:
Ilya Averyanov 2021-03-06 02:11:42 +03:00
parent 672bbc0052
commit e53dd6a0dd
8 changed files with 22 additions and 29 deletions

View file

@ -10,7 +10,7 @@ pub fn show_basic_vertical_plot(ui: &Ui, plot_ui: &PlotUi) {
Plot::new("Vertical bar plot") Plot::new("Vertical bar plot")
// The size call could also be omitted, though the defaults don't consider window // The size call could also be omitted, though the defaults don't consider window
// width, which is why we're not doing so here. // width, which is why we're not doing so here.
.size(content_width, 300.0) .size([content_width, 300.0])
.build(plot_ui, || { .build(plot_ui, || {
// If this is called outside a plot build callback, the program will panic. // If this is called outside a plot build callback, the program will panic.
let axis_positions = vec![0.2, 0.4, 0.6, 0.8]; let axis_positions = vec![0.2, 0.4, 0.6, 0.8];
@ -27,7 +27,7 @@ pub fn show_basic_horizontal_plot(ui: &Ui, plot_ui: &PlotUi) {
Plot::new("Horizontal bar plot") Plot::new("Horizontal bar plot")
// The size call could also be omitted, though the defaults don't consider window // The size call could also be omitted, though the defaults don't consider window
// width, which is why we're not doing so here. // width, which is why we're not doing so here.
.size(content_width, 300.0) .size([content_width, 300.0])
.build(plot_ui, || { .build(plot_ui, || {
// If this is called outside a plot build callback, the program will panic. // If this is called outside a plot build callback, the program will panic.
let axis_positions = vec![0.2, 0.4, 0.6, 0.8]; let axis_positions = vec![0.2, 0.4, 0.6, 0.8];

View file

@ -10,7 +10,7 @@ pub fn show_basic_heatmap(ui: &Ui, plot_ui: &PlotUi) {
Plot::new("Heatmap plot") Plot::new("Heatmap plot")
// The size call could also be omitted, though the defaults don't consider window // The size call could also be omitted, though the defaults don't consider window
// width, which is why we're not doing so here. // width, which is why we're not doing so here.
.size(content_width, 300.0) .size([content_width, 300.0])
.build(plot_ui, || { .build(plot_ui, || {
let values = (0..100).map(|x| 0.1 * x as f64).collect::<Vec<_>>(); let values = (0..100).map(|x| 0.1 * x as f64).collect::<Vec<_>>();
PlotHeatmap::new("my favourite heatmap") PlotHeatmap::new("my favourite heatmap")

View file

@ -19,7 +19,7 @@ pub fn show_basic_plot(ui: &Ui, plot_ui: &PlotUi) {
Plot::new("Simple line plot") Plot::new("Simple line plot")
// The size call could also be omitted, though the defaults don't consider window // The size call could also be omitted, though the defaults don't consider window
// width, which is why we're not doing so here. // width, which is why we're not doing so here.
.size(content_width, 300.0) .size([content_width, 300.0])
.build(plot_ui, || { .build(plot_ui, || {
// If this is called outside a plot build callback, the program will panic. // If this is called outside a plot build callback, the program will panic.
let x_positions = vec![0.1, 0.9]; let x_positions = vec![0.1, 0.9];
@ -36,7 +36,7 @@ pub fn show_two_yaxis_plot(ui: &Ui, plot_ui: &PlotUi) {
Plot::new("Multiple Y axis plots") Plot::new("Multiple Y axis plots")
// The size call could also be omitted, though the defaults don't consider window // The size call could also be omitted, though the defaults don't consider window
// width, which is why we're not doing so here. // width, which is why we're not doing so here.
.size(content_width, 300.0) .size([content_width, 300.0])
.with_plot_flags(&(PlotFlags::NONE | PlotFlags::Y_AXIS_2)) .with_plot_flags(&(PlotFlags::NONE | PlotFlags::Y_AXIS_2))
.y_limits( .y_limits(
&ImPlotRange { Min: 0.0, Max: 1.0 }, &ImPlotRange { Min: 0.0, Max: 1.0 },
@ -68,7 +68,7 @@ pub fn show_axis_equal_plot(ui: &Ui, plot_ui: &PlotUi) {
Plot::new("Axis equal line plot") Plot::new("Axis equal line plot")
// The size call could also be omitted, though the defaults don't consider window // The size call could also be omitted, though the defaults don't consider window
// width, which is why we're not doing so here. // width, which is why we're not doing so here.
.size(content_width, 300.0) .size([content_width, 300.0])
.with_plot_flags(&(PlotFlags::NONE | PlotFlags::AXIS_EQUAL)) .with_plot_flags(&(PlotFlags::NONE | PlotFlags::AXIS_EQUAL))
.build(plot_ui, || { .build(plot_ui, || {
// If this is called outside a plot build callback, the program will panic. // If this is called outside a plot build callback, the program will panic.
@ -110,7 +110,7 @@ pub fn show_configurable_plot(ui: &Ui, plot_ui: &PlotUi) {
// Axis labels // Axis labels
Plot::new("Configured line plot") Plot::new("Configured line plot")
.size(x_size, y_size) .size([x_size, y_size])
.x_label(&x_label) .x_label(&x_label)
.y_label(&y_label) .y_label(&y_label)
.x_limits( .x_limits(
@ -161,7 +161,7 @@ pub fn show_query_features_plot(ui: &Ui, plot_ui: &PlotUi) {
// Draw a plot // Draw a plot
Plot::new("Plot querying") Plot::new("Plot querying")
.size(content_width, 300.0) .size([content_width, 300.0])
.x_limits(&ImPlotRange { Min: 0.0, Max: 5.0 }, Condition::FirstUseEver) .x_limits(&ImPlotRange { Min: 0.0, Max: 5.0 }, Condition::FirstUseEver)
.y_limits( .y_limits(
&ImPlotRange { Min: 0.0, Max: 5.0 }, &ImPlotRange { Min: 0.0, Max: 5.0 },
@ -246,7 +246,7 @@ pub fn show_style_plot(ui: &Ui, plot_ui: &PlotUi) {
// variables can be done outside of plot calls as well. // variables can be done outside of plot calls as well.
let style = push_style_color(&PlotColorElement::PlotBg, 1.0, 1.0, 1.0, 0.2); let style = push_style_color(&PlotColorElement::PlotBg, 1.0, 1.0, 1.0, 0.2);
Plot::new("Style demo plot") Plot::new("Style demo plot")
.size(content_width, 300.0) .size([content_width, 300.0])
.x_limits(&ImPlotRange { Min: 0.0, Max: 6.0 }, Condition::Always) .x_limits(&ImPlotRange { Min: 0.0, Max: 6.0 }, Condition::Always)
.y_limits( .y_limits(
&ImPlotRange { &ImPlotRange {
@ -291,7 +291,7 @@ pub fn show_colormaps_plot(ui: &Ui, plot_ui: &PlotUi) {
set_colormap_from_preset(Colormap::Plasma, 1); set_colormap_from_preset(Colormap::Plasma, 1);
Plot::new("Colormap demo plot") Plot::new("Colormap demo plot")
.size(content_width, 300.0) .size([content_width, 300.0])
.build(plot_ui, || { .build(plot_ui, || {
(1..10) (1..10)
.map(|x| x as f64 * 0.1) .map(|x| x as f64 * 0.1)
@ -318,7 +318,7 @@ pub fn show_colormaps_plot(ui: &Ui, plot_ui: &PlotUi) {
]); ]);
Plot::new("Colormap demo plot #2") Plot::new("Colormap demo plot #2")
.size(content_width, 300.0) .size([content_width, 300.0])
.build(plot_ui, || { .build(plot_ui, || {
(1..10) (1..10)
.map(|x| x as f64 * 0.1) .map(|x| x as f64 * 0.1)

View file

@ -12,7 +12,7 @@ pub fn show_basic_plot(ui: &Ui, plot_ui: &PlotUi) {
Plot::new("Simple scatter plot") Plot::new("Simple scatter plot")
// The size call could also be omitted, though the defaults don't consider window // The size call could also be omitted, though the defaults don't consider window
// width, which is why we're not doing so here. // width, which is why we're not doing so here.
.size(content_width, 300.0) .size([content_width, 300.0])
.build(plot_ui, || { .build(plot_ui, || {
// If this is called outside a plot build callback, the program will panic. // If this is called outside a plot build callback, the program will panic.
let x_positions = vec![0.1, 0.2, 0.1, 0.5, 0.9]; let x_positions = vec![0.1, 0.2, 0.1, 0.5, 0.9];
@ -29,7 +29,7 @@ pub fn show_custom_markers_plot(ui: &Ui, plot_ui: &PlotUi) {
Plot::new("Multi-marker scatter plot") Plot::new("Multi-marker scatter plot")
// The size call could also be omitted, though the defaults don't consider window // The size call could also be omitted, though the defaults don't consider window
// width, which is why we're not doing so here. // width, which is why we're not doing so here.
.size(content_width, 300.0) .size([content_width, 300.0])
.build(plot_ui, || { .build(plot_ui, || {
// Change to cross marker for one scatter plot call // Change to cross marker for one scatter plot call
let x_positions = vec![0.1, 0.2, 0.1, 0.5, 0.9]; let x_positions = vec![0.1, 0.2, 0.1, 0.5, 0.9];

View file

@ -12,7 +12,7 @@ pub fn show_basic_plot(ui: &Ui, plot_ui: &PlotUi) {
Plot::new("Simple stairs plot") Plot::new("Simple stairs plot")
// The size call could also be omitted, though the defaults don't consider window // The size call could also be omitted, though the defaults don't consider window
// width, which is why we're not doing so here. // width, which is why we're not doing so here.
.size(content_width, 300.0) .size([content_width, 300.0])
.build(plot_ui, || { .build(plot_ui, || {
// If this is called outside a plot build callback, the program will panic. // If this is called outside a plot build callback, the program will panic.
let x_positions = vec![0.1, 0.2, 0.5]; let x_positions = vec![0.1, 0.2, 0.5];

View file

@ -10,7 +10,7 @@ pub fn show_basic_plot(ui: &Ui, plot_ui: &PlotUi) {
Plot::new("Stem plot") Plot::new("Stem plot")
// The size call could also be omitted, though the defaults don't consider window // The size call could also be omitted, though the defaults don't consider window
// width, which is why we're not doing so here. // width, which is why we're not doing so here.
.size(content_width, 300.0) .size([content_width, 300.0])
.build(plot_ui, || { .build(plot_ui, || {
// If this is called outside a plot build callback, the program will panic. // If this is called outside a plot build callback, the program will panic.
let axis_positions = vec![0.2, 0.4, 0.6, 0.8, 0.9, 0.93]; let axis_positions = vec![0.2, 0.4, 0.6, 0.8, 0.9, 0.93];

View file

@ -12,7 +12,7 @@ pub fn show_basic_plot(ui: &Ui, plot_ui: &PlotUi) {
Plot::new("Simple text plot") Plot::new("Simple text plot")
// The size call could also be omitted, though the defaults don't consider window // The size call could also be omitted, though the defaults don't consider window
// width, which is why we're not doing so here. // width, which is why we're not doing so here.
.size(content_width, 300.0) .size([content_width, 300.0])
.build(plot_ui, || { .build(plot_ui, || {
// The text passed to "new" is what gets displayed. // The text passed to "new" is what gets displayed.
let x_position: f64 = 0.5; let x_position: f64 = 0.5;

View file

@ -97,10 +97,8 @@ pub struct Plot {
/// Title of the plot, shown on top. Stored as ImString because that's what we'll use /// Title of the plot, shown on top. Stored as ImString because that's what we'll use
/// afterwards, and this ensures the ImString itself will stay alive long enough for the plot. /// afterwards, and this ensures the ImString itself will stay alive long enough for the plot.
title: ImString, title: ImString,
/// Size of the plot in x direction, in the same units imgui uses. /// Size of the plot in [x, y] direction, in the same units imgui uses.
size_x: f32, size: [f32; 2],
/// Size of the plot in y direction, in the same units imgui uses.
size_y: f32,
/// Label of the x axis, shown on the bottom. Stored as ImString because that's what we'll use /// Label of the x axis, shown on the bottom. Stored as ImString because that's what we'll use
/// afterwards, and this ensures the ImString itself will stay alive long enough for the plot. /// afterwards, and this ensures the ImString itself will stay alive long enough for the plot.
x_label: ImString, x_label: ImString,
@ -162,8 +160,7 @@ impl Plot {
// TODO(4bb4) question these defaults, maybe remove some of them // TODO(4bb4) question these defaults, maybe remove some of them
Self { Self {
title: im_str!("{}", title), title: im_str!("{}", title),
size_x: DEFAULT_PLOT_SIZE_X, size: [DEFAULT_PLOT_SIZE_X, DEFAULT_PLOT_SIZE_Y],
size_y: DEFAULT_PLOT_SIZE_Y,
x_label: im_str!("").into(), x_label: im_str!("").into(),
y_label: im_str!("").into(), y_label: im_str!("").into(),
x_limits: None, x_limits: None,
@ -186,9 +183,8 @@ impl Plot {
/// Sets the plot size, given as [size_x, size_y]. Units are the same as /// Sets the plot size, given as [size_x, size_y]. Units are the same as
/// what imgui uses. TODO(4b4) ... which is? I'm not sure it's pixels /// what imgui uses. TODO(4b4) ... which is? I'm not sure it's pixels
#[inline] #[inline]
pub fn size(mut self, size_x: f32, size_y: f32) -> Self { pub fn size(mut self, size: [f32; 2]) -> Self {
self.size_x = size_x; self.size = size;
self.size_y = size_y;
self self
} }
@ -427,10 +423,7 @@ impl Plot {
self.title.as_ptr(), self.title.as_ptr(),
self.x_label.as_ptr(), self.x_label.as_ptr(),
self.y_label.as_ptr(), self.y_label.as_ptr(),
sys::ImVec2 { self.size.into(),
x: self.size_x as f32,
y: self.size_y as f32,
},
self.plot_flags, self.plot_flags,
self.x_flags, self.x_flags,
self.y_flags[0], self.y_flags[0],