Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/tsukinaha/tsukimi into feat…
Browse files Browse the repository at this point in the history
…ure/win
  • Loading branch information
Kosette committed May 16, 2024
2 parents e4116f7 + d915f97 commit f832bca
Show file tree
Hide file tree
Showing 8 changed files with 138 additions and 3 deletions.
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
## 0.4.13-1

- 增加首页每日推荐开关
- 增加字体显示设置

> [!NOTE]
> 如果你使用的字体包含的字符集不完整,将可能会出现缺字等显示异常
- Add a switch for daily recommendations on the homepage
- Add font display settings

> [!NOTE]
> If the font you are using has an incomplete character set, there may be missing characters or other display abnormalities.
## 0.4.13

### Added
Expand Down
8 changes: 8 additions & 0 deletions moe.tsuna.tsukimi.gschema.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@
<default>true</default>
<summary>Default switch state</summary>
</key>
<key name="is-daily-recommend" type="b">
<default>true</default>
<summary>Default switch state</summary>
</key>
<key name="theme" type="s">
<default>"Adwaita"</default>
<summary>Default switch state</summary>
Expand Down Expand Up @@ -77,6 +81,10 @@
<default>""</default>
<summary>Default switch state</summary>
</key>
<key name="font-name" type="s">
<default>""</default>
<summary>Default switch state</summary>
</key>
<key name="is-auto-select-server" type="b">
<default>false</default>
<summary>Default switch state</summary>
Expand Down
2 changes: 1 addition & 1 deletion resources/ui/home.ui
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<property name="orientation">vertical</property>
<property name="spacing">9</property>
<child>
<object class="GtkOverlay">
<object class="GtkOverlay" id="carouseloverlay">
<property name="halign">fill</property>
<property name="height-request">500</property>
<property name="valign">start</property>
Expand Down
33 changes: 33 additions & 0 deletions resources/ui/settings.ui
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@
<property name="title" translatable="yes">Auto Select Last Server</property>
</object>
</child>
<child>
<object class="AdwSwitchRow" id="dailyrecommendcontrol">
<property name="title" translatable="yes">Daily Recommend</property>
</object>
</child>
<child>
<object class="AdwSpinRow" id="fontspinrow">
<property name="title" translatable="yes">Font Scale</property>
Expand Down Expand Up @@ -220,6 +225,34 @@
</child>
</object>
</child>
<child>
<object class="AdwActionRow">
<property name="title" translatable="yes">Font Family</property>
<child type="suffix">
<object class="GtkFontDialogButton" id="font">
<property name="level">family</property>
<property name="valign">center</property>
<property name="dialog">
<object class="GtkFontDialog"/>
</property>
<style>
<class name="flat" />
</style>
</object>
</child>
<child type="suffix">
<object class="GtkButton">
<property name="icon-name" translatable="yes">user-trash-symbolic</property>
<property name="valign">center</property>
<property name="action-name">setting.fontclear</property>
<property name="tooltip-text" translatable="yes">Restart App To Take Effect</property>
<style>
<class name="flat" />
</style>
</object>
</child>
</object>
</child>
<child>
<object class="AdwComboRow" id="themecontrol">
<property name="title" translatable="yes">Theme</property>
Expand Down
18 changes: 18 additions & 0 deletions src/ui/models/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,24 @@ impl Settings {
const KEY_PREFERRED_SERVER: &'static str = "preferred-server";
const KEY_IS_AUTO_SELECT_SERVER: &'static str = "is-auto-select-server";
const KEY_FONT_SIZE: &'static str = "font-size";
const KEY_FONT_NAME: &'static str = "font-name";
const KEY_DAILY_RECOMMEND: &'static str = "is-daily-recommend";

pub fn set_daily_recommend(&self, daily_recommend: bool) -> Result<(), glib::BoolError> {
self.set_boolean(Self::KEY_DAILY_RECOMMEND, daily_recommend)
}

pub fn daily_recommend(&self) -> bool {
self.boolean(Self::KEY_DAILY_RECOMMEND)
}

pub fn set_font_name(&self, font_name: &str) -> Result<(), glib::BoolError> {
self.set_string(Self::KEY_FONT_NAME, font_name)
}

pub fn font_name(&self) -> String {
self.string(Self::KEY_FONT_NAME).to_string()
}

pub fn set_font_size(&self, font_size: i32) -> Result<(), glib::BoolError> {
self.set_int(Self::KEY_FONT_SIZE, font_size)
Expand Down
8 changes: 8 additions & 0 deletions src/ui/widgets/home.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use super::tu_list_item::TuListItem;
use super::{fix::ScrolledWindowFixExt, list::ListPage, window::Window};
use crate::client::{network::*, structs::*};
use crate::ui::image::set_image;
use crate::ui::models::SETTINGS;
use crate::ui::provider::tu_item::TuItem;
use crate::ui::widgets::tu_list_item::tu_list_item_register;
use crate::utils::{
Expand Down Expand Up @@ -56,6 +57,8 @@ mod imp {
#[template_child]
pub carousel: TemplateChild<adw::Carousel>,
pub carouset_items: RefCell<Vec<SimpleListItem>>,
#[template_child]
pub carouseloverlay: TemplateChild<gtk::Overlay>,
pub selection: gtk::SingleSelection,
pub hisselection: gtk::SingleSelection,
}
Expand Down Expand Up @@ -178,6 +181,11 @@ impl HomePage {
}

pub async fn set_carousel(&self) {
if !SETTINGS.daily_recommend() {
self.imp().carouseloverlay.set_visible(false);
return;
}

let date = Local::now();
let formatted_date = format!("{:04}{:02}{:02}", date.year(), date.month(), date.day());
let results =
Expand Down
48 changes: 47 additions & 1 deletion src/ui/widgets/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ use adw::prelude::*;
use glib::Object;
use gtk::{gio, glib, subclass::prelude::*};

use crate::ui::models::{emby_cache_path, SETTINGS};
use crate::{
toast,
ui::models::{emby_cache_path, SETTINGS},
};

use super::window::Window;

Expand Down Expand Up @@ -50,6 +53,10 @@ mod imp {
pub toast: TemplateChild<adw::ToastOverlay>,
#[template_child]
pub fontspinrow: TemplateChild<adw::SpinRow>,
#[template_child]
pub font: TemplateChild<gtk::FontDialogButton>,
#[template_child]
pub dailyrecommendcontrol: TemplateChild<adw::SwitchRow>,
}

// The central trait for subclassing a GObject
Expand Down Expand Up @@ -85,6 +92,13 @@ mod imp {
set.clearpic();
},
);
klass.install_action(
"setting.fontclear",
None,
move |set, _action, _parameter| {
set.clear_font();
},
);
}

fn instance_init(obj: &InitializingObject<Self>) {
Expand Down Expand Up @@ -113,6 +127,8 @@ mod imp {
obj.change_picblur();
obj.set_auto_select_server();
obj.set_fontsize();
obj.set_font();
obj.set_daily_recommend();
}));
}
}
Expand Down Expand Up @@ -367,4 +383,34 @@ impl SettingsPage {
}));
SETTINGS.set_root_pic("").unwrap();
}

