1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
// SPDX-License-Identifier: GPL-3.0-only
/*
Copyright (C) 2024-2026 jgabaut, gioninjo
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, version 3 of the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
use crate::app::core::{Action, Action::*};
use crate::app::model::Model;
use crate::views::{propheight, propwidth, rrect, View};
use crate::MainState;
use esox::domain::index::Indice;
use raylib::consts::GuiIconName::ICON_OK_TICK;
use raylib::consts::GuiState::{STATE_DISABLED, STATE_NORMAL};
use raylib::drawing::RaylibDrawHandle;
use raylib::prelude::*;
use raylib::RaylibThread;
pub(crate) struct ProduzioneOutputView {}
impl View for ProduzioneOutputView {
fn draw(
&mut self,
d: &mut RaylibDrawHandle,
_thread: &RaylibThread,
state: &Model,
main_state: &MainState,
) -> Vec<Action> {
self.draw_background(d, main_state);
let current_index = match state.indice_model.get_selected_index() {
Some(index) => index,
None => {
eprintln!("ProduzioneOutputView: Per qualche assurdo motivo l'indice corrente non รจ validato. Uso NISECI.");
Indice::Niseci
}
};
let button_calcola_width = propwidth(d, 200);
let button_calcola_x = d.get_screen_width() / 2 - button_calcola_width / 2;
let button_calcola_height = propwidth(d, 50);
let button_calcola_y = d.get_screen_height() / 4 - button_calcola_height / 2;
let groupbox_width = button_calcola_width + propwidth(d, 100);
let groupbox_x = button_calcola_x - propwidth(d, 50);
let groupbox_height = button_calcola_height + propheight(d, 100);
let groupbox_y = button_calcola_y - propheight(d, 50);
let panel_width = groupbox_width + propwidth(d, 175);
let panel_x = d.get_screen_width() / 2 - panel_width / 2;
let panel_y = groupbox_y + groupbox_height + propwidth(d, 50);
let panel_height = groupbox_height + propheight(d, 50);
d.gui_group_box(
rrect(groupbox_x, groupbox_y, groupbox_width, groupbox_height),
"Produzione output",
);
let mut actions = Vec::<Action>::new();
if d.gui_button(
rrect(
button_calcola_x,
button_calcola_y,
button_calcola_width,
button_calcola_height,
),
"Calcola",
) {
actions.push(RunCalc);
}
let submit_width = propwidth(d, 125);
let panel_x_end = panel_x + panel_width;
let submit_x = panel_x_end + (d.get_screen_width() - panel_x_end) / 2 - submit_width / 2;
let submit_height = propheight(d, 50);
let submit_y = d.get_screen_height() / 2 - submit_height / 2;
let confirm_itext = d.gui_icon_text(ICON_OK_TICK, "Conferma");
let done_calc = state.output_model.is_done_calc();
let _really_done_calc = match current_index {
// This distinguishes the case where the calc finished but the resulting value is None.
// It should only really happen when we try to get x2 with a divide-by-zero, as in:
// our campionamento had no records matching a riferimentore record with specie_attesa == 1
Indice::Niseci => done_calc && state.data_model.get_niseci_value().is_some(),
Indice::Hfbi => {
false //TODO: Implement this
//
//Maybe the is_some won't be needed
//done_calc && controller.get_hfbi_value().is_some()
}
};
let lock_user_submit = !done_calc;
// If one wanted to avoid users pressing submit when the calc ended in the None case
// let lock_submit = !done_calc || !really_done_calc;
if lock_user_submit {
d.gui_lock();
d.gui_set_state(STATE_DISABLED);
}
if d.gui_button(
rrect(submit_x, submit_y, submit_width, submit_height),
confirm_itext.as_str(),
) {
actions.push(ConfirmCalc);
}
if lock_user_submit {
d.gui_set_state(STATE_NORMAL);
d.gui_unlock();
}
d.gui_panel(
rrect(panel_x, panel_y, panel_width, panel_height),
Some("Output"),
);
let y_spacing = main_state.current_font_height + propwidth(d, 5);
let output_start_y = panel_y + propwidth(d, 15);
match current_index {
Indice::Niseci => {
let niseci_opt = state.data_model.get_niseci_value();
let niseci_str = match niseci_opt {
Some(v) => {
format!("{}", v)
}
None => {
if state.output_model.is_done_calc() {
// Could use done_calc and avoid another
// lock call
"NC".to_string()
} else {
"Non calcolato".to_string()
}
}
};
let niseci_line = format!("NISECI: {}", niseci_str);
d.draw_text_ex(
&main_state.current_font,
&niseci_line,
// We use propwidth/height for the text starting position:
// this is not the bound
Vector2::new(
(panel_x + propwidth(d, 25)) as f32,
(output_start_y + (y_spacing)) as f32,
),
main_state.current_font_height as f32,
main_state.default_txt_spacing as f32,
main_state.colors.default_txt_color,
);
let rqe_niseci_opt = state.data_model.get_rqe_niseci_value();
let rqe_niseci_str = match rqe_niseci_opt {
Some(v) => {
format!("{}", v)
}
None => {
if state.output_model.is_done_calc() {
"NC".to_string()
} else {
"Non calcolato".to_string()
}
}
};
let rqe_line = format!("RQE NISECI: {}", rqe_niseci_str);
d.draw_text_ex(
&main_state.current_font,
&rqe_line,
// We use propwidth/height for the text starting position:
// this is not the bound
Vector2::new(
(panel_x + propwidth(d, 25)) as f32,
(output_start_y + (y_spacing * 2)) as f32,
),
main_state.current_font_height as f32,
main_state.default_txt_spacing as f32,
main_state.colors.default_txt_color,
);
let stato_eco_niseci_opt = state.data_model.get_stato_eco_niseci_value(state);
let stato_eco_niseci_str = match stato_eco_niseci_opt {
Some(v) => {
format!("{}", v)
}
None => {
if state.output_model.is_done_calc() {
"NC".to_string()
} else {
"Non calcolato".to_string()
}
}
};
let stato_eco_line = format!("STATO ECOLOGICO NISECI: {}", stato_eco_niseci_str);
d.draw_text_ex(
&main_state.current_font,
&stato_eco_line,
// We use propwidth/height for the text starting position:
// this is not the bound
Vector2::new(
(panel_x + propwidth(d, 25)) as f32,
(output_start_y + (y_spacing * 3)) as f32,
),
main_state.current_font_height as f32,
main_state.default_txt_spacing as f32,
main_state.colors.default_txt_color,
);
let x1_opt = state.data_model.get_x1_value();
let x1_str = match x1_opt {
Some(v) => {
format!("{}", v)
}
None => {
if state.output_model.is_done_calc() {
"NC".to_string()
} else {
"Non calcolato".to_string()
}
}
};
let x1_line = format!("X1: {}", x1_str);
d.draw_text_ex(
&main_state.current_font,
&x1_line,
// We use propwidth/height for the text starting position:
// this is not the bound
Vector2::new(
(panel_x + propwidth(d, 25)) as f32,
(output_start_y + (y_spacing * 4)) as f32,
),
main_state.current_font_height as f32,
main_state.default_txt_spacing as f32,
main_state.colors.default_txt_color,
);
let x2_opt = state.data_model.get_x2_value();
let x2_str = match x2_opt {
Some(v) => {
format!("{}", v)
}
None => {
if state.output_model.is_done_calc() {
"NC".to_string()
} else {
"Non calcolato".to_string()
}
}
};
let x2_line = format!("X2: {}", x2_str);
d.draw_text_ex(
&main_state.current_font,
&x2_line,
// We use propwidth/height for the text starting position:
// this is not the bound
Vector2::new(
(panel_x + propwidth(d, 25)) as f32,
(output_start_y + (y_spacing * 5)) as f32,
),
main_state.current_font_height as f32,
main_state.default_txt_spacing as f32,
main_state.colors.default_txt_color,
);
let x3_opt = state.data_model.get_x3_value();
let x3_str = match x3_opt {
Some(v) => {
format!("{}", v)
}
None => {
if state.output_model.is_done_calc() {
"NC".to_string()
} else {
"Non calcolato".to_string()
}
}
};
let x3_line = format!("X3: {}", x3_str);
d.draw_text_ex(
&main_state.current_font,
&x3_line,
// We use propwidth/height for the text starting position:
// this is not the bound
Vector2::new(
(panel_x + propwidth(d, 25)) as f32,
(output_start_y + (y_spacing * 6)) as f32,
),
main_state.current_font_height as f32,
main_state.default_txt_spacing as f32,
main_state.colors.default_txt_color,
);
}
Indice::Hfbi => {
let hfbi_opt = state.data_model.get_hfbi_value();
let hfbi_str = match hfbi_opt {
Some(v) => {
format!("{}", v)
}
None => {
if state.output_model.is_done_calc() {
// Could use done_calc and avoid another
// lock call
"NC".to_string()
} else {
"Non calcolato".to_string()
}
}
};
let hfbi_line = format!("HFBI: {}", hfbi_str);
d.draw_text_ex(
&main_state.current_font,
&hfbi_line,
// We use propwidth/height for the text starting position:
// this is not the bound
Vector2::new(
(panel_x + propwidth(d, 25)) as f32,
(output_start_y + (y_spacing)) as f32,
),
main_state.current_font_height as f32,
main_state.default_txt_spacing as f32,
main_state.colors.default_txt_color,
);
let data_res_opt = state.data_model.get_risultato_hfbi();
let mmi_str = match data_res_opt {
Some(v) => {
format!("{}", v.get_intermediates().mmi)
}
None => {
if state.output_model.is_done_calc() {
// Could use done_calc and avoid another
// lock call
"NC".to_string()
} else {
"Non calcolato".to_string()
}
}
};
let mmi_line = format!("MMI: {}", mmi_str);
d.draw_text_ex(
&main_state.current_font,
&mmi_line,
// We use propwidth/height for the text starting position:
// this is not the bound
Vector2::new(
(panel_x + propwidth(d, 25)) as f32,
(output_start_y + (y_spacing * 2)) as f32,
),
main_state.current_font_height as f32,
main_state.default_txt_spacing as f32,
main_state.colors.default_txt_color,
);
let stato_eco_hfbi_opt = state.data_model.get_stato_eco_hfbi_value(state);
let stato_eco_hfbi_str = match stato_eco_hfbi_opt {
Some(v) => {
format!("{}", v)
}
None => {
if state.output_model.is_done_calc() {
"NC".to_string()
} else {
"Non calcolato".to_string()
}
}
};
let stato_eco_line = format!("STATO ECOLOGICO HFBI: {}", stato_eco_hfbi_str);
d.draw_text_ex(
&main_state.current_font,
&stato_eco_line,
// We use propwidth/height for the text starting position:
// this is not the bound
Vector2::new(
(panel_x + propwidth(d, 25)) as f32,
(output_start_y + (y_spacing * 3)) as f32,
),
main_state.current_font_height as f32,
main_state.default_txt_spacing as f32,
main_state.colors.default_txt_color,
);
}
}
actions
}
}
impl ProduzioneOutputView {
pub(crate) fn new() -> Self {
Self {}
}
}