Skip to content

Commit

Permalink
attribute integers can also be negative
Browse files Browse the repository at this point in the history
  • Loading branch information
bertiqwerty committed Aug 26, 2024
1 parent 6775944 commit 7500121
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
14 changes: 7 additions & 7 deletions rvimage/src/rvlib/menu/tools_menus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ use crate::{
},
};
use egui::Ui;
use rvimage_domain::{to_rv, RvResult};
use rvimage_domain::{TPtF, TPtI};
use rvimage_domain::TPtF;
use rvimage_domain::{to_rv, RvResult, TPtS};
use tracing::{info, warn};

use super::ui_util::{slider, text_edit_singleline};
Expand Down Expand Up @@ -504,7 +504,7 @@ pub fn attributes_menu(
);
ui.selectable_value(
&mut data.new_attr_val,
AttrVal::Int(TPtI::default()),
AttrVal::Int(TPtS::default()),
INT_LABEL,
);
ui.selectable_value(
Expand Down Expand Up @@ -539,7 +539,7 @@ pub fn attributes_menu(
}
}
Some(AttrVal::Float(x)) => {
let (lost_focus, new_val) = process_number(
let (input_changed, new_val) = process_number(
ui,
are_tools_active,
FLOAT_LABEL,
Expand All @@ -548,7 +548,7 @@ pub fn attributes_menu(
if let Some(new_val) = new_val {
*x = new_val;
}
if lost_focus || ui.button("OK").clicked() {
if input_changed {
data.options.is_update_triggered = true;
}
}
Expand All @@ -562,15 +562,15 @@ pub fn attributes_menu(
if let Some(new_val) = new_val {
*x = new_val;
}
if lost_focus || ui.button("OK").clicked() {
if lost_focus {
data.options.is_update_triggered = true;
}
}
Some(AttrVal::Str(s)) => {
let lost_focus = text_edit_singleline(ui, s, are_tools_active)
.on_hover_text(TEXT_LABEL)
.lost_focus();
if lost_focus || ui.button("OK").clicked() {
if lost_focus {
data.options.is_update_triggered = true;
}
}
Expand Down
6 changes: 3 additions & 3 deletions rvimage/src/rvlib/menu/ui_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,14 @@ where
let new_val = text_edit_singleline(ui, buffer, are_tools_active).on_hover_text(label);
if new_val.changed() {
match buffer.parse::<T>() {
Ok(val) => (new_val.lost_focus(), Some(val)),
Ok(val) => (true, Some(val)),
Err(_) => {
warn!("could not parse {buffer} as number");
(new_val.lost_focus(), None)
(false, None)
}
}
} else {
(new_val.lost_focus(), None)
(false, None)
}
}
pub fn button_triggerable_number<T>(
Expand Down
6 changes: 3 additions & 3 deletions rvimage/src/rvlib/tools_data/attributes_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::{
};

use crate::{cfg::ExportPath, implement_annotate, implement_annotations_getters, ShapeI};
use rvimage_domain::{rverr, to_rv, RvResult, TPtF, TPtI};
use rvimage_domain::{rverr, to_rv, RvResult, TPtF, TPtS};

use super::label_map::LabelMap;

Expand All @@ -25,7 +25,7 @@ pub const ATTR_INTERVAL_SEPARATOR: &str = "-";
#[derive(Deserialize, Serialize, Clone, PartialEq, Debug)]
pub enum AttrVal {
Float(TPtF),
Int(TPtI),
Int(TPtS),
Str(String),
Bool(bool),
}
Expand Down Expand Up @@ -55,7 +55,7 @@ impl AttrVal {
x == &attr_val
}
AttrVal::Int(x) => {
let attr_val = attr_val.parse::<TPtI>().map_err(to_rv)?;
let attr_val = attr_val.parse::<TPtS>().map_err(to_rv)?;
x == &attr_val
}
AttrVal::Str(s) => {
Expand Down

0 comments on commit 7500121

Please sign in to comment.