How to use eframe + egui to create an emacs style window manager?

⚓ Rust    📅 2025-09-20    👤 surdeus    👁️ 9      

surdeus

Warning

This post was published 41 days ago. The information described in this article may have changed.

I have this code:

// Import eframe (egui's platform integration library)
use eframe::egui;

// Entry point for the application
fn main() -> Result<(), eframe::Error> {
    // Create and run the egui app
    eframe::run_native(
        "app",                  // Window title
        eframe::NativeOptions::default(), // Window configuration
        Box::new(|_| Ok(Box::new(App::default()))), // Initialize the app
    )
}

// Define the application struct
struct App {
    zoom: f32,
    windows: Vec<Window>,
}

struct Window {
    content: String,
    id: usize,
    divisions: Vec<Window>,
    split: Split
}

enum Split {
    Vertical,
    Horizontal
}

// Default state for the application
impl Default for App {
    fn default() -> Self {
        Self {
	    zoom: 1.0,
	    windows: vec![],
        }
    }
}

// Define GUI logic for the app
impl eframe::App for App {
    fn update(&mut self, ctx: &egui::Context, _: &mut eframe::Frame) {
	ctx.set_pixels_per_point(self.zoom);
        // Create the GUI layout
        egui::CentralPanel::default().show(ctx, |ui| {
	    egui::MenuBar::new().ui(ui, |ui| {
		ui.menu_button("Options", |ui| {
		    if ui.button("Quit").clicked() {
			ui.ctx().send_viewport_cmd(egui::ViewportCommand::Close);
		    }
		    if ui.button("Zoom in").clicked() {
			self.zoom += 0.25
		    }
		    if ui.button("Zoom out").clicked() {
			if self.zoom > 0.0 {
			    self.zoom -= 0.25
			}
		    }
		    if ui.button("New window horizontal").clicked() {
			/* ??? */
		    };
		    if ui.button("New window vertical").clicked() {
			/* ??? */
		    }
		    if ui.button("Kill all").clicked() {
			/* ??? */
		    }
		})
	    });
	});
    }
}

What do I need to replace /* ??? */ with so that it tiles like emacs. It should also save the window data with the provided structs. It should store a vector of windows with a string as it's content, an id, divisions (windows within windows, like emacs) and split, if it is split vertically or horizontally.

1 post - 1 participant

Read full topic

🏷️ Rust_feed