mirror of
https://github.com/storytold/texturecraft.git
synced 2026-11-21 06:50:43 +01:00
Tool shelf: grey the tools that can't act on the selection
The shelf follows the reference order (Paint, Eraser, Path, Projection, Polygon fill, Smudge, Clone, picker, geometry mask; keys unchanged), greys each tool the selection can't take, with its name on hover, and greys quick mask Edit and Invert while the mask is off. Their shortcuts and menu items follow. Rendering hides the paint tools; baking keeps them greyed.
This commit is contained in:
1 parent
fc2f62656e
commit
e64385f331
5 files changed
+133
-59
No files matched your search
@@ -215,6 +215,9 @@ pub fn validate(workspace: &Workspace) -> Result<(), String> {
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
// The live dock
|
||||
|
||||
/// Height of a panel group's tab strip, in points
|
||||
pub(crate) const TAB_HEIGHT: f32 = 30.0;
|
||||
|
||||
/// Width of the bake layout's texture set and mesh map bakers column, in points
|
||||
const BAKERS_COLUMN_WIDTH: f32 = 200.0;
|
||||
/// Width of the bake layout's common and mesh map settings column, in points
|
||||
@@ -367,29 +370,42 @@ fn area_id() -> Id {
|
||||
Id::unique("texturecraft-docking")
|
||||
}
|
||||
|
||||
/// The dock look: every panel group is a card on the window's frame colour, its tab strip
|
||||
/// without hard lines, the shown tab a pill.
|
||||
fn style(ui: &Ui, t: &Tokens) -> DockStyle {
|
||||
let mut s = DockStyle::from_ui(ui);
|
||||
s.gap = f32::from(crate::theme::GUTTER);
|
||||
// Smallest panel extent a divider drag leaves.
|
||||
s.min_pane = 60.0;
|
||||
s.background = t.panel;
|
||||
s.tab_background = t.panel;
|
||||
s.active_background = t.button;
|
||||
s.text = t.text_strong;
|
||||
s.inactive_text = t.text_dim;
|
||||
s.border = egui::Stroke::NONE;
|
||||
s.accent = t.accent;
|
||||
s.floating_background = t.panel;
|
||||
s.floating_stroke = egui::Stroke::new(1.0, t.button_border);
|
||||
s.font = egui::FontId::proportional(12.5);
|
||||
s.min_tab_width = 54.0;
|
||||
s.tab_height = 30.0;
|
||||
// Panels arrange in a split tree around the viewport; floating title bars only move windows.
|
||||
s.new_dock_zones = false;
|
||||
s.title_bar_docks = false;
|
||||
s
|
||||
/// Smallest panel extent a divider drag leaves, in points
|
||||
const MIN_PANE_EXTENT: f32 = 60.0;
|
||||
|
||||
/// Border width of a floating panel, in points
|
||||
const FLOATING_BORDER_WIDTH: f32 = 1.0;
|
||||
|
||||
/// Text size of the panel tabs, in points
|
||||
const TAB_TEXT_SIZE: f32 = 12.5;
|
||||
|
||||
/// Narrowest panel tab, in points
|
||||
const MIN_TAB_WIDTH: f32 = 54.0;
|
||||
|
||||
/// The dock look: each panel group a card on the window's frame colour, tab strips without hard lines, the shown tab a pill
|
||||
fn style(ui: &Ui, tokens: &Tokens) -> DockStyle {
|
||||
let mut dock_style = DockStyle::from_ui(ui);
|
||||
dock_style.gap = f32::from(crate::theme::GUTTER);
|
||||
dock_style.min_pane = MIN_PANE_EXTENT;
|
||||
|
||||
dock_style.background = tokens.panel;
|
||||
dock_style.tab_background = tokens.panel;
|
||||
dock_style.active_background = tokens.button;
|
||||
dock_style.text = tokens.text_strong;
|
||||
dock_style.inactive_text = tokens.text_dim;
|
||||
dock_style.border = egui::Stroke::NONE;
|
||||
dock_style.accent = tokens.accent;
|
||||
dock_style.floating_background = tokens.panel;
|
||||
dock_style.floating_stroke = egui::Stroke::new(FLOATING_BORDER_WIDTH, tokens.button_border);
|
||||
|
||||
dock_style.font = egui::FontId::proportional(TAB_TEXT_SIZE);
|
||||
dock_style.min_tab_width = MIN_TAB_WIDTH;
|
||||
dock_style.tab_height = TAB_HEIGHT;
|
||||
|
||||
// Panels arrange in a split tree around the viewport; floating title bars only move windows
|
||||
dock_style.new_dock_zones = false;
|
||||
dock_style.title_bar_docks = false;
|
||||
dock_style
|
||||
}
|
||||
|
||||
/// Whether a modal layer or update dialog holds the input, so the panels, floating ones included,
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
|
||||
use egui::{Key, Modifiers};
|
||||
use serde_json::{Value, json};
|
||||
use texturecraft_engine::Tool;
|
||||
|
||||
use crate::TextureCraftApp;
|
||||
use crate::i18n::tr;
|
||||
@@ -110,7 +111,7 @@ fn is_ui(id: &str) -> bool {
|
||||
id.starts_with("ui.")
|
||||
}
|
||||
|
||||
/// Whether an item can run now.
|
||||
/// Whether an item can run now
|
||||
pub fn enabled(app: &TextureCraftApp, id: &str) -> bool {
|
||||
if let Some(panel) = crate::docking::view_panel(id) {
|
||||
return panel.available_in(app.ui.mode);
|
||||
@@ -123,7 +124,14 @@ pub fn enabled(app: &TextureCraftApp, id: &str) -> bool {
|
||||
if is_ui(id) {
|
||||
return true;
|
||||
}
|
||||
texturecraft_engine::find(id).is_some_and(|c| (c.enabled)(&app.session).is_ok())
|
||||
|
||||
// Scripts may pick any tool, but the shelf and its shortcuts offer only those that can act
|
||||
let tool = id.strip_prefix("tool.").and_then(|tool_id| Tool::ALL.into_iter().find(|tool| tool.id() == tool_id));
|
||||
if tool.is_some_and(|tool| !app.session.tool_usable(tool)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
texturecraft_engine::find(id).is_some_and(|command| (command.enabled)(&app.session).is_ok())
|
||||
}
|
||||
|
||||
/// Whether an id is implemented at all (parity report).
|
||||
|
||||
@@ -344,41 +344,90 @@ pub fn path_controls(app: &mut TextureCraftApp, ui: &mut egui::Ui) {
|
||||
}
|
||||
}
|
||||
|
||||
/// Shelf order of the tools; their shortcut keys follow `Tool::ALL`
|
||||
const SHELF_TOOLS: [Tool; 9] =
|
||||
[Tool::Paint, Tool::Eraser, Tool::Path, Tool::Projection, Tool::PolygonFill, Tool::Smudge, Tool::Clone, Tool::ColorPicker, Tool::GeometryMask];
|
||||
|
||||
/// The tools Baking keeps on its shelf, greyed
|
||||
const BAKING_SHELF_TOOLS: [Tool; 3] = [Tool::Paint, Tool::Eraser, Tool::PolygonFill];
|
||||
|
||||
/// Width of the tool shelf, in points
|
||||
const SHELF_WIDTH: f32 = 40.0;
|
||||
|
||||
/// Size of a shelf button, in points
|
||||
const SHELF_BUTTON_SIZE: f32 = 28.0;
|
||||
|
||||
/// Vertical gap between shelf buttons, in points
|
||||
const SHELF_BUTTON_SPACING: f32 = 3.0;
|
||||
|
||||
/// Space on each side of the lines between shelf groups, in points
|
||||
const SHELF_GROUP_GAP: f32 = 6.0;
|
||||
|
||||
/// Padding inside the shelf card around its buttons, in points (sides, then top and bottom)
|
||||
const SHELF_PADDING: egui::Margin = egui::Margin::symmetric(3, 6);
|
||||
|
||||
pub fn tool_shelf(app: &mut TextureCraftApp, ui: &mut egui::Ui) {
|
||||
let tokens = Tokens::get(ui.ctx());
|
||||
egui::Panel::left("tool_shelf").resizable(false).exact_size(40.0).show_separator_line(false).frame(egui::Frame::NONE).show(ui, |ui| {
|
||||
card(ui, &tokens, egui::Margin { left: GUTTER, right: 0, top: GUTTER, bottom: GUTTER }, egui::Margin::symmetric(3, 6), |ui| {
|
||||
ui.spacing_mut().item_spacing.y = 3.0;
|
||||
ui.add_enabled_ui(app.ui.mode == Mode::Painting, |ui| {
|
||||
for tool in Tool::ALL {
|
||||
let selected = app.ui.mode == Mode::Painting && app.session.tool.tool == tool;
|
||||
let hint = tip(&app.ui.keymap, tr(tool.label()), &format!("tool.{}", tool.id()));
|
||||
if icon_button(ui, tool_icon(tool), &hint, selected, 28.0).clicked() {
|
||||
egui::Panel::left("tool_shelf").resizable(false).exact_size(SHELF_WIDTH).show_separator_line(false).frame(egui::Frame::NONE).show(ui, |ui| {
|
||||
// The tools start level with the panels' contents, below their tab strips
|
||||
let top = GUTTER + crate::docking::TAB_HEIGHT as i8;
|
||||
card(ui, &tokens, egui::Margin { left: GUTTER, right: 0, top, bottom: GUTTER }, SHELF_PADDING, |ui| {
|
||||
ui.spacing_mut().item_spacing.y = SHELF_BUTTON_SPACING;
|
||||
|
||||
// Rendering has nothing to paint, so its shelf keeps only the buttons below the tools
|
||||
let tools: &[Tool] = match app.ui.mode {
|
||||
Mode::Painting => &SHELF_TOOLS,
|
||||
Mode::Baking => &BAKING_SHELF_TOOLS,
|
||||
Mode::Rendering => &[],
|
||||
};
|
||||
if !tools.is_empty() {
|
||||
for &tool in tools {
|
||||
let command = format!("tool.{}", tool.id());
|
||||
let hint = tip(&app.ui.keymap, tr(tool.label()), &command);
|
||||
let (usable, selected) = match app.ui.mode {
|
||||
// In bake mode Paint is the cage or skew brush while one of them is being painted
|
||||
Mode::Baking => {
|
||||
let bake_brush = tool == Tool::Paint && app.ui.bake_paint_brush.on;
|
||||
(bake_brush, bake_brush)
|
||||
}
|
||||
// A greyed tool never shows as selected, even while it stays equipped
|
||||
_ => {
|
||||
let usable = crate::menus::enabled(app, &command);
|
||||
(usable, usable && app.session.tool.tool == tool)
|
||||
}
|
||||
};
|
||||
let button = ui.add_enabled_ui(usable, |ui| icon_button(ui, tool_icon(tool), &hint, selected, SHELF_BUTTON_SIZE)).inner;
|
||||
if button.on_disabled_hover_text(tr(tool.label())).clicked() && app.ui.mode == Mode::Painting {
|
||||
app.run("tool.select", json!({"tool": tool.id()}));
|
||||
}
|
||||
}
|
||||
|
||||
ui.add_space(6.0);
|
||||
ui.add_space(SHELF_GROUP_GAP);
|
||||
ui.separator();
|
||||
ui.add_space(6.0);
|
||||
let quick_mask = &app.session.quick_mask;
|
||||
for (command, icon, label, selected) in [
|
||||
("viewport.quickMask", ic::SELECTION_BACKGROUND, tr("Quick mask"), quick_mask.enabled),
|
||||
("viewport.quickMask.edit", ic::SELECTION, tr("Edit quick mask"), quick_mask.editing),
|
||||
("viewport.quickMask.invert", ic::SELECTION_INVERSE, tr("Invert quick mask"), quick_mask.inverted),
|
||||
] {
|
||||
if icon_button(ui, icon, &tip(&app.ui.keymap, label, command), selected, 28.0).clicked() {
|
||||
app.run(command, json!({}));
|
||||
}
|
||||
}
|
||||
ui.add_space(SHELF_GROUP_GAP);
|
||||
}
|
||||
|
||||
ui.add_space(6.0);
|
||||
ui.separator();
|
||||
ui.add_space(6.0);
|
||||
if icon_button(ui, ic::SPHERE, tr("Add smart material from the shelf"), false, 28.0).clicked() {
|
||||
app.ui.dock.focus(Panel::Assets);
|
||||
let quick_mask = &app.session.quick_mask;
|
||||
for (command, icon, label, selected) in [
|
||||
("viewport.quickMask", ic::SELECTION_BACKGROUND, tr("Quick mask"), quick_mask.enabled),
|
||||
("viewport.quickMask.edit", ic::SELECTION, tr("Edit quick mask"), quick_mask.editing),
|
||||
("viewport.quickMask.invert", ic::SELECTION_INVERSE, tr("Invert quick mask"), quick_mask.inverted),
|
||||
] {
|
||||
let hint = tip(&app.ui.keymap, label, command);
|
||||
let button = ui.add_enabled_ui(crate::menus::enabled(app, command), |ui| icon_button(ui, icon, &hint, selected, SHELF_BUTTON_SIZE)).inner;
|
||||
if button.on_disabled_hover_text(label).clicked() {
|
||||
app.run(command, json!({}));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
ui.add_space(SHELF_GROUP_GAP);
|
||||
ui.separator();
|
||||
ui.add_space(SHELF_GROUP_GAP);
|
||||
let painting = app.ui.mode == Mode::Painting;
|
||||
if ui.add_enabled_ui(painting, |ui| icon_button(ui, ic::SPHERE, tr("Add smart material from the shelf"), false, SHELF_BUTTON_SIZE)).inner.clicked()
|
||||
{
|
||||
app.ui.dock.focus(Panel::Assets);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -34,6 +34,7 @@ mod shortcut_keys;
|
||||
mod skew_paint;
|
||||
mod split_divider;
|
||||
mod start_window;
|
||||
mod tool_availability;
|
||||
mod toolbar;
|
||||
|
||||
mod symmetry;
|
||||
@@ -43,39 +43,39 @@ fn tool_availability_snapshots() {
|
||||
let paint = add_layer(session, "layer.add.paint");
|
||||
select(session, paint, json!("content"));
|
||||
session.tool.tool = Tool::Paint;
|
||||
save(&mut harness, "01-paint-layer");
|
||||
save(&mut harness, "paint-layer");
|
||||
|
||||
let session = &mut harness.state_mut().session;
|
||||
let fill = add_layer(session, "layer.add.fill");
|
||||
select(session, fill, json!("content"));
|
||||
session.tool.tool = Tool::PolygonFill;
|
||||
save(&mut harness, "04-fill-content-polygon-fill");
|
||||
save(&mut harness, "fill-content-polygon-fill");
|
||||
|
||||
let session = &mut harness.state_mut().session;
|
||||
execute(session, "effect.add.filter", &json!({"layer": paint, "target": "content", "filter": "blur"})).unwrap();
|
||||
let filter = session.doc.project.layer(texturecraft_engine::core::LayerId(paint)).unwrap().content_effects.last().unwrap().id.0;
|
||||
select(session, paint, json!(filter));
|
||||
session.tool.tool = Tool::Paint;
|
||||
save(&mut harness, "07-filter");
|
||||
save(&mut harness, "filter");
|
||||
|
||||
let session = &mut harness.state_mut().session;
|
||||
execute(session, "mask.add.black", &json!({"layer": paint})).unwrap();
|
||||
select(session, paint, json!("mask"));
|
||||
session.tool.tool = Tool::Smudge;
|
||||
save(&mut harness, "05-mask-smudge");
|
||||
save(&mut harness, "mask-smudge");
|
||||
|
||||
let session = &mut harness.state_mut().session;
|
||||
let folder = add_layer(session, "layer.add.group");
|
||||
select(session, folder, json!("content"));
|
||||
session.tool.tool = Tool::Paint;
|
||||
save(&mut harness, "09-folder");
|
||||
save(&mut harness, "folder");
|
||||
|
||||
select_nothing(&mut harness.state_mut().session);
|
||||
save(&mut harness, "12-nothing-selected");
|
||||
save(&mut harness, "nothing-selected");
|
||||
|
||||
harness.state_mut().ui.mode = Mode::Baking;
|
||||
save(&mut harness, "15-bake");
|
||||
save(&mut harness, "baking");
|
||||
|
||||
harness.state_mut().ui.mode = Mode::Rendering;
|
||||
save(&mut harness, "16-render");
|
||||
save(&mut harness, "rendering");
|
||||
}
|
||||
Reference in new issue
Block a user