@@ -14,30 +14,37 @@ fn main() -> eframe::Result<()> {
1414
1515struct TabViewer ;
1616
17+ #[ derive( Hash , Debug ) ]
18+ enum Opinion {
19+ Changing ( bool ) ,
20+ Fixed ( bool ) ,
21+ }
22+ #[ derive( Hash , Debug ) ]
1723struct OpinionatedTab {
18- can_become_window : Result < bool , bool > ,
24+ can_become_window : Opinion ,
1925 title : String ,
2026 content : String ,
2127}
2228
2329impl egui_dock:: TabViewer for TabViewer {
2430 type Tab = OpinionatedTab ;
2531
32+ fn id ( & mut self , tab : & mut Self :: Tab ) -> egui:: Id {
33+ egui:: Id :: new ( tab)
34+ }
35+
2636 fn title ( & mut self , tab : & mut Self :: Tab ) -> egui:: WidgetText {
2737 ( & tab. title ) . into ( )
2838 }
2939
3040 fn ui ( & mut self , ui : & mut egui:: Ui , tab : & mut Self :: Tab ) {
3141 ui. label ( & tab. content ) ;
3242 match & mut tab. can_become_window {
33- Ok ( changing_opinion) => {
34- ui. add ( egui:: Checkbox :: new (
35- changing_opinion,
36- "can be turned into window" ,
37- ) ) ;
43+ Opinion :: Changing ( opinion) => {
44+ ui. add ( egui:: Checkbox :: new ( opinion, "can be turned into window" ) ) ;
3845 }
39- Err ( fixed_opinion ) => {
40- if * fixed_opinion {
46+ Opinion :: Fixed ( opinion ) => {
47+ if * opinion {
4148 ui. small ( "this tab can exist in a window" ) ;
4249 } else {
4350 ui. small ( "this tab cannot exist in a window" ) ;
@@ -48,7 +55,7 @@ impl egui_dock::TabViewer for TabViewer {
4855
4956 fn allowed_in_windows ( & self , tab : & mut Self :: Tab ) -> bool {
5057 match tab. can_become_window {
51- Ok ( opinion) | Err ( opinion) => opinion,
58+ Opinion :: Changing ( opinion) | Opinion :: Fixed ( opinion) => opinion,
5259 }
5360 }
5461}
@@ -61,12 +68,12 @@ impl Default for MyApp {
6168 fn default ( ) -> Self {
6269 let mut tree = DockState :: new ( vec ! [
6370 OpinionatedTab {
64- can_become_window: Ok ( false ) ,
71+ can_become_window: Opinion :: Changing ( false ) ,
6572 title: "old tab" . to_owned( ) ,
6673 content: "since when could tabs become windows?" . to_string( ) ,
6774 } ,
6875 OpinionatedTab {
69- can_become_window: Err ( false ) ,
76+ can_become_window: Opinion :: Fixed ( false ) ,
7077 title: "grumpy tab" . to_owned( ) ,
7178 content: "I don't want to be a window!" . to_string( ) ,
7279 } ,
@@ -77,7 +84,7 @@ impl Default for MyApp {
7784 NodeIndex :: root ( ) ,
7885 0.6 ,
7986 vec ! [ OpinionatedTab {
80- can_become_window: Ok ( true ) ,
87+ can_become_window: Opinion :: Changing ( true ) ,
8188 title: "wise tab" . to_owned( ) ,
8289 content: "egui_dock 0.7!" . to_string( ) ,
8390 } ] ,
@@ -86,7 +93,7 @@ impl Default for MyApp {
8693 a,
8794 0.4 ,
8895 vec ! [ OpinionatedTab {
89- can_become_window: Ok ( true ) ,
96+ can_become_window: Opinion :: Changing ( true ) ,
9097 title: "instructional tab" . to_owned( ) ,
9198 content: "This demo is meant to showcase the ability for tabs to become/be placed inside windows.
9299 \n individual tabs have the ability to accept/reject being put/turned into a window.
@@ -96,7 +103,7 @@ impl Default for MyApp {
96103 } ] ,
97104 ) ;
98105 let _ = tree. add_window ( vec ! [ OpinionatedTab {
99- can_become_window: Err ( true ) ,
106+ can_become_window: Opinion :: Fixed ( true ) ,
100107 title: "egotistical tab" . to_owned( ) ,
101108 content: "im above you all!" . to_string( ) ,
102109 } ] ) ;
0 commit comments