Complete Clean Architecture migration
Phase 1-7: Full migration from src/app/ to Clean Architecture
BREAKING CHANGES:
- Removed src/app/ (old TEA-style implementation)
- Removed src/constant.rs (constants now local to modules)
- Removed deprecated canvas_to_image_coords functions
NEW STRUCTURE:
- src/ui/ - UI Layer (COSMIC interface)
- src/application/ - Application Layer (DocumentManager, Commands)
- src/domain/ - Domain Layer (Document types, Operations)
- src/infrastructure/ - Infrastructure Layer (Loaders, Cache, System)
FEATURES:
- DocumentManager as Single Source of Truth
- Command Pattern for all operations
- Model caching for render data (performance)
- Sync mechanism between DocumentManager and UI Model
- Wallpaper support (COSMIC, KDE, GNOME, feh)
- Thumbnail cache with disk persistence
IMPROVEMENTS:
- Warnings: 62 → 43 (-31%)
- Deprecated warnings: 2 → 0 (-100%)
- Code removed: src/app/ (~2000 lines), constant.rs, deprecated functions
- Better Locality of Reference (constants local to modules)
- Clean separation of concerns
- No circular dependencies
DOCUMENTATION:
- Updated AGENTS.md (100% migration status)
- Updated README.md (architecture section)
- Updated Workflow.md
- Added Migration-Plan.md with full completion summary
TESTS:
- All 41 tests passing
- Build successful (0 errors, 43 warnings)
- Release build verified
Migration Status: ✅ 100% Complete
2026-02-03 08:43:21 +01:00
|
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
|
// src/domain/document/core/page.rs
|
|
|
|
|
//
|
|
|
|
|
// Page abstraction for multi-page documents.
|
|
|
|
|
|
|
|
|
|
use cosmic::widget::image::Handle as ImageHandle;
|
|
|
|
|
|
|
|
|
|
/// Represents a single page in a multi-page document.
|
|
|
|
|
#[derive(Debug, Clone)]
|
feat: UI rewrite - TEA architecture, eliminate sync pattern
Complete UI layer refactoring to achieve Clean Architecture + TEA principles.
Major Changes:
- Eliminated sync.rs (76 LOC of manual synchronization)
- Restructured AppModel: pure UI state only
- Introduced AppMode enum (View, Crop, Transform, Fullscreen)
- Added Viewport struct (scale, pan, canvas, cached_image_handle)
- Added PanelState struct (left, right panels)
- Removed all cached document data from UI layer
- Views now access DocumentManager directly (no caching)
- Update functions work on both model and manager directly
Architecture:
- TEA-compliant: Single source of truth, unidirectional flow
- Clean separation: UI state vs Document state
- No manual synchronization required
Benefits:
- Simplified codebase: -1,986 LOC net (-75.6%)
- Better maintainability: Clear responsibilities
- Type-safe state: Enums instead of flags
- Performance: Cached rendering where needed
Refactored Files:
- src/ui/model.rs: Complete rewrite
- src/ui/update.rs: Complete rewrite
- src/ui/views/*: Updated to use new architecture
- src/ui/views/meta_panel.rs: Extracted from panels.rs
Testing:
- All 24 unit tests passing
- Compiles successfully (cargo check, cargo build)
- 32 warnings (non-critical, future features)
BREAKING CHANGES: None (internal refactoring only)
Co-authored-by: Clean Architecture principles
Co-authored-by: TEA (The Elm Architecture) pattern
2026-02-05 10:41:51 +01:00
|
|
|
#[allow(dead_code)]
|
Complete Clean Architecture migration
Phase 1-7: Full migration from src/app/ to Clean Architecture
BREAKING CHANGES:
- Removed src/app/ (old TEA-style implementation)
- Removed src/constant.rs (constants now local to modules)
- Removed deprecated canvas_to_image_coords functions
NEW STRUCTURE:
- src/ui/ - UI Layer (COSMIC interface)
- src/application/ - Application Layer (DocumentManager, Commands)
- src/domain/ - Domain Layer (Document types, Operations)
- src/infrastructure/ - Infrastructure Layer (Loaders, Cache, System)
FEATURES:
- DocumentManager as Single Source of Truth
- Command Pattern for all operations
- Model caching for render data (performance)
- Sync mechanism between DocumentManager and UI Model
- Wallpaper support (COSMIC, KDE, GNOME, feh)
- Thumbnail cache with disk persistence
IMPROVEMENTS:
- Warnings: 62 → 43 (-31%)
- Deprecated warnings: 2 → 0 (-100%)
- Code removed: src/app/ (~2000 lines), constant.rs, deprecated functions
- Better Locality of Reference (constants local to modules)
- Clean separation of concerns
- No circular dependencies
DOCUMENTATION:
- Updated AGENTS.md (100% migration status)
- Updated README.md (architecture section)
- Updated Workflow.md
- Added Migration-Plan.md with full completion summary
TESTS:
- All 41 tests passing
- Build successful (0 errors, 43 warnings)
- Release build verified
Migration Status: ✅ 100% Complete
2026-02-03 08:43:21 +01:00
|
|
|
pub struct Page {
|
|
|
|
|
/// Page index (0-based).
|
|
|
|
|
pub index: usize,
|
|
|
|
|
/// Page width in pixels.
|
|
|
|
|
pub width: u32,
|
|
|
|
|
/// Page height in pixels.
|
|
|
|
|
pub height: u32,
|
|
|
|
|
/// Optional thumbnail handle.
|
|
|
|
|
pub thumbnail: Option<ImageHandle>,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl Page {
|
|
|
|
|
/// Create a new page.
|
|
|
|
|
#[must_use]
|
|
|
|
|
pub fn new(index: usize, width: u32, height: u32) -> Self {
|
|
|
|
|
Self {
|
|
|
|
|
index,
|
|
|
|
|
width,
|
|
|
|
|
height,
|
|
|
|
|
thumbnail: None,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Create a page with a thumbnail.
|
|
|
|
|
#[must_use]
|
|
|
|
|
pub fn with_thumbnail(index: usize, width: u32, height: u32, thumbnail: ImageHandle) -> Self {
|
|
|
|
|
Self {
|
|
|
|
|
index,
|
|
|
|
|
width,
|
|
|
|
|
height,
|
|
|
|
|
thumbnail: Some(thumbnail),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Set the thumbnail for this page.
|
|
|
|
|
pub fn set_thumbnail(&mut self, thumbnail: ImageHandle) {
|
|
|
|
|
self.thumbnail = Some(thumbnail);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Check if this page has a thumbnail.
|
|
|
|
|
#[must_use]
|
|
|
|
|
pub fn has_thumbnail(&self) -> bool {
|
|
|
|
|
self.thumbnail.is_some()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Get the aspect ratio of the page.
|
|
|
|
|
#[must_use]
|
|
|
|
|
pub fn aspect_ratio(&self) -> f32 {
|
|
|
|
|
if self.height == 0 {
|
|
|
|
|
1.0
|
|
|
|
|
} else {
|
|
|
|
|
#[allow(clippy::cast_precision_loss)]
|
|
|
|
|
{
|
|
|
|
|
self.width as f32 / self.height as f32
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Get page dimensions as a tuple.
|
|
|
|
|
#[must_use]
|
|
|
|
|
pub fn dimensions(&self) -> (u32, u32) {
|
|
|
|
|
(self.width, self.height)
|
|
|
|
|
}
|
|
|
|
|
}
|