AIT/src/view/pages/signal_reducing.rs

80 lines
2.1 KiB
Rust
Raw Normal View History

use gtk4 as gtk;
use std::{fmt::Debug, num::ParseFloatError, str::FromStr, sync::Arc, time::Duration};
use crate::{
event_handlers::button_event_handlers::BtnEventHandler,
model::{builder_traits::Product, models::*},
view::{
components::{info_bar::InfoBar, input::Input},
properties::*,
},
view_utils::signal_reduce_input_utils::{get_error_message, parse_fields},
};
2024-04-19 11:03:16 +03:00
use gtk::{
prelude::{BoxExt, GridExt, TextBufferExt, TextViewExt},
2024-04-19 11:03:16 +03:00
Align, WrapMode, *,
};
pub fn signal_reducing_page(wrapper: &Box) {
let (input_height, monospace, input_alignment, input_wrapping): (i32, bool, Align, WrapMode) =
(24, true, Align::Fill, WrapMode::Word);
let input_block: Grid = Grid::new();
input_block.set_column_homogeneous(true);
input_block.set_row_homogeneous(true);
let input_label_alignment = Alignment {
horizontal: Align::Start,
vertical: Align::Fill,
};
let input_labels: [&str; 6] = [
"l, м:",
"Rм, Ом:",
"Cм, пФ:",
"Vи, мВ",
"Rи, Ом:",
"f, мГц:",
];
let all_inputs: Vec<Input> = input_labels
.iter()
.map(move |label| {
Input::builder()
.set_label(label)
.set_margins(MarginData::EqualsMargin(5))
.set_align(input_label_alignment)
.build(monospace, input_wrapping, input_height)
})
.collect();
let mut row_position = 0i32;
for (id, elem) in all_inputs.iter().enumerate() {
if id % 3 == 0 {
row_position += 1;
2024-04-19 11:03:16 +03:00
}
input_block.attach(
&elem.clone().get(),
(id as i32) - (3 * row_position),
row_position,
1,
1,
);
2024-04-19 11:03:16 +03:00
}
let calculate_button = Button::builder().label("Расчитать").build();
EventHandler::new(calculate_button.clone(), move |_| {
let values: Option<[f64; 6]> = parse_fields(all_inputs.clone());
println!("values: {:?}", values);
})
.on_click();
wrapper.append(&input_block);
wrapper.append(&calculate_button);
}