Egui - is it possible to avoid using eframe?

Hey guys, is it possible to avoid using eframe for egui and can I still make buttons, sliders and stuff and make it for a native app?

1 Like

You don't need to use eframe. I use egui-winit with egui-wgpu-backend in this app: parasyte/cartunes: Simple comparison app for iRacing car setups. (github.com) It's more complex than a simple example, though.

2 Likes

What about just using egui on its own, is that even possible?

Define "on its own"? Do you mean without a backend? With no other dependencies? I'm not sure what your goal is.

I mean like can I just use egui without using egui-winit etc?

You need something that provides input (keyboard and mouse events, for instance) and output (mostly drawing stuff and displaying it on a screen). That's what winit does. But you could also use another windowing crate like sdl2 or fltk.

Are you asking how to use egui without a windowing system? Is that even feasible?

2 Likes

egui on its own is a library to manage descriptions how the UI should be look like and behave when certain event is arrived. It doesn't interact directly to your monitor, keyboard and mouse. Those integration crates like eframe/egui-winit/etc have responsibility to take those descriptions and draw it on the screen.

5 Likes

If I use different windowing crates, then the code when using egui will change?

Is there a crate for egui where I can write one run everywhere sort of thing?

Only the part which integrates with the windowing crate. The UI definitions should not change.

What's "everywhere" in your case? Windows, Linux, MacOS, other Unixes, Android, IOS, web browser, whatever else?

With eframe, it changes a lot of the syntax, like it locks you into a framework. Is this the same case if I used fltk or sd12 or winit?

When somebody creates their own backend for example bevy_egui, bevy_egui would be a library on its own, and thats the same case with fltk_egui etc?

Say if I want to write a program which has sliders and some buttons. If I wrote it using fltk_egui, and if I wanted to now create the same thing this time using winit_egui, the code will remain exactly the same?

Well yeah those platforms.

What changes do you mean here?

The code for defining the sliders and buttons - yes. The code for passing the to the backend - of course not (however, backend can opt in to use epi and thus hide itself behind the common interface).

You hardly do anything in the main function, that's one thing for sure. I can't quite say exactly what the differences are between egui-winit and eframe as I haven't used it enough but egui's own page itself claims that eframe is a framework. And I don't want to use any frameworks.

The code responsible for passing it to the backend, would that be egui-bevy, egui-winit etc? Are these libraries, not binaries?

Ok so does egui-winit support epi?

You should check it yourself, since you know better what you need, but probably yes.

1 Like

eframe is slightly more abstract than egui-winit. The former uses the latter, so you can think of eframe as "higher level" and wgui-winit as "lower level".

The use of the term "framework" might be misleading here. eframe is not a framework in the sense that Angular is a framework. eframe is opinioned, like any framework ought to be, but the whole crate is only 313 lines of code!

As I said, you don't have to use eframe. If you want to manage your own event loop, you can just use egui-winit. You also do not have to use epi. It's really up to you to decide what you are looking for, and gluing it all together.

2 Likes

I see guys thanks.

One question off topic (but still in regards to egui), using either eframe, winit or whatever, am I able to design stuff in the main function such as buttons, sliders etc rather than having to use some kind of a structure and I just simply run it in the main?

kinda like what fltk-rs does in regards to how it does the design principles in the main function (here is their example code):

use fltk::{app, button::Button, frame::Frame, prelude::*, window::Window};
fn main() {
    let app = app::App::default();
    let mut wind = Window::default()
        .with_size(160, 200)
        .center_screen()
        .with_label("Counter");
    let mut frame = Frame::default()
        .with_size(100, 40)
        .center_of(&wind)
        .with_label("0");
    let mut but_inc = Button::default()
        .size_of(&frame)
        .above_of(&frame, 0)
        .with_label("+");
    let mut but_dec = Button::default()
        .size_of(&frame)
        .below_of(&frame, 0)
        .with_label("-");
    wind.make_resizable(true);
    wind.end();
    wind.show();
    /* Event handling */
    app.run().unwrap();
}

?

Do you mean something like this example? egui/pure_glow.rs at 0.16.1 · emilk/egui (github.com)

Yeah something like this, is this possible with eframe as well?

Not exactly the same. But it would be very similar. fltk being retained has to handle state in the widgets’ handle callback, passed as a smart pointer, since it’s also needed in fltk’s event loop.
It also offers some convenience functions for handling input and output.

Sample fltk-egui code:

Sample sdl egui code (fltk-egui is largely based on this implementation):

1 Like

Interesting mate, I could give it a try then. Would it be possible to integrate a GUI game engine with egui-fltk-rs?

I understand you have fltk-rs (on its own). Is it possible to also integrate it into a game engine?

FLTK offers OpenGL integration, and via raw-window-handle allows usage of wgpu to draw on its windows, and fltk handles the windowing and events, so technically yes. But I would probably go with a dedicated game engine myself.