Changed some strings to be stored as ImString directly

This commit is contained in:
4bb4 2020-10-13 17:02:10 +02:00
parent f8bb5d07c4
commit 44a065c8c7
2 changed files with 19 additions and 16 deletions

View file

@ -30,7 +30,7 @@ fn show_basic_plot(ui: &Ui, plot_ui: &PlotUi) {
fn show_configurable_plot(ui: &Ui, plot_ui: &PlotUi) { fn show_configurable_plot(ui: &Ui, plot_ui: &PlotUi) {
ui.text(im_str!( ui.text(im_str!(
"This header demos what we can configure about plots." "This header demos what we can configure about plots. €."
)); ));
// Settings for the plot // Settings for the plot

View file

@ -91,16 +91,19 @@ bitflags! {
/// (If you are coming from the C++ implementation or the C bindings: build() calls both /// (If you are coming from the C++ implementation or the C bindings: build() calls both
/// begin() and end() internally) /// begin() and end() internally)
pub struct Plot { pub struct Plot {
/// Title of the plot, shown on top. /// Title of the plot, shown on top. Stored as ImString because that's what we'll use
title: String, /// afterwards, and this ensures the ImString itself will stay alive long enough for the plot.
title: ImString,
/// Size of the plot in x direction, in the same units imgui uses. /// Size of the plot in x direction, in the same units imgui uses.
size_x: f32, size_x: f32,
/// Size of the plot in y direction, in the same units imgui uses. /// Size of the plot in y direction, in the same units imgui uses.
size_y: f32, size_y: f32,
/// Label of the x axis, shown on the bottom /// Label of the x axis, shown on the bottom. Stored as ImString because that's what we'll use
x_label: String, /// afterwards, and this ensures the ImString itself will stay alive long enough for the plot.
/// Label of the y axis, shown on the left x_label: ImString,
y_label: String, /// Label of the y axis, shown on the left. 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.
y_label: ImString,
/// X axis limits, if present /// X axis limits, if present
x_limits: Option<ImPlotRange>, x_limits: Option<ImPlotRange>,
/// Y axis limits, if present /// Y axis limits, if present
@ -150,11 +153,11 @@ impl Plot {
pub fn new(title: &str) -> Self { pub fn new(title: &str) -> Self {
// TODO(4bb4) question these defaults, maybe remove some of them // TODO(4bb4) question these defaults, maybe remove some of them
Self { Self {
title: title.to_owned(), title: im_str!("{}", title),
size_x: DEFAULT_PLOT_SIZE_X, size_x: DEFAULT_PLOT_SIZE_X,
size_y: DEFAULT_PLOT_SIZE_Y, size_y: DEFAULT_PLOT_SIZE_Y,
x_label: "".to_owned(), x_label: im_str!("").into(),
y_label: "".to_owned(), y_label: im_str!("").into(),
x_limits: None, x_limits: None,
y_limits: None, y_limits: None,
x_limit_condition: None, x_limit_condition: None,
@ -185,14 +188,14 @@ impl Plot {
/// Set the x label of the plot /// Set the x label of the plot
#[inline] #[inline]
pub fn x_label(mut self, label: &str) -> Self { pub fn x_label(mut self, label: &str) -> Self {
self.x_label = label.to_owned(); self.x_label = im_str!("{}", label);
self self
} }
/// Set the y label of the plot /// Set the y label of the plot
#[inline] #[inline]
pub fn y_label(mut self, label: &str) -> Self { pub fn y_label(mut self, label: &str) -> Self {
self.y_label = label.to_owned(); self.y_label = im_str!("{}", label);
self self
} }
@ -385,9 +388,9 @@ impl Plot {
let should_render = unsafe { let should_render = unsafe {
sys::ImPlot_BeginPlot( sys::ImPlot_BeginPlot(
im_str!("{}", self.title).as_ptr(), self.title.as_ptr(),
im_str!("{}", self.x_label).as_ptr(), self.x_label.as_ptr(),
im_str!("{}", self.y_label).as_ptr(), self.y_label.as_ptr(),
sys::ImVec2 { sys::ImVec2 {
x: self.size_x as f32, x: self.size_x as f32,
y: self.size_y as f32, y: self.size_y as f32,
@ -428,7 +431,7 @@ impl Plot {
pub struct PlotToken { pub struct PlotToken {
context: *const Context, context: *const Context,
/// For better error messages /// For better error messages
plot_title: String, plot_title: ImString,
} }
impl PlotToken { impl PlotToken {