Compare commits

..

No commits in common. "cc4ba6168f229576406485df907a2e7e8efac319" and "2399903cda6b3a9cd431eb4c1732a9c643181db4" have entirely different histories.

11 changed files with 44 additions and 151 deletions

22
Cargo.lock generated
View File

@ -2,17 +2,6 @@
# It is not intended for manual editing. # It is not intended for manual editing.
version = 3 version = 3
[[package]]
name = "AIT"
version = "0.1.0"
dependencies = [
"bitvec",
"gio",
"gtk4",
"libadwaita",
"tokio",
]
[[package]] [[package]]
name = "addr2line" name = "addr2line"
version = "0.21.0" version = "0.21.0"
@ -476,6 +465,17 @@ dependencies = [
"hashbrown", "hashbrown",
] ]
[[package]]
name = "laboratory_works"
version = "0.1.0"
dependencies = [
"bitvec",
"gio",
"gtk4",
"libadwaita",
"tokio",
]
[[package]] [[package]]
name = "libadwaita" name = "libadwaita"
version = "0.7.0" version = "0.7.0"

View File

@ -1,5 +1,5 @@
[package] [package]
name = "AIT" name = "laboratory_works"
version = "0.1.0" version = "0.1.0"
edition = "2021" edition = "2021"

View File

