This commit is contained in:
Tsuki 2024-02-21 20:49:17 +08:00
parent 9b1491cebb
commit 749326a502
9 changed files with 1662 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
/target

8
.idea/.gitignore generated vendored Normal file
View File

@ -0,0 +1,8 @@
# Default ignored files
/shelf/
/workspace.xml
# Editor-based HTTP Client requests
/httpRequests/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml

8
.idea/modules.xml generated Normal file
View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/rsproject.iml" filepath="$PROJECT_DIR$/.idea/rsproject.iml" />
</modules>
</component>
</project>

11
.idea/rsproject.iml generated Normal file
View File

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="EMPTY_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
<excludeFolder url="file://$MODULE_DIR$/target" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

6
.idea/vcs.xml generated Normal file
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="" vcs="Git" />
</component>
</project>

1505
Cargo.lock generated Normal file

File diff suppressed because it is too large Load Diff

14
Cargo.toml Normal file
View File

@ -0,0 +1,14 @@
[package]
name = "rsproject"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
gtk = { version = "0.6.6", package = "gtk4", features = ["v4_8"] }
adw = { version = "0.4.3", package = "libadwaita", features = ["v1_4"]}
relm4 = { version = "0.6.2", features = ["libadwaita"]}
relm4-icons = { version = "0.6.0", features = ["add-filled"] }
chrono = "0.4.34"
tracker = "0.2.1"

View File

@ -0,0 +1,75 @@
use std::rc::Rc;
use adw::prelude::*;
use gtk::prelude::*;
use gtk::{StringList, Widget};
use relm4::{factory::FactoryView, gtk, prelude::*, FactorySender};
#[derive(Debug)]
pub enum Msg {}
#[derive(Debug)]
pub enum OutputMsg {}
pub enum SettingType {
Select(Vec<String>),
Action,
Entry(Option<String>, Option<Box<dyn Fn(&str) -> bool>>),
Switch(bool),
Spin((f64, f64,f64,f64))
}
pub struct SettingItem {
title: String,
pub _type: SettingType,
}
impl SettingItem {
pub fn new(title: String, _type: SettingType) -> Self {
Self { title, _type }
}
pub fn to_widget(&mut self) -> impl IsA<Widget>{
(match &mut self._type {
SettingType::Select(selects) => {
let w = adw::ComboRow::builder().title(&self.title).build();
let model = StringList::new(selects.iter().map(|s| s.as_str()).collect::<Vec<_>>().as_ref());
w.set_model(Some(&model));
w.upcast::<Widget>()
}
SettingType::Action => {
adw::EntryRow::builder().title(&self.title).build().upcast::<Widget>()
}
SettingType::Entry(text, f) => {
let w = adw::EntryRow::new();
w.set_title(&self.title);
let f = f.take();
if let Some(f) = f{
println!("test");
w.connect_text_notify(move |s|{
let text =s.text();
if !f(&text) {
s.set_text("");
}
});
}
if let Some(text) = text {
w.set_text(text);
}
w.upcast::<Widget>()
}
SettingType::Switch(t) => {
let w = adw::SwitchRow::new();
w.set_title(&self.title);
w.set_active(*t);
w.upcast::<Widget>()
}
SettingType::Spin((min, max,clamb, value)) => {
let w = adw::SpinRow::new(Some(gtk::Adjustment::), *clamb,0);
w.set_numeric(true);
// w.set_range(*min, *max);
w.set_value(*value);
w.set_title(&self.title);
w.upcast::<Widget>()
}
})
}
}

34
src/main.rs Normal file
View File

@ -0,0 +1,34 @@
#![allow(unused)]
#![allow(dead_code)]
use gtk::{
gio::{self, Settings},
prelude::SettingsExt,
};
use std::{ptr, sync::Mutex};
mod components;
mod config;
use components::AppModel;
const APP_ID: &str = "org.tsuki.radar_g";
fn main() {
// Load GL pointers from epoxy (GL context management library used by GTK).
let relm = relm4::RelmApp::new(APP_ID);
relm.run::<AppModel>(());
// initialize_custom_css();
}
// fn initialize_custom_css() {
// gio::resources_register_include!("css.gresource").unwrap();
// // Load the CSS file and add it to the provider
// let provider = gtk::CssProvider::new();
// // provider.load_from_string();
// provider.load_from_resource("/org/tsuki/radar_g/css/main.css");
// use gtk::gdk::Display;
// // Add the provider to the default screen
// gtk::style_context_add_provider_for_display(
// &Display::default().expect("Could not connect to a display."),
// &provider,
// gtk::STYLE_PROVIDER_PRIORITY_APPLICATION,
// );
// }