ability to show/hide axes values in the curve editor widget
@@ -81,6 +81,8 @@ pub struct CurveEditor {
context_menu: ContextMenu,
text: RefCell<FormattedText>,
view_bounds: Option<Rect<f32>>,
+ show_x_values: bool,
+ show_y_values: bool,
}
crate::define_widget_deref!(CurveEditor);
@@ -840,6 +842,8 @@ impl CurveEditor {
// Draw values.
let mut text = self.text.borrow_mut();
+
+ if self.show_y_values {
for ny in 0..=nh {
let k = ny as f32 / (nh) as f32;
let y = local_left_bottom.y - k * h;
@@ -850,7 +854,9 @@ impl CurveEditor {
&text,
);
}
+ }
+ if self.show_x_values {
for nx in 0..=nw {
let k = nx as f32 / (nw) as f32;
let x = local_left_bottom.x + k * w;
@@ -862,6 +868,7 @@ impl CurveEditor {
);
}
}
+ }
fn draw_curve(&self, ctx: &mut DrawingContext) {
let screen_bounds = self.screen_bounds();
@@ -1063,6 +1070,8 @@ pub struct CurveEditorBuilder {
view_position: Vector2<f32>,
zoom: f32,
view_bounds: Option<Rect<f32>>,
+ show_x_values: bool,
+ show_y_values: bool,
}
impl CurveEditorBuilder {
@@ -1073,6 +1082,8 @@ impl CurveEditorBuilder {
view_position: Default::default(),
zoom: 1.0,
view_bounds: None,
+ show_x_values: true,
+ show_y_values: true,
}
}
@@ -1091,6 +1102,16 @@ impl CurveEditorBuilder {
self
}
+ pub fn with_show_x_values(mut self, show_x_values: bool) -> Self {
+ self.show_x_values = show_x_values;
+ self
+ }
+
+ pub fn with_show_y_values(mut self, show_y_values: bool) -> Self {
+ self.show_y_values = show_y_values;
+ self
+ }
+
/// View bounds in value-space.
pub fn with_view_bounds(mut self, bounds: Rect<f32>) -> Self {
self.view_bounds = Some(bounds);
@@ -1199,6 +1220,8 @@ impl CurveEditorBuilder {
zoom_to_fit,
},
view_bounds: self.view_bounds,
+ show_x_values: self.show_x_values,
+ show_y_values: self.show_y_values,
};
ctx.add_node(UiNode::new(editor))
