Deprecate old DragValue constructors in favor of DragValue::new
This commit is contained in:
parent
de439b6e21
commit
5011623744
9 changed files with 16 additions and 13 deletions
|
@ -68,7 +68,7 @@
|
||||||
//! ui.text_edit_singleline(&mut my_string);
|
//! ui.text_edit_singleline(&mut my_string);
|
||||||
//! if ui.button("Click me").clicked() { }
|
//! if ui.button("Click me").clicked() { }
|
||||||
//! ui.add(egui::Slider::new(&mut my_f32, 0.0..=100.0));
|
//! ui.add(egui::Slider::new(&mut my_f32, 0.0..=100.0));
|
||||||
//! ui.add(egui::DragValue::f32(&mut my_f32));
|
//! ui.add(egui::DragValue::new(&mut my_f32));
|
||||||
//!
|
//!
|
||||||
//! ui.checkbox(&mut my_boolean, "Checkbox");
|
//! ui.checkbox(&mut my_boolean, "Checkbox");
|
||||||
//!
|
//!
|
||||||
|
|
|
@ -416,7 +416,7 @@ impl Response {
|
||||||
/// ```
|
/// ```
|
||||||
/// use egui::*;
|
/// use egui::*;
|
||||||
/// fn draw_vec2(ui: &mut Ui, v: &mut Vec2) -> Response {
|
/// fn draw_vec2(ui: &mut Ui, v: &mut Vec2) -> Response {
|
||||||
/// ui.add(DragValue::f32(&mut v.x)) | ui.add(DragValue::f32(&mut v.y))
|
/// ui.add(DragValue::new(&mut v.x)) | ui.add(DragValue::new(&mut v.y))
|
||||||
/// }
|
/// }
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
|
|
|
@ -985,7 +985,7 @@ impl Ui {
|
||||||
#![allow(clippy::float_cmp)]
|
#![allow(clippy::float_cmp)]
|
||||||
|
|
||||||
let mut degrees = radians.to_degrees();
|
let mut degrees = radians.to_degrees();
|
||||||
let mut response = self.add(DragValue::f32(&mut degrees).speed(1.0).suffix("°"));
|
let mut response = self.add(DragValue::new(&mut degrees).speed(1.0).suffix("°"));
|
||||||
|
|
||||||
// only touch `*radians` if we actually changed the degree value
|
// only touch `*radians` if we actually changed the degree value
|
||||||
if degrees != radians.to_degrees() {
|
if degrees != radians.to_degrees() {
|
||||||
|
@ -1006,7 +1006,7 @@ impl Ui {
|
||||||
|
|
||||||
let mut taus = *radians / TAU;
|
let mut taus = *radians / TAU;
|
||||||
let mut response = self
|
let mut response = self
|
||||||
.add(DragValue::f32(&mut taus).speed(0.01).suffix("τ"))
|
.add(DragValue::new(&mut taus).speed(0.01).suffix("τ"))
|
||||||
.on_hover_text("1τ = one turn, 0.5τ = half a turn, etc. 0.25τ = 90°");
|
.on_hover_text("1τ = one turn, 0.5τ = half a turn, etc. 0.25τ = 90°");
|
||||||
|
|
||||||
// only touch `*radians` if we actually changed the value
|
// only touch `*radians` if we actually changed the value
|
||||||
|
|
|
@ -44,7 +44,7 @@ fn set(get_set_value: &mut GetSetValue<'_>, value: f64) {
|
||||||
/// ```
|
/// ```
|
||||||
/// # let ui = &mut egui::Ui::__test();
|
/// # let ui = &mut egui::Ui::__test();
|
||||||
/// # let mut my_f32: f32 = 0.0;
|
/// # let mut my_f32: f32 = 0.0;
|
||||||
/// ui.add(egui::DragValue::f32(&mut my_f32).speed(0.1));
|
/// ui.add(egui::DragValue::new(&mut my_f32).speed(0.1));
|
||||||
/// ```
|
/// ```
|
||||||
#[must_use = "You should put this widget in an ui with `ui.add(widget);`"]
|
#[must_use = "You should put this widget in an ui with `ui.add(widget);`"]
|
||||||
pub struct DragValue<'a> {
|
pub struct DragValue<'a> {
|
||||||
|
@ -59,6 +59,7 @@ pub struct DragValue<'a> {
|
||||||
|
|
||||||
macro_rules! impl_integer_constructor {
|
macro_rules! impl_integer_constructor {
|
||||||
($int:ident) => {
|
($int:ident) => {
|
||||||
|
#[deprecated = "Use DragValue::new instead"]
|
||||||
pub fn $int(value: &'a mut $int) -> Self {
|
pub fn $int(value: &'a mut $int) -> Self {
|
||||||
Self::from_get_set(move |v: Option<f64>| {
|
Self::from_get_set(move |v: Option<f64>| {
|
||||||
if let Some(v) = v {
|
if let Some(v) = v {
|
||||||
|
@ -91,6 +92,7 @@ impl<'a> DragValue<'a> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[deprecated = "Use DragValue::new instead"]
|
||||||
pub fn f32(value: &'a mut f32) -> Self {
|
pub fn f32(value: &'a mut f32) -> Self {
|
||||||
Self::from_get_set(move |v: Option<f64>| {
|
Self::from_get_set(move |v: Option<f64>| {
|
||||||
if let Some(v) = v {
|
if let Some(v) = v {
|
||||||
|
@ -100,6 +102,7 @@ impl<'a> DragValue<'a> {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[deprecated = "Use DragValue::new instead"]
|
||||||
pub fn f64(value: &'a mut f64) -> Self {
|
pub fn f64(value: &'a mut f64) -> Self {
|
||||||
Self::from_get_set(move |v: Option<f64>| {
|
Self::from_get_set(move |v: Option<f64>| {
|
||||||
if let Some(v) = v {
|
if let Some(v) = v {
|
||||||
|
|
|
@ -83,7 +83,7 @@ pub fn reset_button<T: Default + PartialEq>(ui: &mut Ui, value: &mut T) {
|
||||||
pub fn stroke_ui(ui: &mut crate::Ui, stroke: &mut epaint::Stroke, text: &str) {
|
pub fn stroke_ui(ui: &mut crate::Ui, stroke: &mut epaint::Stroke, text: &str) {
|
||||||
let epaint::Stroke { width, color } = stroke;
|
let epaint::Stroke { width, color } = stroke;
|
||||||
ui.horizontal(|ui| {
|
ui.horizontal(|ui| {
|
||||||
ui.add(DragValue::f32(width).speed(0.1).clamp_range(0.0..=5.0))
|
ui.add(DragValue::new(width).speed(0.1).clamp_range(0.0..=5.0))
|
||||||
.on_hover_text("Width");
|
.on_hover_text("Width");
|
||||||
ui.color_edit_button_srgba(color);
|
ui.color_edit_button_srgba(color);
|
||||||
ui.label(text);
|
ui.label(text);
|
||||||
|
@ -101,7 +101,7 @@ pub(crate) fn shadow_ui(ui: &mut Ui, shadow: &mut epaint::Shadow, text: &str) {
|
||||||
ui.horizontal(|ui| {
|
ui.horizontal(|ui| {
|
||||||
ui.label(text);
|
ui.label(text);
|
||||||
ui.add(
|
ui.add(
|
||||||
DragValue::f32(extrusion)
|
DragValue::new(extrusion)
|
||||||
.speed(1.0)
|
.speed(1.0)
|
||||||
.clamp_range(0.0..=100.0),
|
.clamp_range(0.0..=100.0),
|
||||||
)
|
)
|
||||||
|
|
|
@ -413,7 +413,7 @@ impl<'a> Slider<'a> {
|
||||||
fn value_ui(&mut self, ui: &mut Ui, x_range: RangeInclusive<f32>) {
|
fn value_ui(&mut self, ui: &mut Ui, x_range: RangeInclusive<f32>) {
|
||||||
let mut value = self.get_value();
|
let mut value = self.get_value();
|
||||||
ui.add(
|
ui.add(
|
||||||
DragValue::f64(&mut value)
|
DragValue::new(&mut value)
|
||||||
.speed(self.current_gradient(&x_range))
|
.speed(self.current_gradient(&x_range))
|
||||||
.clamp_range(self.clamp_range())
|
.clamp_range(self.clamp_range())
|
||||||
.min_decimals(self.min_decimals)
|
.min_decimals(self.min_decimals)
|
||||||
|
|
|
@ -62,7 +62,7 @@ impl PlotDemo {
|
||||||
ui.vertical(|ui| {
|
ui.vertical(|ui| {
|
||||||
ui.label("Circle:");
|
ui.label("Circle:");
|
||||||
ui.add(
|
ui.add(
|
||||||
egui::DragValue::f32(circle_radius)
|
egui::DragValue::new(circle_radius)
|
||||||
.speed(0.1)
|
.speed(0.1)
|
||||||
.clamp_range(0.0..=f32::INFINITY)
|
.clamp_range(0.0..=f32::INFINITY)
|
||||||
// .logarithmic(true)
|
// .logarithmic(true)
|
||||||
|
@ -71,14 +71,14 @@ impl PlotDemo {
|
||||||
);
|
);
|
||||||
ui.horizontal(|ui| {
|
ui.horizontal(|ui| {
|
||||||
ui.add(
|
ui.add(
|
||||||
egui::DragValue::f32(&mut circle_center.x)
|
egui::DragValue::new(&mut circle_center.x)
|
||||||
.speed(0.1)
|
.speed(0.1)
|
||||||
// .logarithmic(true)
|
// .logarithmic(true)
|
||||||
// .smallest_positive(1e-2)
|
// .smallest_positive(1e-2)
|
||||||
.prefix("x: "),
|
.prefix("x: "),
|
||||||
);
|
);
|
||||||
ui.add(
|
ui.add(
|
||||||
egui::DragValue::f32(&mut circle_center.y)
|
egui::DragValue::new(&mut circle_center.y)
|
||||||
.speed(1.0)
|
.speed(1.0)
|
||||||
// .logarithmic(true)
|
// .logarithmic(true)
|
||||||
// .smallest_positive(1e-2)
|
// .smallest_positive(1e-2)
|
||||||
|
|
|
@ -67,7 +67,7 @@ impl super::View for Scrolling {
|
||||||
ui.horizontal(|ui| {
|
ui.horizontal(|ui| {
|
||||||
ui.label("Scroll to a specific offset:");
|
ui.label("Scroll to a specific offset:");
|
||||||
go_to_scroll_offset |= ui
|
go_to_scroll_offset |= ui
|
||||||
.add(DragValue::f32(&mut self.offset).speed(1.0).suffix("px"))
|
.add(DragValue::new(&mut self.offset).speed(1.0).suffix("px"))
|
||||||
.dragged();
|
.dragged();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -151,7 +151,7 @@ impl WidgetGallery {
|
||||||
ui.end_row();
|
ui.end_row();
|
||||||
|
|
||||||
ui.add(doc_link_label("DragValue", "DragValue"));
|
ui.add(doc_link_label("DragValue", "DragValue"));
|
||||||
ui.add(egui::DragValue::f32(scalar).speed(1.0));
|
ui.add(egui::DragValue::new(scalar).speed(1.0));
|
||||||
ui.end_row();
|
ui.end_row();
|
||||||
|
|
||||||
ui.add(doc_link_label("Color picker", "color_edit"));
|
ui.add(doc_link_label("Color picker", "color_edit"));
|
||||||
|
|
Loading…
Reference in a new issue