Compare commits
No commits in common. "cbde9a8af1afeae3635e634348306866e8a763b9" and "81a8d9b2c67c8204964cdd0735d9dee6e4b97321" have entirely different histories.
cbde9a8af1
...
81a8d9b2c6
|
@ -463,6 +463,12 @@ version = "0.5.0"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea"
|
||||
|
||||
[[package]]
|
||||
name = "hermit-abi"
|
||||
version = "0.3.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024"
|
||||
|
||||
[[package]]
|
||||
name = "indexmap"
|
||||
version = "2.2.6"
|
||||
|
@ -517,9 +523,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "libc"
|
||||
version = "0.2.155"
|
||||
version = "0.2.153"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c"
|
||||
checksum = "9c198f91728a82281a64e1f4f9eeb25d82cb32a5de251c6bd1b5154d63a8e7bd"
|
||||
|
||||
[[package]]
|
||||
name = "memchr"
|
||||
|
@ -545,6 +551,16 @@ dependencies = [
|
|||
"adler",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "num_cpus"
|
||||
version = "1.16.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43"
|
||||
dependencies = [
|
||||
"hermit-abi",
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "object"
|
||||
version = "0.32.2"
|
||||
|
@ -787,20 +803,21 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "tokio"
|
||||
version = "1.39.2"
|
||||
version = "1.37.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "daa4fb1bc778bd6f04cbfc4bb2d06a7396a8f299dc33ea1900cedaa316f467b1"
|
||||
checksum = "1adbebffeca75fcfd058afa480fb6c0b81e165a0323f9c9d39c9697e37c46787"
|
||||
dependencies = [
|
||||
"backtrace",
|
||||
"num_cpus",
|
||||
"pin-project-lite",
|
||||
"tokio-macros",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tokio-macros"
|
||||
version = "2.4.0"
|
||||
version = "2.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "693d596312e88961bc67d7f1f97af8a70227d9f90c31bba5806eec004978d752"
|
||||
checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
|
|
|
@ -9,5 +9,5 @@ edition = "2021"
|
|||
adw = { version = "0.6.0", package = "libadwaita", features = ["v1_4"] }
|
||||
bitvec = "1.0.1"
|
||||
gtk4 = "0.8.1"
|
||||
tokio = { version = "1.39.2", features = ["rt", "time", "rt-multi-thread", "macros", "sync"] }
|
||||
tokio = { version = "1.0.0", features = ["rt", "time", "rt-multi-thread", "macros"] }
|
||||
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
use gtk::*;
|
||||
use gtk4 as gtk;
|
||||
|
||||
pub fn state_controller(switch: &Switch, label: &Label) {
|
||||
if switch.state() {
|
||||
pub fn state_controller(switch: &Switch, label: &Label) -> () {
|
||||
if switch.state() == true {
|
||||
label.set_label("Режим: проверка");
|
||||
} else {
|
||||
label.set_label("Режим: кодирование");
|
||||
|
|
|
@ -4,7 +4,7 @@ impl<F, C> EventHandler<F, C>
|
|||
where
|
||||
F: Fn(&C) + FnOnce(&C) + FnMut(&C),
|
||||
{
|
||||
pub fn new(component: C, callback: F) -> Self {
|
||||
pub fn new(component: C, callback: F) -> EventHandler<F, C> {
|
||||
Self {
|
||||
component,
|
||||
callback,
|
||||
|
@ -13,7 +13,7 @@ where
|
|||
}
|
||||
|
||||
pub trait BtnEventHandler {
|
||||
fn on_click(self);
|
||||
fn on_click(self) -> ();
|
||||
}
|
||||
|
||||
impl<F, C> BtnEventHandler for EventHandler<F, C>
|
||||
|
@ -21,7 +21,7 @@ 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.callback)(button));
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use crate::{gtk::prelude::*, model::models::*, view::components::switch::SwitchExt};
|
||||
|
||||
pub trait SwEventHandler {
|
||||
fn on_toggle(self);
|
||||
fn on_toggle(self) -> ();
|
||||
}
|
||||
|
||||
impl<F, C> SwEventHandler for EventHandler<F, C>
|
||||
|
@ -9,7 +9,7 @@ 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.callback)(switch));
|
||||
}
|
||||
|
|
|
@ -41,7 +41,7 @@ pub fn hamming(raw_input: String, mode: HammingMode) -> Result<String, String> {
|
|||
HammingMode::Decrypt => hamming_decrypt_data(&prepared_data, &mut data, length_of_code),
|
||||
}
|
||||
|
||||
Ok(data)
|
||||
return Ok(data);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -97,7 +97,7 @@ pub fn hamming_decrypt_data(data: &Vec<u8>, result_string: &mut String, length_o
|
|||
.unwrap()
|
||||
.0;
|
||||
|
||||
let uncorrect_code: String = from_vec_bits_to_string(data_bits);
|
||||
let uncorrect_code: String = from_vec_bits_to_string(&data_bits);
|
||||
let correct_code: String = from_vec_bits_to_string(
|
||||
data_bits
|
||||
.iter()
|
||||
|
@ -125,8 +125,8 @@ pub fn hamming_decrypt_data(data: &Vec<u8>, result_string: &mut String, length_o
|
|||
}
|
||||
}
|
||||
|
||||
if !data.is_empty() {
|
||||
if errors.is_empty() {
|
||||
if data.len() > 0 {
|
||||
if errors.len() == 0 {
|
||||
result_string.push_str("Все коды корректны.");
|
||||
} else {
|
||||
result_string.push_str(errors.as_str());
|
||||
|
|
|
@ -1,31 +1,15 @@
|
|||
#[allow(non_snake_case)]
|
||||
pub fn reactive_resistance_of_capacitor(Cm: f64, L: f64, f: f64) -> f64 {
|
||||
if f == 0.0 || Cm == 0.0 || L == 0.0 {
|
||||
0.0
|
||||
} else {
|
||||
1f64 / (2f64 * std::f64::consts::PI * f * Cm * L)
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(non_snake_case)]
|
||||
pub fn full_resistance_of_capacitor(Xc: f64, Rs: f64, Rm: f64, L: f64) -> f64 {
|
||||
(Xc.powf(2f64) + (Rs + Rm * L).powf(2f64)).sqrt()
|
||||
}
|
||||
|
||||
#[allow(non_snake_case)]
|
||||
pub fn voltage_from_signal_source(Vs: f64, Xc: f64, Z: f64) -> f64 {
|
||||
if Z == 0.0 {
|
||||
0.0
|
||||
} else {
|
||||
(Vs * Xc) / Z
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(non_snake_case)]
|
||||
pub fn coef_of_signal_reduce(Vs: f64, V: f64) -> f64 {
|
||||
if V == 0.0 {
|
||||
0.0
|
||||
} else {
|
||||
Vs / V
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,7 +13,7 @@ pub fn start_hamming_algorithm(input: &TextView, output: &TextView, mode: bool)
|
|||
.parse()
|
||||
.unwrap();
|
||||
|
||||
let operation = if mode {
|
||||
let operation = if mode == false {
|
||||
HammingMode::Encrypt
|
||||
} else {
|
||||
HammingMode::Decrypt
|
||||
|
|
|
@ -1,44 +1,119 @@
|
|||
use gtk4 as gtk;
|
||||
|
||||
use std::{num::ParseFloatError, str::FromStr};
|
||||
use crate::controller::model_utils::signal_reducer::*;
|
||||
use crate::model::models::SchemeCharacteristics;
|
||||
use gtk::{prelude::*, *};
|
||||
|
||||
use gtk::{
|
||||
prelude::{TextBufferExt, TextViewExt},
|
||||
TextBuffer,
|
||||
};
|
||||
pub fn check_characteristics(
|
||||
raw_characteristics: &Vec<TextView>,
|
||||
all_inputs_data: &mut Vec<f64>,
|
||||
output: &mut String,
|
||||
) -> bool {
|
||||
for input in raw_characteristics {
|
||||
let (iter_start, iter_end) = input.buffer().bounds();
|
||||
let parsed_input: Result<f64, _> = input
|
||||
.buffer()
|
||||
.text(&iter_start, &iter_end, false)
|
||||
.to_string()
|
||||
.trim()
|
||||
.parse();
|
||||
|
||||
use crate::{model::models::SignalReduce, view::components::input::Input};
|
||||
|
||||
pub fn get_error_message(error_instance: ParseFloatError) -> Option<&'static str> {
|
||||
match error_instance.to_string().as_str() {
|
||||
"cannot parse float from empty string" => Some("Вы не ввели данные в поле/-я"),
|
||||
"invalid float literal" => Some("Вы ввели не корректные данные в поле/-я"),
|
||||
_ => None,
|
||||
match parsed_input {
|
||||
Ok(int) => {
|
||||
all_inputs_data.push(int);
|
||||
println!("{:?}", int);
|
||||
}
|
||||
Err(err) => {
|
||||
if output.is_empty() {
|
||||
output.push_str("Введите пожалуйста числа в полях");
|
||||
println!("{:?}", err);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn parse_fields(all_inputs: Vec<Input>) -> Result<SignalReduce, ParseFloatError> {
|
||||
let mut values: [f64; 6] = [0f64; 6];
|
||||
!output.is_empty()
|
||||
}
|
||||
|
||||
for (i, input) in all_inputs.iter().enumerate() {
|
||||
let input_text_buffer: TextBuffer = input.clone().get_input().buffer();
|
||||
let try_extract_value = f64::from_str(
|
||||
input_text_buffer
|
||||
.text(
|
||||
&input_text_buffer.start_iter(),
|
||||
&input_text_buffer.end_iter(),
|
||||
false,
|
||||
)
|
||||
.as_str()
|
||||
.trim(),
|
||||
pub fn start_algorithm(
|
||||
error_log_label: &Label,
|
||||
raw_characteristics: &Vec<TextView>,
|
||||
table: &Frame,
|
||||
header: &ListBoxRow,
|
||||
) {
|
||||
let mut all_inputs_data: Vec<f64> = Vec::new();
|
||||
let mut output: String = String::new();
|
||||
|
||||
if !check_characteristics(raw_characteristics, &mut all_inputs_data, &mut output) {
|
||||
error_log_label.set_text(output.as_str());
|
||||
} else {
|
||||
error_log_label.set_text("");
|
||||
|
||||
let new_table = ListBox::builder().hexpand(true).halign(Align::Fill).build();
|
||||
|
||||
new_table.append(header);
|
||||
|
||||
let (L, Rm, Cm, Vs, Rs, f): SchemeCharacteristics = (
|
||||
all_inputs_data[0],
|
||||
all_inputs_data[1],
|
||||
all_inputs_data[2],
|
||||
all_inputs_data[3],
|
||||
all_inputs_data[4],
|
||||
all_inputs_data[5],
|
||||
);
|
||||
match try_extract_value {
|
||||
Ok(value) => values[i] = value,
|
||||
Err(error) => return Err(error),
|
||||
}
|
||||
|
||||
let mut frequencies: Vec<usize> = vec![f as usize, 1usize];
|
||||
|
||||
frequencies.append(&mut (0..100).step_by(5).collect());
|
||||
|
||||
for i in frequencies {
|
||||
if i == 0 {
|
||||
continue;
|
||||
}
|
||||
|
||||
Ok(SignalReduce(
|
||||
values[0], values[1], values[2], values[3], values[4], values[5],
|
||||
))
|
||||
let table_row = ListBoxRow::new();
|
||||
|
||||
let columns = ColumnView::builder().reorderable(false).build();
|
||||
|
||||
let frequency_column = ColumnViewColumn::builder()
|
||||
.title(format!("{i}"))
|
||||
.fixed_width(200)
|
||||
.expand(true)
|
||||
.build();
|
||||
|
||||
let Xc: f64 = reactive_resistance_of_capacitor(Cm, L, f);
|
||||
let Z: f64 = full_resistance_of_capacitor(Xc, Vs, Rm, L);
|
||||
let V: f64 = voltage_from_signal_source(Vs, Xc, Z);
|
||||
let xi: f64 = coef_of_signal_reduce(Vs, V);
|
||||
|
||||
let reactive_resistance_column = ColumnViewColumn::builder()
|
||||
.title(format!("{:?}", Xc))
|
||||
.fixed_width(200)
|
||||
.expand(true)
|
||||
.build();
|
||||
|
||||
let voltage_column = ColumnViewColumn::builder()
|
||||
.title(format!("{:?}", V))
|
||||
.fixed_width(200)
|
||||
.expand(true)
|
||||
.build();
|
||||
|
||||
let coef_column = ColumnViewColumn::builder()
|
||||
.title(format!("{:?}", xi))
|
||||
.fixed_width(200)
|
||||
.expand(true)
|
||||
.build();
|
||||
|
||||
columns.append_column(&frequency_column);
|
||||
columns.append_column(&reactive_resistance_column);
|
||||
columns.append_column(&voltage_column);
|
||||
columns.append_column(&coef_column);
|
||||
|
||||
table_row.set_child(Some(&columns));
|
||||
|
||||
new_table.append(&table_row);
|
||||
|
||||
table.set_child(Some(&new_table));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,8 +9,7 @@ mod view;
|
|||
use controller::*;
|
||||
use view::view::*;
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() {
|
||||
fn main() {
|
||||
let app: adw::Application = adw::Application::builder()
|
||||
.application_id("com.github.gtk-rs.examples.basic")
|
||||
.build();
|
||||
|
|
|
@ -1,15 +1,2 @@
|
|||
pub mod builder_traits;
|
||||
pub mod models;
|
||||
|
||||
use crate::gtk::glib;
|
||||
use glib::Object;
|
||||
|
||||
glib::wrapper! {
|
||||
pub struct ResultValue(ObjectSubclass<models::ResultValue>);
|
||||
}
|
||||
|
||||
impl ResultValue {
|
||||
pub fn new(val: f64) -> Self {
|
||||
Object::builder().property("value", val).build()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,12 +1,3 @@
|
|||
use std::cell::Cell;
|
||||
|
||||
use crate::gtk;
|
||||
|
||||
use glib::Properties;
|
||||
use gtk::glib;
|
||||
use gtk::prelude::*;
|
||||
use gtk::subclass::prelude::*;
|
||||
|
||||
#[repr(usize)]
|
||||
#[derive(Clone)]
|
||||
pub enum HammingMode {
|
||||
|
@ -19,28 +10,4 @@ pub struct EventHandler<F, C> {
|
|||
pub(crate) callback: F,
|
||||
}
|
||||
|
||||
#[derive(Default, Copy, Clone)]
|
||||
pub struct SignalReduce(pub f64, pub f64, pub f64, pub f64, pub f64, pub f64);
|
||||
|
||||
impl SignalReduce {
|
||||
pub fn new() -> Self {
|
||||
Self(0.0, 0.0, 0.0, 0.0, 0.0, 0.0)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Properties, Default)]
|
||||
#[properties(wrapper_type = super::ResultValue)]
|
||||
pub struct ResultValue {
|
||||
#[property(get, set)]
|
||||
value: Cell<f64>,
|
||||
}
|
||||
|
||||
// The central trait for subclassing a GObject
|
||||
#[glib::object_subclass]
|
||||
impl ObjectSubclass for ResultValue {
|
||||
const NAME: &'static str = "MyGtkAppCustomButton";
|
||||
type Type = super::ResultValue;
|
||||
}
|
||||
|
||||
#[glib::derived_properties]
|
||||
impl ObjectImpl for ResultValue {}
|
||||
pub type SchemeCharacteristics = (f64, f64, f64, f64, f64, f64);
|
||||
|
|
|
@ -1,146 +0,0 @@
|
|||
use gtk4 as gtk;
|
||||
|
||||
use std::{collections::VecDeque, sync::LazyLock};
|
||||
|
||||
use gtk::{
|
||||
builders::{BoxBuilder, ButtonBuilder, LabelBuilder},
|
||||
prelude::{BoxExt, ObjectExt, WidgetExt},
|
||||
Box, Button, Label, Revealer, RevealerTransitionType,
|
||||
};
|
||||
|
||||
use crate::{
|
||||
event_handlers::button_event_handlers::BtnEventHandler,
|
||||
model::{builder_traits::Product, models::EventHandler},
|
||||
};
|
||||
|
||||
use tokio::{
|
||||
task::{spawn, JoinHandle},
|
||||
time::{sleep, Duration},
|
||||
};
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct InfoBar {
|
||||
instance: Revealer,
|
||||
}
|
||||
|
||||
pub struct InfoBarBuilder {
|
||||
label: LabelBuilder,
|
||||
r#box: BoxBuilder,
|
||||
button: ButtonBuilder,
|
||||
}
|
||||
|
||||
// TODO: Develop a method to safely mutate static.
|
||||
// Not necessary.
|
||||
static mut TASKS_QUEUE: VecDeque<JoinHandle<()>> = VecDeque::new();
|
||||
|
||||
//
|
||||
// Singleton pattern implementation
|
||||
//
|
||||
|
||||
unsafe impl Send for InfoBar {}
|
||||
unsafe impl Sync for InfoBar {}
|
||||
|
||||
static INFO_BAR_INSTANCE: LazyLock<InfoBar> = LazyLock::new(|| InfoBar {
|
||||
instance: Revealer::new(),
|
||||
});
|
||||
|
||||
impl InfoBar {
|
||||
pub fn get_instance() -> &'static Self {
|
||||
&INFO_BAR_INSTANCE
|
||||
}
|
||||
|
||||
pub fn set_text_label(&self, text_label: Option<&str>) {
|
||||
if let Some(text) = text_label {
|
||||
let _ = &INFO_BAR_INSTANCE
|
||||
.instance
|
||||
.child()
|
||||
.unwrap()
|
||||
.first_child()
|
||||
.unwrap()
|
||||
.set_property("label", text);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_reveal_child(&self, is_reveal: bool) {
|
||||
let _ = &INFO_BAR_INSTANCE.instance.set_reveal_child(is_reveal);
|
||||
}
|
||||
|
||||
pub fn show_infobar(&self, duration_secs: u64) {
|
||||
if !INFO_BAR_INSTANCE.instance.reveals_child() {
|
||||
INFO_BAR_INSTANCE.set_reveal_child(true);
|
||||
}
|
||||
|
||||
let callback = spawn(async move {
|
||||
sleep(Duration::from_secs(duration_secs)).await;
|
||||
INFO_BAR_INSTANCE.set_reveal_child(false);
|
||||
});
|
||||
|
||||
unsafe {
|
||||
if !TASKS_QUEUE.is_empty() {
|
||||
TASKS_QUEUE.pop_back().unwrap().abort();
|
||||
}
|
||||
|
||||
TASKS_QUEUE.push_back(callback);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Builder pattern implementation
|
||||
//
|
||||
|
||||
impl InfoBarBuilder {
|
||||
pub fn build(self) -> &'static InfoBar {
|
||||
let info_bar_label = self.label.build();
|
||||
let info_bar_box = self.r#box.build();
|
||||
let info_bar_close_btn = self.button.build();
|
||||
|
||||
info_bar_label.set_hexpand(true);
|
||||
|
||||
info_bar_box.append(&info_bar_label);
|
||||
info_bar_box.append(&info_bar_close_btn);
|
||||
info_bar_box.set_widget_name("info_bar");
|
||||
|
||||
let info_bar: &Revealer = &INFO_BAR_INSTANCE.instance;
|
||||
|
||||
info_bar.set_transition_type(RevealerTransitionType::SlideUp);
|
||||
info_bar.set_transition_duration(200);
|
||||
|
||||
info_bar.set_child(Some(&info_bar_box));
|
||||
|
||||
let info_bar_to_close = info_bar.clone();
|
||||
|
||||
EventHandler::new(info_bar_close_btn.clone(), move |_| {
|
||||
info_bar_to_close.set_reveal_child(false);
|
||||
})
|
||||
.on_click();
|
||||
|
||||
&INFO_BAR_INSTANCE
|
||||
}
|
||||
|
||||
pub fn set_text_label(mut self, text: &str) -> Self {
|
||||
self.label = self.label.label(text);
|
||||
|
||||
self
|
||||
}
|
||||
|
||||
pub fn set_button_icon(mut self, icon_name: &str) -> Self {
|
||||
self.button = self.button.icon_name(icon_name);
|
||||
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl Product<InfoBarBuilder, &'static Revealer> for InfoBar {
|
||||
fn builder() -> InfoBarBuilder {
|
||||
InfoBarBuilder {
|
||||
label: Label::builder(),
|
||||
r#box: Box::builder(),
|
||||
button: Button::builder(),
|
||||
}
|
||||
}
|
||||
|
||||
fn get(self) -> &'static Revealer {
|
||||
&INFO_BAR_INSTANCE.instance
|
||||
}
|
||||
}
|
|
@ -1,4 +1,3 @@
|
|||
pub mod info_bar;
|
||||
pub mod input;
|
||||
pub mod pages;
|
||||
pub mod switch;
|
||||
|
|
|
@ -12,7 +12,7 @@ use crate::{
|
|||
|
||||
use gtk::{prelude::*, *};
|
||||
|
||||
pub fn hamming_code_page(wrapper: &Box) {
|
||||
pub fn hamming_code_page(wrapper: &Box, info_bar: Revealer) {
|
||||
// input
|
||||
|
||||
let hamming_text_view_input_label = Label::builder()
|
||||
|
|
|
@ -1,38 +1,21 @@
|
|||
use std::{cell::Cell, rc::Rc};
|
||||
use glib::property::PropertyGet;
|
||||
use gtk4 as gtk;
|
||||
use gtk4::prelude::WidgetExt;
|
||||
use std::{str::FromStr, time::Duration};
|
||||
|
||||
use crate::{
|
||||
event_handlers::button_event_handlers::BtnEventHandler,
|
||||
model::{
|
||||
builder_traits::Product,
|
||||
models::{EventHandler, SignalReduce},
|
||||
ResultValue,
|
||||
},
|
||||
model_utils::signal_reducer::{
|
||||
coef_of_signal_reduce, full_resistance_of_capacitor, reactive_resistance_of_capacitor,
|
||||
voltage_from_signal_source,
|
||||
},
|
||||
view::{
|
||||
components::{info_bar::InfoBar, input::Input},
|
||||
properties::*,
|
||||
},
|
||||
view_utils::signal_reduce_input_utils::{get_error_message, parse_fields},
|
||||
model::{builder_traits::Product, models::*},
|
||||
view::{components::input::Input, properties::*},
|
||||
};
|
||||
|
||||
use gtk::{
|
||||
prelude::{BoxExt, Cast, CastNone, GridExt, ListItemExt},
|
||||
prelude::{BoxExt, GridExt, TextBufferExt, TextViewExt},
|
||||
Align, WrapMode, *,
|
||||
};
|
||||
use gtk4 as gtk;
|
||||
|
||||
pub fn signal_reducing_page(wrapper: &Box) {
|
||||
let values = Rc::new(Cell::new(SignalReduce::default()));
|
||||
|
||||
let last_query: Vec<TreeIter> = Vec::new();
|
||||
|
||||
let info_bar = InfoBar::get_instance();
|
||||
|
||||
let (input_height, monospace, input_wrapping): (i32, bool, WrapMode) =
|
||||
(24, true, WrapMode::Word);
|
||||
pub fn signal_reducing_page(wrapper: &Box, info_bar: Revealer) {
|
||||
let (input_height, monospace, input_alignment, input_wrapping): (i32, bool, Align, WrapMode) =
|
||||
(24, true, Align::Fill, WrapMode::Word);
|
||||
|
||||
let input_block: Grid = Grid::new();
|
||||
|
||||
|
@ -82,123 +65,49 @@ pub fn signal_reducing_page(wrapper: &Box) {
|
|||
|
||||
let calculate_button = Button::builder().label("Расчитать").build();
|
||||
|
||||
let result_table_headers_labels: [&str; 4] = ["f, МГц", "Xc, пФ", "Vп, мВ", "ζ"];
|
||||
// TODO: Make asynchronious auto-hide info bar.
|
||||
let test = info_bar.clone();
|
||||
|
||||
let model = gio::ListStore::new::<ResultValue>();
|
||||
|
||||
let cloned_model = model.clone();
|
||||
|
||||
let selection_model = SingleSelection::new(Some(model));
|
||||
|
||||
let result_table = ColumnView::builder()
|
||||
.reorderable(true)
|
||||
.model(&selection_model)
|
||||
.build();
|
||||
|
||||
for label in result_table_headers_labels {
|
||||
let factory = SignalListItemFactory::new();
|
||||
|
||||
factory.connect_setup(move |_, list_item| {
|
||||
list_item
|
||||
.downcast_ref::<ListItem>()
|
||||
.expect("Needs to be ListItem")
|
||||
.set_child(Some(&Label::new(None)));
|
||||
});
|
||||
|
||||
let values_for_factory = values.clone();
|
||||
|
||||
factory.connect_bind(move |_, list_item| {
|
||||
let cell_value = list_item
|
||||
.downcast_ref::<ListItem>()
|
||||
.expect("Needs to be ListItem")
|
||||
.item()
|
||||
.and_downcast::<ResultValue>()
|
||||
.expect("The item has to be an `IntegerObject`.");
|
||||
|
||||
let cell_label = list_item
|
||||
.downcast_ref::<ListItem>()
|
||||
.expect("Needs to be ListItem")
|
||||
.child()
|
||||
.and_downcast::<Label>()
|
||||
.expect("The child has to be a `Label`.");
|
||||
|
||||
let result_values = values_for_factory.clone().get();
|
||||
|
||||
let reactive_resist: f64 = reactive_resistance_of_capacitor(
|
||||
result_values.2,
|
||||
result_values.0,
|
||||
cell_value.value(),
|
||||
);
|
||||
|
||||
let full_resistance: f64 = full_resistance_of_capacitor(
|
||||
reactive_resist,
|
||||
result_values.4,
|
||||
result_values.1,
|
||||
result_values.0,
|
||||
);
|
||||
|
||||
let signal_source_voltage: f64 =
|
||||
voltage_from_signal_source(result_values.3, reactive_resist, full_resistance);
|
||||
|
||||
let coef: f64 = coef_of_signal_reduce(signal_source_voltage, signal_source_voltage);
|
||||
|
||||
match label {
|
||||
"f, МГц" => {
|
||||
cell_label.set_label(&cell_value.value().to_string());
|
||||
}
|
||||
"Xc, пФ" => {
|
||||
cell_label.set_label(&reactive_resist.to_string());
|
||||
}
|
||||
"Vп, мВ" => {
|
||||
cell_label.set_label(&signal_source_voltage.to_string());
|
||||
}
|
||||
"ζ" => {
|
||||
cell_label.set_label(&coef.to_string());
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
});
|
||||
|
||||
let column = ColumnViewColumn::builder()
|
||||
.title(label)
|
||||
.expand(true)
|
||||
.resizable(false)
|
||||
.factory(&factory)
|
||||
.build();
|
||||
|
||||
result_table.append_column(&column);
|
||||
}
|
||||
|
||||
let scrollable_table = ScrolledWindow::builder()
|
||||
.vexpand(true)
|
||||
.child(&result_table)
|
||||
.build();
|
||||
|
||||
let table = Frame::builder()
|
||||
.child(&scrollable_table)
|
||||
.vexpand(true)
|
||||
.build();
|
||||
// let (tx, rx) = std::sync::mpsc::channel::<bool>();
|
||||
|
||||
EventHandler::new(calculate_button.clone(), move |_| {
|
||||
match parse_fields(all_inputs.clone()) {
|
||||
Ok(results) => {
|
||||
values.set(results);
|
||||
let mut values: [f64; 6] = [0f64; 6];
|
||||
|
||||
let tree_iter: TreeIter = cloned_model.append(&ResultValue::new(results.5));
|
||||
for (i, input) in all_inputs.iter().enumerate() {
|
||||
let input_text_buffer: TextBuffer = input.clone().get_input().buffer();
|
||||
let try_extract_value = f64::from_str(
|
||||
input_text_buffer
|
||||
.text(
|
||||
&input_text_buffer.start_iter(),
|
||||
&input_text_buffer.end_iter(),
|
||||
false,
|
||||
)
|
||||
.as_str()
|
||||
.trim(),
|
||||
);
|
||||
if let Ok(value) = try_extract_value {
|
||||
values[i] = value;
|
||||
} else {
|
||||
test.set_reveal_child(true);
|
||||
|
||||
last_query.append(tree_iter);
|
||||
}
|
||||
Err(error) => {
|
||||
let error_kind: Option<&str> = get_error_message(error);
|
||||
// TODO: Make asynchronious auto-hide info bar.
|
||||
// let transmitter = tx.clone();
|
||||
//
|
||||
// gio::spawn_blocking(move || {
|
||||
// std::thread::sleep(Duration::from_secs(5));
|
||||
// transmitter.send(false).unwrap();
|
||||
// });
|
||||
//
|
||||
// test.set_reveal_child(rx.recv().unwrap());
|
||||
|
||||
info_bar.set_text_label(error_kind);
|
||||
info_bar.show_infobar(5u64);
|
||||
println!("Вы ввели некорректное значение поля.");
|
||||
return;
|
||||
}
|
||||
}
|
||||
println!("{:?}", values);
|
||||
})
|
||||
.on_click();
|
||||
|
||||
wrapper.append(&input_block);
|
||||
wrapper.append(&calculate_button);
|
||||
wrapper.append(&table);
|
||||
}
|
||||
|
|
|
@ -117,3 +117,4 @@ impl Alignment {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,15 +1,3 @@
|
|||
#info_bar{
|
||||
background-color:#F1E6D9;
|
||||
padding: 5px;
|
||||
font-size: 11pt;
|
||||
}
|
||||
#info_bar > button {
|
||||
transform: scale(0.9);
|
||||
background-color: transparent;
|
||||
}
|
||||
#info_bar > button:hover {
|
||||
background-color: #00000010;
|
||||
}
|
||||
#info_bar > button:active {
|
||||
background-color: #00000020;
|
||||
.info_box{
|
||||
background-color: yellow;
|
||||
}
|
||||
|
|
|
@ -1,13 +1,14 @@
|
|||
use crate::model::builder_traits::*;
|
||||
|
||||
use builders::{BoxBuilder, RevealerBuilder};
|
||||
use gtk4 as gtk;
|
||||
|
||||
use gtk::{prelude::*, StackTransitionType::SlideLeftRight, *};
|
||||
use info_bar::InfoBar;
|
||||
use gtk::{prelude::*, Revealer, StackTransitionType::SlideLeftRight, *};
|
||||
|
||||
use crate::view::components::pages::Pages;
|
||||
|
||||
#[allow(unused)]
|
||||
use crate::view::{
|
||||
components::{pages::Pages, wrapper::*, *},
|
||||
components::{wrapper::*, *},
|
||||
pages::*,
|
||||
properties::*,
|
||||
};
|
||||
|
@ -23,12 +24,15 @@ pub fn ui(application: &adw::Application) {
|
|||
.spacing(10)
|
||||
.build();
|
||||
|
||||
let info_bar = InfoBar::builder()
|
||||
.set_text_label("Sample text")
|
||||
.set_button_icon("close")
|
||||
let info_bar_label = Label::builder().label("test").build();
|
||||
|
||||
let info_bar: Revealer = Revealer::builder()
|
||||
.child(&info_bar_label)
|
||||
.transition_type(RevealerTransitionType::SlideUp)
|
||||
.transition_duration(200)
|
||||
.build();
|
||||
|
||||
hamming_code::hamming_code_page(&hamming_code);
|
||||
hamming_code::hamming_code_page(&hamming_code, info_bar.clone());
|
||||
|
||||
let signal_reducing = Wrapper::row_builder()
|
||||
.set_align(Alignment::new(Align::Fill, Align::Fill))
|
||||
|
@ -36,7 +40,7 @@ pub fn ui(application: &adw::Application) {
|
|||
.spacing(10)
|
||||
.build();
|
||||
|
||||
signal_reducing::signal_reducing_page(&signal_reducing);
|
||||
signal_reducing::signal_reducing_page(&signal_reducing, info_bar.clone());
|
||||
|
||||
let pages = Pages::builder()
|
||||
.set_transition(SlideLeftRight, 200)
|
||||
|
@ -49,7 +53,7 @@ pub fn ui(application: &adw::Application) {
|
|||
|
||||
let application_box = Box::new(Orientation::Vertical, 0);
|
||||
|
||||
application_box.append(info_bar.clone().get());
|
||||
application_box.append(&info_bar);
|
||||
application_box.append(&pages);
|
||||
|
||||
let window = ApplicationWindow::builder()
|
||||
|
|
Loading…
Reference in New Issue