mirror of
https://github.com/storytold/photocraft.git
synced 2026-12-02 06:20:48 +01:00
Brush Settings: Brush Pose Pressure takes 1 to 100 % (#17629)
This commit is contained in:
1 parent
cf0753ad7b
commit
b4657ddf8d
2 files changed
+97
-1
No files matched your search
@@ -0,0 +1,91 @@
|
||||
//! #17629: Brush Settings › Brush Pose › Pressure takes 1 to 100 %, as the reference does: 0 typed
|
||||
//! in it becomes 1 % and 150 becomes 100 %. The other fields sharing the 0 to 100 % range keep it.
|
||||
|
||||
use super::*;
|
||||
use crate::theme::AppTheme;
|
||||
use egui::accesskit::Role;
|
||||
use egui::vec2;
|
||||
use egui_kittest::{
|
||||
Harness,
|
||||
kittest::{NodeT, Queryable},
|
||||
};
|
||||
|
||||
const POSE: usize = 7;
|
||||
const SHAPE_DYNAMICS: usize = 1;
|
||||
|
||||
struct State {
|
||||
app: Box<PhotocraftApp>,
|
||||
brush: BrushSettings,
|
||||
}
|
||||
|
||||
fn harness(section: usize, brush: BrushSettings) -> Harness<'static, State> {
|
||||
let mut ready = false;
|
||||
let state = State { app: PhotocraftApp::new(photocraft_engine::Session::new(), crate::Services::default()), brush };
|
||||
let mut h = Harness::builder().with_context(state.app.ctx().clone()).with_size(vec2(340.0, 1400.0)).build_ui_state(
|
||||
move |ui, state: &mut State| {
|
||||
if !ready {
|
||||
PhotocraftApp::setup_context(ui.ctx(), AppTheme::pro_medium());
|
||||
ready = true;
|
||||
return;
|
||||
}
|
||||
section_body(&mut state.app, ui, &mut state.brush, section, Tool::Brush);
|
||||
},
|
||||
state,
|
||||
);
|
||||
h.run_steps(3);
|
||||
h
|
||||
}
|
||||
|
||||
/// Types `text` into the number field showing `value` and presses Enter.
|
||||
fn type_into(h: &mut Harness<'static, State>, value: f64, text: &str) {
|
||||
h.query_all_by_role(Role::SpinButton)
|
||||
.find(|n| n.accesskit_node().numeric_value() == Some(value))
|
||||
.unwrap_or_else(|| panic!("a number field showing {value}"))
|
||||
.click();
|
||||
h.run_steps(2);
|
||||
h.key_press_modifiers(egui::Modifiers::COMMAND, egui::Key::A);
|
||||
h.run_steps(1);
|
||||
h.event(egui::Event::Text(text.into()));
|
||||
h.run_steps(1);
|
||||
h.key_press(egui::Key::Enter);
|
||||
h.run_steps(3);
|
||||
}
|
||||
|
||||
fn pose_brush(pressure: f32) -> BrushSettings {
|
||||
let mut b = BrushSettings::default();
|
||||
b.pose.pressure = pressure;
|
||||
b
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn zero_typed_in_pose_pressure_becomes_one_percent() {
|
||||
let mut h = harness(POSE, pose_brush(0.5));
|
||||
type_into(&mut h, 50.0, "0");
|
||||
assert!((h.state().brush.pose.pressure - 0.01).abs() < 1e-6, "pressure {}", h.state().brush.pose.pressure);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn one_hundred_fifty_typed_in_pose_pressure_becomes_one_hundred_percent() {
|
||||
let mut h = harness(POSE, pose_brush(0.5));
|
||||
type_into(&mut h, 50.0, "150");
|
||||
assert_eq!(h.state().brush.pose.pressure, 1.0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn values_inside_the_range_are_kept() {
|
||||
let mut h = harness(POSE, pose_brush(0.5));
|
||||
type_into(&mut h, 50.0, "1");
|
||||
assert!((h.state().brush.pose.pressure - 0.01).abs() < 1e-6);
|
||||
type_into(&mut h, 1.0, "37");
|
||||
assert!((h.state().brush.pose.pressure - 0.37).abs() < 1e-6);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn other_percent_fields_still_take_zero() {
|
||||
let mut b = BrushSettings::default();
|
||||
b.shape_dynamics.enabled = true;
|
||||
b.shape_dynamics.size.jitter = 0.5;
|
||||
let mut h = harness(SHAPE_DYNAMICS, b);
|
||||
type_into(&mut h, 50.0, "0");
|
||||
assert_eq!(h.state().brush.shape_dynamics.size.jitter, 0.0, "Size Jitter keeps 0 to 100 %");
|
||||
}
|
||||
@@ -497,7 +497,8 @@ impl Pane<'_> {
|
||||
self.check(ui, tl!("Override Tilt Y"), &mut p.override_tilt_y);
|
||||
self.field(ui, tl!("Rotation"), &mut p.rotation, dd.rotation, Shown::whole(0.0, 360.0, Some(UnitKind::Degrees)), true);
|
||||
self.check(ui, tl!("Override Rotation"), &mut p.override_rotation);
|
||||
self.field(ui, tl!("Pressure"), &mut p.pressure, dd.pressure, AMOUNT, true);
|
||||
// 1 to 100 %, as the reference takes it: 0 typed becomes 1 % (#17629).
|
||||
self.field(ui, tl!("Pressure"), &mut p.pressure, dd.pressure, Shown::percent(1.0, 100.0), true);
|
||||
self.check(ui, tl!("Override Pressure"), &mut p.override_pressure);
|
||||
}
|
||||
}
|
||||
@@ -539,3 +540,7 @@ pub(crate) fn section_body(app: &mut PhotocraftApp, ui: &mut Ui, b: &mut BrushSe
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests;
|
||||
|
||||
#[cfg(test)]
|
||||
#[path = "brush_pose_pressure_range_tests.rs"]
|
||||
mod brush_pose_pressure_range_tests;
|
||||
Reference in new issue
Block a user