Compare commits
No commits in common. "81a8d9b2c67c8204964cdd0735d9dee6e4b97321" and "7c16964b83b1ad0171371b3e3555122469d9bad1" have entirely different histories.
81a8d9b2c6
...
7c16964b83
|
@ -9,5 +9,4 @@ edition = "2021"
|
|||
adw = { version = "0.6.0", package = "libadwaita", features = ["v1_4"] }
|
||||
bitvec = "1.0.1"
|
||||
gtk4 = "0.8.1"
|
||||
tokio = { version = "1.0.0", features = ["rt", "time", "rt-multi-thread", "macros"] }
|
||||
|
||||
tokio = { version = "1.0.0", features = ["rt", "rt-multi-thread", "macros"] }
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use crate::{gtk::prelude::*, model::models::*};
|
||||
use crate::{gtk::prelude::*, model::model::*};
|
||||
|
||||
impl<F, C> EventHandler<F, C>
|
||||
where
|
||||
|
@ -26,3 +26,4 @@ where
|
|||
.connect_clicked(move |button| (self.callback)(button));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use crate::{gtk::prelude::*, model::models::*, view::components::switch::SwitchExt};
|
||||
use crate::{gtk::prelude::*, model::model::*, view::components::switch::SwitchExt};
|
||||
|
||||
pub trait SwEventHandler {
|
||||
fn on_toggle(self) -> ();
|
||||
|
|
|
@ -2,7 +2,7 @@ use std::collections::HashMap;
|
|||
|
||||
use crate::{
|
||||
controller::view_utils::{hamming_code_input_utils::*, input_utils::*},
|
||||
model::models::*,
|
||||
model::model::*,
|
||||
};
|
||||
|
||||
/// **Синдромы**
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
pub fn reactive_resistance_of_capacitor(Cm: f64, L: f64, f: f64) -> f64 {
|
||||
1f64 / (2f64 * std::f64::consts::PI * f * Cm * L)
|
||||
1f64 / (2f64 * 3.14f64 * f * Cm * L)
|
||||
}
|
||||
|
||||
pub fn full_resistance_of_capacitor(Xc: f64, Rs: f64, Rm: f64, L: f64) -> f64 {
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
use gtk4 as gtk;
|
||||
|
||||
use crate::{model::models::*, model_utils::hamming_code_seven_four::*};
|
||||
use crate::{model::model::*, model_utils::hamming_code_seven_four::*};
|
||||
use gtk::{prelude::*, *};
|
||||
|
||||
pub fn start_hamming_algorithm(input: &TextView, output: &TextView, mode: bool) {
|
||||
pub fn start_hamming_algorithm(input: &TextView, output: &TextView, mode: bool) -> () {
|
||||
let (iter_start, iter_end) = input.buffer().bounds();
|
||||
let parsed_input: String = input
|
||||
.buffer()
|
||||
|
|
|
@ -9,7 +9,7 @@ const ASCII_ZERO_CHAR_POSITION: u8 = 48;
|
|||
pub fn processing_input(input: &String) -> String {
|
||||
input
|
||||
.split_ascii_whitespace()
|
||||
.filter(|&x| x.is_empty())
|
||||
.filter(|&x| x != "")
|
||||
.fold(String::new(), |c: String, n: &str| c + n)
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use gtk4 as gtk;
|
||||
|
||||
use crate::controller::model_utils::signal_reducer::*;
|
||||
use crate::model::models::SchemeCharacteristics;
|
||||
use crate::model::model::SchemeCharacteristics;
|
||||
use gtk::{prelude::*, *};
|
||||
|
||||
pub fn check_characteristics(
|
||||
|
@ -24,7 +24,7 @@ pub fn check_characteristics(
|
|||
println!("{:?}", int);
|
||||
}
|
||||
Err(err) => {
|
||||
if output.is_empty() {
|
||||
if output.len() == 0 {
|
||||
output.push_str("Введите пожалуйста числа в полях");
|
||||
println!("{:?}", err);
|
||||
}
|
||||
|
@ -32,7 +32,11 @@ pub fn check_characteristics(
|
|||
}
|
||||
}
|
||||
|
||||
!output.is_empty()
|
||||
if output.len() != 0 {
|
||||
false
|
||||
} else {
|
||||
true
|
||||
}
|
||||
}
|
||||
|
||||
pub fn start_algorithm(
|
||||
|
@ -44,7 +48,7 @@ pub fn start_algorithm(
|
|||
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) {
|
||||
if let false = check_characteristics(raw_characteristics, &mut all_inputs_data, &mut output) {
|
||||
error_log_label.set_text(output.as_str());
|
||||
} else {
|
||||
error_log_label.set_text("");
|
||||
|
|
|
@ -10,7 +10,7 @@ use controller::*;
|
|||
use view::view::*;
|
||||
|
||||
fn main() {
|
||||
let app: adw::Application = adw::Application::builder()
|
||||
let app = adw::Application::builder()
|
||||
.application_id("com.github.gtk-rs.examples.basic")
|
||||
.build();
|
||||
|
||||
|
|
|
@ -1,2 +1,2 @@
|
|||
pub mod builder_traits;
|
||||
pub mod models;
|
||||
pub mod model;
|
||||
pub mod builder_traits;
|
|
@ -1,7 +1,7 @@
|
|||
pub mod tabs;
|
||||
pub mod input;
|
||||
pub mod pages;
|
||||
pub mod switch;
|
||||
pub mod tabs;
|
||||
pub mod wrapper;
|
||||
|
||||
use crate::model::builder_traits;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use gtk4::{self as gtk, prelude::WidgetExt, Align};
|
||||
use gtk4 as gtk;
|
||||
|
||||
#[allow(unused)]
|
||||
use gtk::{
|
||||
|
@ -42,7 +42,6 @@ impl Builder<Pages, Page<'_>, i32> for PagesBuilder {
|
|||
|
||||
wrapper.append(&stack_sidebar);
|
||||
wrapper.append(&self.pages_content);
|
||||
wrapper.set_vexpand(true);
|
||||
|
||||
Pages { wrapper }
|
||||
}
|
||||
|
@ -74,3 +73,4 @@ impl PagesBuilder {
|
|||
self
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
pub mod components;
|
||||
pub mod pages;
|
||||
pub mod properties;
|
||||
pub mod styles;
|
||||
pub mod view;
|
||||
pub mod pages;
|
||||
pub mod components;
|
||||
pub mod properties;
|
||||
|
|
|
@ -6,13 +6,13 @@ use crate::{
|
|||
event_handlers::{button_event_handlers::*, switch_event_handlers::*},
|
||||
view_utils::{hamming_code_input_utils::*, input_utils::*},
|
||||
},
|
||||
model::models::*,
|
||||
model::model::*,
|
||||
view::{components::wrapper::*, properties::*},
|
||||
};
|
||||
|
||||
use gtk::{prelude::*, *};
|
||||
|
||||
pub fn hamming_code_page(wrapper: &Box, info_bar: Revealer) {
|
||||
pub fn hamming_code_page(wrapper: &Box) -> () {
|
||||
// input
|
||||
|
||||
let hamming_text_view_input_label = Label::builder()
|
||||
|
|
|
@ -1,113 +1,211 @@
|
|||
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::*},
|
||||
view::{components::input::Input, properties::*},
|
||||
controller::event_handlers::button_event_handlers::*,
|
||||
model::{builder_traits::Product, model::*},
|
||||
view::{
|
||||
components::{input::Input, wrapper::Wrapper},
|
||||
properties::*,
|
||||
},
|
||||
view_utils::signal_reduce_input_utils::start_algorithm,
|
||||
};
|
||||
use gtk::{
|
||||
prelude::{BoxExt, GridExt, TextBufferExt, TextViewExt},
|
||||
prelude::{BoxExt, ListBoxRowExt, WidgetExt},
|
||||
Align, WrapMode, *,
|
||||
};
|
||||
|
||||
pub fn signal_reducing_page(wrapper: &Box, info_bar: Revealer) {
|
||||
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 input_block: Grid = Grid::new();
|
||||
|
||||
input_block.set_column_homogeneous(true);
|
||||
input_block.set_row_homogeneous(true);
|
||||
|
||||
let input_label_alignment = Alignment {
|
||||
horizontal: Align::Start,
|
||||
vertical: Align::Fill,
|
||||
};
|
||||
|
||||
let input_labels: [&str; 6] = [
|
||||
"l, м:",
|
||||
"Rм, Ом:",
|
||||
"Cм, пФ:",
|
||||
"Vи, мВ",
|
||||
"Rи, Ом:",
|
||||
"f, мГц:",
|
||||
let wire_length_input: Input = Input::builder()
|
||||
.set_label("l, м:")
|
||||
.set_margins(MarginData::EqualsMargin(5))
|
||||
.set_align(input_label_alignment)
|
||||
.build(monospace, input_wrapping, input_height);
|
||||
|
||||
let resistance_per_meter_input: Input = Input::builder()
|
||||
.set_label("Rм, Ом:")
|
||||
.set_margins(MarginData::EqualsMargin(5))
|
||||
.set_align(input_label_alignment)
|
||||
.build(monospace, input_wrapping, input_height);
|
||||
|
||||
let capacity_per_meter_input: Input = Input::builder()
|
||||
.set_label("Cм, пФ:")
|
||||
.set_margins(MarginData::EqualsMargin(5))
|
||||
.set_align(input_label_alignment)
|
||||
.build(monospace, input_wrapping, input_height);
|
||||
|
||||
let wrapper_first_row = Wrapper::col_builder()
|
||||
.halign(Align::Fill)
|
||||
.hexpand(true)
|
||||
.spacing(5)
|
||||
.build();
|
||||
|
||||
let first_row_elements: Vec<&Input> = vec![
|
||||
&wire_length_input,
|
||||
&resistance_per_meter_input,
|
||||
&capacity_per_meter_input,
|
||||
];
|
||||
|
||||
let all_inputs: Vec<Input> = input_labels
|
||||
.iter()
|
||||
.map(move |label| {
|
||||
Input::builder()
|
||||
.set_label(label)
|
||||
.set_margins(MarginData::EqualsMargin(5))
|
||||
.set_align(input_label_alignment)
|
||||
.build(monospace, input_wrapping, input_height)
|
||||
})
|
||||
.collect();
|
||||
for elem in first_row_elements {
|
||||
let input: Box = elem.clone().get();
|
||||
|
||||
let mut row_position = 0i32;
|
||||
input.set_halign(input_alignment);
|
||||
input.set_hexpand(true);
|
||||
|
||||
for (id, elem) in all_inputs.iter().enumerate() {
|
||||
if id % 3 == 0 {
|
||||
row_position += 1;
|
||||
}
|
||||
|
||||
input_block.attach(
|
||||
&elem.clone().get(),
|
||||
(id as i32) - (3 * row_position),
|
||||
row_position,
|
||||
1,
|
||||
1,
|
||||
);
|
||||
wrapper_first_row.append(&input);
|
||||
}
|
||||
|
||||
let calculate_button = Button::builder().label("Расчитать").build();
|
||||
let info_signal_voltage_input: Input = Input::builder()
|
||||
.set_label("Vи, мВ:")
|
||||
.set_margins(MarginData::EqualsMargin(5))
|
||||
.set_align(input_label_alignment)
|
||||
.build(monospace, input_wrapping, input_height);
|
||||
|
||||
// TODO: Make asynchronious auto-hide info bar.
|
||||
let test = info_bar.clone();
|
||||
let resistance_of_info_voltage_source_input: Input = Input::builder()
|
||||
.set_label("Rи, Ом:")
|
||||
.set_margins(MarginData::EqualsMargin(5))
|
||||
.set_align(input_label_alignment)
|
||||
.build(monospace, input_wrapping, input_height);
|
||||
|
||||
// let (tx, rx) = std::sync::mpsc::channel::<bool>();
|
||||
let info_voltage_source_frequency_input: Input = Input::builder()
|
||||
.set_label("f, мГц:")
|
||||
.set_margins(MarginData::EqualsMargin(5))
|
||||
.set_align(input_label_alignment)
|
||||
.build(monospace, input_wrapping, input_height);
|
||||
|
||||
let wrapper_second_row = Wrapper::col_builder()
|
||||
.halign(Align::Fill)
|
||||
.hexpand(true)
|
||||
.spacing(5)
|
||||
.build();
|
||||
|
||||
let second_row_elements: Vec<&Input> = vec![
|
||||
&info_signal_voltage_input,
|
||||
&resistance_of_info_voltage_source_input,
|
||||
&info_voltage_source_frequency_input,
|
||||
];
|
||||
|
||||
for elem in second_row_elements {
|
||||
let input: Box = elem.clone().get();
|
||||
|
||||
input.set_halign(input_alignment);
|
||||
input.set_hexpand(true);
|
||||
|
||||
wrapper_second_row.append(&input);
|
||||
}
|
||||
|
||||
let all_text_views: Vec<TextView> = vec![
|
||||
wire_length_input.get_input(),
|
||||
resistance_per_meter_input.get_input(),
|
||||
capacity_per_meter_input.get_input(),
|
||||
info_signal_voltage_input.get_input(),
|
||||
resistance_of_info_voltage_source_input.get_input(),
|
||||
info_voltage_source_frequency_input.get_input(),
|
||||
];
|
||||
|
||||
let main_wrapper = Wrapper::row_builder().spacing(5).build();
|
||||
|
||||
main_wrapper.append(&wrapper_first_row);
|
||||
main_wrapper.append(&wrapper_second_row);
|
||||
|
||||
let calculate_button = Button::builder()
|
||||
.label("Расчитать")
|
||||
.halign(Align::End)
|
||||
.set_margin(MarginData::MultipleMargin((10, 5, 0, 0)))
|
||||
.build();
|
||||
|
||||
let table_header_labels = vec!["f, Гц", "Xc, пФ", "Vп, мВ", "ζ"];
|
||||
|
||||
let table_header = ColumnView::builder()
|
||||
.focusable(false)
|
||||
.reorderable(false)
|
||||
.show_row_separators(true)
|
||||
.show_column_separators(true)
|
||||
.halign(Align::Fill)
|
||||
.hexpand(true)
|
||||
.build();
|
||||
|
||||
for table_header_label in table_header_labels {
|
||||
let column = ColumnViewColumn::builder()
|
||||
.title(table_header_label)
|
||||
.fixed_width(200)
|
||||
.expand(true)
|
||||
.build();
|
||||
|
||||
table_header.append_column(&column);
|
||||
}
|
||||
|
||||
let mut table = ListBox::builder().hexpand(true).halign(Align::Fill).build();
|
||||
|
||||
let header = ListBoxRow::builder().child(&table_header).build();
|
||||
|
||||
table.append(&header);
|
||||
|
||||
for i in (0..=100).step_by(5) {
|
||||
if i == 0 {
|
||||
continue;
|
||||
}
|
||||
|
||||
let table_row = ListBoxRow::new();
|
||||
|
||||
let columns = ColumnView::builder().reorderable(false).build();
|
||||
|
||||
let column = ColumnViewColumn::builder()
|
||||
.title(format!("{i}"))
|
||||
.fixed_width(200)
|
||||
.expand(true)
|
||||
.build();
|
||||
|
||||
columns.append_column(&column);
|
||||
|
||||
for table_row_label in 1..=3 {
|
||||
let column = ColumnViewColumn::builder()
|
||||
.title(format!("{table_row_label}"))
|
||||
.fixed_width(200)
|
||||
.expand(true)
|
||||
.build();
|
||||
|
||||
columns.append_column(&column);
|
||||
}
|
||||
|
||||
table_row.set_child(Some(&columns));
|
||||
|
||||
table.append(&table_row);
|
||||
}
|
||||
|
||||
let table_of_calculated_values = Frame::builder()
|
||||
.height_request(64)
|
||||
.hexpand(true)
|
||||
.child(&table)
|
||||
.halign(Align::Fill)
|
||||
.set_margin(MarginData::MultipleMargin((10, 5, 0, 0)))
|
||||
.build();
|
||||
|
||||
let table_frame = table_of_calculated_values.clone();
|
||||
|
||||
let errors_label: Label = Label::new(Some(""));
|
||||
let errors_label_for_handler: Label = errors_label.clone();
|
||||
|
||||
EventHandler::new(calculate_button.clone(), move |_| {
|
||||
let mut values: [f64; 6] = [0f64; 6];
|
||||
|
||||
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);
|
||||
|
||||
// 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());
|
||||
|
||||
println!("Вы ввели некорректное значение поля.");
|
||||
return;
|
||||
}
|
||||
}
|
||||
println!("{:?}", values);
|
||||
start_algorithm(
|
||||
&errors_label_for_handler,
|
||||
&all_text_views,
|
||||
&table_frame.clone(),
|
||||
&header,
|
||||
)
|
||||
})
|
||||
.on_click();
|
||||
|
||||
wrapper.append(&input_block);
|
||||
wrapper.append(&calculate_button);
|
||||
main_wrapper.append(&errors_label);
|
||||
main_wrapper.append(&calculate_button);
|
||||
main_wrapper.append(&table_of_calculated_values);
|
||||
|
||||
wrapper.append(&main_wrapper);
|
||||
}
|
||||
|
|
|
@ -1,3 +0,0 @@
|
|||
.info_box{
|
||||
background-color: yellow;
|
||||
}
|
|
@ -1,19 +0,0 @@
|
|||
use adw::gdk::Display;
|
||||
use gtk4 as gtk;
|
||||
|
||||
use std::path::Path;
|
||||
|
||||
use gtk::{
|
||||
style_context_add_provider_for_display, CssProvider, STYLE_PROVIDER_PRIORITY_APPLICATION,
|
||||
};
|
||||
|
||||
pub fn load_css() {
|
||||
let style_provider = CssProvider::new();
|
||||
style_provider.load_from_path(Path::new("./src/view/styles/info_bar.css"));
|
||||
|
||||
style_context_add_provider_for_display(
|
||||
&Display::default().expect("Could not connect to a display"),
|
||||
&style_provider,
|
||||
STYLE_PROVIDER_PRIORITY_APPLICATION,
|
||||
);
|
||||
}
|
|
@ -1,8 +1,7 @@
|
|||
use crate::model::builder_traits::*;
|
||||
use builders::{BoxBuilder, RevealerBuilder};
|
||||
use gtk4 as gtk;
|
||||
|
||||
use gtk::{prelude::*, Revealer, StackTransitionType::SlideLeftRight, *};
|
||||
use gtk::{prelude::*, StackTransitionType::SlideLeftRight, *};
|
||||
|
||||
use crate::view::components::pages::Pages;
|
||||
|
||||
|
@ -13,26 +12,14 @@ use crate::view::{
|
|||
properties::*,
|
||||
};
|
||||
|
||||
use super::styles::load_css;
|
||||
|
||||
pub fn ui(application: &adw::Application) {
|
||||
load_css();
|
||||
|
||||
let hamming_code = Wrapper::row_builder()
|
||||
.set_align(Alignment::new(Align::Fill, Align::Fill))
|
||||
.set_margin(MarginData::EqualsMargin(15))
|
||||
.spacing(10)
|
||||
.build();
|
||||
|
||||
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, info_bar.clone());
|
||||
hamming_code::hamming_code_page(&hamming_code);
|
||||
|
||||
let signal_reducing = Wrapper::row_builder()
|
||||
.set_align(Alignment::new(Align::Fill, Align::Fill))
|
||||
|
@ -40,7 +27,7 @@ pub fn ui(application: &adw::Application) {
|
|||
.spacing(10)
|
||||
.build();
|
||||
|
||||
signal_reducing::signal_reducing_page(&signal_reducing, info_bar.clone());
|
||||
signal_reducing::signal_reducing_page(&signal_reducing);
|
||||
|
||||
let pages = Pages::builder()
|
||||
.set_transition(SlideLeftRight, 200)
|
||||
|
@ -51,17 +38,12 @@ pub fn ui(application: &adw::Application) {
|
|||
.build(5)
|
||||
.get();
|
||||
|
||||
let application_box = Box::new(Orientation::Vertical, 0);
|
||||
|
||||
application_box.append(&info_bar);
|
||||
application_box.append(&pages);
|
||||
|
||||
let window = ApplicationWindow::builder()
|
||||
.title("Комплексная программа для лаб. работ")
|
||||
.width_request(700)
|
||||
.height_request(400)
|
||||
.application(application)
|
||||
.child(&application_box)
|
||||
.child(&pages)
|
||||
.build();
|
||||
|
||||
window.show();
|
||||
|
|
Loading…
Reference in New Issue