@ -14,7 +14,7 @@ use view::ui::*;
#[tokio::main] #[tokio::main]
async fn main() { async fn main() {
let app: adw::Application = adw::Application::builder() let app: adw::Application = adw::Application::builder()
.application_id("org.gtk-rs.AIT") .application_id("com.laboratory-work")
.build(); .build();
app.connect_activate(ui); app.connect_activate(ui);

View File

@ -1,19 +0,0 @@
use gio::{glib::Variant, SimpleAction};
use gtk4 as gtk;
use gtk::{prelude::GtkWindowExt, AboutDialog, Image};
use std::path::Path;
pub fn open_about_dialogue(_action: &SimpleAction, _var: Option<&Variant>) {
let logo = Image::from_file(Path::new("./src/view/resources/logo.png"))
.paintable()
.unwrap();
AboutDialog::builder()
.authors(vec!["Сагиев А.Д.", "Ефимов И.П."])
.version("1.0-beta")
.logo(&logo)
.website("https://gitea.doryan04.ru/doryan/AIT")
.build()
.present();
}

View File

@ -1,81 +0,0 @@
use std::fmt::{Debug, Display};
use gtk4 as gtk;
use gio::{
glib::Variant, prelude::ActionMapExtManual, ActionEntry, Menu, SimpleAction, SimpleActionGroup,
};
use gtk::{MenuButton, PopoverMenu};
pub struct HeaderMenu<T> {
model: Menu,
actions_group: (SimpleActionGroup, Option<T>),
button: MenuButton,
}
impl<T> HeaderMenu<T>
where
T: Into<String> + Debug + Display + Clone,
{
pub fn new() -> Self {
let menu_btn = MenuButton::builder().icon_name("open-menu").build();
let menu_model = Menu::new();
let menu_popover = PopoverMenu::from_model(Some(&menu_model));
menu_btn.set_popover(Some(&menu_popover));
let action_group = SimpleActionGroup::new();
Self {
model: menu_model,
actions_group: (action_group, None),
button: menu_btn,
}
}
#[inline]
pub fn set_action_group_name(&mut self, name: Option<T>) {
self.actions_group.1 = name;
}
#[inline]
pub fn get_button(&self) -> &MenuButton {
&self.button
}
#[inline]
pub fn get_model(&self) -> &Menu {
&self.model
}
#[inline]
pub fn get_actions_group(&self) -> &SimpleActionGroup {
&self.actions_group.0
}
pub fn append_items<Iterable, F>(&self, items: Iterable)
where
Iterable: IntoIterator<Item = (F, &'static str, &'static str)>,
F: Fn(&SimpleAction, Option<&Variant>) + 'static,
{
for (callback, action_name, action_label) in items {
let action = ActionEntry::<SimpleActionGroup>::builder(action_name)
.activate(move |_, a, b| callback(a, b))
.build();
let action_path = &*format!(
"{}.{}",
self.actions_group
.1
.clone()
.expect("ActionGroupName isn't defined"),
action_name
);
self.actions_group.0.add_action_entries([action]);
self.model.append(Some(action_label), Some(action_path));
}
}
}

View File

@ -1,8 +1,7 @@
pub mod about;
pub mod info_bar; pub mod info_bar;
pub mod input; pub mod input;
pub mod menu;
pub mod pages; pub mod pages;
pub mod tabs; pub mod tabs;
pub mod wrapper;
use crate::model::builder_traits; use crate::model::builder_traits;

View File

@ -0,0 +1,18 @@
use gtk4 as gtk;
use gtk::{Orientation, builders::BoxBuilder, Box};
#[allow(dead_code)]
pub struct Wrapper;
impl Wrapper{
pub fn row_builder() -> BoxBuilder {
Box::builder().orientation(Orientation::Vertical)
}
pub fn col_builder() -> BoxBuilder {
Box::builder().orientation(Orientation::Horizontal)
}
}

View File

@ -3,7 +3,7 @@ use gtk4 as gtk;
use crate::{ use crate::{
model::builder_traits::Product, model::builder_traits::Product,
view::{ view::{
components::{info_bar::InfoBar, input::Input}, components::{info_bar::InfoBar, input::Input, wrapper::*},
properties::*, properties::*,
}, },
view_utils::{hamming_code_utils::start_hamming_algorithm, input_utils::clearing}, view_utils::{hamming_code_utils::start_hamming_algorithm, input_utils::clearing},
@ -47,15 +47,13 @@ pub fn hamming_code_page(wrapper: &Box) {
let crypt_mode_label = Label::builder().label("Режим: кодирование").build(); let crypt_mode_label = Label::builder().label("Режим: кодирование").build();
let crypt_mode_wrapper = Box::builder() let crypt_mode_wrapper = Wrapper::col_builder()
.orientation(Orientation::Horizontal)
.set_align(Alignment::new(Align::Fill, Align::Center)) .set_align(Alignment::new(Align::Fill, Align::Center))
.hexpand(true) .hexpand(true)
.spacing(10) .spacing(10)
.build(); .build();
let action_components_wrapper = Box::builder() let action_components_wrapper = Wrapper::col_builder()
.orientation(Orientation::Horizontal)
.set_align(Alignment::new(Align::Fill, Align::Fill)) .set_align(Alignment::new(Align::Fill, Align::Fill))
.set_margin(MarginData::MultipleMargin((0, 5, 0, 5))) .set_margin(MarginData::MultipleMargin((0, 5, 0, 5)))
.spacing(10) .spacing(10)

View File

@ -132,10 +132,11 @@ pub fn signal_reducing_page(wrapper: &Box) {
let new_elem = Frequency::new(values.get().frequency); let new_elem = Frequency::new(values.get().frequency);
if find_by_frequency_value(&model, &new_elem).is_none() { let exist_elem_pos = find_by_frequency_value(&model, &new_elem);
if exist_elem_pos.is_none() {
model.append(&new_elem); model.append(&new_elem);
} }
update_column_view(&result_table); update_column_view(&result_table);
} }
} }

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.9 KiB

View File

@ -1,12 +1,13 @@
use crate::model::builder_traits::*; use crate::model::builder_traits::*;
use adw::HeaderBar;
use gtk4 as gtk; use gtk4 as gtk;
use gtk::{prelude::*, StackTransitionType::SlideLeftRight, *}; use gtk::{prelude::*, StackTransitionType::SlideLeftRight, *};
use info_bar::InfoBar;
#[allow(unused)]
use crate::view::{ use crate::view::{
components::{about::open_about_dialogue, info_bar::InfoBar, menu::HeaderMenu, pages::Pages}, components::{pages::Pages, wrapper::*, *},
pages::*, pages::*,
properties::*, properties::*,
}; };
@ -16,8 +17,7 @@ use super::styles::load_css;
pub fn ui(application: &adw::Application) { pub fn ui(application: &adw::Application) {
load_css(); load_css();
let hamming_code = Box::builder() let hamming_code = Wrapper::row_builder()
.orientation(Orientation::Vertical)
.set_align(Alignment::new(Align::Fill, Align::Fill)) .set_align(Alignment::new(Align::Fill, Align::Fill))
.set_margin(MarginData::EqualsMargin(15)) .set_margin(MarginData::EqualsMargin(15))
.spacing(10) .spacing(10)
@ -30,8 +30,7 @@ pub fn ui(application: &adw::Application) {
hamming_code::hamming_code_page(&hamming_code); hamming_code::hamming_code_page(&hamming_code);
let signal_reducing = Box::builder() let signal_reducing = Wrapper::row_builder()
.orientation(Orientation::Vertical)
.set_align(Alignment::new(Align::Fill, Align::Fill)) .set_align(Alignment::new(Align::Fill, Align::Fill))
.set_margin(MarginData::EqualsMargin(15)) .set_margin(MarginData::EqualsMargin(15))
.spacing(10) .spacing(10)
@ -52,35 +51,13 @@ pub fn ui(application: &adw::Application) {
application_box.append(info_bar.get()); application_box.append(info_bar.get());
application_box.append(pages.get()); application_box.append(pages.get());
let title_bar = Box::new(Orientation::Horizontal, 0);
let mut menu_button = HeaderMenu::<&str>::new();
menu_button.set_action_group_name(Some("menu_group_action"));
menu_button.append_items([(open_about_dialogue, "about_software", "О программе")]);
title_bar.append(
&Label::builder()
.css_name("title")
.set_align(Alignment::new(Align::Center, Align::Center))
.hexpand(true)
.vexpand(true)
.label("Комплексная программа для лаб. работ")
.build(),
);
title_bar.append(menu_button.get_button());
let header_bar = HeaderBar::builder().title_widget(&title_bar).build();
let window = ApplicationWindow::builder() let window = ApplicationWindow::builder()
.title("Комплексная программа для лаб. работ")
.width_request(800) .width_request(800)
.height_request(600) .height_request(600)
.application(application) .application(application)
.titlebar(&header_bar)
.child(&application_box) .child(&application_box)
.build(); .build();
window.insert_action_group("menu_group_action", Some(menu_button.get_actions_group()));
window.present(); window.present();
} }