Compare commits

...

7 Commits

9 changed files with 68 additions and 81 deletions

View File

@ -9,6 +9,6 @@ edition = "2021"
adw = { version = "0.7.0", package = "libadwaita", features = ["v1_4"] }
bitvec = "1.0.1"
gio = { version = "0.20.0", features = ["v2_74"] }
gtk4 = { version = "0.9.0"}
gtk4 = { version = "0.9.0", features = ["v4_12"] }
tokio = { version = "1.39.2", features = ["rt", "time", "rt-multi-thread", "macros", "sync"] }

View File

@ -1,3 +1,4 @@
use gio::glib::Object;
use gtk4 as gtk;
use std::str::FromStr;
@ -9,7 +10,7 @@ use crate::{
};
use gtk::{
prelude::{Cast, CastNone, EditableExt, ListItemExt, ObjectExt, WidgetExt},
prelude::{Cast, CastNone, EditableExt, ListItemExt, WidgetExt},
ColumnView, Entry, Label, ListItem, SignalListItemFactory,
};
@ -42,12 +43,12 @@ pub fn parse_fields(all_inputs: Vec<Input<Entry>>) -> Result<SignalReduce> {
#[inline]
pub fn update_column_view(column_view: &ColumnView) {
column_view.hide();
column_view.show();
column_view.set_visible(false);
column_view.set_visible(true);
}
#[inline]
pub fn column_view_setup_factory(_factory: &SignalListItemFactory, list_item: &ListItem) {
pub fn column_view_setup_factory(_factory: &SignalListItemFactory, list_item: &Object) {
list_item
.downcast_ref::<ListItem>()
.expect("Needs to be ListItem")
@ -56,7 +57,7 @@ pub fn column_view_setup_factory(_factory: &SignalListItemFactory, list_item: &L
pub fn column_view_bind_factory(
_factory: &SignalListItemFactory,
list_item: &ListItem,
list_item: &Object,
values: SignalReduce,
label: &str,
) {
@ -74,29 +75,19 @@ pub fn column_view_bind_factory(
.and_downcast::<Label>()
.expect("The child has to be a `Label`.");
cell_value
.bind_property("frequency", &cell_label, "label")
.sync_create()
.build();
if cell_value.reactive_resist() == 0.0 {
cell_value.set_reactive_resist(reactive_resistance_of_capacitor(
values.wire_capacity * 10f64.powi(-12),
values.length,
cell_value.frequency() * 10f64.powi(6),
));
}
if cell_value.full_resistance() == 0.0 {
cell_value.set_full_resistance(full_resistance_of_capacitor(
cell_value.reactive_resist(),
values.source_resistance,
values.wire_resistance,
values.length,
));
}
if cell_value.signal_source_voltage() == 0.0 {
cell_value.set_signal_source_voltage(
voltage_from_signal_source(
values.source_voltage * 10f64.powi(-3),
@ -104,7 +95,6 @@ pub fn column_view_bind_factory(
cell_value.full_resistance(),
) * 1000.0,
);
}
match label {
"f, МГц" => {

View File

@ -16,7 +16,7 @@ pub enum HammingMode {
}
#[allow(dead_code)]
#[derive(Default, Copy, Clone, Debug)]
#[derive(Default, Copy, Clone, Debug, PartialEq)]
pub struct SignalReduce {
pub length: f64,
pub wire_resistance: f64,

View File

@ -124,18 +124,20 @@ pub fn signal_reducing_page(wrapper: &Box) {
result_table,
move |_| match parse_fields(all_inputs.clone()) {
Ok(results) => {
if values.get() == results {
info_bar.set_text_label(Some("Эти данные уже были введены."));
info_bar.show_infobar(5u64);
} else {
values.set(results);
let new_elem = Frequency::new(values.get().frequency);
let exist_elem_pos = find_by_frequency_value(&model, &new_elem);
if exist_elem_pos.is_some() {
info_bar.set_text_label(Some("Данная частота уже была задана."));
info_bar.show_infobar(5u64);
} else {
if exist_elem_pos.is_none() {
model.append(&new_elem);
update_column_view(&result_table)
}
update_column_view(&result_table);
}
}
Err(error) => {

View File

@ -1,2 +1,28 @@
@import url("info_bar.css");
@import url("text_view.css");
#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;
}
textview {
border-radius: 5px;
padding: 7px 8px;
background: #E6E6E6;
outline-offset: 2px;
outline: 2px solid #81ABDF00;
transition-duration: .15s;
transition-timing-function: ease-in-out;
}
textview:focus-within {
outline-offset: -2px;
outline: 2px solid #81ABDF;
}

View File

@ -1,15 +0,0 @@
#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;
}

View File

@ -1,8 +1,6 @@
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,
};
@ -10,7 +8,7 @@ use gtk::{
pub fn load_css() {
let style_provider = CssProvider::new();
style_provider.load_from_path(Path::new("./src/view/styles/base.css"));
style_provider.load_from_string(include_str!("base.css"));
style_context_add_provider_for_display(
&Display::default().expect("Could not connect to a display"),

View File

@ -1,14 +0,0 @@
textview {
border-radius: 5px;
padding: 7px 8px;
background: #E6E6E6;
outline-offset: 2px;
outline: 2px solid #81ABDF00;
transition-duration: .15s;
transition-timing-function: ease-in-out;
}
textview:focus-within {
outline-offset: -2px;
outline: 2px solid #81ABDF;
}

View File

@ -59,5 +59,5 @@ pub fn ui(application: &adw::Application) {
.child(&application_box)
.build();
window.show();
window.present();
}