feat(editor): finalize M2 content workspace UX

This commit is contained in:
Rbanh committed 2026-07-22 17:14:07 -04:00
1 parent 93e23ba194
commit 106d947c98
69 files changed
+5893 -4343

No files matched your search

File diff suppressed because it is too large. Load diff
File diff suppressed because it is too large. Load diff
@@ -0,0 +1,234 @@
pub const DOCK_HEADER_HEIGHT: f32 = 36.0;
pub const WIDE_FULL_TOOLBAR_HEIGHT: f32 = 91.0;
pub const WIDE_DOCKED_TOOLBAR_HEIGHT: f32 = WIDE_FULL_TOOLBAR_HEIGHT - DOCK_HEADER_HEIGHT;
pub const COMPACT_FULL_TOOLBAR_HEIGHT: f32 = 124.0;
pub const COMPACT_DOCKED_TOOLBAR_HEIGHT: f32 = COMPACT_FULL_TOOLBAR_HEIGHT - DOCK_HEADER_HEIGHT;
pub const STATUS_BAR_HEIGHT: f32 = 32.0;
/// Width below which the 124 px compact reference replaces the one-row 91 px layout.
///
/// The wide row needs enough room for navigation, breadcrumbs, search, filtering, and view
/// controls without overlap. This is also the production breakpoint for Sources/Details panes.
pub const COMPACT_BREAKPOINT: f32 = 1000.0;
/// Width at which sort and thumbnail-scale controls move out of overflow and into the toolbar.
///
/// The 1240 px Penpot wide reference remains unchanged. Expanded workspaces gain the controls
/// without compressing navigation, breadcrumbs, search, or the Details action.
pub const EXPANDED_OPTIONS_BREAKPOINT: f32 = 1400.0;
pub const SOURCES_WIDTH: f32 = 216.0;
pub const DETAILS_WIDTH: f32 = 290.0;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum ContentBrowserChrome {
/// Includes the 36 px title row used by the standalone design reference and UI gallery.
Standalone,
/// The editor dock tab already owns the title row, leaving 55 px wide or 88 px compact chrome.
Docked,
}
impl ContentBrowserChrome {
pub const fn height(self, width: f32) -> f32 {
match (self, width < COMPACT_BREAKPOINT) {
(Self::Standalone, false) => WIDE_FULL_TOOLBAR_HEIGHT,
(Self::Docked, false) => WIDE_DOCKED_TOOLBAR_HEIGHT,
(Self::Standalone, true) => COMPACT_FULL_TOOLBAR_HEIGHT,
(Self::Docked, true) => COMPACT_DOCKED_TOOLBAR_HEIGHT,
}
}
pub(crate) const fn y_offset(self) -> f32 {
match self {
Self::Standalone => DOCK_HEADER_HEIGHT,
Self::Docked => 0.0,
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum ContentBrowserViewMode {
Grid,
List,
}
/// Stable row-major presentation order shared by production and gallery fixtures.
///
/// Folders keep their navigation semantics but do not own a separate layout pass: assets fill any
/// remaining cells in the final folder row.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum ContentBrowserGridEntry {
Folder(usize),
Asset(usize),
}
pub fn continuous_grid_entries(
folder_count: usize,
asset_count: usize,
) -> Vec<ContentBrowserGridEntry> {
(0..folder_count)
.map(ContentBrowserGridEntry::Folder)
.chain((0..asset_count).map(ContentBrowserGridEntry::Asset))
.collect()
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum ContentBrowserKindFilter {
All,
Model,
Texture,
Material,
Audio,
Level,
Prefab,
Builtin,
}
impl ContentBrowserKindFilter {
pub const ALL: [Self; 8] = [
Self::All,
Self::Model,
Self::Texture,
Self::Material,
Self::Audio,
Self::Level,
Self::Prefab,
Self::Builtin,
];
pub const fn label(self) -> &'static str {
match self {
Self::All => "All assets",
Self::Model => "Models",
Self::Texture => "Textures",
Self::Material => "Materials",
Self::Audio => "Audio",
Self::Level => "Levels",
Self::Prefab => "Prefabs",
Self::Builtin => "Built-ins",
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum ContentBrowserSort {
Name,
Kind,
Modified,
Size,
}
impl ContentBrowserSort {
pub const ALL: [Self; 4] = [Self::Name, Self::Kind, Self::Modified, Self::Size];
pub const fn label(self) -> &'static str {
match self {
Self::Name => "Name",
Self::Kind => "Type",
Self::Modified => "Modified",
Self::Size => "Size",
}
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ContentPathSegment {
pub path: String,
pub label: String,
}
#[derive(Debug, Clone)]
pub struct ContentBrowserToolbarViewModel {
pub chrome: ContentBrowserChrome,
pub path: Vec<ContentPathSegment>,
pub search: String,
pub kind_filter: ContentBrowserKindFilter,
pub sort: ContentBrowserSort,
pub view: ContentBrowserViewMode,
pub recursive: bool,
pub show_sources: bool,
pub show_details: bool,
pub thumbnail_size: f32,
pub can_go_parent: bool,
pub can_go_back: bool,
pub can_go_forward: bool,
pub can_edit_folder: bool,
pub can_rename: bool,
pub can_edit_selection: bool,
pub can_paste: bool,
pub can_undo: bool,
pub pending_repairs: usize,
pub direct_folder_count: usize,
pub direct_asset_count: usize,
}
#[derive(Debug, Clone, PartialEq)]
pub enum ContentBrowserToolbarAction {
Back,
Forward,
Parent,
Refresh,
Navigate(String),
ImportHere,
ImportTo,
NewFolder,
Rename,
Duplicate,
Undo,
Cut,
Copy,
Paste,
OpenTrash,
ReviewMoves,
SetSearch(String),
SetKindFilter(ContentBrowserKindFilter),
SetSort(ContentBrowserSort),
SetView(ContentBrowserViewMode),
SetRecursive(bool),
SetShowSources(bool),
SetShowDetails(bool),
SetThumbnailSize(f32),
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn penpot_content_browser_geometry_is_stable() {
assert_eq!(DOCK_HEADER_HEIGHT, 36.0);
assert_eq!(WIDE_FULL_TOOLBAR_HEIGHT, 91.0);
assert_eq!(WIDE_DOCKED_TOOLBAR_HEIGHT, 55.0);
assert_eq!(COMPACT_FULL_TOOLBAR_HEIGHT, 124.0);
assert_eq!(COMPACT_DOCKED_TOOLBAR_HEIGHT, 88.0);
assert_eq!(STATUS_BAR_HEIGHT, 32.0);
assert_eq!(EXPANDED_OPTIONS_BREAKPOINT, 1400.0);
assert_eq!(SOURCES_WIDTH, 216.0);
assert_eq!(DETAILS_WIDTH, 290.0);
assert_eq!(ContentBrowserChrome::Standalone.height(1240.0), 91.0);
assert_eq!(ContentBrowserChrome::Docked.height(1240.0), 55.0);
assert_eq!(ContentBrowserChrome::Standalone.height(620.0), 124.0);
assert_eq!(ContentBrowserChrome::Docked.height(620.0), 88.0);
}
#[test]
fn filters_and_sorts_have_stable_labels() {
assert_eq!(ContentBrowserKindFilter::ALL.len(), 8);
assert_eq!(ContentBrowserKindFilter::All.label(), "All assets");
assert_eq!(ContentBrowserSort::ALL.len(), 4);
assert_eq!(ContentBrowserSort::Kind.label(), "Type");
}
#[test]
fn assets_fill_the_remaining_cells_in_a_folder_row() {
let entries = continuous_grid_entries(2, 3);
let rows = entries.chunks(4).collect::<Vec<_>>();
assert_eq!(
rows[0],
[
ContentBrowserGridEntry::Folder(0),
ContentBrowserGridEntry::Folder(1),
ContentBrowserGridEntry::Asset(0),
ContentBrowserGridEntry::Asset(1),
]
);
assert_eq!(rows[1], [ContentBrowserGridEntry::Asset(2)]);
}
}
@@ -7,6 +7,7 @@ use egui;
use super::typography::TypeRole;
pub(super) const POPUP_SIZE: egui::Vec2 = egui::vec2(420.0, 350.0);
const COLOR_SWATCH_OUTER_RADIUS: u8 = 3;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub(super) enum PickerMode {
@@ -72,21 +73,27 @@ fn color_control_impl(
egui::vec2((width - swatch_width - gap).max(0.0), 22.0),
);
popup::checker(ui.painter(), swatch_rect, palette.control, palette.elevated);
let inner_swatch = swatch_rect.shrink(1.0);
let rgb_rect = egui::Rect::from_min_max(
inner_swatch.min,
egui::pos2(inner_swatch.center().x, inner_swatch.max.y),
);
let alpha_rect = egui::Rect::from_min_max(
egui::pos2(inner_swatch.center().x, inner_swatch.min.y),
inner_swatch.max,
);
let (rgb_rect, alpha_rect) = color_swatch_halves(swatch_rect.shrink(1.0));
ui.painter().rect_filled(
rgb_rect,
3.0,
egui::CornerRadius {
nw: COLOR_SWATCH_OUTER_RADIUS,
ne: 0,
sw: COLOR_SWATCH_OUTER_RADIUS,
se: 0,
},
egui::Color32::from_rgb(byte(rgba[0]), byte(rgba[1]), byte(rgba[2])),
);
ui.painter().rect_filled(alpha_rect, 3.0, color32(*rgba));
ui.painter().rect_filled(
alpha_rect,
egui::CornerRadius {
nw: 0,
ne: COLOR_SWATCH_OUTER_RADIUS,
sw: 0,
se: COLOR_SWATCH_OUTER_RADIUS,
},
color32(*rgba),
);
ui.painter().rect_stroke(
swatch_rect,
4.0,
@@ -194,6 +201,14 @@ fn color_control_impl(
result
}
fn color_swatch_halves(inner: egui::Rect) -> (egui::Rect, egui::Rect) {
let split = inner.center().x;
(
egui::Rect::from_min_max(inner.min, egui::pos2(split, inner.max.y)),
egui::Rect::from_min_max(egui::pos2(split, inner.min.y), inner.max),
)
}
fn centered_popup_rect(owner: egui::Rect, screen: egui::Rect) -> egui::Rect {
const SCREEN_MARGIN: f32 = 12.0;
let desired = owner.center() - POPUP_SIZE * 0.5;
@@ -307,6 +322,30 @@ mod tests {
}
}
#[test]
fn inline_swatch_halves_share_one_unrounded_inner_edge() {
let inner = egui::Rect::from_min_size(egui::pos2(1.0, 1.0), egui::vec2(42.0, 20.0));
let (rgb, alpha) = color_swatch_halves(inner);
assert_eq!(rgb.right(), alpha.left());
assert_eq!(rgb.left(), inner.left());
assert_eq!(alpha.right(), inner.right());
assert_eq!(rgb.height(), alpha.height());
let left = egui::CornerRadius {
nw: COLOR_SWATCH_OUTER_RADIUS,
ne: 0,
sw: COLOR_SWATCH_OUTER_RADIUS,
se: 0,
};
let right = egui::CornerRadius {
nw: 0,
ne: COLOR_SWATCH_OUTER_RADIUS,
sw: 0,
se: COLOR_SWATCH_OUTER_RADIUS,
};
assert_eq!((left.ne, left.se, right.nw, right.sw), (0, 0, 0, 0));
}
#[test]
fn cancel_restores_opening_value_and_apply_keeps_live_preview() {
let original = [0.1, 0.2, 0.3, 1.0];
+39 -1
View File
@@ -7,6 +7,32 @@ use std::ops::RangeInclusive;
use super::palette;
use super::typography::TypeRole;
/// Phosphor font variant used by a design-system glyph.
///
/// Penpot names the intended variant for each icon. Keeping that choice explicit prevents a
/// correct codepoint from silently rendering with the wrong visual weight in production.
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
pub enum PhosphorIconStyle {
Regular,
#[default]
Bold,
Fill,
}
impl PhosphorIconStyle {
const fn family(self) -> &'static str {
match self {
Self::Regular => "phosphor-regular",
Self::Bold => "phosphor-bold",
Self::Fill => "phosphor-fill",
}
}
}
pub fn phosphor_icon_font(style: PhosphorIconStyle, size: f32) -> egui::FontId {
egui::FontId::new(size, egui::FontFamily::Name(style.family().into()))
}
// Penpot's scalar component keeps a six-pixel leading inset inside its value-group frame. The
// exported child geometry is authoritative here; the group's transparent parent frame is six
// pixels narrower than its visible children and must not be mistaken for the control width.
@@ -85,13 +111,25 @@ pub fn icon_label(
role: TypeRole,
icon_size: f32,
color: egui::Color32,
) -> egui::WidgetText {
icon_label_with_style(icon, label, role, icon_size, color, PhosphorIconStyle::Bold)
}
/// Compose a Phosphor glyph in its authored visual weight with a Source Sans label.
pub fn icon_label_with_style(
icon: Icon,
label: &str,
role: TypeRole,
icon_size: f32,
color: egui::Color32,
style: PhosphorIconStyle,
) -> egui::WidgetText {
let mut job = egui::text::LayoutJob::default();
job.append(
icon.as_str(),
0.0,
egui::TextFormat {
font_id: egui::FontId::new(icon_size, egui::FontFamily::Name("phosphor-bold".into())),
font_id: phosphor_icon_font(style, icon_size),
color,
..Default::default()
},
+4 -1
View File
@@ -10,7 +10,7 @@ pub mod typography;
use egui::{self, Color32, CornerRadius, Stroke};
use crate::theme::EditorVisualPalette;
use crate::theme::{AssetTypePalette, EditorVisualPalette};
pub const REFERENCE_WIDTH: f32 = 620.0;
pub const INSPECTOR_MIN_WIDTH: f32 = 420.0;
@@ -52,6 +52,7 @@ pub struct DesignPalette {
pub healthy: Color32,
pub warning: Color32,
pub error: Color32,
pub asset_types: AssetTypePalette,
}
impl From<EditorVisualPalette> for DesignPalette {
@@ -75,6 +76,7 @@ impl From<EditorVisualPalette> for DesignPalette {
healthy: value.success,
warning: value.warning,
error: value.error,
asset_types: value.asset_types,
}
}
}
@@ -149,5 +151,6 @@ mod tests {
assert_eq!(palette.accent, crate::theme::SELECTION);
assert_eq!(palette.panel, crate::theme::PANEL_BG);
assert_eq!(palette.text_primary, crate::theme::TEXT);
assert_eq!(palette.asset_types, crate::theme::ASSET_TYPES);
}
}
+31 -17
View File
@@ -10,8 +10,10 @@ use crate::design_system::controls::status;
use crate::design_system::typography::TypeRole;
use crate::design_system::{self, DesignPalette, HEADER_HEIGHT};
mod drop_feedback;
mod header_actions;
use drop_feedback::{accepted_drop_action, paint_material_drop_feedback, MaterialDropVisualState};
use header_actions::{expanded_status_actions, overflow_menu, SLOT_STATUS_ACTION_WIDTH};
// `Frame` reserves one pixel for the slot stroke before handing its child Ui to us. These local
@@ -252,7 +254,7 @@ pub fn material_slot_panel(
&mut slot_actions,
diagnostics_ui,
);
if parameters_open {
if parameters_open && (view.assigned.is_some() || view.effective.is_some()) {
parameter_body(ui, content_ui);
}
ui.ctx()
@@ -287,6 +289,34 @@ fn slot_header(
};
let width = ui.available_width().max(1.0);
let (rect, response) = ui.allocate_exact_size(egui::vec2(width, height), egui::Sense::click());
let target_hovered = ui.rect_contains_pointer(rect);
if let Some(drop_state) = MaterialDropVisualState::from_view(view, target_hovered) {
paint_material_drop_feedback(ui, rect, drop_state, palette);
if drop_state == MaterialDropVisualState::Empty {
super::pickers::material_picker_popup(
ui,
id.with("material_picker"),
&response,
view,
actions,
);
}
if let Some(action) = accepted_drop_action(
drop_state,
ui.input(|input| input.pointer.any_released()),
view.drop_candidate.as_ref(),
) {
actions.push(action);
}
if drop_state == MaterialDropVisualState::Incompatible {
response.on_hover_text(
view.invalid_drop_reason
.as_deref()
.unwrap_or("Expected a Material asset"),
);
}
return;
}
ui.painter().rect_filled(rect, 7.0, palette.recessed);
ui.painter().rect_filled(
egui::Rect::from_min_size(
@@ -392,22 +422,6 @@ fn slot_header(
view,
actions,
);
if response.hovered()
&& view.drop_candidate.is_some()
&& ui.input(|input| input.pointer.any_released())
{
if let Some(candidate) = view.drop_candidate.as_ref() {
actions.push(MaterialSlotAction::Assign {
reference: candidate.reference.clone(),
from_drop: true,
});
}
}
if response.hovered() {
if let Some(reason) = view.invalid_drop_reason.as_deref() {
response.on_hover_text(reason);
}
}
}
fn compact_material_identity(
@@ -0,0 +1,412 @@
//! Transient assignment and drag feedback for the complete material-slot header.
use egui;
use egui_phosphor_icons::icons;
use super::{MaterialPickerCandidate, MaterialSlotAction, MaterialSlotPanelViewModel};
use crate::design_system::typography::TypeRole;
use crate::design_system::DesignPalette;
const ZONE_INSET: f32 = 1.0;
const CONTENT_INSET: f32 = 8.0;
const ICON_SIZE: f32 = 48.0;
const BUTTON_WIDTH: f32 = 130.0;
const COMPACT_BUTTON_WIDTH: f32 = 116.0;
const BUTTON_HEIGHT: f32 = 30.0;
const CONTENT_GAP: f32 = 10.0;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub(super) enum MaterialDropVisualState {
Empty,
Compatible,
Incompatible,
}
impl MaterialDropVisualState {
pub(super) fn from_view(
view: &MaterialSlotPanelViewModel,
target_hovered: bool,
) -> Option<Self> {
if target_hovered && view.drop_candidate.is_some() {
Some(Self::Compatible)
} else if target_hovered && view.invalid_drop_reason.is_some() {
Some(Self::Incompatible)
} else if view.assigned.is_none() && view.effective.is_none() {
Some(Self::Empty)
} else {
None
}
}
fn copy(self) -> (&'static str, &'static str, &'static str) {
match self {
Self::Empty => (
"No material assigned",
"Drop a material here or choose from the browser",
"Choose material",
),
Self::Compatible => (
"Relevant project material",
"Compatible Material asset",
"Drop material",
),
Self::Incompatible => (
"Incompatible asset",
"Expected a Material asset",
"Cannot assign",
),
}
}
}
pub(super) fn accepted_drop_action(
state: MaterialDropVisualState,
pointer_released: bool,
candidate: Option<&MaterialPickerCandidate>,
) -> Option<MaterialSlotAction> {
if state != MaterialDropVisualState::Compatible || !pointer_released {
return None;
}
candidate.map(|candidate| MaterialSlotAction::Assign {
reference: candidate.reference.clone(),
from_drop: true,
})
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub(super) struct MaterialDropFeedbackGeometry {
pub zone: egui::Rect,
pub icon: egui::Rect,
pub text: egui::Rect,
pub action: egui::Rect,
}
impl MaterialDropFeedbackGeometry {
pub(super) fn from_header(header: egui::Rect) -> Self {
let zone = header.shrink(ZONE_INSET);
let icon = egui::Rect::from_center_size(
egui::pos2(
zone.left() + CONTENT_INSET + ICON_SIZE * 0.5,
zone.center().y,
),
egui::vec2(ICON_SIZE, ICON_SIZE),
);
let available_button_width = if zone.width() >= 430.0 {
BUTTON_WIDTH
} else {
COMPACT_BUTTON_WIDTH
};
let action = egui::Rect::from_center_size(
egui::pos2(
zone.right() - CONTENT_INSET - available_button_width * 0.5,
zone.center().y,
),
egui::vec2(available_button_width, BUTTON_HEIGHT),
);
let text = egui::Rect::from_min_max(
egui::pos2(icon.right() + CONTENT_GAP, icon.top()),
egui::pos2(
(action.left() - CONTENT_GAP).max(icon.right() + CONTENT_GAP),
icon.bottom(),
),
);
Self {
zone,
icon,
text,
action,
}
}
#[cfg(test)]
pub(super) fn is_finite_and_contained(self) -> bool {
[self.zone, self.icon, self.text, self.action]
.into_iter()
.all(|rect| rect.is_finite() && self.zone.contains_rect(rect))
}
}
pub(super) fn paint_material_drop_feedback(
ui: &egui::Ui,
header: egui::Rect,
state: MaterialDropVisualState,
palette: DesignPalette,
) {
let geometry = MaterialDropFeedbackGeometry::from_header(header);
let (title, detail, action_label) = state.copy();
let (fill, stroke, detail_color, icon_fill) = match state {
MaterialDropVisualState::Empty => (
palette.recessed,
palette.border_strong,
palette.text_muted,
palette.elevated,
),
MaterialDropVisualState::Compatible => (
palette.accent_dark,
palette.accent,
palette.accent,
palette.accent_dark,
),
MaterialDropVisualState::Incompatible => (
palette.elevated,
palette.error,
palette.error,
palette.control,
),
};
ui.painter().rect_filled(geometry.zone, 7.0, fill);
if state == MaterialDropVisualState::Empty {
paint_dashed_rect(ui.painter(), geometry.zone, 7.0, stroke);
} else {
ui.painter().rect_stroke(
geometry.zone,
7.0,
egui::Stroke::new(2.0_f32, stroke),
egui::StrokeKind::Inside,
);
}
ui.painter().rect(
geometry.icon,
4.0,
icon_fill,
egui::Stroke::new(1.0_f32, palette.border_strong),
egui::StrokeKind::Inside,
);
ui.painter().text(
geometry.icon.center(),
egui::Align2::CENTER_CENTER,
icons::PALETTE.as_str(),
egui::FontId::new(18.0, egui::FontFamily::Name("phosphor-regular".into())),
if state == MaterialDropVisualState::Incompatible {
palette.text_muted
} else {
palette.accent
},
);
let title_pos = egui::pos2(geometry.text.left(), geometry.text.center().y - 8.0);
let detail_pos = egui::pos2(geometry.text.left(), geometry.text.center().y + 8.0);
let text_painter = ui.painter().with_clip_rect(geometry.text);
text_painter.text(
title_pos,
egui::Align2::LEFT_CENTER,
title,
TypeRole::AssetTitle.font(),
palette.text_primary,
);
text_painter.text(
detail_pos,
egui::Align2::LEFT_CENTER,
detail,
TypeRole::Small.font(),
detail_color,
);
ui.painter().rect(
geometry.action,
5.0,
palette.control,
egui::Stroke::new(
1.0_f32,
if state == MaterialDropVisualState::Incompatible {
palette.error
} else {
palette.accent
},
),
egui::StrokeKind::Inside,
);
let label_width = ui
.painter()
.layout_no_wrap(
action_label.to_owned(),
TypeRole::Control.font(),
palette.text_primary,
)
.size()
.x;
let group_width = 14.0 + 6.0 + label_width;
let group_left = geometry.action.center().x - group_width * 0.5;
ui.painter().text(
egui::pos2(group_left + 7.0, geometry.action.center().y),
egui::Align2::CENTER_CENTER,
icons::FOLDER_OPEN.as_str(),
egui::FontId::new(14.0, egui::FontFamily::Name("phosphor-regular".into())),
if state == MaterialDropVisualState::Incompatible {
palette.error
} else {
palette.accent
},
);
ui.painter().text(
egui::pos2(group_left + 20.0, geometry.action.center().y),
egui::Align2::LEFT_CENTER,
action_label,
TypeRole::Control.font(),
palette.text_primary,
);
}
fn paint_dashed_rect(painter: &egui::Painter, rect: egui::Rect, radius: f32, color: egui::Color32) {
let stroke = egui::Stroke::new(1.0_f32, color);
let dash = 9.0;
let gap = 7.0;
let inset = radius.max(2.0);
for (from, to) in [
(
egui::pos2(rect.left() + inset, rect.top()),
egui::pos2(rect.right() - inset, rect.top()),
),
(
egui::pos2(rect.left() + inset, rect.bottom()),
egui::pos2(rect.right() - inset, rect.bottom()),
),
(
egui::pos2(rect.left(), rect.top() + inset),
egui::pos2(rect.left(), rect.bottom() - inset),
),
(
egui::pos2(rect.right(), rect.top() + inset),
egui::pos2(rect.right(), rect.bottom() - inset),
),
] {
let vector = to - from;
let length = vector.length();
if length <= f32::EPSILON {
continue;
}
let direction = vector / length;
let mut offset = 0.0;
while offset < length {
let end = (offset + dash).min(length);
painter.line_segment([from + direction * offset, from + direction * end], stroke);
offset += dash + gap;
}
}
}
#[cfg(test)]
mod tests {
use super::*;
use crate::materials::{MaterialHealth, MaterialThumbnailPresentation};
fn view() -> MaterialSlotPanelViewModel {
MaterialSlotPanelViewModel {
slot_id: "slot:test".into(),
label: "No material assigned".into(),
path: None,
shader: String::new(),
shader_kind: None,
can_edit_shader: false,
thumbnail: MaterialThumbnailPresentation::Empty,
inherited: None,
health: MaterialHealth::Healthy,
assigned: None,
effective: None,
candidates: Vec::new(),
drop_candidate: None,
invalid_drop_reason: None,
can_locate: false,
can_clear: false,
can_extract: false,
can_create_instance: false,
parameters_initially_open: false,
expanded_header_when_parameters_closed: false,
}
}
#[test]
fn drop_state_matrix_prioritizes_targeted_feedback() {
let mut view = view();
assert_eq!(
MaterialDropVisualState::from_view(&view, false),
Some(MaterialDropVisualState::Empty)
);
view.drop_candidate = Some(super::super::MaterialPickerCandidate {
reference: material_schema::EditorAssetRef::new("mat", "material:source", "M_Test"),
label: "M_Test".into(),
detail: "assets/materials/M_Test.ron".into(),
thumbnail: MaterialThumbnailPresentation::Empty,
});
assert_eq!(
MaterialDropVisualState::from_view(&view, true),
Some(MaterialDropVisualState::Compatible)
);
view.drop_candidate = None;
view.invalid_drop_reason = Some("Expected a Material asset".into());
assert_eq!(
MaterialDropVisualState::from_view(&view, true),
Some(MaterialDropVisualState::Incompatible)
);
assert_eq!(
MaterialDropVisualState::from_view(&view, false),
Some(MaterialDropVisualState::Empty)
);
}
#[test]
fn assigned_slots_only_replace_the_header_while_targeted() {
let mut view = view();
view.assigned = Some(material_schema::EditorAssetRef::new(
"mat",
"material:source",
"M_Test",
));
view.effective = view.assigned.clone();
assert_eq!(MaterialDropVisualState::from_view(&view, false), None);
view.invalid_drop_reason = Some("Expected a Material asset".into());
assert_eq!(
MaterialDropVisualState::from_view(&view, true),
Some(MaterialDropVisualState::Incompatible)
);
}
#[test]
fn only_a_released_compatible_candidate_emits_an_assignment() {
let candidate = MaterialPickerCandidate {
reference: material_schema::EditorAssetRef::new("mat", "material:source", "M_Test"),
label: "M_Test".into(),
detail: "assets/materials/M_Test.ron".into(),
thumbnail: MaterialThumbnailPresentation::Empty,
};
assert_eq!(
accepted_drop_action(MaterialDropVisualState::Compatible, true, Some(&candidate)),
Some(MaterialSlotAction::Assign {
reference: candidate.reference.clone(),
from_drop: true,
})
);
assert_eq!(
accepted_drop_action(MaterialDropVisualState::Compatible, false, Some(&candidate)),
None
);
assert_eq!(
accepted_drop_action(
MaterialDropVisualState::Incompatible,
true,
Some(&candidate)
),
None
);
assert_eq!(
accepted_drop_action(MaterialDropVisualState::Compatible, true, None),
None
);
}
#[test]
fn feedback_geometry_is_finite_and_bounded_at_wide_and_narrow_widths() {
for width in [396.0, 596.0] {
let header = egui::Rect::from_min_size(
egui::pos2(12.0, 24.0),
egui::vec2(width, crate::design_system::HEADER_HEIGHT),
);
let geometry = MaterialDropFeedbackGeometry::from_header(header);
assert!(geometry.is_finite_and_contained());
assert_eq!(geometry.icon.size(), egui::vec2(48.0, 48.0));
assert_eq!(geometry.action.height(), 30.0);
assert!(geometry.text.right() <= geometry.action.left());
}
}
}
+35
View File
@@ -2,6 +2,26 @@
use egui::{self, Color32, CornerRadius, FontId, Id, Stroke, Visuals};
/// Theme-owned colors for Content Browser asset categories.
///
/// These are classification colors, not health or selection states. Keeping them in the palette
/// lets a future Editor Settings theme change the vocabulary without teaching cards about theme
/// preferences.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct AssetTypePalette {
pub primitive: Color32,
pub light: Color32,
pub model: Color32,
pub texture: Color32,
pub material: Color32,
pub audio: Color32,
pub level: Color32,
pub prefab: Color32,
pub post_process: Color32,
pub rendering_profile: Color32,
pub shader: Color32,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct EditorVisualPalette {
pub canvas: Color32,
@@ -24,6 +44,7 @@ pub struct EditorVisualPalette {
pub success: Color32,
pub warning: Color32,
pub error: Color32,
pub asset_types: AssetTypePalette,
}
pub const CANVAS_BG: Color32 = Color32::from_rgb(7, 8, 10);
@@ -46,6 +67,19 @@ pub const BORDER_STRONG: Color32 = Color32::from_rgb(64, 71, 79);
pub const SUCCESS: Color32 = Color32::from_rgb(84, 190, 127);
pub const WARNING: Color32 = Color32::from_rgb(235, 180, 72);
pub const ERROR: Color32 = Color32::from_rgb(226, 94, 94);
pub const ASSET_TYPES: AssetTypePalette = AssetTypePalette {
primitive: Color32::from_rgb(138, 155, 173),
light: Color32::from_rgb(244, 211, 94),
model: Color32::from_rgb(91, 143, 249),
texture: Color32::from_rgb(84, 190, 127),
material: Color32::from_rgb(235, 180, 72),
audio: Color32::from_rgb(208, 125, 232),
level: Color32::from_rgb(65, 198, 207),
prefab: Color32::from_rgb(79, 182, 166),
post_process: Color32::from_rgb(167, 139, 250),
rendering_profile: Color32::from_rgb(154, 167, 184),
shader: Color32::from_rgb(240, 124, 99),
};
pub const BLACKSITE_PALETTE: EditorVisualPalette = EditorVisualPalette {
canvas: CANVAS_BG,
@@ -68,6 +102,7 @@ pub const BLACKSITE_PALETTE: EditorVisualPalette = EditorVisualPalette {
success: SUCCESS,
warning: WARNING,
error: ERROR,
asset_types: ASSET_TYPES,
};
const EDITOR_PALETTE_ID: &str = "blacksite.editor.visual_palette";