AIT/src/view/pages/signal_reducing.rs

165 lines
5.0 KiB
Rust
Raw Normal View History

use gtk4 as gtk;
use crate::{
controller::event_handlers::button_event_handlers::*,
model::{
builder_traits::Product,
model::{EventHandler, SchemeCharacteristics},
},
view::{
components::{input::Input, wrapper::Wrapper},
properties::*,
},
view_utils::signal_reduce_input_utils::start_algorithm,
};
use gtk::{prelude::*, 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_label_alignment = Alignment {
horizontal: Align::Start,
vertical: Align::Fill,
};
let wire_length_input: Input = Input::builder()
.set_label("l, м:")
.set_margins(MarginData::EqualsMargin(5))
.set_align(input_label_alignment)
.build(monospace, input_wrapping, input_height);
let resistance_per_meter_input: Input = Input::builder()
.set_label("Rм, Ом:")
.set_margins(MarginData::EqualsMargin(5))
.set_align(input_label_alignment)
.build(monospace, input_wrapping, input_height);
let capacity_per_meter_input: Input = Input::builder()
.set_label("Cм, пФ:")
.set_margins(MarginData::EqualsMargin(5))
.set_align(input_label_alignment)
.build(monospace, input_wrapping, input_height);
let wrapper_first_row = Wrapper::col_builder()
.halign(Align::Fill)
.hexpand(true)
.spacing(5)
.build();
let first_row_elements: Vec<&Input> = vec![
&wire_length_input,
&resistance_per_meter_input,
&capacity_per_meter_input,
];
for elem in first_row_elements {
let input: Box = elem.clone().get();
input.set_halign(input_alignment);
input.set_hexpand(true);
wrapper_first_row.append(&input);
}
let info_signal_voltage_input: Input = Input::builder()
.set_label("Vи, мВ:")
.set_margins(MarginData::EqualsMargin(5))
.set_align(input_label_alignment)
.build(monospace, input_wrapping, input_height);
let resistance_of_info_voltage_source_input: Input = Input::builder()
.set_label("Rи, Ом:")
.set_margins(MarginData::EqualsMargin(5))
.set_align(input_label_alignment)
.build(monospace, input_wrapping, input_height);
let info_voltage_source_frequency_input: Input = Input::builder()
.set_label("f, мГц:")
.set_margins(MarginData::EqualsMargin(5))
.set_align(input_label_alignment)
.build(monospace, input_wrapping, input_height);
let wrapper_second_row = Wrapper::col_builder()
.halign(Align::Fill)
.hexpand(true)
.spacing(5)
.build();
let second_row_elements: Vec<&Input> = vec![
&info_signal_voltage_input,
&resistance_of_info_voltage_source_input,
&info_voltage_source_frequency_input,
];
for elem in second_row_elements {
let input: Box = elem.clone().get();
input.set_halign(input_alignment);
input.set_hexpand(true);
wrapper_second_row.append(&input);
}
let all_text_views: Vec<TextView> = vec![
wire_length_input.get_input(),
resistance_per_meter_input.get_input(),
capacity_per_meter_input.get_input(),
info_signal_voltage_input.get_input(),
resistance_of_info_voltage_source_input.get_input(),
info_voltage_source_frequency_input.get_input(),
];
let main_wrapper = Wrapper::row_builder().spacing(5).build();
main_wrapper.append(&wrapper_first_row);
main_wrapper.append(&wrapper_second_row);
let calculate_button = Button::builder()
.label("Расчитать")
.halign(Align::End)
.set_margin(MarginData::MultipleMargin((10, 5, 0, 0)))
.build();
let table_header_labels = vec!["f, Гц", "Xc, пФ", "Vп, мВ", "ζ"];
let table_header = ColumnView::builder()
.focusable(false)
.reorderable(true)
.halign(Align::Fill)
.hexpand(true)
.build();
for table_header_label in table_header_labels {
let column = ColumnViewColumn::builder()
.title(table_header_label)
.fixed_width(200)
.expand(true)
.build();
table_header.append_column(&column);
}
let table_of_calculated_values = Frame::builder()
.height_request(64)
.hexpand(true)
.child(&table_header)
.halign(Align::Fill)
.set_margin(MarginData::MultipleMargin((10, 5, 0, 0)))
.build();
let errors_label: Label = Label::new(Some(""));
let errors_label_for_handler: Label = errors_label.clone();
EventHandler::new(calculate_button.clone(), move |_| {
start_algorithm(&errors_label_for_handler, &all_text_views)
})
.on_click();
main_wrapper.append(&calculate_button);
main_wrapper.append(&table_of_calculated_values);
main_wrapper.append(&errors_label);
wrapper.append(&main_wrapper);
}