The main application window implementation using eframe/egui. Handles window lifecycle, dynamic title updates, responsive layout, and window state persistence.
src/app.rs- MainFerriteAppstruct implementingeframe::Appsrc/main.rs- Application entry point witheframe::run_native
pub struct FerriteApp {
state: AppState, // Central application state
should_exit: bool, // Exit flag after confirmation
last_window_size: Option<egui::Vec2>, // For detecting changes
last_window_pos: Option<egui::Pos2>, // For detecting changes
}The application is launched via eframe::run_native() with NativeOptions:
let viewport = egui::ViewportBuilder::default()
.with_title(APP_NAME)
.with_inner_size([window_size.width, window_size.height])
.with_min_inner_size([400.0, 300.0])
.with_position([x, y]) // If saved
.with_maximized(maximized);The window title updates reactively based on the active tab:
| State | Title Format |
|---|---|
| New file | Untitled - Ferrite |
| Saved file | filename.md - Ferrite |
| Modified | filename.md* - Ferrite |
Implementation uses ViewportCommand::Title:
ctx.send_viewport_cmd(egui::ViewportCommand::Title(title));Window size and position are tracked and saved to settings:
update_window_state()monitors viewport changes- Changes detected via
outer_rectfrom viewport info - Settings updated with new
WindowSizevalues - Saved on application shutdown via
AppState::shutdown()
The app intercepts close requests to check for unsaved changes:
if ctx.input(|i| i.viewport().close_requested()) {
if !self.handle_close_request() {
ctx.send_viewport_cmd(egui::ViewportCommand::CancelClose);
}
}| Panel | Purpose |
|---|---|
TopBottomPanel::top |
Menu bar (File, Help) |
TopBottomPanel::bottom |
Status bar (message, cursor position) |
CentralPanel |
Main content area (tabs, editor placeholder) |
- Confirmation Dialog: Unsaved changes on exit/close
- About Dialog: Application version and info
eframe- Native application frameworkegui- Immediate mode GUI librarylog- Logging for debug/info messages
Run the application:
cargo runThe window will:
- Load size/position from settings (or use defaults: 1200x800)
- Display with menu bar, status bar, and tab bar
- Track and save window state changes
- Show confirmation dialog on exit if unsaved changes exist
This module uses manual testing:
- Window sizing: Resize window → close → reopen → verify size restored
- Position persistence: Move window → close → reopen → verify position
- Title updates: Create tabs, modify content → verify title changes
- Exit handling: Modify tab → try to close → verify confirmation dialog
- Menu actions: File → New, Exit; Help → About
- App State - AppState integration
- Settings & Config - WindowSize struct