Lay out the paint tool's Brush section in the reference's bands

Size (Size, Minimum Size, Spacing), Opacity (Flow, Stroke opacity),
Orientation (the brush's stamp on a dial beside Angle, Follow Path),
Jitter (a strip of jittered dabs above the four jitters) and Projection
(Alignment with a picture per mode, Backface culling with its Angle
fade, Size Space, Stamp depth) as property-sheet bands, each with its
own reset. Brush presets open from the Brush caption's menu button.
Particles and Lazy mouse stay, folded.
This commit is contained in:
Rebornim committed 2026-11-27 08:25:57 +00:00
1 parent 18c7b690ca
commit e6342a9f29
12 files changed
+518 -213

No files matched your search

+149
View File
@@ -0,0 +1,149 @@
//! Pictures of what the brush settings do: the brush's stamp turned to its Angle, a strip of jittered dabs and the alignment modes
use egui::{ColorImage, Painter, Pos2, Rect, Shape, Stroke, pos2};
use texturecraft_engine::compose::ImageRes;
use texturecraft_engine::paint::{Alignment, BrushSettings};
use crate::preview_image::stroke_strip;
use crate::theme::Tokens;
/// The stamp's radius in the Orientation picture, as a share of half its side: room for the dial's ring around it
const STAMP_RADIUS_SHARE: f32 = 0.62;
/// The dial's ring radius, as a share of half the picture's side
const RING_RADIUS_SHARE: f32 = 0.86;
/// How far the Angle tick reaches in and out of the ring, in points
const TICK_REACH: f32 = 3.0;
/// The ring's and the tick's line widths, in points
const RING_WIDTH: f32 = 1.0;
const TICK_WIDTH: f32 = 2.0;
/// How far a dab may reach from the strip's centre line, as a share of half its height
const STRIP_REACH_SHARE: f32 = 0.85;
/// The least spacing between the strip's dabs, in stamp diameters, so each dab reads on its own
const STRIP_DAB_SPACING: f32 = 1.4;
/// The brush's own stamp turned to its Angle, alone in a `size` square: jitter, flow and opacity left out so only the shape and its turn show
pub(crate) fn stamp_image(brush: &BrushSettings, image: Option<&ImageRes>, size: [usize; 2], _pixels_per_point: f32, tints: &[[u8; 3]]) -> ColorImage {
let still = BrushSettings {
jitter_size: 0.0,
jitter_angle: 0.0,
jitter_flow: 0.0,
jitter_position: 0.0,
follow_path: false,
flow: 1.0,
opacity: 1.0,
..brush.clone()
};
let center = (size[0] as f32 * 0.5, size[1] as f32 * 0.5);
let radius = center.0.min(center.1) * STAMP_RADIUS_SHARE;
// A curve that stays put lays exactly one stamp
stroke_strip(&still, image, size, |_| radius, |_| center, |x| column_tint(tints, x))
}
/// A row of the brush's dabs across a `size` strip, scattered by its four jitters; dabs shrink as Position Jitter grows so the scatter stays inside
pub(crate) fn jitter_image(brush: &BrushSettings, image: Option<&ImageRes>, size: [usize; 2], _pixels_per_point: f32, tints: &[[u8; 3]]) -> ColorImage {
let spaced = BrushSettings { spacing: brush.spacing.max(STRIP_DAB_SPACING), follow_path: false, flow: 1.0, opacity: 1.0, ..brush.clone() };
let (width, middle) = (size[0] as f32, size[1] as f32 * 0.5);
// A dab lands up to Position Jitter radii from the line, so its radius and that reach together fill the strip's half height
let radius = middle * STRIP_REACH_SHARE / (1.0 + brush.jitter_position.max(0.0));
let curve = |t: f32| (radius + t * (width - 2.0 * radius), middle);
stroke_strip(&spaced, image, size, |_| radius, curve, |x| column_tint(tints, x))
}
fn column_tint(tints: &[[u8; 3]], x: usize) -> [u8; 3] {
tints.get(x).copied().unwrap_or([u8::MAX; 3])
}
/// The dial around the Orientation picture's stamp: a ring and an accent tick at `degrees` (counter-clockwise from the right, as the stamp turns)
pub(crate) fn dial_ring(painter: &Painter, rect: Rect, degrees: f32, tokens: &Tokens) {
let center = rect.center();
let ring = rect.width().min(rect.height()) * 0.5 * RING_RADIUS_SHARE;
painter.circle_stroke(center, ring, Stroke::new(RING_WIDTH, tokens.button_border));
let (sin, cos) = degrees.to_radians().sin_cos();
let at = |reach: f32| pos2(center.x + reach * cos, center.y - reach * sin);
painter.line_segment([at(ring - TICK_REACH), at(ring + TICK_REACH)], Stroke::new(TICK_WIDTH, tokens.accent));
}
/// Points along the Alignment picture's surface
const SURFACE_POINTS: usize = 16;
/// The surface's bulge and the stamp's height above it, as shares of the picture's height
const SURFACE_BULGE_SHARE: f32 = 0.45;
const STAMP_LIFT_SHARE: f32 = 0.12;
/// Margin inside the Alignment picture, in points
const ALIGNMENT_INSET: f32 = 2.0;
/// The middle share of the surface the stamp covers
const STAMP_SPAN_SHARE: f32 = 0.6;
/// How an Alignment lays the stamp on a curved surface: bent along it (Tangent | Wrap) or flat towards the view (Camera)
pub(crate) fn alignment_picture(painter: &Painter, rect: Rect, alignment: Alignment, tokens: &Tokens) {
let rect = rect.shrink(ALIGNMENT_INSET);
let bulge = rect.height() * SURFACE_BULGE_SHARE;
let surface_y = |across: f32| rect.bottom() - bulge * (1.0 - across * across);
let point = |across: f32, lift: f32| pos2(rect.center().x + across * rect.width() * 0.5, surface_y(across) - lift);
let line = |from: f32, to: f32, lift: f32| -> Vec<Pos2> {
(0..=SURFACE_POINTS).map(|step| point(from + (to - from) * step as f32 / SURFACE_POINTS as f32, lift)).collect()
};
painter.add(Shape::line(line(-1.0, 1.0, 0.0), Stroke::new(RING_WIDTH, tokens.text_dim)));
let lift = rect.height() * STAMP_LIFT_SHARE;
let stamp = match alignment {
Alignment::Tangent => line(-STAMP_SPAN_SHARE, STAMP_SPAN_SHARE, lift),
Alignment::Camera => {
let top = surface_y(0.0) - lift;
vec![pos2(point(-STAMP_SPAN_SHARE, 0.0).x, top), pos2(point(STAMP_SPAN_SHARE, 0.0).x, top)]
}
};
painter.add(Shape::line(stamp, Stroke::new(TICK_WIDTH, tokens.accent)));
}
#[cfg(test)]
mod tests {
use texturecraft_engine::paint::BrushAlpha;
use super::*;
const STAMP_SIZE: [usize; 2] = [48, 48];
const STRIP_SIZE: [usize; 2] = [240, 40];
fn white(width: usize) -> Vec<[u8; 3]> {
vec![[u8::MAX; 3]; width]
}
#[test]
fn the_stamp_turns_with_angle() {
let upright = BrushSettings { alpha: BrushAlpha::Streaks, angle: 0.0, ..BrushSettings::default() };
let turned = BrushSettings { angle: 45.0, ..upright.clone() };
let picture = |brush: &BrushSettings| stamp_image(brush, None, STAMP_SIZE, 1.0, &white(STAMP_SIZE[0])).pixels;
assert!(picture(&upright).iter().any(|pixel| pixel.a() > 0), "the stamp shows");
assert_ne!(picture(&upright), picture(&turned));
}
#[test]
fn each_jitter_changes_the_strip() {
let steady = BrushSettings { hardness: 1.0, ..BrushSettings::default() };
let strip = |brush: &BrushSettings| jitter_image(brush, None, STRIP_SIZE, 1.0, &white(STRIP_SIZE[0])).pixels;
let jittered = [
BrushSettings { jitter_size: 0.8, ..steady.clone() },
BrushSettings { jitter_flow: 0.8, ..steady.clone() },
BrushSettings { jitter_angle: 0.8, alpha: BrushAlpha::Streaks, ..steady.clone() },
BrushSettings { jitter_position: 1.0, ..steady.clone() },
];
for brush in &jittered {
let unjittered = BrushSettings { jitter_size: 0.0, jitter_flow: 0.0, jitter_angle: 0.0, jitter_position: 0.0, ..brush.clone() };
assert_ne!(strip(brush), strip(&unjittered), "{brush:?}");
}
}
}
+264
View File
@@ -0,0 +1,264 @@
//! The Brush section of a paint tool's Properties: the Size, Opacity, Orientation, Jitter and Projection bands, grouped and named as the reference groups them
use std::ops::RangeInclusive;
use std::sync::Arc;
use egui::{Painter, Rect, Response, Sense, Stroke, StrokeKind, Ui, vec2};
use serde_json::json;
use texturecraft_engine::compose::ImageRes;
use texturecraft_engine::paint::{Alignment, BrushSettings};
use crate::TextureCraftApp;
use crate::brush_pictures::{alignment_picture, dial_ring, jitter_image, stamp_image};
use crate::brush_stroke_preview::BrushStrokePreview;
use crate::fill_pictures::backface_picture;
use crate::i18n::tr;
use crate::property_sheet::{PropertySheet, RowLead, StackSlider};
use crate::theme::{Tokens, caption};
use crate::toolbar::{MAX_BRUSH_SIZE, MIN_BRUSH_SIZE};
/// Height of the Jitter band's strip of dabs, in points
const JITTER_STRIP_HEIGHT: f32 = 40.0;
/// Corner radius of the Jitter strip's frame
const JITTER_STRIP_ROUNDING: f32 = 2.0;
/// Width of the Jitter strip's frame, in points; the dabs are drawn inside it
const JITTER_STRIP_OUTLINE_WIDTH: f32 = 1.0;
/// What Angle and each Angle fade may be, in degrees
const ANGLE_RANGE: RangeInclusive<f32> = -180.0..=180.0;
const ANGLE_FADE_RANGE: RangeInclusive<f32> = 0.0..=90.0;
/// Size's slider, in percent of the largest brush
const SIZE_PERCENT_RANGE: RangeInclusive<f32> = 0.05..=100.0;
/// Spacing's slider, in percent of the stamp's width
const SPACING_PERCENT_RANGE: RangeInclusive<f32> = 1.0..=1000.0;
/// Position Jitter's slider, in percent of the stamp's radius
const POSITION_JITTER_PERCENT_RANGE: RangeInclusive<f32> = 0.0..=400.0;
const PERCENT_RANGE: RangeInclusive<f32> = 0.0..=100.0;
/// The ranges of Stamp depth, Gravity, particles per stamp, a particle's lifetime in steps and the lazy mouse distance in pixels
const STAMP_DEPTH_RANGE: RangeInclusive<f32> = 0.05..=4.0;
const GRAVITY_RANGE: RangeInclusive<f32> = 0.0..=2.0;
const PARTICLE_COUNT_RANGE: RangeInclusive<f32> = 1.0..=16.0;
const PARTICLE_LIFETIME_RANGE: RangeInclusive<f32> = 1.0..=128.0;
const LAZY_DISTANCE_RANGE: RangeInclusive<f32> = 0.0..=200.0;
/// Width of the brush presets list
const PRESETS_WIDTH: f32 = 230.0;
/// Height the presets list scrolls past
const PRESETS_MAX_HEIGHT: f32 = 380.0;
/// The Brush section under its caption, whose ≡ button `menu` opens the brush presets
pub(crate) fn brush_section(app: &mut TextureCraftApp, sheet: &mut PropertySheet<'_>, menu: Option<Response>) {
if let Some(menu) = menu {
brush_presets_popover(app, sheet.ui, menu);
}
sheet.dim_line(tr("Ctrl+right-drag in a view sets the size and hardness, Ctrl+left-drag the flow and angle."));
sheet.dim_line(tr("Ctrl+Shift+right-drag: size and hardness in fine steps."));
let tokens = Tokens::get(sheet.ui.ctx());
let image = app.session.tool.brush.alpha_image.as_ref().and_then(|name| app.session.images.get(name)).cloned();
let brush = &mut app.session.tool.brush;
let defaults = BrushSettings::default();
// Each band's reset puts back only the fields it shows
let size_fields = |settings: &BrushSettings| (settings.size, settings.min_size, settings.spacing);
let band = sheet.band(tr("Size"), true, Some(size_fields(brush) != size_fields(&defaults)), None);
if band.reset {
(brush.size, brush.min_size, brush.spacing) = size_fields(&defaults);
}
if band.open {
let mut size_percent = brush.size / MAX_BRUSH_SIZE * 100.0;
if sheet.slider(tr("Size"), &mut size_percent, SIZE_PERCENT_RANGE, 1).is_some() {
brush.size = (size_percent / 100.0 * MAX_BRUSH_SIZE).clamp(MIN_BRUSH_SIZE, MAX_BRUSH_SIZE);
}
percent_slider(sheet, tr("Minimum Size (%)"), &mut brush.min_size, PERCENT_RANGE);
percent_slider(sheet, tr("Spacing"), &mut brush.spacing, SPACING_PERCENT_RANGE);
}
let opacity_fields = |settings: &BrushSettings| (settings.flow, settings.opacity);
let band = sheet.band(tr("Opacity"), true, Some(opacity_fields(brush) != opacity_fields(&defaults)), None);
if band.reset {
(brush.flow, brush.opacity) = opacity_fields(&defaults);
}
if band.open {
percent_slider(sheet, tr("Flow"), &mut brush.flow, PERCENT_RANGE);
percent_slider(sheet, tr("Stroke opacity"), &mut brush.opacity, PERCENT_RANGE);
}
let orientation_fields = |settings: &BrushSettings| (settings.angle, settings.follow_path);
let band = sheet.band(tr("Orientation"), true, Some(orientation_fields(brush) != orientation_fields(&defaults)), None);
if band.reset {
(brush.angle, brush.follow_path) = orientation_fields(&defaults);
}
if band.open {
let shown = brush.clone();
let ctx = sheet.ui.ctx().clone();
let tint = tokens.text.to_array();
let dial = |painter: &Painter, rect: Rect| {
BrushStrokePreview::paint_picture(
&ctx,
painter,
rect,
"brush_stamp_picture",
(&shown, image.as_ref()),
|_| [tint[0], tint[1], tint[2]],
stamp_image,
);
dial_ring(painter, rect, shown.angle, &tokens);
};
let angle = StackSlider { label: tr("Angle"), value: &mut brush.angle, range: ANGLE_RANGE, typed: ANGLE_RANGE, decimals: 0, suffix: "°", dial: false };
sheet.picture_sliders(&dial, &mut [angle]);
sheet.toggle(tr("Follow Path"), &mut brush.follow_path);
}
let jitter_fields = |settings: &BrushSettings| (settings.jitter_size, settings.jitter_flow, settings.jitter_angle, settings.jitter_position);
let band = sheet.band(tr("Jitter"), true, Some(jitter_fields(brush) != jitter_fields(&defaults)), None);
if band.reset {
(brush.jitter_size, brush.jitter_flow, brush.jitter_angle, brush.jitter_position) = jitter_fields(&defaults);
}
if band.open {
jitter_strip(sheet, brush, image.as_ref(), &tokens);
percent_slider(sheet, tr("Size Jitter"), &mut brush.jitter_size, PERCENT_RANGE);
percent_slider(sheet, tr("Flow Jitter"), &mut brush.jitter_flow, PERCENT_RANGE);
percent_slider(sheet, tr("Angle Jitter"), &mut brush.jitter_angle, PERCENT_RANGE);
percent_slider(sheet, tr("Position Jitter"), &mut brush.jitter_position, POSITION_JITTER_PERCENT_RANGE);
}
let projection_fields =
|settings: &BrushSettings| (settings.alignment, settings.backface_culling, settings.angle_fade, settings.screen_space, settings.depth);
let band = sheet.band(tr("Projection"), true, Some(projection_fields(brush) != projection_fields(&defaults)), None);
if band.reset {
(brush.alignment, brush.backface_culling, brush.angle_fade, brush.screen_space, brush.depth) = projection_fields(&defaults);
}
if band.open {
projection_rows(sheet, brush, &tokens);
}
let particles = &mut brush.particles;
let band = sheet.band(tr("Particles"), false, Some(*particles != defaults.particles), None);
if band.reset {
*particles = defaults.particles;
}
if band.open {
sheet.info(tr("Paint slides down the surface"));
sheet.toggle(tr("Particle brush"), &mut particles.enabled);
whole_slider(sheet, tr("Count per stamp"), &mut particles.count, PARTICLE_COUNT_RANGE);
whole_slider(sheet, tr("Lifetime (steps)"), &mut particles.lifetime, PARTICLE_LIFETIME_RANGE);
sheet.slider(tr("Gravity"), &mut particles.gravity, GRAVITY_RANGE, 2);
}
let band = sheet.band(tr("Lazy mouse"), false, Some(brush.lazy != defaults.lazy), None);
if band.reset {
brush.lazy = defaults.lazy;
}
if band.open {
sheet.slider(tr("Lazy mouse distance"), &mut brush.lazy, LAZY_DISTANCE_RANGE, 0);
}
*brush = brush.sanitized();
}
/// Alignment, Backface culling with its Angle fade under it, Size Space and Stamp depth
fn projection_rows(sheet: &mut PropertySheet<'_>, brush: &mut BrushSettings, tokens: &Tokens) {
let alignment_name = |alignment: Alignment| {
match alignment {
Alignment::Tangent => tr("Tangent | Wrap"),
Alignment::Camera => tr("Camera"),
}
.to_owned()
};
let picture = |painter: &Painter, rect: Rect, alignment: Alignment| alignment_picture(painter, rect, alignment, tokens);
let (picked, _) = sheet.dropdown(tr("Alignment"), brush.alignment, &[Alignment::Tangent, Alignment::Camera], alignment_name, Some(&picture));
if let Some(alignment) = picked {
brush.alignment = alignment;
}
let culled = brush.backface_culling;
let picture = |painter: &Painter, rect: Rect| backface_picture(painter, rect, culled, tokens);
sheet.picture_toggle(&picture, tr("Backface culling"), &mut brush.backface_culling);
// Faces only fade towards their edge while backfaces are culled
sheet.greyed(brush.backface_culling, Some(tr("Fades only while Backface culling is on")), |sheet| {
sheet.angle_led(RowLead::Child(tr("Angle fade from")), &mut brush.angle_fade.0, ANGLE_FADE_RANGE);
sheet.angle_led(RowLead::Child(tr("Angle fade to")), &mut brush.angle_fade.1, ANGLE_FADE_RANGE);
});
if let Some(space) = sheet.switch(tr("Size Space"), &[tr("Object"), tr("Viewport")], usize::from(brush.screen_space)) {
brush.screen_space = space == 1;
}
sheet.slider(tr("Stamp depth"), &mut brush.depth, STAMP_DEPTH_RANGE, 2);
}
/// The brush's dabs scattered by its jitters, across the panel above the Jitter sliders
fn jitter_strip(sheet: &mut PropertySheet<'_>, brush: &BrushSettings, image: Option<&Arc<ImageRes>>, tokens: &Tokens) {
let tint = tokens.text.to_array();
sheet.embed(|ui: &mut Ui| {
let (rect, response) = ui.allocate_exact_size(vec2(ui.available_width(), JITTER_STRIP_HEIGHT), Sense::hover());
response.widget_info(|| egui::WidgetInfo::labeled(egui::Role::Image, true, tr("Jitter preview")));
let painter = ui.painter();
painter.rect_filled(rect, JITTER_STRIP_ROUNDING, tokens.field);
painter.rect_stroke(rect, JITTER_STRIP_ROUNDING, Stroke::new(JITTER_STRIP_OUTLINE_WIDTH, tokens.field_border), StrokeKind::Inside);
BrushStrokePreview::paint_picture(
ui.ctx(),
painter,
rect.shrink(JITTER_STRIP_OUTLINE_WIDTH),
"brush_jitter_picture",
(brush, image),
|_| [tint[0], tint[1], tint[2]],
jitter_image,
);
});
}
/// A 0..1 setting shown and typed in whole percent
fn percent_slider(sheet: &mut PropertySheet<'_>, label: &str, fraction: &mut f32, percent: RangeInclusive<f32>) {
let mut shown = *fraction * 100.0;
if sheet.slider(label, &mut shown, percent, 0).is_some() {
*fraction = shown / 100.0;
}
}
/// A count on a slider of whole numbers
fn whole_slider(sheet: &mut PropertySheet<'_>, label: &str, count: &mut u32, range: RangeInclusive<f32>) {
let mut shown = *count as f32;
if sheet.slider(label, &mut shown, range, 0).is_some() {
*count = shown.round() as u32;
}
}
/// The brush presets, listed under the Brush caption's ≡ button
fn brush_presets_popover(app: &mut TextureCraftApp, ui: &Ui, menu: Response) {
menu.widget_info(|| egui::WidgetInfo::labeled(egui::Role::Button, true, tr("Brush presets")));
let menu = menu.on_hover_text(tr("Brush presets"));
let popup_id = ui.make_persistent_id("brush_presets_popup");
if menu.clicked() {
egui::Popup::toggle_id(ui.ctx(), popup_id);
}
egui::Popup::from_response(&menu).id(popup_id).open_memory(None).close_behavior(egui::PopupCloseBehavior::CloseOnClickOutside).show(|ui| {
ui.set_min_width(PRESETS_WIDTH);
egui::ScrollArea::vertical().max_height(PRESETS_MAX_HEIGHT).show(ui, |ui| {
let mut category = "";
for preset in texturecraft_engine::paint::presets::PRESETS.iter() {
if preset.category != category {
category = preset.category;
ui.label(caption(category));
}
if ui.selectable_label(false, preset.label).on_hover_text(tr("Use this brush (keeps its size)")).clicked() {
app.run("brush.preset.apply", json!({"preset": preset.id}));
}
}
ui.separator();
crate::shelf::user_brushes(app, ui, "");
});
});
}
+16 -3
View File
@@ -37,18 +37,31 @@ pub(crate) struct BrushStrokePreview {
impl BrushStrokePreview {
/// Paint the brush's stroke across `rect`, each pixel column coloured by `tint` of its position 0..1; it renders again only on a new brush, alpha image, colour or size
pub(crate) fn paint(ctx: &Context, painter: &Painter, rect: Rect, brush: &BrushSettings, image: Option<&Arc<ImageRes>>, tint: impl Fn(f32) -> [u8; 3]) {
Self::paint_picture(ctx, painter, rect, "brush_stroke_preview", (brush, image), tint, stroke_image);
}
/// Paint `render`'s picture of the brush across `rect`, kept under `key` until the brush, alpha image, colour or size change
pub(crate) fn paint_picture(
ctx: &Context,
painter: &Painter,
rect: Rect,
key: &'static str,
(brush, image): (&BrushSettings, Option<&Arc<ImageRes>>),
tint: impl Fn(f32) -> [u8; 3],
render: impl FnOnce(&BrushSettings, Option<&ImageRes>, [usize; 2], f32, &[[u8; 3]]) -> ColorImage,
) {
let pixels_per_point = ctx.pixels_per_point();
let size = [(rect.width() * pixels_per_point).round().max(1.0) as usize, (rect.height() * pixels_per_point).round().max(1.0) as usize];
let tints: Vec<[u8; 3]> = (0..size[0]).map(|x| tint((x as f32 + 0.5) / size[0] as f32)).collect();
let id = Id::unique("brush_stroke_preview");
let id = Id::unique(key);
let cached = ctx.data(|data| data.get_temp::<BrushStrokePreview>(id)).filter(|preview| {
preview.brush == *brush && preview.size == size && preview.tints == tints && preview.image.as_ref().map(Arc::as_ptr) == image.map(Arc::as_ptr)
});
let preview = match cached {
Some(preview) => preview,
None => {
let picture = stroke_image(brush, image.map(|image| &**image), size, pixels_per_point, &tints);
let texture = ctx.load_texture("brush-stroke-preview", picture, TextureOptions::LINEAR);
let picture = render(brush, image.map(|image| &**image), size, pixels_per_point, &tints);
let texture = ctx.load_texture(key, picture, TextureOptions::LINEAR);
let preview = BrushStrokePreview { brush: brush.clone(), image: image.cloned(), tints, size, texture };
ctx.data_mut(|data| data.insert_temp(id, preview.clone()));
preview
+2 -154
View File
@@ -23,7 +23,6 @@ use crate::property_sheet::{PropertySheet, SectionScope};
use crate::shelf::{Asset, ShelfDrag};
use crate::source_choice::SourceChoice;
use crate::theme::{Tokens, caption};
use crate::toolbar::{MAX_BRUSH_SIZE, MIN_BRUSH_SIZE};
use crate::widgets::{chip, color_swatch, combo, dnd_release, elided, icon_button, press_edit, section, section_with_reset, slider, slider_edit};
const TAG_COLORS: [Color32; 8] = [
@@ -2128,9 +2127,9 @@ fn tool_properties(app: &mut TextureCraftApp, ui: &mut Ui) {
};
PropertySheet::show(ui, "tool_sheet", |sheet| {
for section in tool_sections(app) {
sheet.section(section.title(), false);
let menu = sheet.section(section.title(), section == PaintSection::Brush);
match section {
PaintSection::Brush => legacy(sheet, app, brush_section),
PaintSection::Brush => crate::brush_sheet::brush_section(app, sheet, menu),
PaintSection::Alpha => legacy(sheet, app, alpha_section),
PaintSection::Stencil => legacy(sheet, app, stencil_section),
PaintSection::Material => legacy(sheet, app, material_controls),
@@ -2270,34 +2269,6 @@ fn path_section(app: &mut TextureCraftApp, ui: &mut Ui) {
ui.label(RichText::new(hint).size(10.5).color(tk.text_dim));
}
/// Popover for built-in and saved brush presets
fn brush_presets_popover(app: &mut TextureCraftApp, ui: &mut Ui) {
let response = ui.button(format!("{} {}", ic::PAINT_BRUSH_BROAD, tr("Brush presets")));
let popup_id = ui.make_persistent_id("brush_presets_popup");
if response.clicked() {
egui::Popup::toggle_id(ui.ctx(), popup_id);
}
egui::Popup::from_response(&response).id(popup_id).open_memory(None).close_behavior(egui::PopupCloseBehavior::CloseOnClickOutside).show(|ui| {
ui.set_min_width(230.0);
egui::ScrollArea::vertical().max_height(380.0).show(ui, |ui| {
let mut category = "";
for preset in texturecraft_engine::paint::presets::PRESETS.iter() {
if preset.category != category {
category = preset.category;
ui.label(caption(category));
}
if ui.selectable_label(false, preset.label).on_hover_text(tr("Use this brush (keeps its size)")).clicked() {
app.run("brush.preset.apply", json!({"preset": preset.id}));
}
}
ui.separator();
crate::shelf::user_brushes(app, ui, "");
});
});
}
/// Width of the label column in polygon fill's properties
const POLYGON_FILL_LABEL_WIDTH: f32 = 108.0;
@@ -2396,129 +2367,6 @@ fn polygon_fill_paints_mask(app: &TextureCraftApp) -> Result<bool, String> {
}
}
/// Font size of the dim hint line under the Brush caption
const HINT_TEXT_SIZE: f32 = 10.5;
fn brush_section(app: &mut TextureCraftApp, ui: &mut Ui) {
brush_presets_popover(app, ui);
let brush = &mut app.session.tool.brush;
let defaults = BrushSettings::default();
let hint = tr("Ctrl+right-drag in a view sets the size and hardness, Ctrl+left-drag the flow and angle.");
ui.label(RichText::new(hint).size(HINT_TEXT_SIZE).color(Tokens::get(ui.ctx()).text_dim));
ui.label(RichText::new(tr("Ctrl+Shift+right-drag: size and hardness in fine steps.")).size(HINT_TEXT_SIZE).color(Tokens::get(ui.ctx()).text_dim));
// Each section's reset puts back only the fields it shows
let size_fields = |settings: &BrushSettings| (settings.size, settings.min_size, settings.screen_space);
if section_with_reset(ui, "sec_size", tr("Size"), true, size_fields(brush) == size_fields(&defaults), |ui| {
let mut size_percent = brush.size / MAX_BRUSH_SIZE * 100.0;
if slider(ui, tr("Size"), &mut size_percent, 0.05..=100.0, 1).changed() {
brush.size = (size_percent / 100.0 * MAX_BRUSH_SIZE).clamp(MIN_BRUSH_SIZE, MAX_BRUSH_SIZE);
}
let mut min_size_percent = brush.min_size * 100.0;
if slider(ui, tr("Minimum size (%)"), &mut min_size_percent, 0.0..=100.0, 0).changed() {
brush.min_size = min_size_percent / 100.0;
}
ui.checkbox(&mut brush.screen_space, tr("Size in screen space"));
}) {
(brush.size, brush.min_size, brush.screen_space) = size_fields(&defaults);
}
let flow_fields = |settings: &BrushSettings| (settings.flow, settings.opacity, settings.spacing);
if section_with_reset(ui, "sec_flow", tr("Flow and opacity"), true, flow_fields(brush) == flow_fields(&defaults), |ui| {
let mut flow_percent = brush.flow * 100.0;
if slider(ui, tr("Flow"), &mut flow_percent, 0.0..=100.0, 0).changed() {
brush.flow = flow_percent / 100.0;
}
let mut opacity_percent = brush.opacity * 100.0;
if slider(ui, tr("Stroke opacity"), &mut opacity_percent, 0.0..=100.0, 0).changed() {
brush.opacity = opacity_percent / 100.0;
}
let mut spacing_percent = brush.spacing * 100.0;
if slider(ui, tr("Spacing"), &mut spacing_percent, 1.0..=1000.0, 0).changed() {
brush.spacing = spacing_percent / 100.0;
}
}) {
(brush.flow, brush.opacity, brush.spacing) = flow_fields(&defaults);
}
let angle_fields = |settings: &BrushSettings| (settings.angle, settings.follow_path);
if section_with_reset(ui, "sec_angle", tr("Angle"), false, angle_fields(brush) == angle_fields(&defaults), |ui| {
slider(ui, tr("Angle"), &mut brush.angle, -180.0..=180.0, 0);
ui.checkbox(&mut brush.follow_path, tr("Follow path"));
}) {
(brush.angle, brush.follow_path) = angle_fields(&defaults);
}
let jitter_fields = |settings: &BrushSettings| (settings.jitter_size, settings.jitter_angle, settings.jitter_flow, settings.jitter_position);
if section_with_reset(ui, "sec_jitter", tr("Jitters"), false, jitter_fields(brush) == jitter_fields(&defaults), |ui| {
let jitters = [(tr("Size jitter"), &mut brush.jitter_size), (tr("Angle jitter"), &mut brush.jitter_angle), (tr("Flow jitter"), &mut brush.jitter_flow)];
for (label, jitter) in jitters {
let mut jitter_percent = *jitter * 100.0;
if slider(ui, label, &mut jitter_percent, 0.0..=100.0, 0).changed() {
*jitter = jitter_percent / 100.0;
}
}
let mut position_jitter_percent = brush.jitter_position * 100.0;
if slider(ui, tr("Position jitter"), &mut position_jitter_percent, 0.0..=400.0, 0).changed() {
brush.jitter_position = position_jitter_percent / 100.0;
}
}) {
(brush.jitter_size, brush.jitter_angle, brush.jitter_flow, brush.jitter_position) = jitter_fields(&defaults);
}
let alignment_fields = |settings: &BrushSettings| (settings.alignment, settings.backface_culling, settings.angle_fade, settings.depth);
if section_with_reset(ui, "sec_align", tr("Alignment and culling"), false, alignment_fields(brush) == alignment_fields(&defaults), |ui| {
use texturecraft_engine::paint::Alignment;
let alignments = [(Alignment::Tangent, tr("Tangent | Wrap")), (Alignment::Camera, tr("Camera"))];
let shown = alignments.iter().find(|(alignment, _)| *alignment == brush.alignment).map_or("", |(_, label)| label);
combo(ui, tr("Alignment"), shown, |ui| {
for (alignment, label) in alignments {
ui.selectable_value(&mut brush.alignment, alignment, label);
}
});
ui.checkbox(&mut brush.backface_culling, tr("Backface culling"));
slider(ui, tr("Angle fade from"), &mut brush.angle_fade.0, 0.0..=90.0, 0);
slider(ui, tr("Angle fade to"), &mut brush.angle_fade.1, 0.0..=90.0, 0);
slider(ui, tr("Stamp depth"), &mut brush.depth, 0.05..=4.0, 2);
}) {
(brush.alignment, brush.backface_culling, brush.angle_fade, brush.depth) = alignment_fields(&defaults);
}
if section_with_reset(ui, "sec_particles", tr("Particles"), false, brush.particles == defaults.particles, |ui| {
let particles = &mut brush.particles;
ui.checkbox(&mut particles.enabled, tr("Particle brush (slides down the surface)"));
let mut count = particles.count as f32;
if slider(ui, tr("Count per stamp"), &mut count, 1.0..=16.0, 0).changed() {
particles.count = count as u32;
}
let mut lifetime_steps = particles.lifetime as f32;
if slider(ui, tr("Lifetime (steps)"), &mut lifetime_steps, 1.0..=128.0, 0).changed() {
particles.lifetime = lifetime_steps as u32;
}
slider(ui, tr("Gravity"), &mut particles.gravity, 0.0..=2.0, 2);
}) {
brush.particles = defaults.particles;
}
if section_with_reset(ui, "sec_lazy", tr("Lazy mouse"), false, brush.lazy == defaults.lazy, |ui| {
slider(ui, tr("Lazy mouse distance"), &mut brush.lazy, 0.0..=200.0, 0);
}) {
brush.lazy = defaults.lazy;
}
*brush = brush.sanitized();
}
/// One alpha in the picker: a 52×64 tile with the shape drawn by `paint` and a label.
fn alpha_tile(ui: &mut Ui, on: bool, label: &str, paint: impl FnOnce(&egui::Painter, Rect)) -> egui::Response {
let tk = Tokens::get(ui.ctx());
+2
View File
@@ -16,6 +16,8 @@ mod bake_preset;
pub mod bake_presets;
mod bake_report;
mod bake_scene;
mod brush_pictures;
mod brush_sheet;
mod brush_stroke_preview;
mod color_management;
mod color_picker;
+15 -9
View File
@@ -2,7 +2,7 @@
use std::ops::RangeInclusive;
use egui::{Align2, Color32, FontId, Painter, Rect, Response, Role, Sense, Stroke, StrokeKind, WidgetInfo, pos2, vec2};
use egui::{Align2, Color32, CornerRadius, FontId, Painter, Rect, Response, Role, Sense, Stroke, StrokeKind, WidgetInfo, pos2, vec2};
use super::row::SECTION_CAPTION_CENTER;
use super::slider::{DIAL_AIR, DIAL_RADIUS, KNOB_RADIUS};
@@ -45,6 +45,9 @@ const PICTURE_TOP: f32 = 4.0;
const PICTURE_SHORTER: f32 = 10.0;
const PICTURE_TO_COLUMN: f32 = 6.0;
/// Width of the line around the picture
const PICTURE_OUTLINE_WIDTH: f32 = 1.0;
impl PropertySheet<'_> {
/// A section caption with its on/off switch at the right edge
pub(crate) fn section_switch(&mut self, title: &str, on: bool) -> Response {
@@ -135,32 +138,35 @@ impl PropertySheet<'_> {
Self::apply_typed(value, typed, dragged)
}
/// Draw a picture beside captioned sliders and report the edit on each slider.
/// Draw a picture beside captioned sliders and report the edit on each slider
pub(crate) fn picture_sliders<const N: usize>(&mut self, picture: &dyn Fn(&Painter, Rect), sliders: &mut [StackSlider<'_>; N]) -> [Option<bool>; N] {
let count = sliders.len().max(1) as f32;
let height = count * (STACK_CAPTION_LINE + STACK_PART_LINE) + (count - 1.0) * STACK_GAP;
self.space(BLOCK_MARGIN);
let block = self.take(height);
let x0 = self.column();
let side = (height - PICTURE_SHORTER).min(x0 - self.left - PICTURE_TO_COLUMN).max(1.0);
let column_x = self.column();
let side = (height - PICTURE_SHORTER).min(column_x - self.left - PICTURE_TO_COLUMN).max(1.0);
let square = Rect::from_min_size(pos2(self.left, block.top() + PICTURE_TOP), vec2(side, side));
picture(self.ui.painter(), square);
self.ui.painter().rect_stroke(square, 0, Stroke::new(1.0, self.tokens.field_border), StrokeKind::Inside);
self.ui.painter().rect_stroke(square, CornerRadius::ZERO, Stroke::new(PICTURE_OUTLINE_WIDTH, self.tokens.field_border), StrokeKind::Inside);
let caption_color = self.tokens.text_dim;
let mut edits = [None; N];
let mut y = block.top();
for (edit, slider) in edits.iter_mut().zip(sliders) {
let dim = self.tokens.text_dim;
let caption = pos2(x0, y + STACK_CAPTION_LINE / 2.0);
self.ui.painter().text(caption, Align2::LEFT_CENTER, slider.label, FontId::proportional(SMALL_TEXT_SIZE), dim);
let caption = pos2(column_x, y + STACK_CAPTION_LINE / 2.0);
self.ui.painter().text(caption, Align2::LEFT_CENTER, slider.label, FontId::proportional(SMALL_TEXT_SIZE), caption_color);
let center_y = y + STACK_CAPTION_LINE + STACK_PART_LINE / 2.0;
let id = self.next_id();
let dial_x = self.right - self.used.value_width.max(super::VALUE_MIN_WIDTH) - DIAL_AIR - DIAL_RADIUS;
let end = if slider.dial { dial_x - DIAL_RADIUS - DIAL_AIR } else { self.track_end() };
let track = Track { start: x0 + KNOB_RADIUS, end, center_y, zero: None, ramp: false };
let track = Track { start: column_x + KNOB_RADIUS, end, center_y, zero: (*slider.range.start() < 0.0).then_some(0.0), ramp: false };
if slider.dial {
self.paint_dial(pos2(dial_x, center_y), *slider.value);
}
let dragged = self.track(id, slider.label, &track, slider.value, &slider.range);
let typed = self.value_field(id, slider.label, center_y, *slider.value, &slider.typed, slider.decimals, slider.suffix);
*edit = Self::apply_typed(slider.value, typed, dragged);
+31 -27
View File
@@ -1,11 +1,11 @@
//! Each brush section header has a reset icon that puts only that section's settings back to their defaults
//! Each band of the Brush section has a reset that puts back only that band's settings, grouped as the reference groups them
use egui_kittest::Harness;
use egui_kittest::kittest::{NodeT, Queryable};
use texturecraft_engine::paint::{Alignment, BrushAlpha, BrushSettings, Particles, Symmetry};
use texturecraft_ui_egui::TextureCraftApp;
/// The default window; Properties shows only the top of the brush there, so lower headers are scrolled to
/// The default window; Properties shows only the top of the brush there, so lower bands are scrolled to
const WINDOW_SIZE: egui::Vec2 = egui::vec2(1600.0, 960.0);
/// Frames for the first layout and fonts to settle
@@ -17,22 +17,18 @@ const SETTLE_FRAMES: usize = 3;
/// Puts one section's fields of the first brush back to the second's values
type SectionReset = fn(&mut BrushSettings, &BrushSettings);
/// Each brush section's title, a label shown only while it is open, whether it starts open, and its reset
/// Each band's title, a label shown only while it is open, whether it starts open, and its reset
const SECTIONS: [(&str, &str, bool, SectionReset); 7] = [
("Size", "Minimum size (%)", true, |brush, defaults| {
(brush.size, brush.min_size, brush.screen_space) = (defaults.size, defaults.min_size, defaults.screen_space)
}),
("Flow and opacity", "Stroke opacity", true, |brush, defaults| {
(brush.flow, brush.opacity, brush.spacing) = (defaults.flow, defaults.opacity, defaults.spacing)
}),
("Angle", "Follow path", false, |brush, defaults| (brush.angle, brush.follow_path) = (defaults.angle, defaults.follow_path)),
("Jitters", "Size jitter", false, |brush, defaults| {
("Size", "Minimum Size (%)", true, |brush, defaults| (brush.size, brush.min_size, brush.spacing) = (defaults.size, defaults.min_size, defaults.spacing)),
("Opacity", "Stroke opacity", true, |brush, defaults| (brush.flow, brush.opacity) = (defaults.flow, defaults.opacity)),
("Orientation", "Follow Path", true, |brush, defaults| (brush.angle, brush.follow_path) = (defaults.angle, defaults.follow_path)),
("Jitter", "Size Jitter", true, |brush, defaults| {
(brush.jitter_size, brush.jitter_angle, brush.jitter_flow, brush.jitter_position) =
(defaults.jitter_size, defaults.jitter_angle, defaults.jitter_flow, defaults.jitter_position)
}),
("Alignment and culling", "Backface culling", false, |brush, defaults| {
(brush.alignment, brush.backface_culling, brush.angle_fade, brush.depth) =
(defaults.alignment, defaults.backface_culling, defaults.angle_fade, defaults.depth)
("Projection", "Backface culling", true, |brush, defaults| {
(brush.alignment, brush.backface_culling, brush.angle_fade, brush.screen_space, brush.depth) =
(defaults.alignment, defaults.backface_culling, defaults.angle_fade, defaults.screen_space, defaults.depth)
}),
("Particles", "Gravity", false, |brush, defaults| brush.particles = defaults.particles),
("Lazy mouse", "Lazy mouse distance", false, |brush, defaults| brush.lazy = defaults.lazy),
@@ -82,18 +78,27 @@ fn app_with_brush(brush: BrushSettings) -> Harness<'static, TextureCraftApp> {
harness
}
/// The reset icon on the header row titled `title`
fn reset_icon<'tree>(harness: &'tree Harness<'_, TextureCraftApp>, title: &str) -> egui_kittest::Node<'tree> {
let label = format!("{title}: Reset to defaults");
/// The band titled `title` in Properties: the rightmost, as the top bar has a Size and a Lazy mouse too
fn band<'tree>(harness: &'tree Harness<'_, TextureCraftApp>, title: &str) -> egui_kittest::Node<'tree> {
harness
.query_all_by_role(egui::Role::Button)
.find(|node| node.accesskit_node().label().as_deref() == Some(label.as_str()))
.unwrap_or_else(|| panic!("no reset icon on the {title} header"))
.filter(|node| node.accesskit_node().label().as_deref() == Some(title))
.max_by(|a, b| a.rect().left().total_cmp(&b.rect().left()))
.unwrap_or_else(|| panic!("no {title} band"))
}
/// Scrolls the header titled `title` into view and clicks its reset icon
/// The reset on the band titled `title`
fn reset_icon<'tree>(harness: &'tree Harness<'_, TextureCraftApp>, title: &str) -> egui_kittest::Node<'tree> {
let band = band(harness, title).rect();
harness
.query_all_by_role(egui::Role::Button)
.find(|node| node.accesskit_node().label().as_deref() == Some("Restore defaults") && node.rect().y_range().intersects(band.y_range()))
.unwrap_or_else(|| panic!("no reset on the {title} band"))
}
/// Scrolls the band titled `title` into view and clicks its reset
fn click_reset(harness: &mut Harness<'_, TextureCraftApp>, title: &str) {
reset_icon(harness, title).scroll_to_me();
band(harness, title).scroll_to_me();
harness.run_steps(SETTLE_FRAMES);
reset_icon(harness, title).click();
@@ -118,13 +123,12 @@ fn each_reset_puts_back_only_its_own_section() {
}
}
/// Scrolls the header titled `title` into view and clicks the header itself, folding or unfolding it
/// Scrolls the band titled `title` into view and clicks it, folding or unfolding it
fn click_header(harness: &mut Harness<'_, TextureCraftApp>, title: &str) {
reset_icon(harness, title).scroll_to_me();
band(harness, title).scroll_to_me();
harness.run_steps(SETTLE_FRAMES);
let icon = reset_icon(harness, title).rect();
harness.query_all_by_label(title).find(|label| label.rect().y_range().intersects(icon.y_range())).unwrap_or_else(|| panic!("no {title} header")).click();
band(harness, title).click();
harness.run_steps(SETTLE_FRAMES);
}
@@ -157,7 +161,7 @@ fn at_the_defaults_the_reset_icons_are_inert() {
click_reset(&mut harness, title);
assert_eq!(harness.query_by_label(body_label).is_some(), starts_open, "the click doesn't reach the {title} header");
assert_eq!(harness.query_by_label(body_label).is_some(), !starts_open, "an inert reset folds the {title} band like the rest of it");
assert_eq!(harness.state().session.tool.brush, BrushSettings::default(), "the {title} reset is inert");
}
}
@@ -175,7 +179,7 @@ fn enter_and_space_on_the_focused_reset_icon_reset_only_its_section() {
let defaults = BrushSettings::default();
let mut expected = changed_brush();
(expected.size, expected.min_size, expected.screen_space) = (defaults.size, defaults.min_size, defaults.screen_space);
(expected.size, expected.min_size, expected.spacing) = (defaults.size, defaults.min_size, defaults.spacing);
assert_eq!(harness.state().session.tool.brush, expected, "resetting Size with {key:?}");
}
}
+3 -2
View File
@@ -154,8 +154,9 @@ fn the_output_directory_resets_and_the_dilation_follows_the_padding() {
click(&mut h, "16");
assert!(h.query_by_label("Dilation (pixels)").is_some());
// A click on the slider sets the width and leaves the menu open
h.get_by_role(egui::Role::Slider).click();
// A click on the slider sets the width and leaves the menu open; Properties has sliders too, so take the one under the menu's label
let label = h.get_by_label("Dilation (pixels)").rect().left_bottom();
h.query_all_by_role(egui::Role::Slider).min_by(|a, b| a.rect().left_top().distance(label).total_cmp(&b.rect().left_top().distance(label))).unwrap().click();
h.run_steps(4);
assert_ne!(h.state().ui.export.dilation, 16);
assert!(h.query_by_label("Dilation (pixels)").is_some(), "the menu stays open");
@@ -22,6 +22,9 @@ const GESTURE: Vec2 = vec2(-60.0, 40.0);
/// Where in the view the gestures start, as a share of its width from its left edge
const GESTURE_SHARE: f32 = 0.3;
/// Frames for a scroll to a list to finish its animation
const SCROLL_FRAMES: usize = 30;
/// Escapes between lists, so one that stays open can't leave its popup over the next
const ESCAPES_TO_CLEAR: usize = 2;
@@ -242,6 +245,17 @@ fn every_list_opens_leaves_the_view_its_camera_and_closes_on_escape_a_click_and_
continue;
};
// A list low in a long panel sits below its visible part until scrolled to
let same_before = lists(&harness).iter().take(index).filter(|(_, other)| *other == shown).count();
if let Some(node) = harness.query_all_by_role(Role::ComboBox).find(|node| node.rect() == button) {
node.scroll_to_me();
}
harness.run_steps(SCROLL_FRAMES);
let Some((button, _)) = lists(&harness).into_iter().filter(|(_, other)| *other == shown).nth(same_before) else {
problems.push(format!("{screen}: {shown} is gone after scrolling to it"));
continue;
};
problems.extend(check_list(&mut harness, button, &format!("{screen}: {shown}")));
for _ in 0..ESCAPES_TO_CLEAR {
harness.key_press(egui::Key::Escape);
+18 -14
View File
@@ -9,7 +9,7 @@ use texturecraft_ui_egui::TextureCraftApp;
use texturecraft_ui_egui::properties_popup::{self, PropertiesPopup};
use texturecraft_ui_egui::state::{Mode, ViewLayout};
use crate::{BAKE_RESOLUTION, DRAG_STEP_FRAMES, SETTLE_FRAMES, STARTUP_FRAMES, TEXTURE_RESOLUTION};
use crate::{BAKE_RESOLUTION, DRAG_STEP_FRAMES, SETTLE_FRAMES, SLIDER_END_INSET, STARTUP_FRAMES, TEXTURE_RESOLUTION};
/// A common laptop window
const WINDOW_SIZE: egui::Vec2 = egui::vec2(1600.0, 960.0);
@@ -35,6 +35,9 @@ const SCROLL_FRAMES: usize = 25;
/// How far left of the popup a click lands on the model
const MODEL_LEFT_OF_POPUP: f32 = 60.0;
/// How far in from the popup's right edge a slider drag ends, still over the slider's band
const DROP_LEFT_OF_POPUP_EDGE: f32 = 30.0;
fn harness() -> Harness<'static, TextureCraftApp> {
harness_sized(WINDOW_SIZE)
}
@@ -156,21 +159,22 @@ fn dragging_its_size_slider_changes_the_brush() {
click(&mut harness, PointerButton::Secondary, center);
let popup = harness.ctx.memory(|memory| memory.area_rect(properties_popup::area_id())).unwrap();
// The Size section's header sits above its slider of the same name
let slider_label = harness
.query_all_by_label("Size")
// The Size band holds a slider of the same name, its track right of the label
let slider = harness
.query_all_by_role(egui::Role::Slider)
.filter(|node| node.accesskit_node().label().as_deref() == Some("Size"))
.map(|node| node.rect())
.filter(|rect| popup.contains_rect(*rect))
.max_by(|first, second| first.top().total_cmp(&second.top()))
.find(|rect| popup.contains_rect(*rect))
.unwrap();
let track_y = slider_label.bottom() + 10.0;
let track_y = slider.center().y;
let size = harness.state().session.tool.brush.size;
harness.drag_at(egui::pos2(slider_label.left() + 20.0, track_y));
harness.run_steps(2);
harness.hover_at(egui::pos2(popup.right() - 30.0, track_y));
harness.run_steps(2);
harness.drop_at(egui::pos2(popup.right() - 30.0, track_y));
harness.run_steps(3);
let drop = egui::pos2(popup.right() - DROP_LEFT_OF_POPUP_EDGE, track_y);
harness.drag_at(egui::pos2(slider.left() + SLIDER_END_INSET, track_y));
harness.run_steps(DRAG_STEP_FRAMES);
harness.hover_at(drop);
harness.run_steps(DRAG_STEP_FRAMES);
harness.drop_at(drop);
harness.run_steps(SETTLE_FRAMES);
assert!(harness.state().session.tool.brush.size > size, "{size} -> {}", harness.state().session.tool.brush.size);
assert!(is_open(&harness), "editing it keeps it open");
}
@@ -194,7 +198,7 @@ fn it_shows_what_the_properties_panel_shows() {
let popup = harness.ctx.memory(|memory| memory.area_rect(properties_popup::area_id())).unwrap();
let in_popup = |label: &str| harness.query_all_by_label(label).any(|node| popup.contains_rect(node.rect()));
assert!(in_popup("UV projection"), "a selected fill shows its fill settings");
assert!(!in_popup("Minimum size (%)"), "not the brush's");
assert!(!in_popup("Minimum Size (%)"), "not the brush's");
}
/// Whether the jump tab `name` inside `area` is the lit one
@@ -39,14 +39,14 @@ fn materials_shelf(step_seconds: f32, pixels_per_point: f32) -> (Harness<'static
(harness, unique)
}
/// Largest drawn texture in pixels, excluding fonts and images below `min_width` points
fn largest_drawn_texture(h: &Harness<'_, TextureCraftApp>, min_width: f32) -> Option<[usize; 2]> {
/// Largest drawn texture in pixels, excluding fonts and images below `min_side` points on either side (a wide strip is not a big preview)
fn largest_drawn_texture(h: &Harness<'_, TextureCraftApp>, min_side: f32) -> Option<[usize; 2]> {
let textures = h.ctx.tex_manager();
let textures = textures.read();
h.output()
.shapes
.iter()
.filter(|clipped| clipped.shape.texture_id() != egui::TextureId::default() && clipped.shape.visual_bounding_rect().width() >= min_width)
.filter(|clipped| clipped.shape.texture_id() != egui::TextureId::default() && clipped.shape.visual_bounding_rect().size().min_elem() >= min_side)
.filter_map(|clipped| textures.meta(clipped.shape.texture_id()).map(|meta| meta.size))
.max()
}
+1 -1
View File
@@ -3277,7 +3277,7 @@ fn paint_tool_properties_snapshots() {
let in_properties = |harness: &Harness<'_, TextureCraftApp>, label: &str| {
harness.get_all_by_label(label).map(|node| node.rect().center()).max_by(|a, b| a.x.total_cmp(&b.x)).unwrap()
};
for header in ["Angle", "Jitters", "Alignment and culling", "Particles", "Lazy mouse"] {
for header in ["Particles", "Lazy mouse"] {
harness.get_all_by_label(header).max_by(|a, b| a.rect().left().total_cmp(&b.rect().left())).unwrap().scroll_to_me();
harness.run_steps(3);
let at = in_properties(&harness, header);