pub fn set_font(&self) {
let imp = self.imp();
let settings = self.settings();
imp.font
.set_font_desc(&gtk::pango::FontDescription::from_string(
&SETTINGS.font_name(),
));
imp.font.connect_font_desc_notify(move |font| {
let font_desc = font.font_desc().unwrap();
let font_string = gtk::pango::FontDescription::to_string(&font_desc);
settings.set_gtk_font_name(Some(&font_string));
SETTINGS.set_font_name(&font_string).unwrap();
});
}

pub fn clear_font(&self) {
SETTINGS.set_font_name("").unwrap();
toast!(self, "Font Cleared, Restart to take effect.");
}

pub fn set_daily_recommend(&self) {
let imp = self.imp();
imp.dailyrecommendcontrol
.set_active(SETTINGS.daily_recommend());
imp.dailyrecommendcontrol
.connect_active_notify(move |control| {
SETTINGS.set_daily_recommend(control.is_active()).unwrap();
});
}
}
10 changes: 9 additions & 1 deletion src/ui/widgets/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ mod imp {
// Call "constructed" on parent
self.parent_constructed();
let obj = self.obj();

obj.set_fonts();
if crate::ui::models::SETTINGS.font_size() != -1 {
let settings = gtk::Settings::default().unwrap();
settings.set_property(
Expand Down Expand Up @@ -474,7 +476,6 @@ impl Window {
.set_child(Some(&crate::ui::widgets::search::SearchPage::new()));
imp.navipage.set_title("Search");
self.set_pop_visibility(false);
self.set_fraction(1.0);
}

fn historypage(&self) {
Expand Down Expand Up @@ -653,4 +654,11 @@ impl Window {
let imp = self.imp();
imp.progressbar.set_fraction(fraction);
}

pub fn set_fonts(&self) {
if !SETTINGS.font_name().is_empty() {
let settings = self.imp().stack.settings();
settings.set_gtk_font_name(Some(&SETTINGS.font_name()));
}
}
}

0 comments on commit f832bca

Please sign in to comment.