changed inputs for second section and implemented Clone and Copy traits for Alignment data structure
This commit is contained in:
@@ -1,30 +1,29 @@
|
||||
use crate::{
|
||||
model::model::*,
|
||||
gtk::{
|
||||
*,
|
||||
prelude::*
|
||||
},
|
||||
};
|
||||
use crate::{gtk::prelude::*, model::model::*};
|
||||
|
||||
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{
|
||||
where
|
||||
F: Fn(&C) + FnOnce(&C) + FnMut(&C),
|
||||
{
|
||||
pub fn new(component: C, callback: F) -> EventHandler<F, C> {
|
||||
Self {
|
||||
component,
|
||||
callback,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub trait BtnEventHandler{
|
||||
pub trait BtnEventHandler {
|
||||
fn on_click(self) -> ();
|
||||
}
|
||||
|
||||
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) -> () {
|
||||
self.component.connect_clicked(move |button| {
|
||||
(self.callback)(button)
|
||||
});
|
||||
self.component
|
||||
.connect_clicked(move |button| (self.callback)(button));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,9 +1,6 @@
|
||||
use std::{borrow::Borrow, collections::HashMap};
|
||||
use std::collections::HashMap;
|
||||
|
||||
use crate::{
|
||||
model::model::*,
|
||||
controller::view_utils::input_utils::*,
|
||||
};
|
||||
use crate::{controller::view_utils::input_utils::*, model::model::*};
|
||||
|
||||
/// **Синдромы**
|
||||
///
|
||||
@@ -21,21 +18,17 @@ use crate::{
|
||||
///
|
||||
/// ошибочная позиция 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;
|
||||
|
||||
let length_of_code : usize = mode.clone() as usize;
|
||||
|
||||
let prepared_input : String = processing_input(&raw_input);
|
||||
let prepared_input: String = processing_input(&raw_input);
|
||||
|
||||
let (fc, sc) = check_correct_input(&raw_input, &prepared_input, length_of_code);
|
||||
|
||||
if !fc || !sc {
|
||||
|
||||
Err("Ошибка. Проверьте корректность ввода.".to_string())
|
||||
|
||||
} else {
|
||||
|
||||
let mut data : String = String::new();
|
||||
let mut data: String = String::new();
|
||||
|
||||
let prepared_data: Vec<u8> = from_string_to_vec_bits(prepared_input);
|
||||
|
||||
@@ -45,103 +38,90 @@ pub fn hamming(raw_input: String, mode: HammingMode) -> Result<String, String>{
|
||||
}
|
||||
|
||||
return Ok(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(){
|
||||
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() {
|
||||
let data_bits = &data[i - length_of_code..i];
|
||||
let (check_bit_1, check_bit_2, check_bit_3) = (
|
||||
data_bits[0] ^ data_bits[1] ^ data_bits[3],
|
||||
data_bits[0] ^ data_bits[2] ^ data_bits[3],
|
||||
data_bits[1] ^ data_bits[2] ^ data_bits[3]
|
||||
data_bits[1] ^ data_bits[2] ^ data_bits[3],
|
||||
);
|
||||
result_string.push_str(&*format!("{check_bit_1}{}{check_bit_2}{}{check_bit_3}{}{} ",
|
||||
data_bits[0],
|
||||
data_bits[1],
|
||||
data_bits[2],
|
||||
data_bits[3]));
|
||||
result_string.push_str(&*format!(
|
||||
"{check_bit_1}{}{check_bit_2}{}{check_bit_3}{}{} ",
|
||||
data_bits[0], data_bits[1], data_bits[2], data_bits[3]
|
||||
));
|
||||
i += length_of_code;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
pub fn hamming_decrypt_data(
|
||||
data: &Vec<u8>,
|
||||
result_string: &mut String,
|
||||
length_of_code: usize
|
||||
) {
|
||||
pub fn hamming_decrypt_data(data: &Vec<u8>, result_string: &mut String, length_of_code: usize) {
|
||||
let mut general_length: usize = length_of_code;
|
||||
|
||||
let mut i : usize = length_of_code;
|
||||
let syndromes: HashMap<usize, (bool, bool, bool)> = HashMap::from([
|
||||
(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)),
|
||||
]);
|
||||
|
||||
let syndromes : HashMap<usize, (bool, bool, bool)> = HashMap::from(
|
||||
[
|
||||
(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)),
|
||||
]
|
||||
);
|
||||
let mut errors: String = String::new();
|
||||
|
||||
let mut errors : String = String::new();
|
||||
while general_length <= data.len() {
|
||||
let data_bits = &data[general_length - length_of_code..general_length];
|
||||
|
||||
while i <= data.len(){
|
||||
|
||||
let mut data_bits = &data[i - length_of_code..i];
|
||||
|
||||
let checked_bits : (bool, bool, bool) =
|
||||
(
|
||||
(data_bits[1] ^ data_bits[3] ^ data_bits[6]) == data_bits[0],
|
||||
(data_bits[1] ^ data_bits[5] ^ data_bits[6]) == data_bits[2],
|
||||
(data_bits[3] ^ data_bits[5] ^ data_bits[6]) == data_bits[4]
|
||||
);
|
||||
let checked_bits: (bool, bool, bool) = (
|
||||
(data_bits[1] ^ data_bits[3] ^ data_bits[6]) == data_bits[0],
|
||||
(data_bits[1] ^ data_bits[5] ^ data_bits[6]) == data_bits[2],
|
||||
(data_bits[3] ^ data_bits[5] ^ data_bits[6]) == data_bits[4],
|
||||
);
|
||||
|
||||
match checked_bits {
|
||||
(true, true, true) => {
|
||||
i += length_of_code;
|
||||
general_length += length_of_code;
|
||||
continue;
|
||||
},
|
||||
}
|
||||
_ => {
|
||||
|
||||
let error_position = syndromes
|
||||
.iter()
|
||||
.find(move |&(&error_position, &error)| error == checked_bits).
|
||||
unwrap().0;
|
||||
.find(move |&(&_error_position, &error)| error == checked_bits)
|
||||
.unwrap()
|
||||
.0;
|
||||
|
||||
let correctly_code : Vec<u8> = data_bits
|
||||
let correctly_code: Vec<u8> = data_bits
|
||||
.iter()
|
||||
.enumerate()
|
||||
.map(|(index, bit)| {
|
||||
if index == error_position - 1 {
|
||||
if *bit == 1u8 { 0u8 } else { 1u8 }
|
||||
} else {
|
||||
*bit
|
||||
}
|
||||
}).collect();
|
||||
if index == error_position - 1 {
|
||||
if *bit == 1u8 {
|
||||
0u8
|
||||
} else {
|
||||
1u8
|
||||
}
|
||||
} else {
|
||||
*bit
|
||||
}
|
||||
})
|
||||
.collect();
|
||||
|
||||
let error = format!("Ошибка в коде {} {:?}, позиция ошибки {}, корректный код: {:?}; \n",
|
||||
i / 7,
|
||||
&data_bits,
|
||||
error_position,
|
||||
correctly_code
|
||||
let error = format!(
|
||||
"Ошибка в коде {} {:?}, позиция ошибки {}, корректный код: {:?}; \n",
|
||||
general_length / 7,
|
||||
&data_bits,
|
||||
error_position,
|
||||
correctly_code
|
||||
);
|
||||
|
||||
errors.push_str(error.as_str());
|
||||
|
||||
i += length_of_code;
|
||||
|
||||
general_length += length_of_code;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -151,5 +131,4 @@ pub fn hamming_decrypt_data(
|
||||
} else {
|
||||
result_string.push_str(errors.as_str())
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
11
src/main.rs
11
src/main.rs
@@ -1,24 +1,19 @@
|
||||
extern crate core;
|
||||
|
||||
use gtk4 as gtk;
|
||||
|
||||
use gtk::*;
|
||||
use gtk::prelude::*;
|
||||
|
||||
mod view;
|
||||
mod model;
|
||||
mod controller;
|
||||
mod model;
|
||||
mod view;
|
||||
|
||||
use controller::*;
|
||||
use view::view::*;
|
||||
|
||||
fn main() {
|
||||
|
||||
let app = adw::Application::builder()
|
||||
.application_id("com.github.gtk-rs.examples.basic")
|
||||
.build();
|
||||
|
||||
app.connect_activate(ui);
|
||||
app.run();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,19 +1,16 @@
|
||||
use gtk4 as gtk;
|
||||
|
||||
use crate::{
|
||||
view::properties::*,
|
||||
model::builder_traits::*
|
||||
};
|
||||
use gtk::{*, prelude::*};
|
||||
use crate::{model::builder_traits::*, view::properties::*};
|
||||
use gtk::{prelude::*, *};
|
||||
|
||||
pub type InputLabel = String;
|
||||
|
||||
pub struct Input {
|
||||
component: Box
|
||||
component: Box,
|
||||
}
|
||||
|
||||
pub struct InputBuilder {
|
||||
align: Align,
|
||||
align: Alignment,
|
||||
label: InputLabel,
|
||||
margins: MarginData,
|
||||
}
|
||||
@@ -21,7 +18,10 @@ pub struct InputBuilder {
|
||||
impl Product<InputBuilder, Box> for Input {
|
||||
fn builder() -> InputBuilder {
|
||||
InputBuilder {
|
||||
align: Align::Start,
|
||||
align: Alignment {
|
||||
horizontal: Align::Start,
|
||||
vertical: Align::Start,
|
||||
},
|
||||
label: String::new(),
|
||||
margins: MarginData::EqualsMargin(5),
|
||||
}
|
||||
@@ -33,37 +33,30 @@ impl Product<InputBuilder, Box> for Input {
|
||||
}
|
||||
|
||||
impl InputBuilder {
|
||||
|
||||
pub fn set_label(mut self, label: &str) -> Self {
|
||||
|
||||
self.label = String::from(label);
|
||||
|
||||
self
|
||||
|
||||
}
|
||||
|
||||
pub fn set_align(mut self, align: Align) -> Self {
|
||||
|
||||
pub fn set_align(mut self, align: Alignment) -> Self {
|
||||
self.align = align;
|
||||
|
||||
self
|
||||
|
||||
}
|
||||
|
||||
pub fn set_margins(mut self, margin: MarginData) -> Self {
|
||||
|
||||
self.margins = margin;
|
||||
|
||||
self
|
||||
|
||||
}
|
||||
|
||||
pub fn build(self, monospace: bool, wrap_mode: WrapMode, input_height: i32) -> Input {
|
||||
|
||||
let input_component = Box::new(Orientation::Vertical, 0);
|
||||
|
||||
let input_label = Label::builder()
|
||||
.halign(self.align)
|
||||
.halign(self.align.horizontal)
|
||||
.valign(self.align.vertical)
|
||||
.set_margin(self.margins)
|
||||
.label(self.label)
|
||||
.build();
|
||||
@@ -84,9 +77,8 @@ impl InputBuilder {
|
||||
input_component.append(&text_view_input_frame);
|
||||
|
||||
Input {
|
||||
component: input_component
|
||||
component: input_component,
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,31 +1,24 @@
|
||||
use std::ops::Deref;
|
||||
use gtk4 as gtk;
|
||||
|
||||
#[allow(unused)]
|
||||
use gtk::{
|
||||
Box,
|
||||
Stack,
|
||||
Widget,
|
||||
Orientation,
|
||||
StackSidebar,
|
||||
StackSwitcher,
|
||||
StackTransitionType,
|
||||
prelude::{BoxExt, IsA},
|
||||
Box, Orientation, Stack, StackSidebar, StackSwitcher, StackTransitionType, Widget,
|
||||
};
|
||||
|
||||
use crate::view::components::builder_traits::{Builder, Product};
|
||||
|
||||
pub type Page<'a> = (&'a str, &'a str, &'a Box);
|
||||
|
||||
pub struct Pages{
|
||||
wrapper: Box
|
||||
pub struct Pages {
|
||||
wrapper: Box,
|
||||
}
|
||||
|
||||
pub struct PagesBuilder{
|
||||
pub struct PagesBuilder {
|
||||
pages_content: Stack,
|
||||
}
|
||||
|
||||
impl Product<PagesBuilder, Box> for Pages {
|
||||
|
||||
fn builder() -> PagesBuilder {
|
||||
PagesBuilder {
|
||||
pages_content: Stack::new(),
|
||||
@@ -35,11 +28,9 @@ impl Product<PagesBuilder, Box> for Pages {
|
||||
fn get(self) -> Box {
|
||||
self.wrapper
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
impl Builder<Pages, Page<'_>, i32> for PagesBuilder{
|
||||
|
||||
impl Builder<Pages, Page<'_>, i32> for PagesBuilder {
|
||||
fn build(&self, build_param: i32) -> Pages {
|
||||
let stack_sidebar = StackSidebar::new();
|
||||
let stack_switcher = StackSwitcher::new();
|
||||
@@ -52,9 +43,7 @@ impl Builder<Pages, Page<'_>, i32> for PagesBuilder{
|
||||
wrapper.append(&stack_sidebar);
|
||||
wrapper.append(&self.pages_content);
|
||||
|
||||
Pages{
|
||||
wrapper
|
||||
}
|
||||
Pages { wrapper }
|
||||
}
|
||||
|
||||
fn append_item(self, item: Page) -> Self {
|
||||
@@ -70,27 +59,18 @@ impl Builder<Pages, Page<'_>, i32> for PagesBuilder{
|
||||
|
||||
self
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
impl PagesBuilder {
|
||||
|
||||
fn append_page_private(
|
||||
&self,
|
||||
item: Page
|
||||
) {
|
||||
fn append_page_private(&self, item: Page) {
|
||||
self.pages_content.add_titled(item.2, Some(item.1), item.0);
|
||||
}
|
||||
|
||||
pub fn set_transition(
|
||||
self,
|
||||
type_transition : StackTransitionType,
|
||||
duration: u32
|
||||
) -> Self {
|
||||
pub fn set_transition(self, type_transition: StackTransitionType, duration: u32) -> Self {
|
||||
self.pages_content.set_transition_type(type_transition);
|
||||
self.pages_content.set_transition_duration(duration);
|
||||
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
use gtk4 as gtk;
|
||||
|
||||
use gtk::{Notebook, Label, Box};
|
||||
use super::builder_traits::*;
|
||||
use gtk::{Box, Label, Notebook};
|
||||
|
||||
pub type TabLabel = Label;
|
||||
pub type TabContent = Box;
|
||||
@@ -9,43 +9,32 @@ pub type TabPage<'a> = (&'a str, TabContent);
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct TabsBuilder {
|
||||
tabs: Vec<(TabLabel, TabContent)>
|
||||
tabs: Vec<(TabLabel, TabContent)>,
|
||||
}
|
||||
|
||||
pub struct Tabs {
|
||||
tabs_wrapper: Notebook
|
||||
tabs_wrapper: Notebook,
|
||||
}
|
||||
|
||||
impl Product<TabsBuilder, Notebook> for Tabs {
|
||||
|
||||
fn builder() -> TabsBuilder {
|
||||
TabsBuilder {
|
||||
tabs: Vec::new(),
|
||||
}
|
||||
TabsBuilder { tabs: Vec::new() }
|
||||
}
|
||||
|
||||
fn get(self) -> Notebook {
|
||||
self.tabs_wrapper
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
impl Builder<Tabs, TabPage<'_>, &str> for TabsBuilder{
|
||||
|
||||
impl Builder<Tabs, TabPage<'_>, &str> for TabsBuilder {
|
||||
fn build(&self, build_param: &str) -> Tabs {
|
||||
let tabs_wrapper = Notebook::builder()
|
||||
.group_name(build_param)
|
||||
.build();
|
||||
let tabs_wrapper = Notebook::builder().group_name(build_param).build();
|
||||
|
||||
self.tabs
|
||||
.iter()
|
||||
.for_each(|(label, content)| {
|
||||
tabs_wrapper.append_page(content, Some(label));
|
||||
});
|
||||
self.tabs.iter().for_each(|(label, content)| {
|
||||
tabs_wrapper.append_page(content, Some(label));
|
||||
});
|
||||
|
||||
Tabs {
|
||||
tabs_wrapper
|
||||
}
|
||||
Tabs { tabs_wrapper }
|
||||
}
|
||||
|
||||
fn append_item(mut self, item: TabPage) -> Self {
|
||||
@@ -55,21 +44,18 @@ impl Builder<Tabs, TabPage<'_>, &str> for TabsBuilder{
|
||||
}
|
||||
|
||||
fn append_items(mut self, items: Vec<TabPage>) -> Self {
|
||||
for item in items{
|
||||
for item in items {
|
||||
self.append_tab_private(item);
|
||||
}
|
||||
|
||||
self
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
impl TabsBuilder {
|
||||
|
||||
fn append_tab_private(&mut self, item: TabPage) {
|
||||
let tab_label = Label::new(Some(item.0));
|
||||
self.tabs.push((tab_label, item.1));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,29 +1,18 @@
|
||||
use gtk4 as gtk;
|
||||
|
||||
use crate::{
|
||||
model::model::*,
|
||||
view::{
|
||||
properties::*,
|
||||
components::{
|
||||
*,
|
||||
switch::*,
|
||||
wrapper::*,
|
||||
}
|
||||
},
|
||||
controller::{
|
||||
controller::*,
|
||||
event_handlers::{button_event_handlers::*, switch_event_handlers::*},
|
||||
view_utils::input_utils::*,
|
||||
event_handlers::{
|
||||
button_event_handlers::*,
|
||||
switch_event_handlers::*,
|
||||
},
|
||||
}
|
||||
},
|
||||
model::model::*,
|
||||
view::{components::wrapper::*, properties::*},
|
||||
};
|
||||
|
||||
use gtk::{*, prelude::*};
|
||||
|
||||
pub fn hamming_code_page(wrapper: &Box) -> (){
|
||||
use gtk::{prelude::*, *};
|
||||
|
||||
pub fn hamming_code_page(wrapper: &Box) -> () {
|
||||
// input
|
||||
|
||||
let hamming_text_view_input_label = Label::builder()
|
||||
@@ -67,11 +56,10 @@ pub fn hamming_code_page(wrapper: &Box) -> (){
|
||||
|
||||
// interactive panel
|
||||
|
||||
let clear_input_button =
|
||||
Button::builder()
|
||||
.set_align(Alignment::new(Align::Fill, Align::Fill))
|
||||
.label("Очистка полей")
|
||||
.build();
|
||||
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))
|
||||
@@ -80,9 +68,7 @@ pub fn hamming_code_page(wrapper: &Box) -> (){
|
||||
|
||||
let crypt_mode_switch = Switch::new();
|
||||
|
||||
let crypt_mode_label = Label::builder()
|
||||
.label("Режим: кодирование")
|
||||
.build();
|
||||
let crypt_mode_label = Label::builder().label("Режим: кодирование").build();
|
||||
|
||||
// references for binding actions
|
||||
|
||||
@@ -99,28 +85,27 @@ pub fn hamming_code_page(wrapper: &Box) -> (){
|
||||
|
||||
// actions
|
||||
|
||||
EventHandler::new(
|
||||
clear_input_button_to_handle,
|
||||
move |_| {
|
||||
clearing(&text_view_input_for_clearing, &text_view_output_for_clearing);
|
||||
}
|
||||
).on_click();
|
||||
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(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();
|
||||
EventHandler::new(crypt_mode_switch.clone(), move |s: &Switch| {
|
||||
state_controller(s, &crypt_mode_label_to_handle);
|
||||
})
|
||||
.on_toggle();
|
||||
|
||||
// wrappers
|
||||
|
||||
@@ -148,5 +133,4 @@ pub fn hamming_code_page(wrapper: &Box) -> (){
|
||||
wrapper.append(&interactive_components_wrapper);
|
||||
wrapper.append(&hamming_text_view_output_label);
|
||||
wrapper.append(&hamming_text_view_output_frame);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,78 +1,107 @@
|
||||
use gtk4 as gtk;
|
||||
|
||||
use gtk::{*, prelude::*};
|
||||
use crate::model::builder_traits::Product;
|
||||
use crate::view::{
|
||||
properties::*,
|
||||
components::{
|
||||
wrapper::*,
|
||||
input::Input,
|
||||
use crate::{
|
||||
model::builder_traits::Product,
|
||||
view::{
|
||||
components::{input::Input, wrapper::Wrapper},
|
||||
properties::*,
|
||||
},
|
||||
};
|
||||
use gtk::{prelude::*, Align, WrapMode, *};
|
||||
|
||||
pub fn signal_reducing_page(wrapper: &Box) {
|
||||
let (input_height, monospace, input_alignment, input_wrapping): (i32, bool, Align, WrapMode) =
|
||||
(24, true, Align::Fill, WrapMode::Word);
|
||||
|
||||
let inputs_first_line = Box::new(Orientation::Horizontal, 5);
|
||||
|
||||
inputs_first_line.set_valign(Align::Fill);
|
||||
|
||||
let input_height : i32 = 20;
|
||||
let input_label_alignment = Alignment {
|
||||
horizontal: Align::Start,
|
||||
vertical: Align::Fill,
|
||||
};
|
||||
|
||||
let wire_length_input = Input::builder()
|
||||
.set_label("Длина провода (L = [м]):")
|
||||
.set_align(Align::Fill)
|
||||
.set_label("l, м:")
|
||||
.set_margins(MarginData::EqualsMargin(5))
|
||||
.build(true, WrapMode::Word, input_height)
|
||||
.set_align(input_label_alignment)
|
||||
.build(monospace, input_wrapping, input_height)
|
||||
.get();
|
||||
|
||||
let resistance_input = Input::builder()
|
||||
.set_label("Сопротивление (Rм = [Ом * м]):")
|
||||
.set_align(Align::Fill)
|
||||
wire_length_input.set_halign(input_alignment);
|
||||
wire_length_input.set_hexpand(true);
|
||||
|
||||
let resistance_per_meter_input = Input::builder()
|
||||
.set_label("Rм, Ом:")
|
||||
.set_margins(MarginData::EqualsMargin(5))
|
||||
.build(true, WrapMode::Word, input_height)
|
||||
.set_align(input_label_alignment)
|
||||
.build(monospace, input_wrapping, input_height)
|
||||
.get();
|
||||
|
||||
let capacity_input = Input::builder()
|
||||
.set_label("Ёмкость (Cм = [пФ * м]):")
|
||||
.set_align(Align::Fill)
|
||||
resistance_per_meter_input.set_halign(input_alignment);
|
||||
resistance_per_meter_input.set_hexpand(true);
|
||||
|
||||
let capacity_per_meter_input = Input::builder()
|
||||
.set_label("Cм, пФ:")
|
||||
.set_margins(MarginData::EqualsMargin(5))
|
||||
.build(true, WrapMode::Word, input_height)
|
||||
.set_align(input_label_alignment)
|
||||
.build(monospace, input_wrapping, input_height)
|
||||
.get();
|
||||
|
||||
let inputs_second_line = Box::new(Orientation::Horizontal, 5);
|
||||
capacity_per_meter_input.set_halign(input_alignment);
|
||||
capacity_per_meter_input.set_hexpand(true);
|
||||
|
||||
inputs_second_line.set_valign(Align::Fill);
|
||||
let wrapper_first_row = Wrapper::col_builder()
|
||||
.halign(Align::Fill)
|
||||
.hexpand(true)
|
||||
.spacing(5)
|
||||
.build();
|
||||
|
||||
let voltage_input = Input::builder()
|
||||
.set_label("Напряжение (Vи = [мВ]):")
|
||||
.set_align(Align::Fill)
|
||||
wrapper_first_row.append(&wire_length_input);
|
||||
wrapper_first_row.append(&resistance_per_meter_input);
|
||||
wrapper_first_row.append(&capacity_per_meter_input);
|
||||
|
||||
let info_signal_voltage_input = Input::builder()
|
||||
.set_label("Vи, мВ:")
|
||||
.set_margins(MarginData::EqualsMargin(5))
|
||||
.build(true, WrapMode::Word, input_height)
|
||||
.set_align(input_label_alignment)
|
||||
.build(monospace, input_wrapping, input_height)
|
||||
.get();
|
||||
|
||||
let source_implicit_resistance_input = Input::builder()
|
||||
.set_label("Сопротивление источника (R = [Ом]):")
|
||||
.set_align(Align::Fill)
|
||||
info_signal_voltage_input.set_halign(input_alignment);
|
||||
info_signal_voltage_input.set_hexpand(true);
|
||||
|
||||
let resistance_of_info_voltage_source_input = Input::builder()
|
||||
.set_label("Rи, Ом:")
|
||||
.set_margins(MarginData::EqualsMargin(5))
|
||||
.build(true, WrapMode::Word, input_height)
|
||||
.set_align(input_label_alignment)
|
||||
.build(monospace, input_wrapping, input_height)
|
||||
.get();
|
||||
|
||||
let freq_input = Input::builder()
|
||||
.set_label("Частота (f = [МГц]):")
|
||||
.set_align(Align::Fill)
|
||||
resistance_of_info_voltage_source_input.set_halign(input_alignment);
|
||||
resistance_of_info_voltage_source_input.set_hexpand(true);
|
||||
|
||||
let info_voltage_source_frequency_input = Input::builder()
|
||||
.set_label("f, мГц:")
|
||||
.set_margins(MarginData::EqualsMargin(5))
|
||||
.build(true, WrapMode::Word, input_height)
|
||||
.set_align(input_label_alignment)
|
||||
.build(monospace, input_wrapping, input_height)
|
||||
.get();
|
||||
|
||||
info_voltage_source_frequency_input.set_halign(input_alignment);
|
||||
info_voltage_source_frequency_input.set_hexpand(true);
|
||||
|
||||
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);
|
||||
let wrapper_second_row = Wrapper::col_builder()
|
||||
.halign(Align::Fill)
|
||||
.hexpand(true)
|
||||
.spacing(5)
|
||||
.build();
|
||||
|
||||
wrapper.append(&inputs_first_line);
|
||||
wrapper.append(&inputs_second_line);
|
||||
wrapper_second_row.append(&info_signal_voltage_input);
|
||||
wrapper_second_row.append(&resistance_of_info_voltage_source_input);
|
||||
wrapper_second_row.append(&info_voltage_source_frequency_input);
|
||||
|
||||
}
|
||||
let main_wpapper = Wrapper::row_builder().spacing(5).build();
|
||||
|
||||
main_wpapper.append(&wrapper_first_row);
|
||||
main_wpapper.append(&wrapper_second_row);
|
||||
|
||||
wrapper.append(&main_wpapper);
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use gtk4 as gtk;
|
||||
|
||||
use gtk::{Align};
|
||||
use gtk::builders::*;
|
||||
use gtk::Align;
|
||||
|
||||
/**
|
||||
* Types
|
||||
@@ -13,7 +13,7 @@ pub type Margin = (i32, i32, i32, i32);
|
||||
* Enums
|
||||
*/
|
||||
|
||||
pub enum MarginData{
|
||||
pub enum MarginData {
|
||||
EqualsMargin(i32),
|
||||
MultipleMargin(Margin),
|
||||
}
|
||||
@@ -26,40 +26,41 @@ pub enum MarginData{
|
||||
|
||||
pub struct Size {
|
||||
pub width: i32,
|
||||
pub height: i32
|
||||
pub height: i32,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone)]
|
||||
pub struct Alignment {
|
||||
pub horizontal: Align,
|
||||
pub vertical : 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{
|
||||
fn set_text_view_margin(self, margin: MarginData) -> Self{
|
||||
match margin{
|
||||
MarginData::EqualsMargin(margin) =>
|
||||
self.top_margin(margin)
|
||||
.left_margin(margin)
|
||||
.bottom_margin(margin)
|
||||
.right_margin(margin),
|
||||
MarginData::MultipleMargin(margins) =>
|
||||
self.top_margin(margins.0)
|
||||
.left_margin(margins.1)
|
||||
.bottom_margin(margins.2)
|
||||
.right_margin(margins.3),
|
||||
impl TextViewSetters for TextViewBuilder {
|
||||
fn set_text_view_margin(self, margin: MarginData) -> Self {
|
||||
match margin {
|
||||
MarginData::EqualsMargin(margin) => self
|
||||
.top_margin(margin)
|
||||
.left_margin(margin)
|
||||
.bottom_margin(margin)
|
||||
.right_margin(margin),
|
||||
MarginData::MultipleMargin(margins) => self
|
||||
.top_margin(margins.0)
|
||||
.left_margin(margins.1)
|
||||
.bottom_margin(margins.2)
|
||||
.right_margin(margins.3),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -95,24 +96,25 @@ macro_rules! impl_setters {
|
||||
}
|
||||
}
|
||||
|
||||
impl_setters!{ButtonBuilder, EntryBuilder, TextViewBuilder,
|
||||
impl_setters! {ButtonBuilder, EntryBuilder, TextViewBuilder,
|
||||
BoxBuilder, SwitchBuilder, FrameBuilder, LabelBuilder}
|
||||
|
||||
#[allow(dead_code)]
|
||||
impl Size{
|
||||
pub fn new(w: i32, h: i32) -> Size{
|
||||
Size{
|
||||
impl Size {
|
||||
pub fn new(w: i32, h: i32) -> Size {
|
||||
Size {
|
||||
width: w,
|
||||
height: h,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Alignment{
|
||||
pub fn new(horizontal: Align, vertical : Align) -> Alignment{
|
||||
Alignment{
|
||||
impl Alignment {
|
||||
pub fn new(horizontal: Align, vertical: Align) -> Alignment {
|
||||
Alignment {
|
||||
horizontal,
|
||||
vertical,
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,22 +1,18 @@
|
||||
use crate::model::builder_traits::*;
|
||||
use gtk4 as gtk;
|
||||
|
||||
use gtk::{*, prelude::*, StackTransitionType::SlideLeftRight};
|
||||
use gtk::{prelude::*, StackTransitionType::SlideLeftRight, *};
|
||||
|
||||
use crate::{
|
||||
view::{
|
||||
properties::*,
|
||||
components::{
|
||||
*,
|
||||
wrapper::*,
|
||||
},
|
||||
pages::*
|
||||
},
|
||||
};
|
||||
use crate::view::components::pages::Pages;
|
||||
|
||||
pub fn ui(application: &adw::Application) {
|
||||
#[allow(unused)]
|
||||
use crate::view::{
|
||||
components::{wrapper::*, *},
|
||||
pages::*,
|
||||
properties::*,
|
||||
};
|
||||
|
||||
pub fn ui(application: &adw::Application) {
|
||||
let hamming_code = Wrapper::row_builder()
|
||||
.set_align(Alignment::new(Align::Fill, Align::Fill))
|
||||
.set_margin(MarginData::EqualsMargin(15))
|
||||
@@ -37,7 +33,7 @@ pub fn ui(application: &adw::Application) {
|
||||
.set_transition(SlideLeftRight, 200)
|
||||
.append_items(vec![
|
||||
("Код Хэмминга", "Код Хэмминга", &hamming_code),
|
||||
("Затухание сигнала", "Затухание сигнала", &signal_reducing)
|
||||
("Затухание сигнала", "Затухание сигнала", &signal_reducing),
|
||||
])
|
||||
.build(5)
|
||||
.get();
|
||||
@@ -51,4 +47,4 @@ pub fn ui(application: &adw::Application) {
|
||||
.build();
|
||||
|
||||
window.show();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user