#How to edit the top bar in dioxus desktop apps

1 messages · Page 1 of 1 (latest)

inland flame
#

So i am a begginer at dioxus and also at tauri, and intermediate at rust.

How can I edit the top bar (The bar that says "File", "Settings" and "Help" in desktop apps)

I would like to add elements to it.

Do I have to create multiple main functions? What is the recommended way?

I have read the dioxus docs, I think I have to use dioxus:🖥️:launch function or the use_window() hook but am unsure on how.

thank you

(using dioxus 0.7.1)

brave iris
#

I think you'll need to use the muda crate directly for this. We should definitely expose a better API here (probably something like a use_menu hook).

inland flame
#

yes

but could you please help me on how to start? like a little example.

brave iris
#

Sorry, don't have time for that rn

inland flame
#

ok, thanks anyway. I'll write/log here what i find

Until know I have found dioxus_desktop crate reexports muda

brave iris
#

I believe the general approach you need is to get access to the RawWindowHandle from the window, which you can then use with muda. Not sure whether this is possible with current dioxus-desktop or not.

inland flame
#

ok

brave iris
#

Something like use_window().window.raw_window_handle()

#

Where use_window is a function exported by dioxus-desktop

inland flame
#

thx

inland flame
#

So in the App component (the function), I have a desktop! {} macro. Inside i use

use muda::{accelerator::Accelerator, Menu, MenuItem};

let menu = Menu::with_items(&[&MenuItem::new(
    "Menu item #1 (Alt-D)",
    true,
    Some(Accelerator::new(Some(Modifiers::ALT), Code::KeyD)),
)]).unwrap();
#

then I get the window with use_window

let window = use_window();

menu.init_for_gtk_window(window.window.as_ref(), window.default_vbox())
#

So default_vbox() already returns an Option. But don't know how to make the other parameter to be correct

brave iris
#

For gtk, try window.window.gtk_window()

inland flame
#

compiler complains:

    --> src/main.rs:39:34                                                     ▐
     |                                                                        ▐
  39 |         menu.init_for_gtk_window(&window.window, window.default_vbox())▐
 ;                                                                            ▐
     |              ------------------- ^^^^^^^^^^^^^^ the trait `glib::object▐
 ::IsA<gtk::auto::window::Window>` is not implemented for `Arc<Window>`       ▐
     |              |                                                         ▐
     |              required by a bound introduced by this call 
inland flame
#

lets see ifit worksd

#

ill be back in 10 min

#

Ok, so it did compiled but didn't changed the bar

#

Here is the code

#

This is what it looks like

#

With the same options in the top bar

inland flame
#

finally!

Got it working by setting it in the main function

#
fn main() {
    dioxus::LaunchBuilder::new()
        .with_cfg(desktop! {
            use muda::{accelerator::Accelerator, Menu, MenuItem};

            let menu = Menu::with_items(&[&MenuItem::new(
                "Menu item #1 (Alt-D)",
                true,
                Some(Accelerator::new(Some(Modifiers::ALT), Code::KeyD)),
            )]).unwrap();

            let window =  WindowBuilder::new().with_title("My App");

            let config = Config::new().with_window(window).with_menu(menu);

            config
        })
        .launch(App);
}
#

I don't know how to close this. I will stop following this.

#

I'm getting an error in dx serve tho, when closing the window
It doesn't bother me, but i will put it because it might mean something

19:04:40 [linux] (rss-app-0331e036:48499): Gtk-WARNING **: 19:04:40.225: ../../../gtk/gtkwidget.c:6787: no accelerator (68,8) installed in accel group (0x564b74f0b720) for GtkMenuItem (0x564b74f088a0)