added inputs components and created page for fifth lab
This commit is contained in:
152
src/view/pages/hamming_code.rs
Normal file
152
src/view/pages/hamming_code.rs
Normal file
@@ -0,0 +1,152 @@
|
||||
use gtk4 as gtk;
|
||||
|
||||
use crate::{
|
||||
model::model::*,
|
||||
view::{
|
||||
properties::*,
|
||||
components::{
|
||||
*,
|
||||
switch::*,
|
||||
wrapper::*,
|
||||
}
|
||||
},
|
||||
controller::{
|
||||
controller::*,
|
||||
view_utils::input_utils::*,
|
||||
event_handlers::{
|
||||
button_event_handlers::*,
|
||||
switch_event_handlers::*,
|
||||
},
|
||||
}
|
||||
};
|
||||
|
||||
use gtk::{*, prelude::*};
|
||||
|
||||
pub fn hamming_code_page(wrapper: &Box) -> (){
|
||||
|
||||
// input
|
||||
|
||||
let hamming_text_view_input_label = Label::builder()
|
||||
.halign(Align::Start)
|
||||
.set_margin(MarginData::MultipleMargin((10, 5, 0, 0)))
|
||||
.label(String::from("Поле ввода для кода:"))
|
||||
.build();
|
||||
|
||||
let hamming_text_view_input = TextView::builder()
|
||||
.monospace(true)
|
||||
.set_text_view_margin(MarginData::EqualsMargin(6))
|
||||
.wrap_mode(WrapMode::Word)
|
||||
.build();
|
||||
|
||||
let hamming_text_view_input_frame = Frame::builder()
|
||||
.child(&hamming_text_view_input)
|
||||
.height_request(64)
|
||||
.set_margin(MarginData::MultipleMargin((0, 5, 0, 5)))
|
||||
.build();
|
||||
|
||||
// output
|
||||
|
||||
let hamming_text_view_output_label = Label::builder()
|
||||
.halign(Align::Start)
|
||||
.set_margin(MarginData::MultipleMargin((10, 5, 0, 0)))
|
||||
.label(String::from("Результат:"))
|
||||
.build();
|
||||
|
||||
let hamming_text_view_output = TextView::builder()
|
||||
.monospace(true)
|
||||
.editable(false)
|
||||
.set_text_view_margin(MarginData::EqualsMargin(6))
|
||||
.wrap_mode(WrapMode::Word)
|
||||
.build();
|
||||
|
||||
let hamming_text_view_output_frame = Frame::builder()
|
||||
.child(&hamming_text_view_output)
|
||||
.height_request(64)
|
||||
.set_margin(MarginData::MultipleMargin((0, 5, 0, 5)))
|
||||
.build();
|
||||
|
||||
// interactive panel
|
||||
|
||||
let clear_input_button =
|
||||
Button::builder()
|
||||
.set_align(Alignment::new(Align::Fill, Align::Fill))
|
||||
.label("Очистка полей")
|
||||
.build();
|
||||
|
||||
let hamming_crypt_button = Button::builder()
|
||||
.set_align(Alignment::new(Align::Fill, Align::Fill))
|
||||
.label("Выполнить")
|
||||
.build();
|
||||
|
||||
let crypt_mode_switch = Switch::new();
|
||||
|
||||
let crypt_mode_label = Label::builder()
|
||||
.label("Режим: кодирование")
|
||||
.build();
|
||||
|
||||
// references for binding actions
|
||||
|
||||
let clear_input_button_to_handle = clear_input_button.clone();
|
||||
|
||||
let crypt_mode_label_to_handle = crypt_mode_label.clone();
|
||||
let crypt_mode_switch_to_handle = crypt_mode_switch.clone();
|
||||
|
||||
let text_view_input_for_parse = hamming_text_view_input.clone();
|
||||
let text_view_output_for_output = hamming_text_view_output.clone();
|
||||
|
||||
let text_view_input_for_clearing = hamming_text_view_input.clone();
|
||||
let text_view_output_for_clearing = hamming_text_view_input.clone();
|
||||
|
||||
// actions
|
||||
|
||||
EventHandler::new(
|
||||
clear_input_button_to_handle,
|
||||
move |_| {
|
||||
clearing(&text_view_input_for_clearing, &text_view_output_for_clearing);
|
||||
}
|
||||
).on_click();
|
||||
|
||||
EventHandler::new(
|
||||
hamming_crypt_button.clone(),
|
||||
move |button: &Button| {
|
||||
parse_input(
|
||||
&text_view_input_for_parse,
|
||||
&text_view_output_for_output,
|
||||
crypt_mode_switch_to_handle.state()
|
||||
)
|
||||
}).on_click();
|
||||
|
||||
EventHandler::new(
|
||||
crypt_mode_switch.clone(),
|
||||
move |s : &Switch| {
|
||||
state_controller(s, &crypt_mode_label_to_handle);
|
||||
}).on_toggle();
|
||||
|
||||
// wrappers
|
||||
|
||||
let crypt_mode_wrapper = Wrapper::col_builder()
|
||||
.set_align(Alignment::new(Align::Fill, Align::Center))
|
||||
.hexpand(true)
|
||||
.spacing(10)
|
||||
.build();
|
||||
|
||||
let interactive_components_wrapper = Wrapper::col_builder()
|
||||
.set_align(Alignment::new(Align::Fill, Align::Fill))
|
||||
.set_margin(MarginData::MultipleMargin((0, 5, 0, 5)))
|
||||
.spacing(10)
|
||||
.build();
|
||||
|
||||
crypt_mode_wrapper.append(&crypt_mode_switch);
|
||||
crypt_mode_wrapper.append(&crypt_mode_label);
|
||||
|
||||
interactive_components_wrapper.append(&clear_input_button);
|
||||
interactive_components_wrapper.append(&crypt_mode_wrapper);
|
||||
interactive_components_wrapper.append(&hamming_crypt_button);
|
||||
|
||||
wrapper.append(&hamming_text_view_input_label);
|
||||
wrapper.append(&hamming_text_view_input_frame);
|
||||
wrapper.append(&interactive_components_wrapper);
|
||||
wrapper.append(&hamming_text_view_output_label);
|
||||
wrapper.append(&hamming_text_view_output_frame);
|
||||
|
||||
}
|
||||
2
src/view/pages/mod.rs
Normal file
2
src/view/pages/mod.rs
Normal file
@@ -0,0 +1,2 @@
|
||||
pub mod hamming_code;
|
||||
pub mod signal_reducing;
|
||||
78
src/view/pages/signal_reducing.rs
Normal file
78
src/view/pages/signal_reducing.rs
Normal file
@@ -0,0 +1,78 @@
|
||||
use gtk4 as gtk;
|
||||
|
||||
use gtk::{*, prelude::*};
|
||||
use crate::model::builder_traits::Product;
|
||||
use crate::view::{
|
||||
properties::*,
|
||||
components::{
|
||||
wrapper::*,
|
||||
input::Input,
|
||||
},
|
||||
};
|
||||
|
||||
pub fn signal_reducing_page(wrapper: &Box) {
|
||||
|
||||
let inputs_first_line = Box::new(Orientation::Horizontal, 5);
|
||||
|
||||
inputs_first_line.set_valign(Align::Fill);
|
||||
|
||||
let input_height : i32 = 20;
|
||||
|
||||
let wire_length_input = Input::builder()
|
||||
.set_label("Длина провода (L = [м]):")
|
||||
.set_align(Align::Fill)
|
||||
.set_margins(MarginData::EqualsMargin(5))
|
||||
.build(true, WrapMode::Word, input_height)
|
||||
.get();
|
||||
|
||||
let resistance_input = Input::builder()
|
||||
.set_label("Сопротивление (Rм = [Ом * м]):")
|
||||
.set_align(Align::Fill)
|
||||
.set_margins(MarginData::EqualsMargin(5))
|
||||
.build(true, WrapMode::Word, input_height)
|
||||
.get();
|
||||
|
||||
let capacity_input = Input::builder()
|
||||
.set_label("Ёмкость (Cм = [пФ * м]):")
|
||||
.set_align(Align::Fill)
|
||||
.set_margins(MarginData::EqualsMargin(5))
|
||||
.build(true, WrapMode::Word, input_height)
|
||||
.get();
|
||||
|
||||
let inputs_second_line = Box::new(Orientation::Horizontal, 5);
|
||||
|
||||
inputs_second_line.set_valign(Align::Fill);
|
||||
|
||||
let voltage_input = Input::builder()
|
||||
.set_label("Напряжение (Vи = [мВ]):")
|
||||
.set_align(Align::Fill)
|
||||
.set_margins(MarginData::EqualsMargin(5))
|
||||
.build(true, WrapMode::Word, input_height)
|
||||
.get();
|
||||
|
||||
let source_implicit_resistance_input = Input::builder()
|
||||
.set_label("Сопротивление источника (R = [Ом]):")
|
||||
.set_align(Align::Fill)
|
||||
.set_margins(MarginData::EqualsMargin(5))
|
||||
.build(true, WrapMode::Word, input_height)
|
||||
.get();
|
||||
|
||||
let freq_input = Input::builder()
|
||||
.set_label("Частота (f = [МГц]):")
|
||||
.set_align(Align::Fill)
|
||||
.set_margins(MarginData::EqualsMargin(5))
|
||||
.build(true, WrapMode::Word, input_height)
|
||||
.get();
|
||||
|
||||
|
||||
inputs_first_line.append(&wire_length_input);
|
||||
inputs_first_line.append(&resistance_input);
|
||||
inputs_first_line.append(&capacity_input);
|
||||
inputs_second_line.append(&voltage_input);
|
||||
inputs_second_line.append(&source_implicit_resistance_input);
|
||||
inputs_second_line.append(&freq_input);
|
||||
|
||||
wrapper.append(&inputs_first_line);
|
||||
wrapper.append(&inputs_second_line);
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user