removed unnecessary module definitions

This commit is contained in:
doryan04 2024-03-10 12:54:32 +04:00
parent 54619cd3f9
commit 4c230c090d
11 changed files with 702 additions and 743 deletions

View File

@ -1,14 +1,12 @@
pub mod button_event_handlers_module{ use crate::{
model::model::*,
use crate::{
model::model::model_module::*,
gtk::{ gtk::{
*, *,
prelude::* prelude::*
}, },
}; };
impl<F, C> EventHandler<F, C> impl<F, C> EventHandler<F, C>
where F: Fn(&C) + FnOnce(&C) + FnMut(&C){ where F: Fn(&C) + FnOnce(&C) + FnMut(&C){
pub fn new(component: C, callback: F) -> EventHandler<F, C>{ pub fn new(component: C, callback: F) -> EventHandler<F, C>{
Self{ Self{
@ -16,19 +14,17 @@ pub mod button_event_handlers_module{
callback, callback,
} }
} }
} }
pub trait BtnEventHandler{ pub trait BtnEventHandler{
fn on_click(self) -> (); 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{ where F: Fn(&C) + FnOnce(&C) + FnMut(&C) + 'static, C: ButtonExt + WidgetExt{
fn on_click(self) -> () { fn on_click(self) -> () {
self.component.connect_clicked(move |button| { self.component.connect_clicked(move |button| {
(self.callback)(button) (self.callback)(button)
}); });
} }
}
} }

View File

@ -1,30 +1,26 @@
pub mod switch_event_handlers_module{ use crate::{
model::model::*,
use crate::{ view::components::switch::SwitchExt,
model::model::model_module::*,
view::components::switch::switch_module::SwitchExt,
gtk::{ gtk::{
*, *,
prelude::* prelude::*
}, },
}; };
pub trait SwEventHandler{ pub trait SwEventHandler{
fn on_toggle(self) -> (); 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{ where F: Fn(&C) + FnOnce(&C) + FnMut(&C) + 'static, C: SwitchExt + WidgetExt{
fn on_toggle(self) -> () { fn on_toggle(self) -> () {
self.component.connect_state_notify(move |switch| { self.component.connect_state_notify(move |switch| {
(self.callback)(switch) (self.callback)(switch)
}); });
} }
} }
pub fn clearing(output : &TextView, input: &TextView){ pub fn clearing(output : &TextView, input: &TextView){
input.buffer().set_text(""); input.buffer().set_text("");
output.buffer().set_text(""); output.buffer().set_text("");
}
} }

View File

@ -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.
/// **Синдромы** pub fn hamming(raw_input: String, mode: HammingMode) -> Result<String, String>{
///
/// ошибочная позиция 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>{
let length_of_code : usize = mode.clone() as usize; 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>, data: &Vec<u8>,
result_string: &mut String, result_string: &mut String,
length_of_code: usize length_of_code: usize
) { ) {
let mut i : usize = length_of_code; let mut i : usize = length_of_code;
while i <= data.len(){ while i <= data.len(){
@ -75,13 +73,13 @@ pub mod hamming_code{
i += length_of_code; i += length_of_code;
} }
} }
pub fn hamming_decrypt_data( pub fn hamming_decrypt_data(
data: &Vec<u8>, data: &Vec<u8>,
result_string: &mut String, result_string: &mut String,
length_of_code: usize length_of_code: usize
) { ) {
let mut i : usize = length_of_code; let mut i : usize = length_of_code;
@ -154,6 +152,4 @@ pub mod hamming_code{
result_string.push_str(errors.as_str()) result_string.push_str(errors.as_str())
} }
}
} }

View File

