2024-03-17 20:34:12 +03:00
|
|
|
use gtk4 as gtk;
|
|
|
|
|
|
|
|
use crate::{
|
|
|
|
controller::{
|
|
|
|
controller::*,
|
2024-04-14 19:13:15 +03:00
|
|
|
event_handlers::{button_event_handlers::*, switch_event_handlers::*},
|
2024-04-19 00:30:51 +03:00
|
|
|
view_utils::{hamming_code_input_utils::*, input_utils::*},
|
2024-04-14 19:13:15 +03:00
|
|
|
},
|
2024-07-19 22:17:02 +03:00
|
|
|
model::models::*,
|
2024-04-14 19:13:15 +03:00
|
|
|
view::{components::wrapper::*, properties::*},
|
2024-03-17 20:34:12 +03:00
|
|
|
};
|
|
|
|
|
2024-04-14 19:13:15 +03:00
|
|
|
use gtk::{prelude::*, *};
|
2024-03-17 20:34:12 +03:00
|
|
|
|
2024-07-19 22:17:02 +03:00
|
|
|
pub fn hamming_code_page(wrapper: &Box, info_bar: Revealer) {
|
2024-03-17 20:34:12 +03:00
|
|
|
// 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
|
|
|
|
|
2024-04-14 19:13:15 +03:00
|
|
|
let clear_input_button = Button::builder()
|
|
|
|
.set_align(Alignment::new(Align::Fill, Align::Fill))
|
|
|
|
.label("Очистка полей")
|
|
|
|
.build();
|
2024-03-17 20:34:12 +03:00
|
|
|
|
|
|
|
let hamming_crypt_button = Button::builder()
|
|
|
|
.set_align(Alignment::new(Align::Fill, Align::Fill))
|
|
|
|
.label("Выполнить")
|
|
|
|
.build();
|
|
|
|
|
|
|
|
let crypt_mode_switch = Switch::new();
|
|
|
|
|
2024-04-14 19:13:15 +03:00
|
|
|
let crypt_mode_label = Label::builder().label("Режим: кодирование").build();
|
2024-03-17 20:34:12 +03:00
|
|
|
|
|
|
|
// 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();
|
2024-04-16 23:06:56 +03:00
|
|
|
let text_view_output_for_clearing = hamming_text_view_output.clone();
|
2024-03-17 20:34:12 +03:00
|
|
|
|
|
|
|
// actions
|
|
|
|
|
2024-04-14 19:13:15 +03:00
|
|
|
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| {
|
2024-04-19 00:30:51 +03:00
|
|
|
start_hamming_algorithm(
|
2024-04-14 19:13:15 +03:00
|
|
|
&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();
|
2024-03-17 20:34:12 +03:00
|
|
|
|
|
|
|
// 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);
|
2024-04-14 19:13:15 +03:00
|
|
|
}
|