Compare commits

...

7 Commits

9 changed files with 68 additions and 81 deletions

View File

@ -8,7 +8,7 @@ edition = "2021"
[dependencies] [dependencies]
adw = { version = "0.7.0", package = "libadwaita", features = ["v1_4"] } adw = { version = "0.7.0", package = "libadwaita", features = ["v1_4"] }
bitvec = "1.0.1" bitvec = "1.0.1"
gio = {version = "0.20.0", features = ["v2_74"]} 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"] } 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 gtk4 as gtk;
use std::str::FromStr; use std::str::FromStr;
@ -9,7 +10,7 @@ use crate::{
}; };
use gtk::{ use gtk::{
prelude::{Cast, CastNone, EditableExt, ListItemExt, ObjectExt, WidgetExt}, prelude::{Cast, CastNone, EditableExt, ListItemExt, WidgetExt},
ColumnView, Entry, Label, ListItem, SignalListItemFactory, ColumnView, Entry, Label, ListItem, SignalListItemFactory,
}; };
@ -42,12 +43,12 @@ pub fn parse_fields(all_inputs: Vec<Input<Entry>>) -> Result<SignalReduce> {
#[inline] #[inline]
pub fn update_column_view(column_view: &ColumnView) { pub fn update_column_view(column_view: &ColumnView) {
column_view.hide(); column_view.set_visible(false);
column_view.show(); column_view.set_visible(true);
} }
#[inline] #[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 list_item
.downcast_ref::<ListItem>() .downcast_ref::<ListItem>()
.expect("Needs to be 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( pub fn column_view_bind_factory(
_factory: &SignalListItemFactory, _factory: &SignalListItemFactory,
list_item: &ListItem, list_item: &Object,
values: SignalReduce, values: SignalReduce,
label: &str, label: &str,
) { ) {
@ -74,29 +75,19 @@ pub fn column_view_bind_factory(
.and_downcast::<Label>() .and_downcast::<Label>()
.expect("The child has to be a `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( cell_value.set_reactive_resist(reactive_resistance_of_capacitor(
values.wire_capacity * 10f64.powi(-12), values.wire_capacity * 10f64.powi(-12),
values.length, values.length,
cell_value.frequency() * 10f64.powi(6), cell_value.frequency() * 10f64.powi(6),
)); ));
}
if cell_value.full_resistance() == 0.0 {
cell_value.set_full_resistance(full_resistance_of_capacitor( cell_value.set_full_resistance(full_resistance_of_capacitor(
cell_value.reactive_resist(), cell_value.reactive_resist(),
values.source_resistance, values.source_resistance,
values.wire_resistance, values.wire_resistance,
values.length, values.length,
)); ));
}
if cell_value.signal_source_voltage() == 0.0 {
cell_value.set_signal_source_voltage( cell_value.set_signal_source_voltage(
voltage_from_signal_source( voltage_from_signal_source(
values.source_voltage * 10f64.powi(-3), values.source_voltage * 10f64.powi(-3),
@ -104,7 +95,6 @@ pub fn column_view_bind_factory(
cell_value.full_resistance(), cell_value.full_resistance(),
) * 1000.0, ) * 1000.0,
); );
}
match label { match label {
"f, МГц" => { "f, МГц" => {

View File

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

View File

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

View File

@ -1,2 +1,28 @@
@import url("info_bar.css"); #info_bar{
@import url("text_view.css"); 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 adw::gdk::Display;
use gtk4 as gtk; use gtk4 as gtk;
use std::path::Path;
use gtk::{ use gtk::{
style_context_add_provider_for_display, CssProvider, STYLE_PROVIDER_PRIORITY_APPLICATION, style_context_add_provider_for_display, CssProvider, STYLE_PROVIDER_PRIORITY_APPLICATION,
}; };
@ -10,7 +8,7 @@ use gtk::{
pub fn load_css() { pub fn load_css() {
let style_provider = CssProvider::new(); 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( style_context_add_provider_for_display(
&Display::default().expect("Could not connect to a 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) .child(&application_box)
.build(); .build();
window.show(); window.present();
} }