slint-ui / slint

Slint is a declarative GUI toolkit to build native user interfaces for Rust, C++, or JavaScript apps.
https://slint.dev
Other
17.52k stars 600 forks source link

Closeable tabs #768

Open nahla-nee opened 2 years ago

nahla-nee commented 2 years ago

A great feature to add to the tab widget, or as a separate widget is the ability to make closable tabs. I'm currently working on a browser for the gemini protocol and sixtyfps was on top of the priority list until I quickly ran into the problem of not being able to have tabs that worked how I wanted.

I searched the docs and as far as I can tell its not currently possible to do this with sixtyfps as it stands, nor could I find anything that allows for creating custom widgets or modifying the base widgets.

ogoffart commented 2 years ago

Currently, the TabWidget as it is can't close tab. But it should be possible to implement one yourself

   VerticalLayout {
      tab_bar := HorizontalLayout {  
           for tab in tab_model : Tab {  // Tab is a component you implement
                title => tab.title;
                closed => { root.tab_closed(tab.id); }
                selected => { root.current_tab = tab.id; }
           }
      }
      contents := Rectangle {
          //  something that depends on  current_tab
      }
    }