Text Editor in Rust egui — Open, Save & File Dialogs | Learn egui Ep32
1views
0011:33
T
Taught by Celeste AI - AI Coding Coach
View on YouTubeDescription
Build a text editor with file dialogs in Rust using egui! In this episode, we create a text editor with the rfd crate for native file dialogs,
FileDialog::new() with add_filter for file type filtering, pick_file and save_file for open/save operations, std::fs::read_to_string and fs::write for
file I/O, Option to track the current file, TextEdit::multiline with monospace font, a toolbar with New/Open/Save/Save As buttons, and a status bar
with character count.
Student code: https://github.com/GoCelesteAI/egui_text_editor
What You'll Learn:
- rfd crate for native file dialogs (open, save)
- rfd::FileDialog::new() to create a file dialog builder
- .add_filter("Text", &["txt", "rs", "md", "toml"]) for file type filtering
- .pick_file() to open a native file picker dialog
- .save_file() to open a native save dialog
- std::fs::read_to_string() to read file contents into a String
- std::fs::write() to write String content to a file
- PathBuf for owned file system paths
- Option to track whether a file is open
- TextEdit::multiline() for a multi-line text editing area
- .font(TextStyle::Monospace) for monospace editor font
- ScrollArea::vertical() for scrollable content
- TopBottomPanel for toolbar and status bar
- Layout::right_to_left() for right-aligned character count
- Save delegates to Save As when no file path exists
- Neo-tree file browsing in a Rust project
This is Episode 32 of the "Learn egui in Neovim" series — 36 episodes teaching Rust GUI development with egui, all coded in Neovim with Neo-tree.
Chapters:
0:00 Intro
0:12 What We're Building
0:22 Preview: Key Concepts
0:54 Create Project & Dependencies
1:30 main.rs — Window Setup
2:10 app.rs — MyApp Struct & State
2:50 Default Implementation
3:20 open_file — FileDialog & read_to_string
4:20 save_file — Write to Current Path
5:00 save_file_as — FileDialog Save
5:40 new_file — Clear Content & Path
6:00 update() — Toolbar Panel with Buttons
7:00 Status Bar — File Status & Char Count
7:40 CentralPanel — TextEdit::multiline
8:20 Save & Review Code
8:50 cargo build
9:20 Neo-tree Browse
9:50 App Demo
10:50 Recap
11:30 Next Episode
Tags: rust, egui, text editor, gui, tutorial, neovim, neo-tree, eframe, rfd, file dialog, open file, save file, pathbuf, textedit, multiline,
monospace, toolbar, status bar, file io, coding, programming, learn rust, rust gui, desktop app
Hashtags: #rust #egui #texteditor #gui #neovim #rustlang #coding #tutorial
Tags
rusteguitext editorguitutorialneovimneo-treeeframerfdfile dialogopen filesave filepathbuftexteditmultiline