@ -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 crate::{
use gtk::{*, prelude::*}; model::model::*,
use bitvec::{order::Lsb0, view::AsBits}; model_utils::hamming_code_seven_four::*
};
use crate::{ pub fn parse_input(input : &TextView, output : &TextView, mode: bool) -> (){
model::model::model_module::*,
model_utils::hamming_code_seven_four::hamming_code::*
};
pub fn parse_input(input : &TextView, output : &TextView, mode: bool) -> (){
let (iter_start, iter_end) = input.buffer().bounds(); let (iter_start, iter_end) = input.buffer().bounds();
let parsed_input : String = input let parsed_input : String = input
@ -33,9 +31,9 @@ pub mod input_utils_module {
Err(rej) => output.buffer().set_text(rej.as_str()), Err(rej) => output.buffer().set_text(rej.as_str()),
} }
} }
pub fn processing_input(input : &String) -> String { pub fn processing_input(input : &String) -> String {
input input
.split_ascii_whitespace() .split_ascii_whitespace()
@ -44,9 +42,9 @@ pub mod input_utils_module {
}) })
.fold(String::new(), |c: String, n: &str| { c + n }) .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 let first_condition = input
.chars() .chars()
@ -56,9 +54,9 @@ pub mod input_utils_module {
(first_condition, second_condition) (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 raw_data
.as_bits::<Lsb0>() .as_bits::<Lsb0>()
@ -67,6 +65,4 @@ pub mod input_utils_module {
.map(|x| *x.deref() as u8) .map(|x| *x.deref() as u8)
.collect() .collect()
}
} }

View File

@ -6,13 +6,11 @@ use gtk::*;
use gtk::prelude::*; use gtk::prelude::*;
mod view; mod view;
use view::view::view_module::*;
mod model; mod model;
mod controller; mod controller;
use controller::*;
use controller::*;
use view::view::*;
fn main() { fn main() {
@ -22,4 +20,5 @@ fn main() {
app.connect_activate(ui); app.connect_activate(ui);
app.run(); app.run();
} }

View File

@ -1,16 +1,11 @@
pub mod model_module{ #[repr(usize)]
#[derive(Clone)]
#[repr(usize)] pub enum HammingMode{
#[derive(Clone)]
pub enum HammingMode{
Encrypt = 4, Encrypt = 4,
Decrypt = 7 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,
}

View File

@ -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}, signal::{connect_raw, SignalHandlerId},
translate::*, translate::*,
}; };
use std::boxed::Box as Box_; use std::boxed::Box as Box_;
mod sealed { mod sealed {
pub trait Sealed {} pub trait Sealed {}
impl<T: super::IsA<super::Switch>> Sealed for T {} 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 = "gtk_switch_get_active")]
#[doc(alias = "get_active")] #[doc(alias = "get_active")]
fn is_active(&self) -> bool { 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 {}

View File

@ -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; #[derive(Clone)]
pub type TabContent = Box; pub struct TabsBuilder {
#[derive(Clone)]
pub struct TabsBuilder {
tabs: Vec<(TabLabel, TabContent)> tabs: Vec<(TabLabel, TabContent)>
} }
pub struct Tabs { pub struct Tabs {
tabs_wrapper: Notebook tabs_wrapper: Notebook
} }
impl Tabs { impl Tabs {
pub fn builder() -> TabsBuilder { pub fn builder() -> TabsBuilder {
TabsBuilder{ TabsBuilder{
tabs: Vec::new(), tabs: Vec::new(),
@ -27,9 +25,9 @@ pub mod tabs_module {
self.tabs_wrapper self.tabs_wrapper
} }
} }
impl TabsBuilder { impl TabsBuilder {
fn append_tab_private(&mut self, label: &str, page: TabContent) { fn append_tab_private(&mut self, label: &str, page: TabContent) {
let tab_label = Label::new(Some(label)); let tab_label = Label::new(Some(label));
@ -66,6 +64,4 @@ pub mod tabs_module {
} }
} }
}
} }

View File

@ -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)] impl Wrapper{
pub struct Wrapper;
impl Wrapper{
pub fn row_builder() -> BoxBuilder { pub fn row_builder() -> BoxBuilder {
Box::builder().orientation(Orientation::Vertical) Box::builder().orientation(Orientation::Vertical)
@ -17,7 +15,4 @@ pub mod wrapper_module {
Box::builder().orientation(Orientation::Horizontal) Box::builder().orientation(Orientation::Horizontal)
} }
}
} }

View File

