@@ -45,42 +45,22 @@ fn color_background(ui: &mut Ui, color: egui::Color32) {
45
45
impl eframe :: App for MyApp {
46
46
fn update (& mut self , ctx : & egui :: Context , _frame : & mut eframe :: Frame ) {
47
47
egui :: CentralPanel :: default (). show (ctx , | ui | {
48
- let dynamic_x = 5.0 ;
49
- let dynamic_if_separator = true ;
50
-
51
48
load_layout! (
52
- <? xml version = " 1.0" encoding = " utf-8" ? >
53
- <Form >
54
- <Strip direction = " north" gap = " @dynamic_x" separator = " @dynamic_if_separator" >
55
- <Panel size = " relative" value = " 0.4" >
56
- <Strip direction = " west" >
57
- <Panel size = " exact" value = " 250.0" >
58
- color_background (ui , egui :: Color32 :: from_rgb (255 , 255 , 0 ));
59
- </ Panel >
60
- <Panel size = " remainder" >
61
- color_background (ui , egui :: Color32 :: from_rgb (255 , 0 , 0 ));
62
- </ Panel >
63
- </ Strip >
64
- </ Panel >
65
- <Panel size = " remainder" >
66
- <Strip direction = " west" >
67
- <Panel size = " relative" value = " 0.3" >
68
- color_background (ui , egui :: Color32 :: from_rgb (0 , 0 , 255 ));
69
- </ Panel >
70
- <Panel size = " remainder" >
71
- <Strip direction = " north" gap = " 1.5" >
72
- <Panel size = " relative" value = " 0.3" >
73
- color_background (ui , egui :: Color32 :: from_rgb (0 , 255 , 255 ));
74
- </ Panel >
75
- <Panel size = " remainder" >
76
- color_background (ui , egui :: Color32 :: from_rgb (255 , 0 , 255 ));
77
- </ Panel >
78
- </ Strip >
79
- </ Panel >
80
- </ Strip >
81
- </ Panel >
82
- </ Strip >
83
- </ Form >
49
+ <Strip direction = " west" >
50
+ <Panel size = " relative" value = " 0.3" >
51
+ color_background (ui , egui :: Color32 :: from_rgb (0 , 0 , 255 ));
52
+ </ Panel >
53
+ <Panel size = " remainder" >
54
+ <Strip direction = " north" >
55
+ <Panel size = " relative" value = " 0.3" >
56
+ color_background (ui , egui :: Color32 :: from_rgb (0 , 255 , 255 ));
57
+ </ Panel >
58
+ <Panel size = " remainder" >
59
+ color_background (ui , egui :: Color32 :: from_rgb (255 , 0 , 255 ));
60
+ </ Panel >
61
+ </ Strip >
62
+ </ Panel >
63
+ </ Strip >
84
64
);
85
65
});
86
66
}
@@ -93,63 +73,38 @@ impl eframe::App for MyApp {
93
73
use eframe :: egui;
94
74
use egui :: {Rounding , Ui };
95
75
use egui_xml :: load_layout;
76
+
96
77
fn main () -> Result <(), eframe :: Error > {
97
78
let options = eframe :: NativeOptions {
98
79
.. Default :: default ()
99
80
};
100
81
eframe :: run_native (" My egui App" , options , Box :: new (| _cc | Box :: <MyApp >:: new (MyApp )))
101
82
}
83
+
102
84
struct MyApp ;
85
+
103
86
fn color_background (ui : & mut Ui , color : egui :: Color32 ) {
104
87
ui . painter ()
105
88
. rect_filled (ui . available_rect_before_wrap (), Rounding :: same (5.0 ), color );
106
89
}
90
+
107
91
impl eframe :: App for MyApp {
108
92
fn update (& mut self , ctx : & egui :: Context , _frame : & mut eframe :: Frame ) {
109
93
egui :: CentralPanel :: default ()
110
94
. show (
111
95
ctx ,
112
96
| ui | {
113
- let dynamic_x = 5.0 ;
114
- let dynamic_if_separator = true ;
115
97
let mut macro_strip_builder = egui_extras :: StripBuilder :: new (ui );
116
98
macro_strip_builder = macro_strip_builder
117
- . size (egui_extras :: Size :: relative (0.4 ));
118
- macro_strip_builder = macro_strip_builder
119
- . size (egui_extras :: Size :: exact (dynamic_x ));
99
+ . size (egui_extras :: Size :: relative (0.3 ));
120
100
macro_strip_builder = macro_strip_builder
121
101
. size (egui_extras :: Size :: remainder ());
122
102
let macro_strip_response = macro_strip_builder
123
- . vertical (| mut strip | {
103
+ . horizontal (| mut strip | {
124
104
strip
125
105
. cell (| ui | {
126
- let mut macro_strip_builder = egui_extras :: StripBuilder :: new (
127
- ui ,
128
- );
129
- macro_strip_builder = macro_strip_builder
130
- . size (egui_extras :: Size :: exact (250.0 ));
131
- macro_strip_builder = macro_strip_builder
132
- . size (egui_extras :: Size :: remainder ());
133
- let macro_strip_response = macro_strip_builder
134
- . horizontal (| mut strip | {
135
- strip
136
- . cell (| ui | {
137
- color_background (ui , egui :: Color32 :: from_rgb (255 , 255 , 0 ));
138
- });
139
- strip
140
- . cell (| ui | {
141
- color_background (ui , egui :: Color32 :: from_rgb (255 , 0 , 0 ));
142
- });
143
- });
106
+ color_background (ui , egui :: Color32 :: from_rgb (0 , 0 , 255 ));
144
107
});
145
- if dynamic_if_separator {
146
- strip
147
- . cell (| ui | {
148
- ui . separator ();
149
- });
150
- } else {
151
- strip . empty ();
152
- }
153
108
strip
154
109
. cell (| ui | {
155
110
let mut macro_strip_builder = egui_extras :: StripBuilder :: new (
@@ -160,33 +115,14 @@ impl eframe::App for MyApp {
160
115
macro_strip_builder = macro_strip_builder
161
116
. size (egui_extras :: Size :: remainder ());
162
117
let macro_strip_response = macro_strip_builder
163
- . horizontal (| mut strip | {
118
+ . vertical (| mut strip | {
164
119
strip
165
120
. cell (| ui | {
166
- color_background (ui , egui :: Color32 :: from_rgb (0 , 0 , 255 ));
121
+ color_background (ui , egui :: Color32 :: from_rgb (0 , 255 , 255 ));
167
122
});
168
123
strip
169
124
. cell (| ui | {
170
- let mut macro_strip_builder = egui_extras :: StripBuilder :: new (
171
- ui ,
172
- );
173
- macro_strip_builder = macro_strip_builder
174
- . size (egui_extras :: Size :: relative (0.3 ));
175
- macro_strip_builder = macro_strip_builder
176
- . size (egui_extras :: Size :: exact (1.5 ));
177
- macro_strip_builder = macro_strip_builder
178
- . size (egui_extras :: Size :: remainder ());
179
- let macro_strip_response = macro_strip_builder
180
- . vertical (| mut strip | {
181
- strip
182
- . cell (| ui | {
183
- color_background (ui , egui :: Color32 :: from_rgb (0 , 255 , 255 ));
184
- });
185
- strip
186
- . cell (| ui | {
187
- color_background (ui , egui :: Color32 :: from_rgb (255 , 0 , 255 ));
188
- });
189
- });
125
+ color_background (ui , egui :: Color32 :: from_rgb (255 , 0 , 255 ));
190
126
});
191
127
});
192
128
});
@@ -197,8 +133,6 @@ impl eframe::App for MyApp {
197
133
}
198
134
```
199
135
200
-
201
-
202
136
In this example, the load_layout! macro takes an XML string that defines the structure and style of the UI. Dynamic values and conditions can be injected directly into the XML, allowing for a flexible and dynamic UI creation process.
203
137
Getting Started
204
138
0 commit comments