Giter VIP home page Giter VIP logo

Comments (2)

ogoffart avatar ogoffart commented on August 20, 2024 3

We probably need a few things here. Which we still need to design API for.

1. Some kind of built-in Action type.

maybe a struct { text: string, icon: image, tool-tip: string, enabled: bool, checkable : bool, sub-menu: [Action], shortcut: string }
maybe we even need an icon type instead of re-using image?

For convenience, we might want to have implicit conversion from string to Menu

It is also quite similar to the StandardListViewItem we already have.

What about sub_menus? currently we can't have a recursive struct. but maybe we can make an exception for the action type.

2. How to represent a Menu Bar

Maybe something like this

MainWindow := Window {
    MenuBar {
        model: [
           { 
              text: "File",
              sub-menu: [ { text: "Open", icon: @image-url(...) }, { text: "Close", ... }, ... ]
           },
           { 
              text: "Edit",
              sub-menu: [ { text: "Copy", icon: @image-url(...) }, { text: "Paste", ... }, ... ]
           },
        ];
        trigerred(item) => {
           if (item == "File")  { // re-using the text is a very bad idea because of translation, we need something better than data
               ... 
           } else ...
        }
    }
   ...
}

An alternative would be NOT using an Action type, but using something more looking like our syntax like this:

MainWindow := Window {
    property <[Action]> recent_model;
    MenuBar {
        Menu {
            name: "File";
            MenuItem { name: "Open"; icon: "..."; triggered => { ... } }
            MenuItem { name: "Close"; icon: "..."; triggered => { ... }  }
            Menu {
                name: "Open Recent";
                model: recent_model; // provided by the logic
            }
        }
    }
    ...
    
}

Another way would be to have a collection of action with another special syntax

global MyActions := ActionCollections {
   file-open := Action { 
       text: "Open"; 
       icon: @image-url(...);  
       triggered => {...} 
       shortcut: "Ctrl+O";
    }
   file-close := Action { 
        text: "Close"; 
        icon: @image-url(...); 
        triggered => {...} 
   }
}

MainWindow := Window {
    MenuBar {
        Menu { 
           text: "File";
           model: [MyActions.file-open, MyActions.file-close, ...];
        }
       Menu { ... }
   }

The problem with that last approach is that ActionCollections it is kind of a very special case which somehow re-use the same syntax, but with a completely different semantic. Although we also abuse that for the Path sub-elements and the Row within GridLayout.
What i mean here is that Elements are no longer really graphical items. But also that one can access the sub elements of an ActionCollection by their id from a different component.

3. ContextMenu

Similar to Menu bar, we want to be able to set context menu to element.

Do we want each element to get a context-menu property:

Foo := Rectangle {
   ...
   Rectangle {
     context-menu: [ MyActions.file-open, {text: "Another Action" } ];
     ...
   }
}

Or should we get another element

Foo := Rectangle {
   ...
   Rectangle {
      ContextMenu {
          // similar to the MenuBar above
          model: [ ... ];
      }
   }
}

from slint.

tronical avatar tronical commented on August 20, 2024

Implementation wise, I see that tauri has created a separate crate for menubar / popup menus that works on macOS, Windows, and Linux - the latter using gtk: https://github.com/tauri-apps/muda

from slint.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.