Set the brush's channel values in cards under the fill layer's pills

The Material section of a brush tool's Properties now looks like a fill
layer's: the channel strip uses the fill's pills (Color, Metal, Rough,
Normal, Height; a click turns a channel on or off, Alt+click keeps it
alone), and each channel that is on gets a card with its swatch, name
and "Uniform" under it. Base color has the colour bar with its
eyedropper, Metallic, Roughness and Height a gray ramp with its value
and invert glyph, and Normal reads "Flat" with no value row (the brush
paints the flat normal). Each card's reset puts the channel back to its
default value. Every change goes through tool.material.

The eraser shows only the strip: it removes paint from the channels
that are on and has no values to set. The hint lines under the old
chips are gone. Polygon fill keeps its own material rows.

A slot card whose source can't be swapped (these uniform channels)
answers no clicks on its row and reads as a label, not a list.
This commit is contained in:
Rebornim committed 2026-11-27 08:25:57 +00:00
1 parent 44dceb6059
commit d627b8c004
10 files changed
+250 -69

No files matched your search

+3 -17
View File
@@ -2114,15 +2114,6 @@ fn tool_header(app: &mut TextureCraftApp, ui: &mut Ui) {
/// The tool's sections, one page under the panel's jump tabs
fn tool_properties(app: &mut TextureCraftApp, ui: &mut Ui) {
legacy_body(ui, |ui| tool_header(app, ui));
// Rows not yet laid out by the sheet keep the spacing they were made with
let item_spacing = ui.spacing().item_spacing;
let legacy = |sheet: &mut PropertySheet<'_>, app: &mut TextureCraftApp, body: fn(&mut TextureCraftApp, &mut Ui)| {
sheet.ui.scope(|ui| {
ui.spacing_mut().item_spacing = item_spacing;
legacy_body(ui, |ui| body(app, ui));
});
};
PropertySheet::show(ui, "tool_sheet", |sheet| {
for section in tool_sections(app) {
// The Stencil caption carries its own reset
@@ -2131,7 +2122,7 @@ fn tool_properties(app: &mut TextureCraftApp, ui: &mut Ui) {
PaintSection::Brush => crate::brush_sheet::brush_section(app, sheet, menu),
PaintSection::Alpha => crate::alpha_sheet::alpha_section(app, sheet),
PaintSection::Stencil => crate::stencil_sheet::stencil_section(app, sheet),
PaintSection::Material => legacy(sheet, app, material_controls),
PaintSection::Material => crate::material_sheet::material_section(app, sheet),
PaintSection::Grayscale => crate::mask_paint_panel::grayscale_section(app, sheet),
}
}
@@ -2319,8 +2310,7 @@ const CHIPS_GAP: f32 = 4.0;
/// Room right of the tool's colour swatch, like a linked material's
const TOOL_SWATCH_RIGHT_MARGIN: f32 = LINK_SWATCH_RIGHT_MARGIN;
/// One chip per channel of the texture set, on while the tool's material has it enabled; returns the channels.
/// The Material tab and the Smudge panel both draw these, so they share one set of flags.
/// One chip per channel of the texture set, on while the tool's material has it enabled (the flags the Material section's pills show); returns the channels
fn material_channel_chips(app: &mut TextureCraftApp, ui: &mut Ui) -> Vec<Channel> {
let channels = app.session.doc.project.texture_set(app.session.ts()).map(|set| set.channel_list()).unwrap_or_default();
ui.horizontal_wrapped(|ui| {
@@ -2335,7 +2325,7 @@ fn material_channel_chips(app: &mut TextureCraftApp, ui: &mut Ui) -> Vec<Channel
channels
}
/// The tool's material: channel chips, then each enabled channel's value
/// Polygon fill's material: channel chips, then each enabled channel's value
fn material_controls(app: &mut TextureCraftApp, ui: &mut Ui) {
use texturecraft_engine::core::ChannelKind;
@@ -2376,10 +2366,6 @@ fn material_controls(app: &mut TextureCraftApp, ui: &mut Ui) {
}
}
}
if app.session.tool.tool == Tool::Eraser {
ui.label(RichText::new(tr("The eraser removes paint from the enabled channels.")).color(tokens.text_dim));
}
}
fn fill_properties(app: &mut TextureCraftApp, ui: &mut Ui, layer: &Layer) {
+1
View File
@@ -89,6 +89,7 @@ mod mask_preview_image;
mod mask_source_choice;
mod material_orb;
mod material_preview_image;
mod material_sheet;
pub mod menus;
mod mesh_export_options;
#[cfg(not(target_arch = "wasm32"))]
+71
View File
@@ -0,0 +1,71 @@
//! The Material section of a brush tool's Properties: the channel strip, then one card per channel that is on with the value the brush paints there
use serde_json::json;
use texturecraft_engine::Tool;
use texturecraft_engine::core::{Channel, ChannelKind, Source};
use crate::TextureCraftApp;
use crate::fill_material_panel::{pill_name, take_color_pick};
use crate::i18n::tr;
use crate::property_sheet::PropertySheet;
use crate::slot_thumbnail::{paint_thumbnail, thumbnail};
use crate::source_slot::SourceSlot;
use crate::theme::Tokens;
/// The channel strip (the fill layer's pills), then a card per channel that is on; the eraser only picks channels
pub(crate) fn material_section(app: &mut TextureCraftApp, sheet: &mut PropertySheet<'_>) {
let channels = app.session.doc.project.texture_set(app.session.ts()).map(|texture_set| texture_set.channel_list()).unwrap_or_default();
let names: Vec<&str> = channels.iter().map(|channel| tr(pill_name(*channel))).collect();
let enabled: Vec<bool> = channels.iter().map(|channel| app.session.tool.enabled.contains(channel)).collect();
if let Some((index, solo)) = sheet.channel_pills(&names, &enabled)
&& let Some(channel) = channels.get(index)
{
let enable = solo || !enabled.get(index).copied().unwrap_or(false);
app.run("tool.material", json!({"channel": channel.id(), "enabled": enable, "solo": solo}));
}
if app.session.tool.tool == Tool::Eraser {
return;
}
let shown: Vec<Channel> = channels.into_iter().filter(|channel| app.session.tool.enabled.contains(channel)).collect();
for channel in shown {
channel_card(app, sheet, channel);
}
}
/// One channel's card: its swatch, name and source, the ⟲ back to the channel's default, then its colour bar or gray ramp (a normal paints flat and has none)
fn channel_card(app: &mut TextureCraftApp, sheet: &mut PropertySheet<'_>, channel: Channel) {
let slot_of = SourceSlot::Channel(channel);
let kind = channel.kind();
let default = channel.default_value();
let value = if kind == ChannelKind::NormalMap { default } else { app.session.tool.values.get(&channel).copied().unwrap_or(default) };
let tokens = Tokens::get(sheet.ui.ctx());
let picture = thumbnail(app, &sheet.ui.ctx().clone(), &Source::Uniform(value));
let thumb = |painter: &egui::Painter, rect: egui::Rect| paint_thumbnail(painter, rect, &picture, &tokens);
let line = if kind == ChannelKind::NormalMap { tr("Flat") } else { tr("Uniform") };
if sheet.slot_fixed(&thumb, slot_of.name(), line, value != default).reset {
app.run("tool.material", json!({"channel": channel.id(), "value": default}));
}
match kind {
ChannelKind::Color => {
let pick = sheet.color_bar(slot_of.name(), value, app.picking_color, &app.session.doc.project.swatches);
if let Some(color) = take_color_pick(app, pick) {
app.run("tool.material", json!({"channel": channel.id(), "color": color}));
}
}
ChannelKind::Scalar | ChannelKind::Signed => {
let mut gray = value[0];
let edit = sheet.ramp(slot_of.name(), &mut gray, slot_of.range());
if edit.invert {
let inverted = if kind == ChannelKind::Signed { -gray } else { 1.0 - gray };
app.run("tool.material", json!({"channel": channel.id(), "value": inverted}));
} else if edit.changed.is_some() {
app.run("tool.material", json!({"channel": channel.id(), "value": gray}));
}
}
ChannelKind::NormalMap => {}
}
sheet.close_card();
}
+1
View File
@@ -47,6 +47,7 @@ mod size_columns;
mod size_columns_response;
mod slider;
mod slot;
mod slot_ends;
mod slot_response;
mod source_card;
mod stack_slider;
+35 -19
View File
@@ -1,6 +1,7 @@
use egui::{Align2, CornerRadius, FontId, Painter, Rect, Sense, Stroke, StrokeKind, Vec2, pos2, vec2};
use egui_phosphor::regular as ic;
use super::slot_ends::SlotEnds;
use super::switch_control::PILL_SIZE;
use super::{ButtonIcon, CONTROL_RADIUS, PropertySheet, ROW_HEIGHT, SlotResponse, TEXT_SIZE};
use crate::theme::semibold;
@@ -14,6 +15,9 @@ const SLOT_HEIGHT: f32 = 36.0;
/// Size of a slot's thumbnail
pub(super) const THUMB_SIZE: f32 = 26.0;
/// Width of the thumbnail's frame, lit while the row is hovered, in points
const THUMB_OUTLINE_WIDTH: f32 = 1.0;
/// Air between the thumbnail and the slot's name
const THUMB_TO_NAME: f32 = 10.0;
@@ -73,31 +77,32 @@ impl PropertySheet<'_> {
self.open_card();
self.scope = self.named_id("slot", name);
self.space(SLOT_CARD_TOP);
self.slot_row(thumbnail, name, source, on, clear, reset.then_some(true))
self.slot_row(thumbnail, name, source, SlotEnds { on, clear, reset: reset.then_some(true), pickable: true })
}
/// [`Self::slot`] whose ⟲ always shows beside the ×, faint and inert while what it restores is at its defaults (`changed` false)
pub(crate) fn slot_restorable(&mut self, thumbnail: &dyn Fn(&Painter, Rect), name: &str, source: &str, changed: bool) -> SlotResponse {
self.open_card();
self.space(SLOT_CARD_TOP);
self.slot_row(thumbnail, name, source, None, true, Some(changed))
self.slot_row(thumbnail, name, source, SlotEnds { on: None, clear: true, reset: Some(changed), pickable: true })
}
/// A slot card whose one source can't be swapped (a brush's uniform channel): the row picks nothing, its ⟲ is faint and inert while at the defaults (`changed` false)
pub(crate) fn slot_fixed(&mut self, thumbnail: &dyn Fn(&Painter, Rect), name: &str, source: &str, changed: bool) -> SlotResponse {
self.open_card();
self.scope = self.named_id("slot", name);
self.space(SLOT_CARD_TOP);
self.slot_row(thumbnail, name, source, SlotEnds { on: None, clear: false, reset: Some(changed), pickable: false })
}
/// [`Self::slot`]'s row inside the card open now (an input a mode adds, under that mode), not a card of its own
pub(crate) fn slot_in_card(&mut self, thumbnail: &dyn Fn(&Painter, Rect), name: &str, source: &str, clear: bool) -> SlotResponse {
self.slot_row(thumbnail, name, source, None, clear, None)
self.slot_row(thumbnail, name, source, SlotEnds { on: None, clear, reset: None, pickable: true })
}
/// A slot row: thumbnail, name over source, then ⟲ (`Some(changed)`), × and the toggle on the right; the row opens the source list
fn slot_row(
&mut self,
thumbnail: &dyn Fn(&Painter, Rect),
name: &str,
source: &str,
on: Option<&mut bool>,
clear: bool,
reset: Option<bool>,
) -> SlotResponse {
/// A slot row: thumbnail, name over source, then ⟲ (`Some(changed)`), × and the toggle on the right; the row opens the source list when `pickable`
fn slot_row(&mut self, thumbnail: &dyn Fn(&Painter, Rect), name: &str, source: &str, ends: SlotEnds<'_>) -> SlotResponse {
let SlotEnds { on, clear, reset, pickable } = ends;
let rect = self.take(SLOT_HEIGHT);
let center_y = rect.top() + SLOT_HEIGHT / 2.0;
let enabled = on.as_deref().copied().unwrap_or(true);
@@ -109,8 +114,16 @@ impl PropertySheet<'_> {
// The picker spans the card while the trailing glyphs keep their own hit areas
let row = self.bled_row(rect);
let pick_id = self.next_id();
let pick = self.ui.interact(row, pick_id, Sense::click());
pick.widget_info(|| egui::WidgetInfo { current_text_value: Some(source.to_owned()), ..egui::WidgetInfo::labeled(egui::Role::ComboBox, true, name) });
let pick = self.ui.interact(row, pick_id, if pickable { Sense::click() } else { Sense::hover() });
if pickable {
pick.widget_info(|| egui::WidgetInfo {
current_text_value: Some(source.to_owned()),
..egui::WidgetInfo::labeled(egui::Role::ComboBox, true, name)
});
} else {
// A label's words are its value, so the name and source read as one
pick.widget_info(|| egui::WidgetInfo::labeled(egui::Role::Label, false, format!("{name}: {source}")));
}
let mut result = SlotResponse { pick, clear: false, reset: false, toggled: false };
let tokens = self.tokens;
@@ -119,15 +132,16 @@ impl PropertySheet<'_> {
painter.rect_stroke(
thumb,
CornerRadius::ZERO,
Stroke::new(1.0, if result.pick.hovered() { tokens.accent } else { tokens.field_border }),
Stroke::new(THUMB_OUTLINE_WIDTH, if pickable && result.pick.hovered() { tokens.accent } else { tokens.field_border }),
StrokeKind::Inside,
);
let text_x = thumb.right() + THUMB_TO_NAME;
let (name_font, name_color) = if enabled { (semibold(TEXT_SIZE), tokens.text) } else { (FontId::proportional(TEXT_SIZE), tokens.text_dim) };
painter.text(pos2(text_x, center_y - NAME_ABOVE_CENTER), Align2::LEFT_CENTER, name, name_font, name_color);
painter.text(pos2(text_x, center_y + SOURCE_BELOW_CENTER), Align2::LEFT_CENTER, source, FontId::proportional(SOURCE_TEXT_SIZE), tokens.text_dim);
for (shown, live, x, glyph, tip, slot) in [
for (shown, live, x, glyph, tip, clicked) in [
(clear, true, clear_x, ic::X, crate::i18n::n_("Clear"), &mut result.clear),
(reset.is_some(), reset.unwrap_or(false), reset_x, ic::CLOCK_COUNTER_CLOCKWISE, crate::i18n::n_("Restore defaults"), &mut result.reset),
] {
@@ -138,14 +152,15 @@ impl PropertySheet<'_> {
let glyph_rect = Rect::from_center_size(pos2(x, center_y), Vec2::splat(SLOT_GLYPH_BOX));
let id = self.next_id();
// At the defaults the ⟲ is faint and inert, as on a band: a click there picks the source like the rest of the row
// At the defaults the ⟲ is faint and inert, as on a band: on a pickable row a click there picks the source like the rest of the row
let response = if live {
self.tip(self.ui.interact(glyph_rect, id, Sense::click()), crate::i18n::tr(tip))
} else {
self.ui.interact(glyph_rect, id, Sense::hover())
};
response.widget_info(|| egui::WidgetInfo::labeled(egui::Role::Button, live, crate::i18n::tr(tip)));
*slot = live && response.clicked();
*clicked = live && response.clicked();
let color = self.reset_glyph_color(live, response.hovered(), tokens.text);
painter.text(glyph_rect.center(), Align2::CENTER_CENTER, glyph, FontId::proportional(SLOT_ICON_SIZE), color);
}
@@ -161,6 +176,7 @@ impl PropertySheet<'_> {
response.widget_info(|| egui::WidgetInfo::selected(egui::Role::CheckBox, true, *on, name));
self.pill(pill.center(), *on, true);
}
self.drawn(thumb.bottom());
result
}
@@ -0,0 +1,16 @@
//! What a slot row offers besides its picture and words
/// A slot row's toggle, ×, ⟲ and whether the row opens the source list
pub(super) struct SlotEnds<'a> {
/// The on/off pill at the right end, when the slot has one
pub(super) on: Option<&'a mut bool>,
/// The × back to a uniform source shows
pub(super) clear: bool,
/// The ⟲ shows: `Some(changed)`, faint and inert while unchanged
pub(super) reset: Option<bool>,
/// A click on the row opens the source list
pub(super) pickable: bool,
}
+1
View File
@@ -106,6 +106,7 @@ mod temp_dir;
mod template_invert;
mod templates_681;
mod tool_availability;
mod tool_material;
mod tool_settings_saved;
mod toolbar;
mod user_smart_mask;
+11 -20
View File
@@ -1,4 +1,4 @@
//! A press outside a popup closes it when it turns into a drag (a paint stroke on the model), as a click does: the tool's colour, the layer menus and the symmetry settings, in the default layout and in a rearranged one restored after a restart
//! A press outside a popup closes it when it turns into a drag (a paint stroke on the model), as a click does: the brush presets, the layer menus and the symmetry settings, in the default layout and in a rearranged one restored after a restart
use eframe::App as _;
use egui::accesskit::Role;
@@ -18,9 +18,6 @@ const DRAG_MOVES: usize = 6;
/// A short stroke on the model
const STROKE: Vec2 = vec2(-60.0, 40.0);
/// From the tool's Base color label to inside its swatch
const LABEL_TO_SWATCH: f32 = 60.0;
/// The app started on `storage` (its saved arrangement, if any) with the paint tool's Properties showing
fn app(storage: &MemoryStorage) -> Harness<'static, TextureCraftApp> {
let session = texturecraft_engine::sample_session(TEXTURE_RESOLUTION, BAKE_RESOLUTION).unwrap();
@@ -91,23 +88,17 @@ fn stroke_on_model(harness: &mut Harness<'_, TextureCraftApp>, modifiers: Modifi
drag(harness, view.center(), STROKE, modifiers);
}
/// Opens the paint tool's Base color swatch from its Properties' Material section
fn open_tool_color(harness: &mut Harness<'_, TextureCraftApp>) {
harness.get_by_role_and_label(egui::Role::Tab, "Material").click();
harness.run_steps(SETTLE_FRAMES);
let header = harness.get_by_role_and_label(egui::Role::Tab, "Properties - Paint").rect();
let in_properties = |rect: egui::Rect| header.x_range().contains(rect.center().x) && rect.top() > header.top();
let label = harness.get_all_by_value("Base color").find(|node| in_properties(node.rect())).unwrap().rect();
click(harness, label.right_center() + vec2(LABEL_TO_SWATCH, 0.0));
assert!(egui::Popup::is_any_open(&harness.ctx), "the swatch opens its colour popup");
/// Opens the brush presets from the ≡ on the paint tool's Brush caption
fn open_brush_presets(harness: &mut Harness<'_, TextureCraftApp>) {
let menu = harness.get_by_role_and_label(Role::Button, "Brush presets").rect();
click(harness, menu.center());
assert!(egui::Popup::is_any_open(&harness.ctx), "the ≡ opens the brush presets");
}
#[test]
fn a_stroke_on_the_model_closes_the_tool_colour_popup_in_the_default_and_a_restored_rearranged_layout() {
fn a_stroke_on_the_model_closes_the_brush_presets_in_the_default_and_a_restored_rearranged_layout() {
let check_stroke = |mut harness: Harness<'_, TextureCraftApp>, layout: &str| {
open_tool_color(&mut harness);
open_brush_presets(&mut harness);
let history = harness.state().session.history_labels().len();
stroke_on_model(&mut harness, Modifiers::NONE);
@@ -121,9 +112,9 @@ fn a_stroke_on_the_model_closes_the_tool_colour_popup_in_the_default_and_a_resto
}
#[test]
fn an_alt_orbit_keeps_the_tool_colour_popup_open() {
fn an_alt_orbit_keeps_the_brush_presets_open() {
let mut harness = app(&MemoryStorage::default());
open_tool_color(&mut harness);
open_brush_presets(&mut harness);
stroke_on_model(&mut harness, Modifiers::ALT);
@@ -147,7 +138,7 @@ fn a_stroke_on_the_model_closes_the_add_effect_menu() {
fn outside_drag_dismissal_handles_motion_batched_with_release() {
for (modifiers, stays_open) in [(Modifiers::ALT, true), (Modifiers::NONE, false)] {
let mut harness = app(&MemoryStorage::default());
open_tool_color(&mut harness);
open_brush_presets(&mut harness);
let origin = harness.state().viewport_rect.center();
harness.event(Event::ModifiersChanged(modifiers));
harness.hover_at(origin);
+20 -13
View File
@@ -9,6 +9,9 @@ use texturecraft_engine::geom::primitives;
use texturecraft_engine::{Session, Tool, execute};
use texturecraft_ui_egui::TextureCraftApp;
/// Frames egui's scroll animation takes to bring a row into view
const SCROLL_FRAMES: usize = 30;
fn harness() -> Harness<'static, TextureCraftApp> {
let session = Session::new_project("t", primitives::sphere(1.0, 48, 24), "builtin:sphere", None, 256).unwrap();
let mut harness = Harness::builder()
@@ -25,11 +28,9 @@ fn run(harness: &mut Harness<'_, TextureCraftApp>, command: &str, params: Value)
harness.run_steps(4);
}
/// The Smudge panel's chip for `channel`: the top one, over the Material section's
/// The Smudge panel's chip for `channel` (the Material section's pill below it is a checkbox)
fn smudge_chip<'a>(harness: &'a Harness<'_, TextureCraftApp>, channel: Channel) -> egui_kittest::Node<'a> {
let chips: Vec<_> = harness.get_all_by_role_and_label(Role::Button, channel.short()).collect();
assert_eq!(chips.len(), 2, "the Smudge panel and the Material section each draw a {} chip", channel.short());
chips.into_iter().min_by(|a, b| a.rect().top().total_cmp(&b.rect().top())).unwrap()
harness.get_by_role_and_label(Role::Button, channel.short())
}
fn chip_is_on(harness: &Harness<'_, TextureCraftApp>, channel: Channel) -> bool {
@@ -84,16 +85,22 @@ fn clicking_a_channel_in_the_smudge_panel_turns_it_off_and_on_for_the_material()
#[test]
fn material_tab_and_smudge_panel_stay_in_sync() {
let mut harness = harness();
// Both the Smudge panel and the Material section draw a chip per channel
let chips = harness.get_all_by_role_and_label(Role::Button, Channel::Height.short()).count();
assert_eq!(chips, 2, "Smudge panel and Material tab");
let first = harness.get_all_by_role_and_label(Role::Button, Channel::Height.short()).next().unwrap();
first.click();
// The Smudge panel draws a chip per channel, the Material section a pill
harness.get_by_role_and_label(Role::CheckBox, "Height").scroll_to_me();
harness.run_steps(SCROLL_FRAMES);
harness.get_by_role_and_label(Role::CheckBox, "Height").click();
harness.run_steps(4);
assert!(!harness.state().session.tool.enabled.contains(&Channel::Height));
for chip in harness.get_all_by_role_and_label(Role::Button, Channel::Height.short()) {
assert_ne!(chip.accesskit_node().toggled(), Some(egui::accesskit::Toggled::True), "both chips show height off");
}
assert!(!chip_is_on(&harness, Channel::Height), "the Smudge panel's chip shows height off");
let pill = harness.get_by_role_and_label(Role::CheckBox, "Height");
assert_ne!(pill.accesskit_node().toggled(), Some(egui::accesskit::Toggled::True), "so does the Material section's pill");
smudge_chip(&harness, Channel::Height).scroll_to_me();
harness.run_steps(SCROLL_FRAMES);
smudge_chip(&harness, Channel::Height).click();
harness.run_steps(4);
let pill = harness.get_by_role_and_label(Role::CheckBox, "Height");
assert_eq!(pill.accesskit_node().toggled(), Some(egui::accesskit::Toggled::True), "the chip turns the pill back on")
}
+91
View File
@@ -0,0 +1,91 @@
//! A brush tool's Material section: the fill layer's channel pills, then a card per channel that is on with the value the brush paints
use egui::accesskit::Role;
use egui_kittest::Harness;
use egui_kittest::kittest::{NodeT, Queryable};
use serde_json::json;
use texturecraft_engine::core::Channel;
use texturecraft_engine::execute;
use texturecraft_ui_egui::TextureCraftApp;
use crate::filter_support::drag;
use crate::{BAKE_RESOLUTION, FRAME_SECONDS, PROPERTIES_WINDOW, SETTLE_FRAMES, SLIDER_END_INSET, STARTUP_FRAMES, TEXTURE_RESOLUTION, click_at, click_widget};
/// A second at 60 frames: the Material tab's jump scrolls with egui's scroll animation
const SCROLL_FRAMES: usize = 60;
/// `tool`'s Properties scrolled to its Material section
fn material_section(tool: &str) -> Harness<'static, TextureCraftApp> {
let mut session = texturecraft_engine::sample_session(TEXTURE_RESOLUTION, BAKE_RESOLUTION).unwrap();
execute(&mut session, "tool.select", &json!({"tool": tool})).unwrap();
let mut harness = Harness::builder()
.with_size(PROPERTIES_WINDOW)
.with_step_dt(FRAME_SECONDS)
.with_context_setup(texturecraft_ui_egui::framework::install_headless)
.build_eframe(|cc| TextureCraftApp::new(cc, session));
harness.state_mut().ui.prefs.language = "en".into();
harness.run_steps(STARTUP_FRAMES);
click_widget(&mut harness, Role::Tab, "Material");
harness.run_steps(SCROLL_FRAMES);
harness
}
fn tool_value(harness: &Harness<'_, TextureCraftApp>, channel: Channel) -> [f32; 3] {
harness.state().session.tool.values.get(&channel).copied().unwrap_or(channel.default_value())
}
/// The top row of the card named `card` ("Metallic: Uniform"), if it shows
fn card_row(harness: &Harness<'_, TextureCraftApp>, card: &str) -> Option<egui::Rect> {
let named = |node: &egui_kittest::Node<'_>| node.accesskit_node().value().is_some_and(|value| value.starts_with(&format!("{card}: ")));
harness.query_all_by_role(Role::Label).find(named).map(|node| node.rect())
}
/// Clicks the widget with `role` and `label` on the top row of the card named `card`
fn click_in_card(harness: &mut Harness<'_, TextureCraftApp>, card: &str, role: Role, label: &str) {
let row = card_row(harness, card).unwrap();
let at = harness.get_all_by_role_and_label(role, label).map(|node| node.rect().center()).find(|at| row.contains(*at)).unwrap();
click_at(harness, at);
}
#[test]
fn each_channel_that_is_on_gets_a_card_whose_reset_returns_the_channels_default() {
let mut harness = material_section("paint");
assert!(harness.query_by_role_and_label(Role::Button, "Base color").is_some(), "Base color is a colour bar");
for gray in ["Metallic", "Roughness", "Height"] {
assert!(harness.query_by_role_and_label(Role::Slider, gray).is_some(), "{gray} is a gray ramp");
}
assert!(card_row(&harness, "Normal").is_some(), "Normal has a card");
assert!(harness.query_by_role_and_label(Role::Slider, "Normal").is_none(), "the normal paints flat: no value to set");
execute(&mut harness.state_mut().session, "tool.material", &json!({"channel": "metallic", "value": 0.8})).unwrap();
harness.run_steps(SETTLE_FRAMES);
click_in_card(&mut harness, "Metallic", Role::Button, "Restore defaults");
assert_eq!(tool_value(&harness, Channel::Metallic), Channel::Metallic.default_value(), "⟲ goes back to the channel's default");
click_widget(&mut harness, Role::CheckBox, "Metal");
assert!(!harness.state().session.tool.enabled.contains(&Channel::Metallic), "off in the strip, the brush stops painting Metallic");
assert!(card_row(&harness, "Metallic").is_none(), "a channel that is off has no card");
}
#[test]
fn a_click_on_a_ramp_sets_the_value_the_brush_paints() {
let mut harness = material_section("paint");
let before = tool_value(&harness, Channel::Roughness);
harness.get_by_role_and_label(Role::Slider, "Roughness").scroll_to_me();
harness.run_steps(SCROLL_FRAMES);
let track = harness.get_by_role_and_label(Role::Slider, "Roughness").rect();
drag(&mut harness, track.center(), egui::pos2(track.right() - SLIDER_END_INSET, track.center().y));
assert!(tool_value(&harness, Channel::Roughness)[0] > before[0], "dragged toward the ramp's white end the brush paints rougher");
}
#[test]
fn the_eraser_picks_its_channels_without_value_cards() {
let harness = material_section("eraser");
assert!(harness.query_by_role_and_label(Role::CheckBox, "Color").is_some(), "the channel strip");
assert!(harness.query_by_role_and_label(Role::Button, "Base color").is_none(), "the eraser paints no colour");
assert!(harness.query_by_role_and_label(Role::Slider, "Roughness").is_none());
}