Right-click Brush Preset picker picks presets like Photoshop (#615, #1031) (#1080)

* Right-click Brush Preset picker: pick presets like Photoshop (#615, #1031)

One picker for the canvas right-click and the options-bar brush chip, drawn
once a frame and kept in UiState (brush_picker, brush_picker_list). Its
preset list is the Brushes panel's (brushes_tab::preset_list): a click picks
and keeps it open, a double-click picks and closes it, drag reorders and
right-click renames or deletes. A gear menu adds New Brush Preset… (named in
the rename bar), Rename/Delete Brush, list or grid view and Import Brushes….
Hardness shows for round tips only; Enter applies a typed size before it
closes the picker. ui.set gains brushPicker and brushPickerView.

Also fixes the Brushes panel's Rename Brush…/Rename Group… context items,
which never opened the rename bar.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* Brush Preset picker: Polish translations

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01UHgFEHEsefoQoBParH47JA

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
This commit is contained in:
BFlatandClaude Opus 5.5 authored and GitHub committed 2026-10-08 18:28:06 -04:00
1 parent ef8610adeb
commit da86700693
23 files changed
+536 -259

No files matched your search

+2 -1
View File
@@ -174,7 +174,8 @@ pub struct MenuParams {
pub struct UiSetParams {
/// Fields for the control method `ui.set`: tool, panels, dock, dockTabs, dockWidth, maskTarget,
/// vectorMaskTarget, selectionMode, zoom, center, fit, theme (pro, proMedium, studio,
/// studioLight, classic), brushSection, brushTab, brushesView, brushSize. Other fields are an
/// studioLight, classic), brushSection, brushTab, brushesView, brushPicker ([x, y] opens the
/// Brush Preset picker there, null closes it), brushPickerView, brushSize. Other fields are an
/// error.
pub fields: Value,
}
+36 -2
View File
@@ -513,6 +513,7 @@ fn app_harness_with_language(lang: crate::i18n::Lang) -> Harness<'static, Photoc
crate::shortcuts::handle(app, &ctx);
crate::panels::options_bar(app, ui);
window(app, &ctx);
crate::paint_mouse::show_picker(app, &ctx);
crate::i18n::set_current(previous);
},
app,
@@ -602,9 +603,13 @@ fn options_bar_reaches_brush_settings_and_the_preset_library() {
h.get_by_label("Toggle the Brush Settings panel").click();
h.run_steps(3);
assert!(!h.state().ui.panels.brush_settings);
// The chip's picker lists the session's presets in their groups, not a fixed set of tips.
// The chip opens the same picker a right-click on the canvas does, below the chip; it lists
// the session's presets in their groups, not a fixed set of tips.
h.get_by_label("Brush Preset picker").click();
h.run_steps(3);
let chip = h.get_by_label("Brush Preset picker").rect();
let at = h.state().ui.brush_picker.expect("the chip opened the picker");
assert!((at[0] - chip.left()).abs() < 1.0 && at[1] >= chip.bottom(), "{at:?} below {chip:?}");
let presets = h.state().session.tools.presets.clone();
for (group, _) in grouped_presets(&presets) {
assert!(h.query_by_label(&group).is_some(), "group {group}");
@@ -615,10 +620,39 @@ fn options_bar_reaches_brush_settings_and_the_preset_library() {
h.run_steps(3);
assert_eq!(last_journal(h.state()).unwrap(), ("tools.setBrush".to_string(), json!({ "preset": target })));
assert!(is_current(&paint::presets::find(&presets, &target).unwrap().brush, &h.state().session.tools.brush));
// Its Brush Settings button opens the full editor.
// A click picks and keeps the picker open; the chip's click closes it again.
assert!(h.state().ui.brush_picker.is_some());
h.get_by_label("Brush Preset picker").click();
h.run_steps(3);
assert_eq!(h.state().ui.brush_picker, None, "the chip toggles the picker");
// Its Brush Settings button opens the full editor and closes the picker.
h.get_by_label("Brush Preset picker").click();
h.run_steps(3);
h.get_by_label("Brush Settings…").click();
h.run_steps(3);
assert!(h.state().ui.panels.brush_settings && h.state().ui.brush_tab == 0);
assert_eq!(h.state().ui.brush_picker, None);
}
/// A preset's context menu (the Brushes tab's and the picker's) renames it in the rename bar.
#[test]
fn context_menu_renames_a_preset() {
use egui_kittest::kittest::Queryable;
let mut h = harness(1, 0);
let name = h.state().session.tools.presets[0].name.clone();
h.get_by_label(&name).click_secondary();
h.run_steps(2);
h.get_by_label("Rename Brush…").click();
h.run_steps(2);
assert_eq!(h.state().ui.brushes_panel.renaming.as_ref().map(|r| r.name.clone()), Some(name.clone()), "the rename bar opened");
h.key_press_modifiers(egui::Modifiers::COMMAND, egui::Key::A);
h.event(egui::Event::Text("Renamed".into()));
h.run_steps(1);
h.key_press(egui::Key::Enter);
h.run_steps(3);
assert!(paint::presets::find(&h.state().session.tools.presets, "Renamed").is_some());
assert!(h.state().ui.brushes_panel.renaming.is_none());
assert_eq!(last_journal(h.state()).unwrap(), ("brush.presets.rename".to_string(), json!({ "name": name, "newName": "Renamed" })));
}
#[test]
+117 -123
View File
@@ -1,59 +1,91 @@
//! Photoshop's Brush Preset picker: the options-bar brush chip's popup and the picker a
//! right-click on the canvas opens (`paint_mouse`). It is the quick picker (Size, Hardness and the
//! preset library in its groups); the full editor is the Brush Settings panel (F5), which the
//! picker and the options bar open with one click (#258).
//! Photoshop's Brush Preset picker: the popup that the options-bar brush chip and a right-click on
//! the canvas open (`paint_mouse`). It is the quick picker (Size, Hardness for round tips, a search
//! field, the gear menu and the preset library in its groups); the full editor is the Brush
//! Settings panel (F5), which the picker and the options bar open with one click (#258).
//!
//! The preset list is the Brushes panel's ([`brushes_tab::preset_list`]): a click picks a preset
//! and keeps the picker open, a double-click picks it and closes the picker (#1031); drag to
//! reorder, right-click to rename or delete. Its view state (search, collapsed groups, list or
//! grid, a rename in progress) is `UiState::brush_picker_list`, so the control channel can read
//! and set it.
//!
//! The picker edits a copy of the brush; the caller sends the size and hardness edits through
//! `tools.setBrush` ([`crate::brush_panel::commit_gesture`]) and applies the returned [`Pick`]
//! `tools.setBrush` ([`crate::brush_panel::commit_gesture`]) and applies the returned [`Pick`]s
//! with [`apply`], so every change is a journaled command (Rule 1).
use std::collections::BTreeSet;
use egui::{Color32, RichText, Sense, Stroke, pos2, vec2};
use egui::{RichText, vec2};
use photocraft_engine::BrushSettings;
use photocraft_engine::paint::{BrushPreset, MAX_BRUSH_SIZE};
use photocraft_engine::paint::{BrushPreset, MAX_BRUSH_SIZE, TipShape};
use serde_json::json;
use crate::brush_panel::{full_uv, grouped_presets, is_current, new_preset_name, run_or_status};
use crate::theme::{self, Tokens};
use crate::{PhotocraftApp, brush_preview, icons, widgets};
use crate::brush_panel::{BrushesPanelState, BrushesView, Renaming, is_current, new_preset_name, run_or_status};
use crate::brushes_tab::{self, Action, ListLayout};
use crate::theme::Tokens;
use crate::{PhotocraftApp, icons, widgets};
/// Width of the picker's contents.
pub const WIDTH: f32 = 300.0;
/// A preset cell in the picker's grid.
const CELL: egui::Vec2 = vec2(44.0, 50.0);
/// The picker's preset list: denser than the Brushes tab's.
const LIST: ListLayout = ListLayout { id: "brush-picker-presets", max_height: 300.0, cell: 44.0, indent: 4.0 };
/// What a click in the picker asks for beyond the size and hardness edits.
/// What the picker asks for beyond the size and hardness edits.
#[derive(Clone, Debug, PartialEq)]
pub enum Pick {
/// Pick a preset (`tools.setBrush {"preset": name}`).
Preset(String),
/// A preset-list action: pick, reorder, rename or delete a preset, as in the Brushes panel.
List(Action),
/// Open the Brush Settings panel (Window › Brush Settings, F5).
OpenSettings,
/// Save the current brush as a new preset.
/// Save the current brush as a new preset, then name it in the rename bar.
NewPreset,
/// Import brushes (.abr) with the file dialog.
Import,
}
/// Picker view state kept in egui memory: the name filter and the collapsed groups.
#[derive(Clone, Debug, Default)]
struct View {
filter: String,
collapsed: BTreeSet<String>,
impl Pick {
/// Does this pick dismiss the picker? A double-click on a preset does (Photoshop), and so does
/// anything that opens another panel or dialog.
pub fn closes(&self) -> bool {
matches!(self, Pick::List(Action::Choose(_)) | Pick::OpenSettings | Pick::Import)
}
}
fn view_id() -> egui::Id {
egui::Id::new("brush-picker-view")
/// The options-bar brush chip that shows and hides the picker. A press on it isn't an outside
/// press that closes the picker: the chip's click toggles it.
pub fn chip_id() -> egui::Id {
egui::Id::new("brush-preset-chip")
}
/// Is screen point `p` on the options-bar brush chip?
pub fn on_chip(ctx: &egui::Context, p: egui::Pos2) -> bool {
ctx.read_response(chip_id()).is_some_and(|r| r.rect.contains(p))
}
/// Close the picker. A rename left open in it goes too, like Photoshop's name dialog.
pub fn close(ui: &mut crate::state::UiState) {
ui.brush_picker = None;
ui.brush_picker_list.renaming = None;
}
/// The picker's list view before it is changed: tip thumbnails, like Photoshop's picker.
pub fn list_state() -> BrushesPanelState {
BrushesPanelState { view: BrushesView::Grid, ..Default::default() }
}
/// Run what the picker asked for.
pub fn apply(app: &mut PhotocraftApp, ctx: &egui::Context, pick: Option<Pick>) {
match pick {
None => {}
Some(Pick::Preset(name)) => run_or_status(app, "tools.setBrush", json!({ "preset": name })),
Some(Pick::OpenSettings) => open_settings(app, ctx),
Some(Pick::NewPreset) => {
let name = new_preset_name(&app.session.tools.presets);
run_or_status(app, "brush.presets.save", json!({ "name": name }));
pub fn apply(app: &mut PhotocraftApp, ctx: &egui::Context, picks: Vec<Pick>) {
for pick in picks {
match pick {
Pick::List(a) => brushes_tab::apply(app, vec![a]),
Pick::OpenSettings => open_settings(app, ctx),
Pick::NewPreset => {
let name = new_preset_name(&app.session.tools.presets);
run_or_status(app, "brush.presets.save", json!({ "name": name }));
// Photoshop asks for the new preset's name: the picker's rename bar does.
if app.session.tools.presets.iter().any(|p| p.name == name) {
app.ui.brush_picker_list.renaming = Some(Renaming { group: false, name, text: String::new() });
}
}
Pick::Import => app.open_dialog_file(),
}
}
}
@@ -86,11 +118,11 @@ pub(crate) fn named(resp: egui::Response, label: &str) -> egui::Response {
resp
}
/// The picker's contents: Size, Hardness, a search field with the Brush Settings and New Preset
/// buttons, and the presets in their groups as tip thumbnails.
pub fn body(ui: &mut egui::Ui, b: &mut BrushSettings, presets: &[BrushPreset]) -> Option<Pick> {
/// The picker's contents: Size, Hardness (round tips only: a sampled tip has none), a search
/// field with the Brush Settings, New Preset and gear buttons, and the preset list.
pub fn body(ui: &mut egui::Ui, b: &mut BrushSettings, presets: &[BrushPreset], st: &mut BrushesPanelState) -> Vec<Pick> {
let t = Tokens::get(ui.ctx());
let mut pick = None;
let mut picks = Vec::new();
ui.set_width(WIDTH);
// Size: value field plus a logarithmic slider (small sizes get most of the travel).
ui.horizontal(|ui| {
@@ -106,109 +138,71 @@ pub fn body(ui: &mut egui::Ui, b: &mut BrushSettings, presets: &[BrushPreset]) -
if widgets::slider(ui, &mut lv, 0.0..=MAX_BRUSH_SIZE.ln(), None).changed() {
b.size = lv.exp().round().clamp(1.0, MAX_BRUSH_SIZE);
}
let mut hard = b.hardness * 100.0;
if widgets::slider_row(ui, "Hardness", &mut hard, 0.0..=100.0, "%", None).changed() {
b.hardness = (hard / 100.0).clamp(0.0, 1.0);
if b.tip == TipShape::Round {
let mut hard = b.hardness * 100.0;
if widgets::slider_row(ui, "Hardness", &mut hard, 0.0..=100.0, "%", None).changed() {
b.hardness = (hard / 100.0).clamp(0.0, 1.0);
}
}
ui.add_space(6.0);
widgets::hairline(ui);
ui.add_space(6.0);
let mut view = ui.data(|d| d.get_temp::<View>(view_id())).unwrap_or_default();
ui.horizontal(|ui| {
icons::paint(ui, egui::Rect::from_min_size(ui.cursor().min + vec2(0.0, 3.0), vec2(16.0, 16.0)), "search", 14.0, t.text_faint);
ui.add_space(20.0);
ui.add(egui::TextEdit::singleline(&mut view.filter).hint_text(tl!("Search Brushes")).desired_width(WIDTH - 90.0).id_salt("brush-picker-search"));
ui.add(egui::TextEdit::singleline(&mut st.filter).hint_text(tl!("Search Brushes")).desired_width(WIDTH - 118.0).id_salt("brush-picker-search"));
ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {
gear_menu(ui, b, presets, st, &mut picks);
if named(icons::button(ui, "square-plus", 24.0, false, "Create new brush preset from the current settings"), "New Brush Preset").clicked() {
pick = Some(Pick::NewPreset);
picks.push(Pick::NewPreset);
}
if named(icons::button(ui, "sliders-horizontal", 24.0, false, "Brush Settings… (F5): every option of this brush"), "Brush Settings…").clicked()
{
pick = Some(Pick::OpenSettings);
picks.push(Pick::OpenSettings);
}
});
});
ui.add_space(4.0);
let filter = view.filter.trim().to_lowercase();
egui::ScrollArea::vertical().id_salt("brush-picker-presets").max_height(300.0).auto_shrink([false, true]).show(ui, |ui| {
ui.spacing_mut().item_spacing.y = 1.0;
for (label, items) in grouped_presets(presets) {
let items: Vec<&BrushPreset> =
items.into_iter().filter_map(|i| presets.get(i)).filter(|p| filter.is_empty() || p.name.to_lowercase().contains(&filter)).collect();
if items.is_empty() {
continue;
}
let open = !filter.is_empty() || !view.collapsed.contains(&label);
if group_header(ui, &label, open, items.len()) && !view.collapsed.remove(&label) {
view.collapsed.insert(label.clone());
}
if !open {
continue;
}
ui.horizontal_wrapped(|ui| {
ui.spacing_mut().item_spacing = vec2(3.0, 3.0);
ui.add_space(4.0);
for p in items {
if cell(ui, p, is_current(&p.brush, b)) {
pick = Some(Pick::Preset(p.name.clone()));
}
}
});
ui.add_space(3.0);
picks.extend(brushes_tab::preset_list(ui, presets, b, st, LIST).into_iter().map(Pick::List));
picks
}
/// The gear: Photoshop's picker menu. A new preset, rename or delete the current one, the list's
/// view, and Import Brushes.
fn gear_menu(ui: &mut egui::Ui, b: &BrushSettings, presets: &[BrushPreset], st: &mut BrushesPanelState, picks: &mut Vec<Pick>) {
let gear = named(icons::button(ui, "settings", 24.0, false, tl!("Brush Preset Options")), "Brush Preset Options");
egui::Popup::menu(&gear).close_behavior(egui::PopupCloseBehavior::CloseOnClickOutside).show(|ui| {
if ui.button(tl!("New Brush Preset…")).clicked() {
picks.push(Pick::NewPreset);
ui.close();
}
if presets.is_empty() {
ui.label(RichText::new(tl!("No brush presets")).color(t.text_faint));
ui.separator();
let current = presets.iter().find(|p| is_current(&p.brush, b)).map(|p| p.name.clone());
ui.add_enabled_ui(current.is_some(), |ui| {
if ui.button(tl!("Rename Brush…")).clicked()
&& let Some(name) = current.clone()
{
st.renaming = Some(Renaming { group: false, name, text: String::new() });
ui.close();
}
if ui.button(tl!("Delete Brush")).clicked()
&& let Some(name) = current.clone()
{
picks.push(Pick::List(Action::Delete(name)));
ui.close();
}
});
ui.separator();
for (view, label) in [(BrushesView::List, tl!("List view")), (BrushesView::Grid, tl!("Grid view"))] {
if ui.selectable_label(st.view == view, label).clicked() {
st.view = view;
ui.close();
}
}
ui.separator();
if ui.button(tl!("Import Brushes…")).clicked() {
picks.push(Pick::Import);
ui.close();
}
});
ui.data_mut(|d| d.insert_temp(view_id(), view));
pick
}
/// A group's header row: chevron, folder, name, count. Returns true when clicked (toggle).
fn group_header(ui: &mut egui::Ui, label: &str, open: bool, count: usize) -> bool {
let t = Tokens::get(ui.ctx());
let (r, resp) = ui.allocate_exact_size(vec2(ui.available_width(), 22.0), Sense::click());
if resp.hovered() {
ui.painter().rect_filled(r, t.radius_sm, t.hover);
}
let x = r.left() + 2.0;
let chevron = if open { "chevron-down" } else { "chevron-right" };
icons::paint(ui, egui::Rect::from_min_size(pos2(x, r.center().y - 7.0), vec2(14.0, 14.0)), chevron, 12.0, t.text_dim);
let folder = if open { "folder-open" } else { "folder" };
icons::paint(ui, egui::Rect::from_min_size(pos2(x + 16.0, r.center().y - 8.0), vec2(16.0, 16.0)), folder, 14.0, t.icon);
ui.painter().text(pos2(x + 37.0, r.center().y), egui::Align2::LEFT_CENTER, label, theme::semibold(12.0), t.text);
ui.painter().text(pos2(r.right() - 6.0, r.center().y), egui::Align2::RIGHT_CENTER, count.to_string(), theme::medium(11.0), t.text_faint);
resp.widget_info(|| egui::WidgetInfo::labeled(egui::WidgetType::CollapsingHeader, true, label));
resp.clicked()
}
/// One preset: its tip thumbnail (scaled by size) and its size. Returns true when clicked.
fn cell(ui: &mut egui::Ui, p: &BrushPreset, current: bool) -> bool {
let t = Tokens::get(ui.ctx());
let (r, resp) = ui.allocate_exact_size(CELL, Sense::click());
resp.widget_info(|| egui::WidgetInfo::selected(egui::WidgetType::Button, true, current, &p.name));
if !ui.is_rect_visible(r) {
return resp.clicked();
}
if current {
ui.painter().rect_filled(r, 3.0, t.accent_soft);
ui.painter().rect_stroke(r, 3.0, Stroke::new(1.0, t.accent), egui::StrokeKind::Inside);
} else if resp.hovered() {
ui.painter().rect_filled(r, 3.0, t.hover);
} else {
ui.painter().rect_filled(r, 3.0, t.field);
}
let pb = &p.brush;
// The Brushes tab's thumbnail slot, so both share one cached texture per preset.
let tip = brush_preview::tip_texture(ui.ctx(), &format!("brushes-tip:{}", p.name), &pb.tip, (pb.hardness, pb.angle, pb.roundness), 36, t.text);
let ir = egui::Rect::from_center_size(pos2(r.center().x, r.top() + 20.0), vec2(32.0, 32.0) * crate::brush_sections::thumb_scale(pb.size));
ui.painter().image(tip.id(), ir, full_uv(), Color32::WHITE);
ui.painter().text(
pos2(r.center().x, r.bottom() - 7.0),
egui::Align2::CENTER_CENTER,
format!("{}", pb.size.round() as i64),
egui::FontId::proportional(9.5),
t.text_dim,
);
resp.on_hover_text(&p.name).clicked()
}
+170 -91
View File
@@ -5,12 +5,17 @@
//! into another group (onto a preset, or onto a group's header to append), drag a group's header
//! to reorder groups, and right-click for Rename and Delete. Every change is a `brush.presets.*`
//! command, so it is journaled, drivable, and persisted by the preset store.
//!
//! The list itself ([`preset_list`]) is shared with the Brush Preset picker (`brush_picker`), so
//! both show, pick and organise presets the same way; each keeps its own view state.
use egui::{Color32, RichText, Sense, Stroke, pos2, vec2};
use photocraft_engine::paint::{BrushPreset, MAX_BRUSH_SIZE};
use serde_json::json;
use crate::brush_panel::{BrushesView, Renaming, UNGROUPED, WIDTH, commit_gesture, full_uv, grouped_presets, is_current, new_preset_name, run_or_status};
use crate::brush_panel::{
BrushesPanelState, BrushesView, Renaming, UNGROUPED, WIDTH, commit_gesture, full_uv, grouped_presets, is_current, new_preset_name, run_or_status,
};
use crate::brush_preview;
use crate::theme::{self, Tokens};
use crate::{PhotocraftApp, icons, widgets};
@@ -22,18 +27,47 @@ pub enum BrushDrag {
Group(String),
}
/// What the tab does after drawing (the presets are borrowed while it draws).
/// What a preset list does after drawing (the presets are borrowed while it draws).
#[derive(Clone, Debug, PartialEq)]
pub enum Action {
/// A click: make the preset current.
Select(String),
/// A double-click: make the preset current and dismiss the picker showing it (Photoshop).
Choose(String),
/// View only: open or close a group ([`preset_list`] applies it to its view state).
ToggleGroup(String),
Move { name: String, group: String, index: Option<usize> },
MoveGroup { group: String, before: Option<String> },
Move {
name: String,
group: String,
index: Option<usize>,
},
MoveGroup {
group: String,
before: Option<String>,
},
/// View only: show the rename bar for a preset or group ([`preset_list`] applies it).
BeginRename(Renaming),
/// Commit a rename typed in the rename bar.
Rename(Renaming),
Delete(String),
DeleteGroup(String),
}
/// How a preset list is laid out: the Brushes tab's, or the Brush Preset picker's (narrower,
/// denser).
#[derive(Clone, Copy, Debug, PartialEq)]
pub struct ListLayout {
/// The scroll area's id and its height limit.
pub id: &'static str,
pub max_height: f32,
/// Width of a grid cell (its height is 6 points more) and the grid's left indent.
pub cell: f32,
pub indent: f32,
}
/// The Brushes tab's list.
pub const PANEL_LIST: ListLayout = ListLayout { id: "brush-presets", max_height: 400.0, cell: 52.0, indent: 20.0 };
/// The group key (`BrushPreset::group`) behind a panel label: ungrouped presets show as
/// [`UNGROUPED`].
pub fn group_key(presets: &[BrushPreset], label: &str) -> String {
@@ -55,18 +89,41 @@ pub fn drop_target(presets: &[BrushPreset], dragged: &str, target: &str, after:
Some((t.group.clone(), idx))
}
/// Turn the tab's actions into commands.
pub fn apply(app: &mut PhotocraftApp, acts: Vec<Action>) {
for a in acts {
match a {
Action::Select(name) => run_or_status(app, "tools.setBrush", json!({ "preset": name })),
/// Apply the view-only actions to `st`; returns the rest, the commands for [`apply`].
fn view_actions(st: &mut BrushesPanelState, acts: Vec<Action>) -> Vec<Action> {
acts.into_iter()
.filter_map(|a| match a {
Action::ToggleGroup(g) => {
let c = &mut app.ui.brushes_panel.collapsed;
let c = &mut st.collapsed;
match c.iter().position(|x| *x == g) {
Some(i) => drop(c.remove(i)),
None => c.push(g),
}
None
}
Action::BeginRename(r) => {
st.renaming = Some(r);
None
}
a => Some(a),
})
.collect()
}
/// Turn a preset list's actions into commands.
pub fn apply(app: &mut PhotocraftApp, acts: Vec<Action>) {
for a in acts {
match a {
Action::Select(name) => run_or_status(app, "tools.setBrush", json!({ "preset": name })),
Action::Choose(name) => {
// The double-click's first click already picked it.
let picked =
photocraft_engine::paint::presets::find(&app.session.tools.presets, &name).is_some_and(|p| is_current(&p.brush, &app.session.tools.brush));
if !picked {
run_or_status(app, "tools.setBrush", json!({ "preset": name }));
}
}
Action::ToggleGroup(_) | Action::BeginRename(_) => {}
Action::Move { name, group, index } => {
let mut p = json!({ "name": name, "group": group });
if let Some(i) = index {
@@ -84,7 +141,6 @@ pub fn apply(app: &mut PhotocraftApp, acts: Vec<Action>) {
run_or_status(app, "brush.presets.rename", json!({ "name": r.name, "newName": text }));
}
}
app.ui.brushes_panel.renaming = None;
}
Action::Delete(name) => run_or_status(app, "brush.presets.delete", json!({ "name": name })),
Action::DeleteGroup(g) => run_or_status(app, "brush.presets.deleteGroup", json!({ "group": g })),
@@ -113,12 +169,14 @@ fn preset_interactions(ui: &egui::Ui, resp: &egui::Response, r: egui::Rect, p: &
{
acts.push(Action::Move { name: n.clone(), group, index: Some(index) });
}
if resp.clicked() {
if resp.double_clicked() {
acts.push(Action::Choose(p.name.clone()));
} else if resp.clicked() {
acts.push(Action::Select(p.name.clone()));
}
resp.context_menu(|ui| {
if ui.button(tl!("Rename Brush…")).clicked() {
acts.push(Action::Rename(Renaming { group: false, name: p.name.clone(), text: String::new() }));
acts.push(Action::BeginRename(Renaming { group: false, name: p.name.clone(), text: String::new() }));
ui.close();
}
if ui.button(tl!("Delete Brush")).clicked() {
@@ -128,9 +186,13 @@ fn preset_interactions(ui: &egui::Ui, resp: &egui::Response, r: egui::Rect, p: &
});
}
/// Width a list row keeps for the gaps around its stroke preview and the preset name.
const STROKE_NAME_ROOM: f32 = 140.0;
fn list_row(ui: &mut egui::Ui, p: &BrushPreset, current: bool, presets: &[BrushPreset], acts: &mut Vec<Action>) {
let t = Tokens::get(ui.ctx());
let (r, resp) = ui.allocate_exact_size(vec2(ui.available_width(), 44.0), Sense::click_and_drag());
resp.widget_info(|| egui::WidgetInfo::selected(egui::WidgetType::Button, true, current, &p.name));
if !ui.is_rect_visible(r) {
return;
}
@@ -151,16 +213,20 @@ fn list_row(ui: &mut egui::Ui, p: &BrushPreset, current: bool, presets: &[BrushP
egui::FontId::proportional(9.0),
t.text_faint,
);
let stroke = brush_preview::stroke_texture(ui.ctx(), &format!("brushes-stroke:{}", p.name), pb, 170, 36, t.text);
let sr = egui::Rect::from_min_size(pos2(cell.right() + 8.0, r.top() + 4.0), vec2(170.0, 36.0));
// The stroke preview gives up width so a narrow list (the picker) still shows the name; its
// texture slot carries the width, so lists of different widths don't re-render each other's.
let w = (r.width() - (cell.right() - r.left()) - STROKE_NAME_ROOM).clamp(60.0, 170.0).round();
let stroke = brush_preview::stroke_texture(ui.ctx(), &format!("brushes-stroke-{w}:{}", p.name), pb, w as u32, 36, t.text);
let sr = egui::Rect::from_min_size(pos2(cell.right() + 8.0, r.top() + 4.0), vec2(w, 36.0));
ui.painter().image(stroke.id(), sr, full_uv(), Color32::WHITE);
ui.painter().text(pos2(sr.right() + 12.0, r.center().y), egui::Align2::LEFT_CENTER, &p.name, egui::FontId::proportional(12.0), t.text_dim);
crate::layer_row_ui::label(ui.painter(), sr.right() + 12.0, r.center().y, r.right() - 4.0, &p.name, egui::FontId::proportional(12.0), t.text_dim);
preset_interactions(ui, &resp, r, p, presets, false, acts);
}
fn grid_cell(ui: &mut egui::Ui, p: &BrushPreset, current: bool, presets: &[BrushPreset], acts: &mut Vec<Action>) {
fn grid_cell(ui: &mut egui::Ui, p: &BrushPreset, current: bool, presets: &[BrushPreset], cell: f32, acts: &mut Vec<Action>) {
let t = Tokens::get(ui.ctx());
let (r, resp) = ui.allocate_exact_size(vec2(52.0, 58.0), Sense::click_and_drag());
let (r, resp) = ui.allocate_exact_size(vec2(cell, cell + 6.0), Sense::click_and_drag());
resp.widget_info(|| egui::WidgetInfo::selected(egui::WidgetType::Button, true, current, &p.name));
if !ui.is_rect_visible(r) {
return;
}
@@ -172,7 +238,8 @@ fn grid_cell(ui: &mut egui::Ui, p: &BrushPreset, current: bool, presets: &[Brush
}
let pb = &p.brush;
let tip = brush_preview::tip_texture(ui.ctx(), &format!("brushes-tip:{}", p.name), &pb.tip, (pb.hardness, pb.angle, pb.roundness), 36, t.text);
let ir = egui::Rect::from_center_size(pos2(r.center().x, r.top() + 23.0), vec2(38.0, 38.0) * crate::brush_sections::thumb_scale(pb.size));
let side = cell - 14.0;
let ir = egui::Rect::from_center_size(pos2(r.center().x, r.top() + side / 2.0 + 4.0), vec2(side, side) * crate::brush_sections::thumb_scale(pb.size));
ui.painter().image(tip.id(), ir, full_uv(), Color32::WHITE);
ui.painter().text(
pos2(r.center().x, r.bottom() - 7.0),
@@ -210,6 +277,7 @@ fn group_header(ui: &mut egui::Ui, label: &str, key: &str, open: bool, count: us
);
ui.painter().text(pos2(x + 40.0, r.center().y), egui::Align2::LEFT_CENTER, label, theme::semibold(12.0), t.text);
ui.painter().text(pos2(r.right() - 8.0, r.center().y), egui::Align2::RIGHT_CENTER, count.to_string(), theme::medium(11.0), t.text_faint);
resp.widget_info(|| egui::WidgetInfo::labeled(egui::WidgetType::CollapsingHeader, true, label));
resp.dnd_set_drag_payload(BrushDrag::Group(key.to_string()));
if let Some(d) = resp.dnd_hover_payload::<BrushDrag>() {
match &*d {
@@ -232,7 +300,7 @@ fn group_header(ui: &mut egui::Ui, label: &str, key: &str, open: bool, count: us
}
resp.context_menu(|ui| {
if ui.button(tl!("Rename Group…")).clicked() {
acts.push(Action::Rename(Renaming { group: true, name: key.to_string(), text: String::new() }));
acts.push(Action::BeginRename(Renaming { group: true, name: key.to_string(), text: String::new() }));
ui.close();
}
if ui.button(tl!("Delete Group")).clicked() {
@@ -244,16 +312,16 @@ fn group_header(ui: &mut egui::Ui, label: &str, key: &str, open: bool, count: us
/// The rename bar shown while a preset or group is being renamed. Enter or OK renames, Escape or
/// Cancel stops.
fn rename_bar(app: &mut PhotocraftApp, ui: &mut egui::Ui, acts: &mut Vec<Action>) {
let Some(r) = app.ui.brushes_panel.renaming.as_mut() else { return };
fn rename_bar(ui: &mut egui::Ui, st: &mut BrushesPanelState, acts: &mut Vec<Action>) {
let Some(r) = st.renaming.as_mut() else { return };
let t = Tokens::get(ui.ctx());
if r.text.is_empty() {
r.text = r.name.clone();
}
let mut cancel = false;
let mut done = false;
ui.horizontal(|ui| {
ui.label(RichText::new(if r.group { tl!("Group name") } else { tl!("Brush name") }).color(t.text_dim));
let resp = ui.add(egui::TextEdit::singleline(&mut r.text).desired_width(WIDTH - 230.0).id_salt("brush-rename"));
let resp = ui.add(egui::TextEdit::singleline(&mut r.text).desired_width((ui.available_width() - 140.0).max(60.0)).id_salt("brush-rename"));
if !resp.has_focus() && !resp.lost_focus() {
resp.request_focus();
}
@@ -267,17 +335,91 @@ fn rename_bar(app: &mut PhotocraftApp, ui: &mut egui::Ui, acts: &mut Vec<Action>
);
if clicked == Some(widgets::ButtonRole::Default) || enter {
acts.push(Action::Rename(r.clone()));
done = true;
}
if clicked == Some(widgets::ButtonRole::Cancel) || ui.input(|i| i.key_pressed(egui::Key::Escape)) {
cancel = true;
done = true;
}
});
if cancel {
app.ui.brushes_panel.renaming = None;
if done {
st.renaming = None;
}
ui.add_space(4.0);
}
/// The presets in their groups, filtered by `st.filter`, as rows or tip cells (`st.view`), with
/// the rename bar above them while a rename is open. Group toggles and renames update `st`; the
/// returned actions are commands for [`apply`].
pub fn preset_list(
ui: &mut egui::Ui,
presets: &[BrushPreset],
brush: &photocraft_engine::BrushSettings,
st: &mut BrushesPanelState,
layout: ListLayout,
) -> Vec<Action> {
let mut acts = Vec::new();
rename_bar(ui, st, &mut acts);
let filter = st.filter.trim().to_lowercase();
let grid = st.view == BrushesView::Grid;
let collapsed = &st.collapsed;
egui::ScrollArea::vertical().id_salt(layout.id).max_height(layout.max_height).auto_shrink([false, true]).show(ui, |ui| {
ui.spacing_mut().item_spacing.y = 1.0;
for (label, items) in grouped_presets(presets) {
let items: Vec<&BrushPreset> =
items.into_iter().filter_map(|i| presets.get(i)).filter(|p| filter.is_empty() || p.name.to_lowercase().contains(&filter)).collect();
if items.is_empty() {
continue;
}
let key = group_key(presets, &label);
let open = !filter.is_empty() || !collapsed.contains(&label);
group_header(ui, &label, &key, open, items.len(), &mut acts);
if !open {
continue;
}
if grid {
ui.horizontal_wrapped(|ui| {
ui.spacing_mut().item_spacing = vec2(3.0, 3.0);
ui.add_space(layout.indent);
for p in items {
grid_cell(ui, p, is_current(&p.brush, brush), presets, layout.cell, &mut acts);
}
});
} else {
for p in items {
list_row(ui, p, is_current(&p.brush, brush), presets, &mut acts);
}
}
ui.add_space(2.0);
}
if presets.is_empty() {
ui.label(RichText::new(tl!("No brush presets")).color(Tokens::get(ui.ctx()).text_faint));
}
});
// The dragged preset or group follows the pointer.
if let Some(d) = egui::DragAndDrop::payload::<BrushDrag>(ui.ctx())
&& let Some(p) = ui.ctx().pointer_interact_pos()
{
ui.ctx().set_cursor_icon(egui::CursorIcon::Grabbing);
let name = match &*d {
BrushDrag::Preset(n) => n.clone(),
BrushDrag::Group(g) => {
if g.is_empty() {
UNGROUPED.to_string()
} else {
g.clone()
}
}
};
egui::Area::new(egui::Id::new(("brush-drag-label", layout.id))).order(egui::Order::Tooltip).fixed_pos(p + vec2(12.0, 8.0)).interactable(false).show(
ui.ctx(),
|ui| {
egui::Frame::popup(ui.style()).show(ui, |ui| ui.label(name));
},
);
}
view_actions(st, acts)
}
/// The Brushes tab.
pub fn show(app: &mut PhotocraftApp, ui: &mut egui::Ui) {
let t = Tokens::get(ui.ctx());
@@ -316,70 +458,7 @@ pub fn show(app: &mut PhotocraftApp, ui: &mut egui::Ui) {
});
});
ui.add_space(6.0);
let mut acts = Vec::new();
rename_bar(app, ui, &mut acts);
let filter = app.ui.brushes_panel.filter.trim().to_lowercase();
let grid = app.ui.brushes_panel.view == BrushesView::Grid;
let presets = &app.session.tools.presets;
let groups = grouped_presets(presets);
let brush = &app.session.tools.brush;
let collapsed = &app.ui.brushes_panel.collapsed;
egui::ScrollArea::vertical().id_salt("brush-presets").max_height(400.0).auto_shrink([false, true]).show(ui, |ui| {
ui.spacing_mut().item_spacing.y = 1.0;
for (label, items) in groups {
let items: Vec<usize> =
items.into_iter().filter(|i| filter.is_empty() || presets.get(*i).is_some_and(|p| p.name.to_lowercase().contains(&filter))).collect();
if items.is_empty() {
continue;
}
let key = group_key(presets, &label);
let open = !filter.is_empty() || !collapsed.contains(&label);
group_header(ui, &label, &key, open, items.len(), &mut acts);
if !open {
continue;
}
if grid {
ui.horizontal_wrapped(|ui| {
ui.spacing_mut().item_spacing = vec2(3.0, 3.0);
ui.add_space(20.0);
for i in items {
if let Some(p) = presets.get(i) {
grid_cell(ui, p, is_current(&p.brush, brush), presets, &mut acts);
}
}
});
} else {
for i in items {
if let Some(p) = presets.get(i) {
list_row(ui, p, is_current(&p.brush, brush), presets, &mut acts);
}
}
}
ui.add_space(2.0);
}
});
// The dragged preset or group follows the pointer.
if let Some(d) = egui::DragAndDrop::payload::<BrushDrag>(ui.ctx())
&& let Some(p) = ui.ctx().pointer_interact_pos()
{
ui.ctx().set_cursor_icon(egui::CursorIcon::Grabbing);
let name = match &*d {
BrushDrag::Preset(n) => n.clone(),
BrushDrag::Group(g) => {
if g.is_empty() {
UNGROUPED.to_string()
} else {
g.clone()
}
}
};
egui::Area::new(egui::Id::new("brush-drag-label")).order(egui::Order::Tooltip).fixed_pos(p + vec2(12.0, 8.0)).interactable(false).show(
ui.ctx(),
|ui| {
egui::Frame::popup(ui.style()).show(ui, |ui| ui.label(name));
},
);
}
let acts = preset_list(ui, &app.session.tools.presets, &app.session.tools.brush, &mut app.ui.brushes_panel, PANEL_LIST);
apply(app, acts);
ui.add_space(4.0);
widgets::hairline(ui);
+2 -1
View File
@@ -1061,6 +1061,8 @@ pub(crate) fn retain_gpu_documents(app: &mut PhotocraftApp) {
pub fn document_area(app: &mut PhotocraftApp, ui: &mut egui::Ui) {
documents(app, ui);
crate::layer_transfer::finish(app, ui.ctx());
// Once a frame, not per document view: the right-click or options-bar Brush Preset picker.
crate::paint_mouse::show_picker(app, ui.ctx());
}
/// Window › Arrange tiles: each document shown with its tile in `rect`, or `None` when the
@@ -2172,7 +2174,6 @@ pub fn canvas_view(app: &mut PhotocraftApp, ui: &mut egui::Ui, idx: usize, rect:
crate::zoom_tool::draw(&ctx, &painter);
let resizing = crate::brush_resize::draw(app, &painter, &xf);
draw_transform_controls(app, &painter, &xf);
crate::paint_mouse::show_picker(app, &ctx);
crate::layer_pick_ui::show(app, &ctx);
crate::canvas_tool_menu::show(app, &ctx);
crate::snap_ui::draw(app, &painter, &xf);
+33 -2
View File
@@ -8,7 +8,7 @@
//! - `engine.commands`: list commands with enablement
//! - `ui.inspect`: full UI state (tool, panels, views, dialogs, windows, window size); the menu
//! tree is `ui.menu.list`
//! - `ui.set {tool?, panels?, dock?, dockTabs?, dockWidth?, colorPanel?, maskTarget?, vectorMaskTarget?, selectionMode?, zoom?, center?, fit?, theme?, brushSection?, brushTab?, brushesView?, brushSize?}`:
//! - `ui.set {tool?, panels?, dock?, dockTabs?, dockWidth?, colorPanel?, maskTarget?, vectorMaskTarget?, selectionMode?, zoom?, center?, fit?, theme?, brushSection?, brushTab?, brushesView?, brushPicker?, brushPickerView?, brushSize?}`:
//! change UI state; any other field is an error ([`UI_SET_FIELDS`])
//! - `ui.menu.invoke {id, wait?}` / `ui.menu.list`: activate a menu item by id; list the menu tree
//! - `ui.dialog.open {kind, fields?}` (kinds: newDocument, about, layerStyle {effect?}, colorPicker {target: foreground|background}, command {command}) / `ui.dialog.set {dialog, field, value}` / `ui.dialog.confirm {dialog, wait?}` / `ui.dialog.cancel {dialog}`
@@ -70,7 +70,7 @@ pub enum Outcome {
/// The fields `ui.set` reads. Anything else is rejected before a field is applied, so a typo or
/// a field the method doesn't have can't reply with success while nothing changes (#412).
pub const UI_SET_FIELDS: [&str; 19] = [
pub const UI_SET_FIELDS: [&str; 21] = [
"tool",
"panels",
"dock",
@@ -87,6 +87,8 @@ pub const UI_SET_FIELDS: [&str; 19] = [
"brushSection",
"brushTab",
"brushesView",
"brushPicker",
"brushPickerView",
"brushSize",
"gradientBlendMode",
"gradientClassic",
@@ -330,6 +332,18 @@ fn dispatch(app: &mut PhotocraftApp, ctx: &egui::Context, req: &ControlRequest)
Err(e) => return err(format!("brushesView: {e} (list, grid)")),
}
}
if let Some(v) = p.get("brushPickerView").cloned() {
match serde_json::from_value(v) {
Ok(v) => app.ui.brush_picker_list.view = v,
Err(e) => return err(format!("brushPickerView: {e} (list, grid)")),
}
}
if let Some(v) = p.get("brushPicker").cloned() {
match serde_json::from_value::<Option<[f32; 2]>>(v) {
Ok(at) if at.is_none_or(|[x, y]| x.is_finite() && y.is_finite()) => app.ui.brush_picker = at,
_ => return err("brushPicker must be [x, y] in screen points, or null to close it"),
}
}
if let Some(size) = p.get("brushSize").and_then(Value::as_f64)
&& let Err(e) = app.run("tools.setBrush", json!({"brush": {"size": size}}))
{
@@ -788,6 +802,23 @@ mod tests {
assert!(app.ui.tool_options.gradient_classic, "invalid mode must not change options");
}
#[test]
fn ui_set_opens_the_brush_preset_picker_and_sets_its_view() {
let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), crate::Services::default());
let ctx = egui::Context::default();
assert_eq!(app.ui.brush_picker_list.view, crate::brush_panel::BrushesView::Grid, "tip thumbnails by default");
let r = call(&mut app, &ctx, "ui.set", json!({"tool": "brush", "brushPicker": [120, 80], "brushPickerView": "list"}));
assert_eq!(r["ok"], true, "{r}");
assert_eq!(app.ui.brush_picker, Some([120.0, 80.0]));
assert_eq!(app.ui.brush_picker_list.view, crate::brush_panel::BrushesView::List);
for bad in [json!({"brushPicker": [1]}), json!({"brushPicker": "here"}), json!({"brushPickerView": "tiles"})] {
assert_eq!(call(&mut app, &ctx, "ui.set", bad.clone())["ok"], false, "{bad}");
}
assert_eq!(app.ui.brush_picker, Some([120.0, 80.0]), "a bad value leaves the picker alone");
assert_eq!(call(&mut app, &ctx, "ui.set", json!({"brushPicker": null}))["ok"], true);
assert_eq!(app.ui.brush_picker, None);
}
#[test]
fn ui_set_color_panel_picks_the_edited_chip() {
let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), crate::Services::default());
+2
View File
@@ -1974,6 +1974,8 @@
Brush Settings… (F5): every option of this brush Nastavení štětce… (F5): všechny možnosti tohoto štětce
Rename Brush… Přejmenovat štětec…
Delete Brush Odstranit štětec
New Brush Preset… Nová předvolba štětce…
Brush Preset Options Možnosti přednastavení štětců
Group name Název skupiny
Brush name Název štětce
Grid view Zobrazení mřížky
Can't render this file because it contains an unexpected character in line 6 and column 47.
+2
View File
@@ -1947,6 +1947,8 @@
Brush Settings… (F5): every option of this brush Pinseleinstellungen… (F5): jede Option dieses Pinsels
Rename Brush… Pinsel umbenennen…
Delete Brush Pinsel löschen
New Brush Preset… Neue Pinselvorgabe…
Brush Preset Options Pinselvorgaben-Optionen
Group name Gruppenname
Brush name Pinselname
Grid view Rasteransicht
Can't render this file because it contains an unexpected character in line 6 and column 47.
+2
View File
@@ -1960,6 +1960,8 @@
Brush Settings… (F5): every option of this brush Ajustes del pincel… (F5): todas las opciones de este pincel
Rename Brush… Cambiar el nombre del pincel…
Delete Brush Eliminar pincel
New Brush Preset… Nuevo preajuste de pincel…
Brush Preset Options Opciones de preajustes de pincel
Group name Nombre del grupo
Brush name Nombre del pincel
Grid view Vista de cuadrícula
Can't render this file because it contains an unexpected character in line 4 and column 47.
+2
View File
@@ -1932,6 +1932,8 @@
Brush Settings… (F5): every option of this brush Paramètres du pinceau… (F5) : toutes les options de ce pinceau
Rename Brush… Renommer le pinceau…
Delete Brush Supprimer le pinceau
New Brush Preset… Nouveau préréglage de pinceau…
Brush Preset Options Options des préréglages de pinceau
Group name Nom du groupe
Brush name Nom du pinceau
Grid view Vue en grille
Can't render this file because it contains an unexpected character in line 6 and column 47.
+2
View File
@@ -1926,6 +1926,8 @@
Brush Settings… (F5): every option of this brush Pengaturan Kuas… (F5): semua opsi kuas ini
Rename Brush… Ganti Nama Kuas…
Delete Brush Hapus Kuas
New Brush Preset… Preset Kuas Baru…
Brush Preset Options Opsi Preset Kuas
Group name Nama grup
Brush name Nama kuas
Grid view Tampilan grid
Can't render this file because it contains an unexpected character in line 4 and column 47.
+2
View File
@@ -1957,6 +1957,8 @@
Brush Settings… (F5): every option of this brush Impostazioni pennello… (F5): ogni opzione di questo pennello
Rename Brush… Rinomina pennello…
Delete Brush Elimina pennello
New Brush Preset… Nuovo predefinito pennello…
Brush Preset Options Opzioni predefiniti pennello
Group name Nome gruppo
Brush name Nome pennello
Grid view Vista griglia
1 # Italian (it) catalog. Columns, separated by a TAB: context <TAB> source <TAB> translation
1957
1958
1959
1960
1961
1962
1963
1964
+2
View File
@@ -1965,6 +1965,8 @@
Brush Settings… (F5): every option of this brush ブラシ設定…(F5): このブラシのすべてのオプション
Rename Brush… ブラシの名前を変更…
Delete Brush ブラシを削除
New Brush Preset… 新規ブラシプリセット…
Brush Preset Options ブラシプリセットのオプション
Group name グループ名
Brush name ブラシ名
Grid view グリッド表示
Can't render this file because it contains an unexpected character in line 6 and column 47.
+2
View File
@@ -1927,6 +1927,8 @@
Brush Settings… (F5): every option of this brush 브러시 설정… (F5): 이 브러시의 모든 옵션
Rename Brush… 브러시 이름 바꾸기…
Delete Brush 브러시 삭제
New Brush Preset… 새 브러시 사전 설정…
Brush Preset Options 브러시 사전 설정 옵션
Group name 그룹 이름
Brush name 브러시 이름
Grid view 격자 보기
1 # Korean (ko) catalog. UTF-8: context<TAB>English source<TAB>translation.
1927
1928
1929
1930
1931
1932
1933
1934
+2
View File
@@ -3183,3 +3183,5 @@ cameraRaw Roughness Chropowatość
More documents Więcej dokumentów
Developing {name} Wywoływanie {name}
Camera Raw ({name}) Camera Raw ({name})
New Brush Preset… Nowe ustawienie wstępne pędzla…
Brush Preset Options Opcje ustawień wstępnych pędzla
Can't render this file because it contains an unexpected character in line 6 and column 47.
+2
View File
@@ -1931,6 +1931,8 @@
Brush Settings… (F5): every option of this brush Configurações do pincel… (F5): todas as opções deste pincel
Rename Brush… Renomear pincel…
Delete Brush Excluir pincel
New Brush Preset… Nova predefinição de pincel…
Brush Preset Options Opções de predefinições de pincel
Group name Nome do grupo
Brush name Nome do pincel
Grid view Visualização em grade
Can't render this file because it contains an unexpected character in line 6 and column 47.
+5
View File
@@ -945,6 +945,11 @@
New Layer from Brush Новый слой из кисти
Rename Brush… Переименовать кисть…
Delete Brush Удалить кисть
Import Brushes… Импортировать кисти…
List view Вид списком
Grid view Вид сеткой
New Brush Preset… Новый набор параметров кисти…
Brush Preset Options Параметры наборов кистей
New Brush Новая кисть
Create new brush from these settings Создать новую кисть из этих параметров
Reset the brush to the defaults Сбросить кисть к значениям по умолчанию
Can't render this file because it contains an unexpected character in line 6 and column 47.
+2
View File
@@ -2016,6 +2016,8 @@ cameraRaw Blending 混合
Brush Settings… (F5): every option of this brush 画笔设置… (F5):此画笔的全部选项
Rename Brush… 重命名画笔…
Delete Brush 删除画笔
New Brush Preset… 新建画笔预设…
Brush Preset Options 画笔预设选项
Group name 组名称
Brush name 画笔名称
Grid view 网格视图
1 # Simplified Chinese (zh-hans) catalog. UTF-8, TAB-separated columns:
2016
2017
2018
2019
2020
2021
2022
2023
+2
View File
@@ -1956,6 +1956,8 @@
Brush Settings… (F5): every option of this brush 筆刷設定… (F5):此筆刷的所有選項
Rename Brush… 重新命名筆刷…
Delete Brush 刪除筆刷
New Brush Preset… 新增筆刷預設集…
Brush Preset Options 筆刷預設集選項
Group name 群組名稱
Brush name 筆刷名稱
Grid view 格狀檢視
Can't render this file because it contains an unexpected character in line 6 and column 47.
+122 -12
View File
@@ -117,14 +117,18 @@ pub fn pointer_secondary(app: &mut PhotocraftApp, down: bool, mods: egui::Modifi
false
}
/// The Brush Preset picker a right-click opened, at the pointer. It edits the session brush like
/// the options-bar chip's; a click outside, Escape or Enter closes it.
/// The Brush Preset picker a right-click or the options-bar brush chip opened, at the pointer. It
/// edits the session brush like the Brushes panel; a press outside, Escape, Enter or a
/// double-click on a preset closes it.
pub fn show_picker(app: &mut PhotocraftApp, ctx: &egui::Context) {
let Some([x, y]) = app.ui.brush_picker else { return };
if !has_brush_picker(app.ui.tool) || ctx.input(|i| i.key_pressed(egui::Key::Escape) || i.key_pressed(egui::Key::Enter)) {
if !has_brush_picker(app.ui.tool) {
app.ui.brush_picker = None;
return;
}
// Escape and Enter close it once this frame's edits are in (a typed size applies), unless they
// end a rename in its rename bar.
let key_close = app.ui.brush_picker_list.renaming.is_none() && ctx.input(|i| i.key_pressed(egui::Key::Escape) || i.key_pressed(egui::Key::Enter));
let screen = ctx.content_rect();
// Keep the whole picker on screen: its last size, or about 320 × 480 points before it shows.
let id = egui::Id::new("canvas-brush-picker");
@@ -133,16 +137,19 @@ pub fn show_picker(app: &mut PhotocraftApp, ctx: &egui::Context) {
let area = egui::Area::new(id).order(egui::Order::Foreground).fixed_pos(pos).show(ctx, |ui| {
let before = app.session.tools.brush.clone();
let mut b = before.clone();
let pick = egui::Frame::popup(ui.style()).show(ui, |ui| crate::brush_picker::body(ui, &mut b, &app.session.tools.presets)).inner;
let list = &mut app.ui.brush_picker_list;
let picks = egui::Frame::popup(ui.style()).show(ui, |ui| crate::brush_picker::body(ui, &mut b, &app.session.tools.presets, list)).inner;
crate::brush_panel::commit_gesture(app, ui.ctx(), &before, &b);
if pick == Some(crate::brush_picker::Pick::OpenSettings) {
app.ui.brush_picker = None;
}
crate::brush_picker::apply(app, ui.ctx(), pick);
let closes = picks.iter().any(crate::brush_picker::Pick::closes);
crate::brush_picker::apply(app, ui.ctx(), picks);
closes
});
let outside = ctx.input(|i| i.pointer.any_pressed() && i.pointer.interact_pos().is_some_and(|p| !area.response.rect.contains(p)));
if outside {
app.ui.brush_picker = None;
// Not a press on a menu the picker opened (the gear, a preset's context menu), nor on the
// options-bar chip, whose click toggles the picker.
let press = ctx.input(|i| i.pointer.any_pressed().then(|| i.pointer.interact_pos()).flatten());
let outside = press.is_some_and(|p| !area.response.rect.contains(p) && !crate::brush_picker::on_chip(ctx, p)) && !egui::Popup::is_any_open(ctx);
if outside || key_close || area.inner {
crate::brush_picker::close(&mut app.ui);
}
}
@@ -166,7 +173,7 @@ mod tests {
}
app.ui.tool = Tool::Brush;
app.sync_views();
let mut h = Harness::builder().with_size(vec2(1200.0, 800.0)).build_ui_state(
let mut h = Harness::builder().with_size(vec2(1200.0, 800.0)).with_step_dt(1.0 / 60.0).build_ui_state(
|ui, app: &mut PhotocraftApp| {
let ctx = ui.ctx().clone();
if !ctx.fonts(|f| f.families().contains(&egui::FontFamily::Name("medium".into()))) {
@@ -305,6 +312,109 @@ mod tests {
assert_eq!(h.state().ui.brush_picker, None);
}
/// #1031: the right-click picker picks brushes, not just the size. A click picks a preset and
/// keeps the picker open, a double-click picks one and closes it, and Enter applies a typed
/// size before it closes the picker.
#[test]
fn picker_click_picks_a_preset_and_double_click_closes_it() {
use egui_kittest::kittest::Queryable;
let mut h = harness(None);
let c = h.state().last_canvas_rect.center();
h.event(egui::Event::PointerMoved(c));
h.run_steps(1);
press(&mut h, c, PointerButton::Secondary, true);
press(&mut h, c, PointerButton::Secondary, false);
h.run_steps(2);
let names: Vec<String> = h.state().session.tools.presets.iter().skip(1).take(2).map(|p| p.name.clone()).collect();
let picks = |h: &Harness<'static, PhotocraftApp>, name: &str| {
h.state().session.journal.iter().filter(|(id, p)| id == "tools.setBrush" && *p == json!({ "preset": name })).count()
};
h.get_by_label(&names[0]).click();
h.run_steps(3);
assert_eq!(picks(&h, &names[0]), 1);
assert!(h.state().ui.brush_picker.is_some(), "a click keeps the picker open");
let at = h.get_by_label(&names[1]).rect().center();
h.event(egui::Event::PointerMoved(at));
h.run_steps(1);
// Two clicks 2 frames apart; well after the first click, so not a triple click.
h.run_steps(40);
for pressed in [true, false, true, false] {
h.event(egui::Event::PointerButton { pos: at, button: PointerButton::Primary, pressed, modifiers: Modifiers::NONE });
h.step();
}
h.run_steps(2);
assert_eq!(picks(&h, &names[1]), 1, "picked once: the second click only closes");
assert_eq!(h.state().ui.brush_picker, None, "a double-click closes the picker");
assert!(strokes(&h).is_empty(), "nothing painted under the picker");
// Enter applies the typed size, then closes the picker.
h.state_mut().ui.brush_picker = Some([c.x, c.y]);
h.run_steps(2);
h.get_all_by_role(egui::accesskit::Role::SpinButton).next().expect("the Size field").click();
h.run_steps(1);
h.event(egui::Event::Text("30*2".into()));
h.run_steps(1);
h.key_press(egui::Key::Enter);
h.run_steps(2);
assert_eq!((h.state().session.tools.brush.size, h.state().ui.brush_picker), (60.0, None));
}
/// A sampled tip has no hardness: the picker shows only its size (Photoshop).
#[test]
fn picker_shows_hardness_only_for_round_tips() {
use egui_kittest::kittest::Queryable;
let mut h = harness(None);
let c = h.state().last_canvas_rect.center();
h.state_mut().ui.brush_picker = Some([c.x, c.y]);
h.run_steps(2);
assert!(h.query_by_label("Hardness").is_some());
let sampled = h.state().session.tools.presets.iter().find(|p| p.brush.tip != photocraft_engine::paint::TipShape::Round).map(|p| p.name.clone());
h.state_mut().run("tools.setBrush", json!({ "preset": sampled.expect("a sampled preset") })).unwrap();
h.run_steps(2);
assert!(h.query_by_label("Hardness").is_none());
assert!(h.state().ui.brush_picker.is_some());
}
/// The gear menu's New Brush Preset… saves the brush and asks for its name in the picker's
/// rename bar; Enter there renames it and leaves the picker open (Enter closes it otherwise).
#[test]
fn picker_gear_menu_saves_and_names_a_new_preset() {
use egui_kittest::kittest::Queryable;
let mut h = harness(None);
let c = h.state().last_canvas_rect.center();
h.state_mut().ui.brush_picker = Some([c.x, c.y]);
h.run_steps(2);
h.get_by_label("Brush Preset Options").click();
h.run_steps(2);
h.get_by_label("New Brush Preset…").click();
h.run_steps(3);
let saved = h.state().ui.brush_picker_list.renaming.clone().expect("the rename bar asks for a name");
assert!(h.state().session.tools.presets.iter().any(|p| p.name == saved.name));
assert!(h.state().ui.brush_picker.is_some(), "the menu's click didn't close the picker");
h.key_press_modifiers(egui::Modifiers::COMMAND, egui::Key::A);
h.event(egui::Event::Text("Inky".into()));
h.run_steps(1);
h.key_press(egui::Key::Enter);
h.run_steps(3);
assert!(h.state().session.tools.presets.iter().any(|p| p.name == "Inky"), "renamed");
assert!(h.state().ui.brush_picker_list.renaming.is_none());
assert!(h.state().ui.brush_picker.is_some(), "Enter ended the rename, not the picker");
// The gear's view items switch the list between tips and names.
h.get_by_label("Brush Preset Options").click();
h.run_steps(2);
h.get_by_label("List view").click();
h.run_steps(2);
assert_eq!(h.state().ui.brush_picker_list.view, crate::brush_panel::BrushesView::List);
assert!(h.state().ui.brush_picker.is_some());
// A rename left open goes with the picker.
h.state_mut().ui.brush_picker_list.renaming = Some(crate::brush_panel::Renaming { group: false, name: "Inky".into(), text: String::new() });
h.run_steps(2);
let far = c - vec2(300.0, 200.0);
h.event(egui::Event::PointerMoved(far));
press(&mut h, far, PointerButton::Primary, true);
press(&mut h, far, PointerButton::Primary, false);
assert!(h.state().ui.brush_picker.is_none() && h.state().ui.brush_picker_list.renaming.is_none());
}
#[test]
fn right_drag_erases_with_the_erase_preference() {
let mut h = harness(Some("erase"));
+18 -25
View File
@@ -492,11 +492,7 @@ pub fn options_bar(app: &mut PhotocraftApp, ui: &mut egui::Ui) {
let tool = app.ui.tool;
// Brush edits here go through `tools.setBrush`, one journal entry per gesture (Rule 1).
if (tool.is_brushlike() && !matches!(tool, Tool::Brush | Tool::Pencil | Tool::MixerBrush | Tool::Eraser)) || tool == Tool::QuickSelection {
let before = app.session.tools.brush.clone();
let mut b = before.clone();
let pick = brush_preset_chip(ui, &mut b, &app.session.tools.presets);
crate::brush_panel::commit_gesture(app, ui.ctx(), &before, &b);
crate::brush_picker::apply(app, ui.ctx(), pick);
brush_preset_chip(ui, &app.session.tools.brush, &mut app.ui);
crate::brush_picker::settings_toggle(app, ui);
widgets::vline(ui, 22.0);
}
@@ -512,10 +508,9 @@ pub fn options_bar(app: &mut PhotocraftApp, ui: &mut egui::Ui) {
let brush_before = app.session.tools.brush.clone();
let mut brush = brush_before.clone();
let b = &mut brush;
let mut picked = None;
match app.ui.tool {
Tool::Brush | Tool::Eraser if t.pro => {
picked = brush_preset_chip(ui, b, &app.session.tools.presets);
brush_preset_chip(ui, b, &mut app.ui);
crate::brush_picker::settings_toggle(app, ui);
widgets::vline(ui, 22.0);
opt_label(ui, tl!("Mode"));
@@ -544,7 +539,7 @@ pub fn options_bar(app: &mut PhotocraftApp, ui: &mut egui::Ui) {
}
// Pencil: Photoshop's options (no hardness or flow: the pencil is always hard).
Tool::Pencil => {
picked = brush_preset_chip(ui, b, &app.session.tools.presets);
brush_preset_chip(ui, b, &mut app.ui);
crate::brush_picker::settings_toggle(app, ui);
widgets::vline(ui, 22.0);
if !t.pro {
@@ -565,7 +560,7 @@ pub fn options_bar(app: &mut PhotocraftApp, ui: &mut egui::Ui) {
widgets::checkbox(ui, &mut app.ui.tool_options.pencil_auto_erase, tl!("Auto Erase"));
}
Tool::Brush | Tool::Eraser => {
picked = brush_preset_chip(ui, b, &app.session.tools.presets);
brush_preset_chip(ui, b, &mut app.ui);
crate::brush_picker::settings_toggle(app, ui);
widgets::vline(ui, 22.0);
opt_label(ui, tl!("Size"));
@@ -581,7 +576,7 @@ pub fn options_bar(app: &mut PhotocraftApp, ui: &mut egui::Ui) {
widgets::toggle(ui, &mut b.pressure_opacity, tl!("Pressure for Opacity"));
}
Tool::MixerBrush => {
picked = brush_preset_chip(ui, b, &app.session.tools.presets);
brush_preset_chip(ui, b, &mut app.ui);
crate::brush_picker::settings_toggle(app, ui);
widgets::vline(ui, 22.0);
for (label, value) in [
@@ -932,7 +927,6 @@ pub fn options_bar(app: &mut PhotocraftApp, ui: &mut egui::Ui) {
_ => {}
}
crate::brush_panel::commit_gesture(app, ui.ctx(), &brush_before, &brush);
crate::brush_picker::apply(app, ui.ctx(), picked);
});
});
}
@@ -2628,16 +2622,13 @@ fn symmetry_menu(app: &mut PhotocraftApp, ui: &mut egui::Ui) {
});
}
/// Options-bar brush chip; opens Photoshop's Brush Preset picker (size, hardness, the preset
/// library). Returns what the picker asked for beyond the size and hardness edits in `b`.
fn brush_preset_chip(
ui: &mut egui::Ui,
b: &mut photocraft_engine::BrushSettings,
presets: &[photocraft_engine::paint::BrushPreset],
) -> Option<crate::brush_picker::Pick> {
/// Options-bar brush chip: a click shows or hides Photoshop's Brush Preset picker below it (size,
/// hardness, the preset library), the one a right-click on the canvas opens.
fn brush_preset_chip(ui: &mut egui::Ui, b: &photocraft_engine::BrushSettings, state: &mut crate::state::UiState) {
let t = Tokens::get(ui.ctx());
let (r, resp) = ui.allocate_exact_size(vec2(44.0, 30.0), Sense::click());
if resp.hovered() {
let (r, _) = ui.allocate_exact_size(vec2(44.0, 30.0), Sense::hover());
let resp = ui.interact(r, crate::brush_picker::chip_id(), Sense::click());
if resp.hovered() || state.brush_picker.is_some() {
ui.painter().rect_filled(r, t.radius_sm, t.hover);
}
let c = pos2(r.left() + 14.0, r.top() + 11.0);
@@ -2645,11 +2636,13 @@ fn brush_preset_chip(
ui.painter().text(pos2(c.x, r.bottom() - 5.0), Align2::CENTER_CENTER, format!("{}", b.size.round() as i64), egui::FontId::proportional(9.5), t.text_dim);
icons::paint(ui, Rect::from_center_size(pos2(r.right() - 9.0, c.y), vec2(10.0, 10.0)), "chevron-down", 9.0, t.text_faint);
resp.widget_info(|| egui::WidgetInfo::labeled(egui::WidgetType::Button, true, tl!("Brush Preset picker")));
let resp = resp.on_hover_text(tl!("Brush Preset picker"));
egui::Popup::from_toggle_button_response(&resp)
.close_behavior(egui::PopupCloseBehavior::CloseOnClickOutside)
.show(|ui| crate::brush_picker::body(ui, b, presets))
.and_then(|r| r.inner)
if resp.on_hover_text(tl!("Brush Preset picker")).clicked() {
if state.brush_picker.is_some() {
crate::brush_picker::close(state);
} else {
state.brush_picker = Some([r.left(), r.bottom() + 2.0]);
}
}
}
/// Drag a layer row to reorder: drop on the upper/lower half to place above/below, or on the middle
+6 -1
View File
@@ -730,9 +730,13 @@ pub struct UiState {
/// tools edit it (#196). Never set together with `mask_target`.
#[serde(default)]
pub vector_mask_target: bool,
/// Brush Preset picker opened by a right-click on the canvas: its screen position (points).
/// Brush Preset picker opened by a right-click on the canvas or the options-bar brush chip:
/// its screen position (points).
#[serde(default)]
pub brush_picker: Option<[f32; 2]>,
/// The Brush Preset picker's preset list: search, collapsed groups, view, a rename in progress.
#[serde(default = "crate::brush_picker::list_state")]
pub brush_picker_list: crate::brush_panel::BrushesPanelState,
/// Layers under the pointer, listed by a right-click on the canvas with the Move tool or
/// ⌘/Ctrl+right-click with any tool (`layer_pick_ui`, #307).
#[serde(default)]
@@ -858,6 +862,7 @@ impl Default for UiState {
mask_target: false,
vector_mask_target: false,
brush_picker: None,
brush_picker_list: crate::brush_picker::list_state(),
layer_menu: None,
canvas_tool_menu: None,
smoothing_tool: None,
+1 -1
View File
@@ -35,7 +35,7 @@ The transport is `apps/photocraft/src/control_server.rs`, and the handlers are i
- `engine.execute {command, params}`: run any engine or UI command by id. Engine commands run directly with their default params and never open a dialog. Use `ui.menu.invoke` for menu-click behaviour, which opens a command's dialog when no params are given. `params` must be a JSON object (omit it or pass `null` for none); an array, string, number or boolean is an error naming the command, in every transport (control channel, `serve`, MCP and the CLI)
- `engine.commands`: list commands with enablement
- `ui.inspect`: full UI state (tool, panels, views, dialogs, windows, window size). The menu tree is not included; use `ui.menu.list`. `view` holds the View/Window/Type preferences: `screen_mode`, `extras`, `show` and `snap_to` flags, `flip_horizontal`, `arrange` (Window › Arrange layout), pixel aspect, font preview size, language options. `perf.timings.gpuInfo` holds the graphics adapter, backend, driver, the backend chosen at launch and why, the canvas renderer (`gpu`/`cpu`) and, after a device loss, `lost` (`help.systemInfo` returns the same as `info`)
- `ui.set {tool?, panels?, dockTabs?, dock?, dockWidth?, colorPanel?, maskTarget?, vectorMaskTarget?, selectionMode?, zoom?, center?, fit?, theme?, brushSize?, brushSection?, brushTab?, brushesView?}`: change UI state; any other field is an error, checked before anything changes (`theme` is `pro`, `proMedium`, `studio`, `studioLight` or `classic`; `selectionMode` is the selection tools' options-bar mode, 0 New, 1 Add, 2 Subtract, 3 Intersect; `brushSection` indexes the Brush Settings sections, `brushTab` 0 = Brush Settings, 1 = Brushes; `dock` is `{order: ["layers", …], heights: {"properties": 180}, collapsed: ["color"]}`, the right-dock groups top to bottom, their heights in points and the groups collapsed to their tab strip; `dockWidth` sets the right dock width in points, clamped to 250..520; `colorPanel` is `{background}`, whether the Color panel edits the background colour)
- `ui.set {tool?, panels?, dockTabs?, dock?, dockWidth?, colorPanel?, maskTarget?, vectorMaskTarget?, selectionMode?, zoom?, center?, fit?, theme?, brushSize?, brushSection?, brushTab?, brushesView?, brushPicker?, brushPickerView?}`: change UI state; any other field is an error, checked before anything changes (`theme` is `pro`, `proMedium`, `studio`, `studioLight` or `classic`; `selectionMode` is the selection tools' options-bar mode, 0 New, 1 Add, 2 Subtract, 3 Intersect; `brushSection` indexes the Brush Settings sections, `brushTab` 0 = Brush Settings, 1 = Brushes; `brushesView` and `brushPickerView` are `list` or `grid` for the Brushes panel and the Brush Preset picker; `brushPicker` is `[x, y]` in screen points to open the Brush Preset picker there (as a right-click with a painting tool does) or `null` to close it, and picking a preset in it is `tools.setBrush {"preset": name}`; `dock` is `{order: ["layers", …], heights: {"properties": 180}, collapsed: ["color"]}`, the right-dock groups top to bottom, their heights in points and the groups collapsed to their tab strip; `dockWidth` sets the right dock width in points, clamped to 250..520; `colorPanel` is `{background}`, whether the Color panel edits the background colour)
- `ui.menu.invoke {id, wait?}` / `ui.menu.list`: activate a menu item by id; list the menu tree. A menu item that starts a background job (a filter without a dialog, such as Blur More) replies with the job's result once it has been applied; with `"wait": false` the reply is `{job, pending: true}` at once
- `ui.set` also accepts `gradientBlendMode` (a layer blend mode name, such as `Difference`) and `gradientClassic` (boolean) for the Gradient tool options bar.
Both gradient modes use the current preset, including its opacity stops. Select `Foreground to Transparent` through `gradient.presets.select`, or pass custom `stops` and `transparency: [[0,100],[1,0]]` (location 0..1, opacity 0..100). Use `applyToLayer: false` to edit only the tool preset. Classic gradient drags dispatch `paint.gradient` without overriding them.