@ -1,54 +1,53 @@
pub mod properties_module{ use gtk4 as gtk;
use gtk4 as gtk;
use gtk::{Align}; use gtk::{Align};
use gtk::builders::*; use gtk::builders::*;
/** /**
* Types * Types
*/ */
pub type Margin = (i32, i32, i32, i32); pub type Margin = (i32, i32, i32, i32);
/** /**
* Enums * Enums
*/ */
pub enum MarginData{ pub enum MarginData{
EqualsMargin(i32), EqualsMargin(i32),
MultipleMargin(Margin), MultipleMargin(Margin),
} }
/** /**
* Structs * Structs
*/ */
#[allow(dead_code)] #[allow(dead_code)]
pub struct Size { pub struct Size {
pub width: i32, pub width: i32,
pub height: i32 pub height: i32
} }
pub struct Alignment { pub struct Alignment {
pub horizontal: Align, pub horizontal: Align,
pub vertical : Align pub vertical : Align
} }
/** /**
* Traits * Traits
*/ */
pub trait Setters{ pub trait Setters{
fn set_margin(self, margin: MarginData) -> Self; fn set_margin(self, margin: MarginData) -> Self;
fn set_align(self, align: Alignment) -> Self; fn set_align(self, align: Alignment) -> Self;
} }
pub trait TextViewSetters{ pub trait TextViewSetters{
fn set_text_view_margin(self, margin: MarginData) -> Self; 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{ fn set_text_view_margin(self, margin: MarginData) -> Self{
match margin{ match margin{
MarginData::EqualsMargin(margin) => MarginData::EqualsMargin(margin) =>
@ -63,13 +62,13 @@ pub mod properties_module{
.right_margin(margins.3), .right_margin(margins.3),
} }
} }
} }
/** /**
* Macros * Macros
*/ */
macro_rules! impl_setters { macro_rules! impl_setters {
($($t:ty),+) => { ($($t:ty),+) => {
$( $(
impl Setters for $t { impl Setters for $t {
@ -94,27 +93,26 @@ pub mod properties_module{
} }
)* )*
} }
} }
impl_setters!{ButtonBuilder, EntryBuilder, TextViewBuilder, impl_setters!{ButtonBuilder, EntryBuilder, TextViewBuilder,
BoxBuilder, SwitchBuilder, FrameBuilder, LabelBuilder} BoxBuilder, SwitchBuilder, FrameBuilder, LabelBuilder}
#[allow(dead_code)] #[allow(dead_code)]
impl Size{ impl Size{
pub fn new(w: i32, h: i32) -> Size{ pub fn new(w: i32, h: i32) -> Size{
Size{ Size{
width: w, width: w,
height: h, height: h,
} }
} }
} }
impl Alignment{ impl Alignment{
pub fn new(horizontal: Align, vertical : Align) -> Alignment{ pub fn new(horizontal: Align, vertical : Align) -> Alignment{
Alignment{ Alignment{
horizontal, horizontal,
vertical, vertical,
} }
} }
}
} }

View File

@ -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::*,
use crate::{
model::model::model_module::*,
view::{ view::{
properties::properties_module::*, properties::*,
components::{ components::{
*, *,
tabs::tabs_module::*, tabs::*,
switch::switch_module::*, switch::*,
wrapper::wrapper_module::*, wrapper::*,
} }
}, },
controller::{ controller::{
controller::*, controller::*,
view_utils::input_utils::input_utils_module::*, view_utils::input_utils::*,
event_handlers::{ event_handlers::{
button_event_handlers::button_event_handlers_module::*, button_event_handlers::*,
switch_event_handlers::switch_event_handlers_module::*, switch_event_handlers::*,
}, },
} }
}; };
pub fn laboratory_work_first_section(wrapper: &Box) -> (){ pub fn laboratory_work_first_section(wrapper: &Box) -> (){
// input // input
@ -152,9 +150,9 @@ pub mod view_module{
wrapper.append(&hamming_text_view_output_label); wrapper.append(&hamming_text_view_output_label);
wrapper.append(&hamming_text_view_output_frame); wrapper.append(&hamming_text_view_output_frame);
} }
pub fn ui(application: &Application) { pub fn ui(application: &Application) {
let mutual_wrapper = Wrapper::row_builder() let mutual_wrapper = Wrapper::row_builder()
.set_align(Alignment::new(Align::Fill, Align::Fill)) .set_align(Alignment::new(Align::Fill, Align::Fill))
@ -189,7 +187,4 @@ pub mod view_module{
.build(); .build();
window.show(); window.show();
}
} }