Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
e784d28
fix(core): reject negative overlay table sizes
dimspell Nov 24, 2026
6b421d0
fix(core): bound embedded sprite frame count
dimspell Nov 24, 2026
ec11cec
fix(core): reject negative sprite block counts
dimspell Nov 24, 2026
57ba629
fix(gui): surface workspace load errors
dimspell Nov 24, 2026
b90cce0
fix(core): size WAV output from actual PCM bytes
dimspell Nov 24, 2026
ec8c782
fix(gui): preserve unsaved item edits when loading the store catalog
dimspell Nov 24, 2026
52fbf74
fix(gui): count only parsed event scripts and report index save errors
dimspell Nov 24, 2026
d1b9792
fix(hexedit): make byte colors theme-aware
dimspell Nov 24, 2026
6b64fe6
fix(hexedit): apply the active Iced theme in the standalone binary
dimspell Nov 24, 2026
f723a5a
fix(hexedit): use theme-aware diff byte text colors
dimspell Nov 24, 2026
5e027d4
fix(hexedit): render two-digit hex column labels
dimspell Nov 24, 2026
6b9caf4
fix(gui): mirror flipped entity sprites
dimspell Nov 24, 2026
51360b3
fix(gui): show the hover ring when nothing is selected
dimspell Nov 24, 2026
03d18bb
fix(gui): anchor toolbar zoom at the viewport center
dimspell Nov 24, 2026
0169ac5
fix(gui): fit and clip the sprite preview
dimspell Nov 24, 2026
a8d17df
fix(gui): show disabled state in shared button styles
dimspell Nov 24, 2026
1debd00
fix(gui): expand ancestors of file-tree search matches
dimspell Nov 24, 2026
c0c495a
fix(gui): label composite inspector fields with lookups loaded
dimspell Nov 24, 2026
03435eb
fix(gui): replace static loading progress bars with an indeterminate …
dimspell Nov 24, 2026
4931175
fix(gui): wire inspector lookup fallback text input
dimspell Nov 24, 2026
0a20385
fix(gui): key toast timers by stable id and reset on replace
dimspell Nov 24, 2026
70c14ba
fix(gui): explain empty and filtered-out tables
dimspell Nov 24, 2026
565fcfa
fix(gui): reset zoom when fitting sprite preview
dimspell Nov 24, 2026
e2375de
fix(gui): avoid duplicate labels on composite inspector fields
dimspell Nov 24, 2026
cc527b0
fix(gui): initialize filtered indices when scanning store
dimspell Nov 24, 2026
1e0ad1d
refactor(gui): remove unused style functions
dimspell Nov 24, 2026
1aaf017
refactor(gui): remove duplicate scan and save palette commands
dimspell Nov 24, 2026
c86b029
refactor(gui): remove duplicate store editor palette command
dimspell Nov 24, 2026
6170167
fix(gui): populate spreadsheet cell cache after store scan
dimspell Nov 24, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ dispel-extractor/
│ ├── dispatch_table.rs # Editor message dispatch table
│ ├── binary_layout.rs # Binary layout helpers
│ ├── indexation/ # File/asset caching + full-text search
│ ├── tests/ # Dedicated GUI test suite (28 test files)
│ ├── tests/ # Dedicated GUI test suite (29 test files)
│ └── recording_tests.rs # Mod recording integration tests (38 tests)
├── examples/ # e.g. check_save_roundtrip.rs
├── docs/ # Overview .md files + docs/files/ (36 per-format + CROSS_REFERENCES.md = 37)
Expand Down Expand Up @@ -228,7 +228,7 @@ Structure:
- Top level: `app.rs`, `config.rs`, `state.rs`, `message.rs`, `main.rs`
- `domain/` (~16 files): editing, goto, pattern, provider, search, selection, vanilla_diff, …
- `ui/`: coloring, inspector, update, view/, theme
- `tests/`: 16 dedicated test files (**25 `.rs` files with `#[cfg(test)]` total**)
- `tests/`: 16 dedicated test files (**26 `.rs` files with `#[cfg(test)]` total**)

**Used by `dispel-gui`:** stored as `HashMap<usize, HexEditorState>` in `EditorRegistry`, rendered in tabs, with save wired to mod packager via the domain-level `SavePort` (`SaveRequest` → `SaveOutcome`) in `hex_save.rs`.

Expand Down
425 changes: 0 additions & 425 deletions dispel-gui/src/components/command_palette.rs

Large diffs are not rendered by default.

89 changes: 71 additions & 18 deletions dispel-gui/src/components/composite_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,45 @@ use iced::{Element, Length};
use crate::message::Message;
use crate::style;

const LABEL_W: f32 = 140.0;

/// Render a picker body, optionally prefixed with a fixed-width label column.
///
/// Callers that already render a label above the field pass `show_label = false`
/// so the text is not drawn twice.
fn with_optional_label<'a>(
label: &'static str,
body: Element<'a, Message>,
show_label: bool,
) -> Element<'a, Message> {
if show_label {
row![
text(label)
.size(11)
.width(LABEL_W)
.style(style::subtle_text),
body,
]
.spacing(6)
.align_y(iced::Alignment::Center)
.into()
} else {
body
}
}

/// Build a cascading item-type + item-id picker for `CompositeItem` fields.
///
/// Renders two pick-lists (type then item). Falls back to a plain `text_input`
/// when `entries` is `None` (lookups unavailable).
/// when `entries` is `None` (lookups unavailable). `show_label` controls whether
/// the label column is drawn by this component or by the caller.
pub fn composite_item_picker(
label: &'static str,
value: &str,
entries: Option<&[(String, String)]>,
show_label: bool,
on_change: impl Fn(String) -> Message + 'static,
) -> Element<'static, Message> {
const LABEL_W: f32 = 140.0;

let current_type_byte: u8 = value
.split(':')
.next()
Expand All @@ -31,20 +58,13 @@ pub fn composite_item_picker(

let Some(entries) = entries else {
let oc = on_change;
return row![
text(label)
.size(11)
.width(LABEL_W)
.style(style::subtle_text),
text_input("", value.to_owned())
.on_input(move |v| oc(v))
.padding(4)
.size(11)
.width(Length::Fill),
]
.spacing(6)
.align_y(iced::Alignment::Center)
.into();
let input: Element<'static, Message> = text_input("", value.to_owned())
.on_input(move |v| oc(v))
.padding(4)
.size(11)
.width(Length::Fill)
.into();
return with_optional_label(label, input, show_label);
};

// Deduplicated type list, preserving insertion order
Expand Down Expand Up @@ -125,5 +145,38 @@ pub fn composite_item_picker(
.into()
};

col![type_picker, item_picker].spacing(4).into()
let pickers: Element<'static, Message> = col![type_picker, item_picker].spacing(4).into();
with_optional_label(label, pickers, show_label)
}

#[cfg(all(test, feature = "iced_test"))]
mod tests {
use super::*;
use iced_test::simulator;

fn label_rendered(entries: Option<&[(String, String)]>, show_label: bool) -> bool {
let element: Element<'_, Message> =
composite_item_picker("Invented Item", "1:0", entries, show_label, |_| {
Message::FileTree(crate::message::FileTreeMessage::Search(String::new()))
});
let mut ui = simulator(element);
ui.find("Invented Item").is_ok()
}

#[test]
fn test_composite_picker_label_follows_show_label() {
let entries = [("1:0".to_string(), "Invented Sword".to_string())];
for show_label in [true, false] {
assert_eq!(
label_rendered(None, show_label),
show_label,
"fallback picker label must follow show_label"
);
assert_eq!(
label_rendered(Some(&entries), show_label),
show_label,
"lookup picker label must follow show_label"
);
}
}
}
21 changes: 21 additions & 0 deletions dispel-gui/src/components/file_tree/filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,27 @@ impl FileTreeFilter {
self.matching_paths = paths;
}

/// Expand every directory that is an ancestor of a match so the matching
/// files are actually visible in the collapsible tree.
pub fn expand_matching_directories(&self, root: Option<&mut TreeNode<GameFileNode>>) {
fn visit(node: &mut TreeNode<GameFileNode>, paths: &HashSet<PathBuf>) {
if node.data.is_dir && paths.contains(&node.data.path) {
node.expanded = true;
}
for child in &mut node.children {
visit(child, paths);
}
}

let Some(root) = root else {
return;
};
let Some(paths) = &self.matching_paths else {
return;
};
visit(root, paths);
}

/// Walk the entire tree and collect paths of files that match the current
/// fuzzy search query. Also includes ancestor directories so the tree
/// structure is preserved when rendering.
Expand Down
31 changes: 31 additions & 0 deletions dispel-gui/src/components/file_tree/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,37 @@ fn test_file_tree_search_filters_matching_files() {
);
}

#[test]
fn test_search_expands_collapsed_ancestor_of_match() {
use super::filter::FileTreeFilter;

let temp_dir = tempdir().unwrap();
let game = temp_dir.path().join("game");
let folder = game.join("InventedFolder");
std::fs::create_dir_all(&folder).unwrap();
std::fs::File::create(folder.join("InventedWibble.txt")).unwrap();

let mut tree = FileTree::scan(&game);
{
let root = tree.data.root.as_mut().expect("scanned tree has a root");
let dir = root
.find_mut(&|n: &GameFileNode| n.path == folder)
.expect("folder node");
dir.expanded = false;
assert!(!dir.expanded, "folder starts collapsed");
}

let mut filter = FileTreeFilter::new().with_search_query("wibble".to_string());
filter.build_matching_paths(tree.data.root.as_ref());
filter.expand_matching_directories(tree.data.root.as_mut());

let root = tree.data.root.as_mut().expect("scanned tree has a root");
let dir = root
.find_mut(&|n: &GameFileNode| n.path == folder)
.expect("folder node");
assert!(dir.expanded, "ancestor of a search match must be expanded");
}

/// Test filter functionality
#[test]
fn test_file_tree_filter_functionality() {
Expand Down
43 changes: 43 additions & 0 deletions dispel-gui/src/components/map_render/draw_helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,29 @@ pub fn draw_tile_layer(
}
}

/// Mirror an RGBA image horizontally, one pixel row at a time. Flipped
/// entities need their pixels mirrored as well as their origin offset shifted,
/// otherwise the sprite is drawn in the wrong direction.
pub fn mirror_rgba_rows(pixels: &[u8], width: u32, height: u32) -> Vec<u8> {
let w = width as usize;
let row_len = w.saturating_mul(4);
if row_len == 0 {
return Vec::new();
}
let mut mirrored = vec![0u8; pixels.len()];
for y in 0..height as usize {
let start = y.saturating_mul(row_len);
let Some(row) = pixels.get(start..start.saturating_add(row_len)) else {
break;
};
for (x, px) in row.as_chunks::<4>().0.iter().enumerate() {
let dst = start.saturating_add((w - 1 - x) * 4);
mirrored[dst..dst + 4].copy_from_slice(px);
}
}
mirrored
}

/// Render an entity sprite handle onto the canvas frame.
pub fn draw_entity_sprite(
frame: &mut Frame,
Expand Down Expand Up @@ -79,3 +102,23 @@ pub fn diamond_path(cx: f32, cy: f32, r: f32) -> canvas::Path {
b.close();
})
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn test_mirror_rgba_rows_reverses_each_row() {
// 2×2 image with a distinct colour per pixel.
let pixels = vec![1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16];
assert_eq!(
mirror_rgba_rows(&pixels, 2, 2),
vec![5, 6, 7, 8, 1, 2, 3, 4, 13, 14, 15, 16, 9, 10, 11, 12]
);
}

#[test]
fn test_mirror_rgba_rows_zero_width_is_empty() {
assert!(mirror_rgba_rows(&[1, 2, 3, 4], 0, 2).is_empty());
}
}
42 changes: 42 additions & 0 deletions dispel-gui/src/components/map_render/geometry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,16 @@
use crate::components::map_render::{TILE_H, TILE_W};
use iced::Rectangle;

/// Anchor point for a zoom operation. Toolbar buttons supply no cursor
/// position (NaN), so they zoom around the viewport centre instead.
pub fn zoom_anchor(cx: f32, cy: f32, viewport_w: f32, viewport_h: f32) -> (f32, f32) {
if cx.is_finite() && cy.is_finite() {
(cx, cy)
} else {
(viewport_w * 0.5, viewport_h * 0.5)
}
}

/// World pixel centre of an isometric tile.
pub fn tile_world_center(tx: i32, ty: i32, diagonal: i32) -> (f32, f32) {
let (px, py) = dispel_core::map::types::convert_map_coords_to_image_coords(tx, ty, diagonal);
Expand Down Expand Up @@ -91,3 +101,35 @@ pub fn screen_to_tile(
pub fn is_visible(x: f32, y: f32, w: f32, h: f32, bounds: Rectangle) -> bool {
x + w > 0.0 && x < bounds.width && y + h > 0.0 && y < bounds.height
}

#[cfg(test)]
mod tests {
use super::*;

fn zoom_once(pan: f32, zoom: f32, factor: f32, anchor: f32) -> (f32, f32) {
let new_zoom = (zoom * factor).clamp(0.05, 8.0);
let ratio = new_zoom / zoom;
(anchor - (anchor - pan) * ratio, new_zoom)
}

#[test]
fn test_toolbar_zoom_uses_viewport_center() {
assert_eq!(
zoom_anchor(f32::NAN, f32::NAN, 800.0, 600.0),
(400.0, 300.0)
);
let (ax, _) = zoom_anchor(f32::NAN, f32::NAN, 800.0, 600.0);

let mut pan = 0.0;
let mut zoom = 1.0;
(pan, zoom) = zoom_once(pan, zoom, 1.25, ax);
(pan, zoom) = zoom_once(pan, zoom, 1.0 / 1.25, ax);
assert!((zoom - 1.0).abs() < 1e-5, "zoom must return to 1.0");
assert!(pan.abs() < 1e-4, "viewport centre must stay put, pan={pan}");
}

#[test]
fn test_cursor_zoom_keeps_explicit_anchor() {
assert_eq!(zoom_anchor(123.0, 45.0, 800.0, 600.0), (123.0, 45.0));
}
}
6 changes: 4 additions & 2 deletions dispel-gui/src/components/map_render/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ pub mod traits;
pub mod view_state;

pub use decode::decode_tileset_file;
pub use draw_helpers::{diamond_path, draw_item_color};
pub use geometry::{is_visible, screen_to_tile, tile_center, tile_to_screen, tile_world_center};
pub use draw_helpers::{diamond_path, draw_item_color, mirror_rgba_rows};
pub use geometry::{
is_visible, screen_to_tile, tile_center, tile_to_screen, tile_world_center, zoom_anchor,
};
pub use input::handle_input;
pub use render_tiles::GenericTilesLayer;
pub use state::{EntitySpriteHandle, InternalSpriteHandle, MapCanvasState};
Expand Down
Loading
Loading