I forget, what I changes
This commit is contained in:
parent
703292a799
commit
db1de143d3
|
@ -1,8 +1,11 @@
|
||||||
use gtk4 as gtk;
|
use gtk4 as gtk;
|
||||||
|
|
||||||
use gtk::*;
|
use gtk::*;
|
||||||
use view::*;
|
|
||||||
use gtk::prelude::*;
|
use gtk::prelude::*;
|
||||||
|
use crate::view::ui::ui;
|
||||||
|
|
||||||
|
#[path="utils/parsing_vector.rs"]
|
||||||
|
mod parsing;
|
||||||
|
|
||||||
#[path="ui_src/components/switch.rs"]
|
#[path="ui_src/components/switch.rs"]
|
||||||
mod switch;
|
mod switch;
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
|
|
||||||
pub mod hamming_code{
|
pub mod hamming_code{
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
use crate::parsing::parsing::parse;
|
||||||
|
|
||||||
pub fn hamming_encrypt_data(data: &Vec<u8>, result_string: &mut String, length_of_code: usize) -> () {
|
pub fn hamming_encrypt_data(data: &Vec<u8>, result_string: &mut String, length_of_code: usize) -> () {
|
||||||
let mut i : usize = length_of_code;
|
let mut i : usize = length_of_code;
|
||||||
|
@ -81,11 +82,15 @@ pub mod hamming_code{
|
||||||
}
|
}
|
||||||
}).collect();
|
}).collect();
|
||||||
|
|
||||||
|
let errored_code = parse(data_bits);
|
||||||
|
|
||||||
|
let correct_code = parse(correctly_code.as_slice());
|
||||||
|
|
||||||
let error = format!("Ошибка в коде {} {:?}, позиция ошибки {}, корректный код: {:?}; \n",
|
let error = format!("Ошибка в коде {} {:?}, позиция ошибки {}, корректный код: {:?}; \n",
|
||||||
i / 7,
|
i / 7,
|
||||||
&data_bits,
|
errored_code,
|
||||||
error_position,
|
error_position,
|
||||||
correctly_code
|
correct_code
|
||||||
);
|
);
|
||||||
|
|
||||||
errors.push_str(error.as_str());
|
errors.push_str(error.as_str());
|
||||||
|
|
|
@ -0,0 +1,9 @@
|
||||||
|
pub mod parsing{
|
||||||
|
pub fn parse(slice : &[u8]) -> String {
|
||||||
|
slice
|
||||||
|
.iter()
|
||||||
|
.map(|bit| bit.to_string())
|
||||||
|
.reduce(|accumulator, element| accumulator + &*element)
|
||||||
|
.unwrap()
|
||||||
|
}
|
||||||
|
}
|
241
src/view.rs
241
src/view.rs
|
@ -1,157 +1,154 @@
|
||||||
use gtk4 as gtk;
|
pub mod ui {
|
||||||
|
use gtk4 as gtk;
|
||||||
|
|
||||||
use gtk::*;
|
use gtk::*;
|
||||||
use gtk::prelude::*;
|
use gtk::prelude::*;
|
||||||
use super::wrapper::*;
|
use crate::controller::{BtnEventHandler, EventHandler, SwEventHandler};
|
||||||
use super::controller::*;
|
use crate::parse_input::parse_input;
|
||||||
use super::parse_input::parse_input;
|
use crate::properties::{Alignment, MarginData, Setters, TextViewSetters};
|
||||||
use super::state_controller::state_controller;
|
use crate::state_controller::state_controller;
|
||||||
use super::properties::{MarginData, Setters, TextViewSetters, Alignment};
|
use crate::wrapper::Wrapper;
|
||||||
|
|
||||||
fn clearing(output : &TextView, input: &TextView){
|
pub fn laboratory_work_first_section(wrapper: &Box) -> (){
|
||||||
input.buffer().set_text("");
|
|
||||||
output.buffer().set_text("");
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn laboratory_work_first_section(wrapper: &Box) -> (){
|
let header = Label::builder()
|
||||||
|
.halign(Align::Start)
|
||||||
|
.label("Лабораторная работа №8: Код Хэмминга")
|
||||||
|
.build();
|
||||||
|
|
||||||
let header = Label::builder()
|
// input
|
||||||
.halign(Align::Start)
|
|
||||||
.label("Лабораторная работа №8: Код Хэмминга")
|
|
||||||
.build();
|
|
||||||
|
|
||||||
// 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_label = Label::builder()
|
let hamming_text_view_input = TextView::builder()
|
||||||
.halign(Align::Start)
|
.monospace(true)
|
||||||
.set_margin(MarginData::MultipleMargin((10, 5, 0, 0)))
|
.set_text_view_margin(MarginData::EqualsMargin(6))
|
||||||
.label(String::from("Поле ввода для кода:"))
|
.wrap_mode(WrapMode::Word)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
let hamming_text_view_input = TextView::builder()
|
let hamming_text_view_input_frame = Frame::builder()
|
||||||
.monospace(true)
|
.child(&hamming_text_view_input)
|
||||||
.set_text_view_margin(MarginData::EqualsMargin(6))
|
.height_request(64)
|
||||||
.wrap_mode(WrapMode::Word)
|
.set_margin(MarginData::MultipleMargin((0, 5, 0, 5)))
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
let hamming_text_view_input_frame = Frame::builder()
|
// output
|
||||||
.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_label = Label::builder()
|
let hamming_text_view_output = TextView::builder()
|
||||||
.halign(Align::Start)
|
.monospace(true)
|
||||||
.set_margin(MarginData::MultipleMargin((10, 5, 0, 0)))
|
.editable(false)
|
||||||
.label(String::from("Результат:"))
|
.set_text_view_margin(MarginData::EqualsMargin(6))
|
||||||
.build();
|
.wrap_mode(WrapMode::Word)
|
||||||
|
.build();
|
||||||
|
|
||||||
let hamming_text_view_output = TextView::builder()
|
let hamming_text_view_output_frame = Frame::builder()
|
||||||
.monospace(true)
|
.child(&hamming_text_view_output)
|
||||||
.editable(false)
|
.height_request(64)
|
||||||
.set_text_view_margin(MarginData::EqualsMargin(6))
|
.set_margin(MarginData::MultipleMargin((0, 5, 0, 5)))
|
||||||
.wrap_mode(WrapMode::Word)
|
.build();
|
||||||
.build();
|
|
||||||
|
|
||||||
let hamming_text_view_output_frame = Frame::builder()
|
// interactive panel
|
||||||
.child(&hamming_text_view_output)
|
|
||||||
.height_request(64)
|
|
||||||
.set_margin(MarginData::MultipleMargin((0, 5, 0, 5)))
|
|
||||||
.build();
|
|
||||||
|
|
||||||
// interactive panel
|
let hamming_crypt_button = Button::builder()
|
||||||
|
.set_align(Alignment::new(Align::Fill, Align::Fill))
|
||||||
|
.label("Выполнить")
|
||||||
|
.build();
|
||||||
|
|
||||||
let hamming_crypt_button = Button::builder()
|
let crypt_mode_switch = Switch::new();
|
||||||
.set_align(Alignment::new(Align::Fill, Align::Fill))
|
|
||||||
.label("Выполнить")
|
|
||||||
.build();
|
|
||||||
|
|
||||||
let crypt_mode_switch = Switch::new();
|
let crypt_mode_label = Label::builder()
|
||||||
|
.label("Режим: кодирование")
|
||||||
|
.build();
|
||||||
|
|
||||||
let crypt_mode_label = Label::builder()
|
// references for binding actions
|
||||||
.label("Режим: кодирование")
|
|
||||||
.build();
|
|
||||||
|
|
||||||
// references for binding actions
|
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 crypt_mode_label_to_handle = crypt_mode_label.clone();
|
// actions
|
||||||
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();
|
|
||||||
|
|
||||||
// actions
|
EventHandler::new(
|
||||||
|
hamming_crypt_button.clone(),
|
||||||
|
move |_| {
|
||||||
|
parse_input(
|
||||||
|
&text_view_input_for_parse,
|
||||||
|
&text_view_output_for_output,
|
||||||
|
crypt_mode_switch_to_handle.state()
|
||||||
|
)
|
||||||
|
}).on_click();
|
||||||
|
|
||||||
EventHandler::new(
|
EventHandler::new(
|
||||||
hamming_crypt_button.clone(),
|
crypt_mode_switch.clone(),
|
||||||
move |_| {
|
move |s| {
|
||||||
parse_input(
|
state_controller(s, &crypt_mode_label_to_handle);
|
||||||
&text_view_input_for_parse,
|
}).on_toggle();
|
||||||
&text_view_output_for_output,
|
|
||||||
crypt_mode_switch_to_handle.state()
|
|
||||||
)
|
|
||||||
}).on_click();
|
|
||||||
|
|
||||||
EventHandler::new(
|
// wrappers
|
||||||
crypt_mode_switch.clone(),
|
|
||||||
move |s| {
|
|
||||||
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 crypt_mode_wrapper = Wrapper::col_builder()
|
let interactive_components_wrapper = Wrapper::col_builder()
|
||||||
.set_align(Alignment::new(Align::Fill, Align::Center))
|
.set_align(Alignment::new(Align::Fill, Align::Fill))
|
||||||
.hexpand(true)
|
.set_margin(MarginData::MultipleMargin((0, 5, 0, 5)))
|
||||||
.spacing(10)
|
.spacing(10)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
let interactive_components_wrapper = Wrapper::col_builder()
|
// separators
|
||||||
.set_align(Alignment::new(Align::Fill, Align::Fill))
|
|
||||||
.set_margin(MarginData::MultipleMargin((0, 5, 0, 5)))
|
|
||||||
.spacing(10)
|
|
||||||
.build();
|
|
||||||
|
|
||||||
// separators
|
let separator = Separator::builder()
|
||||||
|
.orientation(Orientation::Horizontal)
|
||||||
|
.build();
|
||||||
|
|
||||||
let separator = Separator::builder()
|
crypt_mode_wrapper.append(&crypt_mode_switch);
|
||||||
.orientation(Orientation::Horizontal)
|
crypt_mode_wrapper.append(&crypt_mode_label);
|
||||||
.build();
|
|
||||||
|
|
||||||
crypt_mode_wrapper.append(&crypt_mode_switch);
|
interactive_components_wrapper.append(&crypt_mode_wrapper);
|
||||||
crypt_mode_wrapper.append(&crypt_mode_label);
|
interactive_components_wrapper.append(&hamming_crypt_button);
|
||||||
|
|
||||||
interactive_components_wrapper.append(&crypt_mode_wrapper);
|
wrapper.append(&header);
|
||||||
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);
|
||||||
|
wrapper.append(&separator);
|
||||||
|
|
||||||
wrapper.append(&header);
|
}
|
||||||
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);
|
|
||||||
wrapper.append(&separator);
|
|
||||||
|
|
||||||
}
|
pub fn ui(application: &Application) {
|
||||||
|
|
||||||
pub fn ui(application: &Application) {
|
let mutual_wrapper = Wrapper::row_builder()
|
||||||
|
.set_align(Alignment::new(Align::Fill, Align::Fill))
|
||||||
|
.set_margin(MarginData::EqualsMargin(15))
|
||||||
|
.spacing(10)
|
||||||
|
.build();
|
||||||
|
|
||||||
let mutual_wrapper = Wrapper::row_builder()
|
laboratory_work_first_section(&mutual_wrapper);
|
||||||
.set_align(Alignment::new(Align::Fill, Align::Fill))
|
|
||||||
.set_margin(MarginData::EqualsMargin(15))
|
|
||||||
.spacing(10)
|
|
||||||
.build();
|
|
||||||
|
|
||||||
laboratory_work_first_section(&mutual_wrapper);
|
let window = ApplicationWindow::builder()
|
||||||
|
.title("Комплексная программа для лаб. работ")
|
||||||
|
.width_request(800)
|
||||||
|
.height_request(400)
|
||||||
|
.application(application)
|
||||||
|
.child(&mutual_wrapper)
|
||||||
|
.build();
|
||||||
|
|
||||||
let window = ApplicationWindow::builder()
|
window.show();
|
||||||
.title("Комплексная программа для лаб. работ")
|
}
|
||||||
.width_request(650)
|
|
||||||
.height_request(400)
|
|
||||||
.application(application)
|
|
||||||
.child(&mutual_wrapper)
|
|
||||||
.build();
|
|
||||||
|
|
||||||
window.show();
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue