removed unnecessary module definitions
This commit is contained in:
parent
54619cd3f9
commit
4c230c090d
|
@ -1,14 +1,12 @@
|
|||
pub mod button_event_handlers_module{
|
||||
|
||||
use crate::{
|
||||
model::model::model_module::*,
|
||||
use crate::{
|
||||
model::model::*,
|
||||
gtk::{
|
||||
*,
|
||||
prelude::*
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
impl<F, C> EventHandler<F, C>
|
||||
impl<F, C> EventHandler<F, C>
|
||||
where F: Fn(&C) + FnOnce(&C) + FnMut(&C){
|
||||
pub fn new(component: C, callback: F) -> EventHandler<F, C>{
|
||||
Self{
|
||||
|
@ -16,19 +14,17 @@ pub mod button_event_handlers_module{
|
|||
callback,
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub trait BtnEventHandler{
|
||||
pub trait BtnEventHandler{
|
||||
fn on_click(self) -> ();
|
||||
}
|
||||
}
|
||||
|
||||
impl<F, C> BtnEventHandler for EventHandler<F, C>
|
||||
impl<F, C> BtnEventHandler for EventHandler<F, C>
|
||||
where F: Fn(&C) + FnOnce(&C) + FnMut(&C) + 'static, C: ButtonExt + WidgetExt{
|
||||
fn on_click(self) -> () {
|
||||
self.component.connect_clicked(move |button| {
|
||||
(self.callback)(button)
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,30 +1,26 @@
|
|||
pub mod switch_event_handlers_module{
|
||||
|
||||
use crate::{
|
||||
model::model::model_module::*,
|
||||
view::components::switch::switch_module::SwitchExt,
|
||||
use crate::{
|
||||
model::model::*,
|
||||
view::components::switch::SwitchExt,
|
||||
gtk::{
|
||||
*,
|
||||
prelude::*
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
pub trait SwEventHandler{
|
||||
pub trait SwEventHandler{
|
||||
fn on_toggle(self) -> ();
|
||||
}
|
||||
}
|
||||
|
||||
impl<F, C> SwEventHandler for EventHandler<F, C>
|
||||
impl<F, C> SwEventHandler for EventHandler<F, C>
|
||||
where F: Fn(&C) + FnOnce(&C) + FnMut(&C) + 'static, C: SwitchExt + WidgetExt{
|
||||
fn on_toggle(self) -> () {
|
||||
self.component.connect_state_notify(move |switch| {
|
||||
(self.callback)(switch)
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn clearing(output : &TextView, input: &TextView){
|
||||
pub fn clearing(output : &TextView, input: &TextView){
|
||||
input.buffer().set_text("");
|
||||
output.buffer().set_text("");
|
||||
}
|
||||
|
||||
}
|
|
@ -1,29 +1,27 @@
|
|||
pub mod hamming_code{
|
||||
use std::{borrow::Borrow, collections::HashMap};
|
||||
|
||||
use std::{borrow::Borrow, collections::HashMap};
|
||||
use crate::{
|
||||
model::model::*,
|
||||
controller::view_utils::input_utils::*,
|
||||
};
|
||||
|
||||
use crate::{
|
||||
model::model::model_module::*,
|
||||
controller::view_utils::input_utils::input_utils_module::*,
|
||||
};
|
||||
/// **Синдромы**
|
||||
///
|
||||
/// ошибочная позиция 1 false true true.
|
||||
///
|
||||
/// ошибочная позиция 2 false false true.
|
||||
///
|
||||
/// ошибочная позиция 3 true false true.
|
||||
///
|
||||
/// ошибочная позиция 4 false true false.
|
||||
///
|
||||
/// ошибочная позиция 5 true true false.
|
||||
///
|
||||
/// ошибочная позиция 6 true false false.
|
||||
///
|
||||
/// ошибочная позиция 7 false false false.
|
||||
|
||||
/// **Синдромы**
|
||||
///
|
||||
/// ошибочная позиция 1 false true true.
|
||||
///
|
||||
/// ошибочная позиция 2 false false true.
|
||||
///
|
||||
/// ошибочная позиция 3 true false true.
|
||||
///
|
||||
/// ошибочная позиция 4 false true false.
|
||||
///
|
||||
/// ошибочная позиция 5 true true false.
|
||||
///
|
||||
/// ошибочная позиция 6 true false false.
|
||||
///
|
||||
/// ошибочная позиция 7 false false false.
|
||||
|
||||
pub fn hamming(raw_input: String, mode: HammingMode) -> Result<String, String>{
|
||||
pub fn hamming(raw_input: String, mode: HammingMode) -> Result<String, String>{
|
||||
|
||||
let length_of_code : usize = mode.clone() as usize;
|
||||
|
||||
|
@ -50,13 +48,13 @@ pub mod hamming_code{
|
|||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
pub fn hamming_encrypt_data(
|
||||
pub fn hamming_encrypt_data(
|
||||
data: &Vec<u8>,
|
||||
result_string: &mut String,
|
||||
length_of_code: usize
|
||||
) {
|
||||
) {
|
||||
let mut i : usize = length_of_code;
|
||||
|
||||
while i <= data.len(){
|
||||
|
@ -75,13 +73,13 @@ pub mod hamming_code{
|
|||
i += length_of_code;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn hamming_decrypt_data(
|
||||
pub fn hamming_decrypt_data(
|
||||
data: &Vec<u8>,
|
||||
result_string: &mut String,
|
||||
length_of_code: usize
|
||||
) {
|
||||
) {
|
||||
|
||||
let mut i : usize = length_of_code;
|
||||
|
||||
|
@ -154,6 +152,4 @@ pub mod hamming_code{
|
|||
result_string.push_str(errors.as_str())
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -1,17 +1,15 @@
|
|||
pub mod input_utils_module {
|
||||
use gtk4 as gtk;
|
||||
|
||||
use gtk4 as gtk;
|
||||
use std::ops::Deref;
|
||||
use gtk::{*, prelude::*};
|
||||
use bitvec::{order::Lsb0, view::AsBits};
|
||||
|
||||
use std::ops::Deref;
|
||||
use gtk::{*, prelude::*};
|
||||
use bitvec::{order::Lsb0, view::AsBits};
|
||||
use crate::{
|
||||
model::model::*,
|
||||
model_utils::hamming_code_seven_four::*
|
||||
};
|
||||
|
||||
use crate::{
|
||||
model::model::model_module::*,
|
||||
model_utils::hamming_code_seven_four::hamming_code::*
|
||||
};
|
||||
|
||||
pub fn parse_input(input : &TextView, output : &TextView, mode: bool) -> (){
|
||||
pub fn parse_input(input : &TextView, output : &TextView, mode: bool) -> (){
|
||||
|
||||
let (iter_start, iter_end) = input.buffer().bounds();
|
||||
let parsed_input : String = input
|
||||
|
@ -33,9 +31,9 @@ pub mod input_utils_module {
|
|||
Err(rej) => output.buffer().set_text(rej.as_str()),
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
pub fn processing_input(input : &String) -> String {
|
||||
pub fn processing_input(input : &String) -> String {
|
||||
|
||||
input
|
||||
.split_ascii_whitespace()
|
||||
|
@ -44,9 +42,9 @@ pub mod input_utils_module {
|
|||
})
|
||||
.fold(String::new(), |c: String, n: &str| { c + n })
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
pub fn check_correct_input(input: &String, prepared_input: &String, l: usize) -> (bool, bool){
|
||||
pub fn check_correct_input(input: &String, prepared_input: &String, l: usize) -> (bool, bool){
|
||||
|
||||
let first_condition = input
|
||||
.chars()
|
||||
|
@ -56,9 +54,9 @@ pub mod input_utils_module {
|
|||
|
||||
(first_condition, second_condition)
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
pub fn from_string_to_vec_bits(raw_data: String) -> Vec<u8>{
|
||||
pub fn from_string_to_vec_bits(raw_data: String) -> Vec<u8>{
|
||||
|
||||
raw_data
|
||||
.as_bits::<Lsb0>()
|
||||
|
@ -67,6 +65,4 @@ pub mod input_utils_module {
|
|||
.map(|x| *x.deref() as u8)
|
||||
.collect()
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -6,13 +6,11 @@ use gtk::*;
|
|||
use gtk::prelude::*;
|
||||
|
||||
mod view;
|
||||
use view::view::view_module::*;
|
||||
|
||||
mod model;
|
||||
|
||||
mod controller;
|
||||
use controller::*;
|
||||
|
||||
use controller::*;
|
||||
use view::view::*;
|
||||
|
||||
fn main() {
|
||||
|
||||
|
@ -22,4 +20,5 @@ fn main() {
|
|||
|
||||
app.connect_activate(ui);
|
||||
app.run();
|
||||
|
||||
}
|
|
@ -1,16 +1,11 @@
|
|||
pub mod model_module{
|
||||
|
||||
#[repr(usize)]
|
||||
#[derive(Clone)]
|
||||
pub enum HammingMode{
|
||||
#[repr(usize)]
|
||||
#[derive(Clone)]
|
||||
pub enum HammingMode{
|
||||
Encrypt = 4,
|
||||
Decrypt = 7
|
||||
}
|
||||
|
||||
pub struct EventHandler<F, C>{
|
||||
pub(crate) component: C,
|
||||
pub(crate) callback: F,
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
pub struct EventHandler<F, C>{
|
||||
pub(crate) component: C,
|
||||
pub(crate) callback: F,
|
||||
}
|
|
@ -1,22 +1,20 @@
|
|||
pub mod switch_module {
|
||||
use gtk4 as gtk;
|
||||
|
||||
use gtk4 as gtk;
|
||||
use gtk::{*, prelude::*};
|
||||
|
||||
use gtk::{*, prelude::*};
|
||||
|
||||
use glib::{
|
||||
use glib::{
|
||||
signal::{connect_raw, SignalHandlerId},
|
||||
translate::*,
|
||||
};
|
||||
};
|
||||
|
||||
use std::boxed::Box as Box_;
|
||||
use std::boxed::Box as Box_;
|
||||
|
||||
mod sealed {
|
||||
mod sealed {
|
||||
pub trait Sealed {}
|
||||
impl<T: super::IsA<super::Switch>> Sealed for T {}
|
||||
}
|
||||
}
|
||||
|
||||
pub trait SwitchExt: IsA<Switch> + sealed::Sealed + 'static {
|
||||
pub trait SwitchExt: IsA<Switch> + sealed::Sealed + 'static {
|
||||
#[doc(alias = "gtk_switch_get_active")]
|
||||
#[doc(alias = "get_active")]
|
||||
fn is_active(&self) -> bool {
|
||||
|
@ -147,7 +145,6 @@ pub mod switch_module {
|
|||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<O: IsA<Switch>> SwitchExt for O {}
|
||||
}
|
||||
|
||||
impl<O: IsA<Switch>> SwitchExt for O {}
|
|
@ -1,22 +1,20 @@
|
|||
pub mod tabs_module {
|
||||
use gtk4 as gtk;
|
||||
|
||||
use gtk4 as gtk;
|
||||
use gtk::{Notebook, Label, Box};
|
||||
|
||||
use gtk::{Notebook, Label, Box};
|
||||
pub type TabLabel = Label;
|
||||
pub type TabContent = Box;
|
||||
|
||||
pub type TabLabel = Label;
|
||||
pub type TabContent = Box;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct TabsBuilder {
|
||||
#[derive(Clone)]
|
||||
pub struct TabsBuilder {
|
||||
tabs: Vec<(TabLabel, TabContent)>
|
||||
}
|
||||
}
|
||||
|
||||
pub struct Tabs {
|
||||
pub struct Tabs {
|
||||
tabs_wrapper: Notebook
|
||||
}
|
||||
}
|
||||
|
||||
impl Tabs {
|
||||
impl Tabs {
|
||||
pub fn builder() -> TabsBuilder {
|
||||
TabsBuilder{
|
||||
tabs: Vec::new(),
|
||||
|
@ -27,9 +25,9 @@ pub mod tabs_module {
|
|||
self.tabs_wrapper
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
impl TabsBuilder {
|
||||
impl TabsBuilder {
|
||||
|
||||
fn append_tab_private(&mut self, label: &str, page: TabContent) {
|
||||
let tab_label = Label::new(Some(label));
|
||||
|
@ -66,6 +64,4 @@ pub mod tabs_module {
|
|||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -1,13 +1,11 @@
|
|||
pub mod wrapper_module {
|
||||
use gtk4 as gtk;
|
||||
|
||||
use gtk4 as gtk;
|
||||
use gtk::{Orientation, builders::BoxBuilder, Box};
|
||||
|
||||
use gtk::{Orientation, builders::BoxBuilder, Box};
|
||||
#[allow(dead_code)]
|
||||
pub struct Wrapper;
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub struct Wrapper;
|
||||
|
||||
impl Wrapper{
|
||||
impl Wrapper{
|
||||
|
||||
pub fn row_builder() -> BoxBuilder {
|
||||
Box::builder().orientation(Orientation::Vertical)
|
||||
|
@ -17,7 +15,4 @@ pub mod wrapper_module {
|
|||
Box::builder().orientation(Orientation::Horizontal)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -1,54 +1,53 @@
|
|||
pub mod properties_module{
|
||||
use gtk4 as gtk;
|
||||
use gtk4 as gtk;
|
||||
|
||||
use gtk::{Align};
|
||||
use gtk::builders::*;
|
||||
use gtk::{Align};
|
||||
use gtk::builders::*;
|
||||
|
||||
/**
|
||||
/**
|
||||
* Types
|
||||
*/
|
||||
|
||||
pub type Margin = (i32, i32, i32, i32);
|
||||
pub type Margin = (i32, i32, i32, i32);
|
||||
|
||||
/**
|
||||
/**
|
||||
* Enums
|
||||
*/
|
||||
|
||||
pub enum MarginData{
|
||||
pub enum MarginData{
|
||||
EqualsMargin(i32),
|
||||
MultipleMargin(Margin),
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Structs
|
||||
*/
|
||||
|
||||
#[allow(dead_code)]
|
||||
#[allow(dead_code)]
|
||||
|
||||
pub struct Size {
|
||||
pub struct Size {
|
||||
pub width: i32,
|
||||
pub height: i32
|
||||
}
|
||||
}
|
||||
|
||||
pub struct Alignment {
|
||||
pub struct Alignment {
|
||||
pub horizontal: Align,
|
||||
pub vertical : Align
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Traits
|
||||
*/
|
||||
|
||||
pub trait Setters{
|
||||
pub trait Setters{
|
||||
fn set_margin(self, margin: MarginData) -> Self;
|
||||
fn set_align(self, align: Alignment) -> Self;
|
||||
}
|
||||
}
|
||||
|
||||
pub trait TextViewSetters{
|
||||
pub trait TextViewSetters{
|
||||
fn set_text_view_margin(self, margin: MarginData) -> Self;
|
||||
}
|
||||
}
|
||||
|
||||
impl TextViewSetters for TextViewBuilder{
|
||||
impl TextViewSetters for TextViewBuilder{
|
||||
fn set_text_view_margin(self, margin: MarginData) -> Self{
|
||||
match margin{
|
||||
MarginData::EqualsMargin(margin) =>
|
||||
|
@ -63,13 +62,13 @@ pub mod properties_module{
|
|||
.right_margin(margins.3),
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Macros
|
||||
*/
|
||||
|
||||
macro_rules! impl_setters {
|
||||
macro_rules! impl_setters {
|
||||
($($t:ty),+) => {
|
||||
$(
|
||||
impl Setters for $t {
|
||||
|
@ -94,27 +93,26 @@ pub mod properties_module{
|
|||
}
|
||||
)*
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl_setters!{ButtonBuilder, EntryBuilder, TextViewBuilder,
|
||||
BoxBuilder, SwitchBuilder, FrameBuilder, LabelBuilder}
|
||||
impl_setters!{ButtonBuilder, EntryBuilder, TextViewBuilder,
|
||||
BoxBuilder, SwitchBuilder, FrameBuilder, LabelBuilder}
|
||||
|
||||
#[allow(dead_code)]
|
||||
impl Size{
|
||||
#[allow(dead_code)]
|
||||
impl Size{
|
||||
pub fn new(w: i32, h: i32) -> Size{
|
||||
Size{
|
||||
width: w,
|
||||
height: h,
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Alignment{
|
||||
impl Alignment{
|
||||
pub fn new(horizontal: Align, vertical : Align) -> Alignment{
|
||||
Alignment{
|
||||
horizontal,
|
||||
vertical,
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,31 +1,29 @@
|
|||
pub mod view_module{
|
||||
use gtk4 as gtk;
|
||||
|
||||
use gtk4 as gtk;
|
||||
use gtk::{*, prelude::*};
|
||||
|
||||
use gtk::{*, prelude::*};
|
||||
|
||||
use crate::{
|
||||
model::model::model_module::*,
|
||||
use crate::{
|
||||
model::model::*,
|
||||
view::{
|
||||
properties::properties_module::*,
|
||||
properties::*,
|
||||
components::{
|
||||
*,
|
||||
tabs::tabs_module::*,
|
||||
switch::switch_module::*,
|
||||
wrapper::wrapper_module::*,
|
||||
tabs::*,
|
||||
switch::*,
|
||||
wrapper::*,
|
||||
}
|
||||
},
|
||||
controller::{
|
||||
controller::*,
|
||||
view_utils::input_utils::input_utils_module::*,
|
||||
view_utils::input_utils::*,
|
||||
event_handlers::{
|
||||
button_event_handlers::button_event_handlers_module::*,
|
||||
switch_event_handlers::switch_event_handlers_module::*,
|
||||
button_event_handlers::*,
|
||||
switch_event_handlers::*,
|
||||
},
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
pub fn laboratory_work_first_section(wrapper: &Box) -> (){
|
||||
pub fn laboratory_work_first_section(wrapper: &Box) -> (){
|
||||
|
||||
// input
|
||||
|
||||
|
@ -152,9 +150,9 @@ pub mod view_module{
|
|||
wrapper.append(&hamming_text_view_output_label);
|
||||
wrapper.append(&hamming_text_view_output_frame);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
pub fn ui(application: &Application) {
|
||||
pub fn ui(application: &Application) {
|
||||
|
||||
let mutual_wrapper = Wrapper::row_builder()
|
||||
.set_align(Alignment::new(Align::Fill, Align::Fill))
|
||||
|
@ -189,7 +187,4 @@ pub mod view_module{
|
|||
.build();
|
||||
|
||||
window.show();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue