Iβm excited to share this as my first post on the DEV Community! π
π‘ Want to build your first GUI app in Rust?
This post walks you through creating a Student Analyzer app using egui
, with form inputs, grade logic, and CSV export β all in a beautiful GUI using the eframe
crate!
π― What Youβll Build
A minimal yet functional GUI that:
β
Accepts student details and marks
β
Calculates average and pass/fail result
β
Exports the data into a CSV file
π§± App Structure
We build this using the eframe
framework β a native GUI library powered by egui
.
Main building blocks:
-
StudentApp
struct β Core data model of GUI application -
impl Default
β Initial state of app at launch -
impl eframe::App
β Draws UI and handles logic
π§ Code Breakdown β GUI + Logic
This code defines the appβs data model and initial state.
struct StudentApp{ name: String, roll_no: String, subjects: Vec<String>, selected_subjects: [usize; 7], marks: [String; 7], average: Option<f32>, result: Option<String>, } impl Default for StudentApp { fn default() -> Self { Self { name: String::new(), roll_no: String::new(), subjects: vec![ "Math".to_string(), "Science".to_string(), "English".to_string(), "Social".to_string(), "Computer".to_string(), "Hindi".to_string(), "Tamil".to_string(), ], selected_subjects: [0; 7], marks: Default::default(), average: None, result: None, } } }
And
In impl eframe::App, the update()
function gets called repeatedly while your app is running.
Inside this function, we:
- Create a window (CentralPanel) where the UI lives.
- Add form fields for user input (like name, roll number, subjects, marks).
- Handle logic for computing average and result.
- Render the result to the user.
π Code Purpose Table (Highlight View)
Purpose | Explanation |
---|---|
TextEdit::singleline(...) | Draws input box for user text |
ui.button("Add Marks") | Adds current mark to the list |
calculate_result() | Computes average and pass/fail |
write_to_csv() | Appends form data to a CSV file |
egui::CentralPanel::default().show(...) | Main layout container of the UI with title centered |
egui::ComboBox::from_id_source(...) | Renders subject dropdown for each entry |
π€ CSV Export Logic
This snippet writes the data by saving each student's entry into a CSV file for future use or reporting.
let file_path = "student_analyzer.csv"; let file_exists = std::path::Path::new(file_path).exists(); let file = OpenOptions::new() .create(true) .append(true) .open(file_path) .expect("Cannot open file");
β¨ Preview Screens
π» Input Form
The StudentApp screen at launch, with fields for name, subject, and marks.
π Average + Result View
The user adds multiple marks, and the app calculates the average and displays the result.
π CSV Export Confirmation
A student_analyzer.csv
file stores the entered data persistently for later use.
π Try the Full App
π Full post with detailed explanations and setup steps:
π Techn0tz Full Blog
Source code
π Download the Student Analyzer Rust code
π Whatβs Next?
In the next post, test your Rust foundations with a quick interactive Mini Quiz on Techn0tz!
Thanks for reading! π±
This is my first post on DEV, and I'm truly excited to be part of this amazing community. If you found it helpful or have suggestions, feel free to drop a comment or connect! π-Techn0tz
Top comments (0)