Merge pull request #826 from luniiya/feat/theme-favorites

UI: favorite themes and appearance shortcuts
This commit is contained in:
Brandon Thomas
2026-10-12 03:23:06 -04:00
8 changed files with 176 additions and 7 deletions
+27 -1
View File
@@ -216,9 +216,35 @@ pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) {
};
let tip = tr_args("Appearance Mode: {}", &[&mode]);
let r = Rect::from_min_max(pos2(rx - 26.0, cy - 13.0), pos2(rx, cy + 13.0));
if widgets::icon_button(ui, r, icon, false, &t, egui::Id::new("hdr-appearance")).on_hover_text(&tip).clicked() {
let response = widgets::icon_button(ui, r, icon, false, &t, egui::Id::new("hdr-appearance")).on_hover_text(&tip);
if response.clicked() {
app.cycle_appearance(ui.ctx());
}
response.context_menu(|ui| {
let settings = ui.button(tr("Appearance Settings…"));
app.auto.add("header.appearanceSettings", settings.rect, "Appearance Settings…");
if settings.clicked() {
crate::panels::settings::open(app, "appearance");
ui.close();
}
let favorites = app.session.prefs.appearance.favorite_themes.clone();
for options in [effectcraft_engine::prefs::LIGHT_THEMES, effectcraft_engine::prefs::DARK_THEMES] {
let group: Vec<_> = options.iter().filter(|(_, id)| favorites.iter().any(|saved| saved == id)).collect();
if !group.is_empty() {
ui.separator();
}
for (label, id) in group {
let r = ui.selectable_label(app.ui.theme.name() == *id, tr(label));
app.auto.add(&format!("header.favoriteTheme.{id}"), r.rect, label);
if r.clicked() {
if let Some(kind) = crate::theme::ThemeKind::from_name(id) {
app.set_theme(ui.ctx(), kind);
}
ui.close();
}
}
}
});
app.auto.add("header.appearance", r, &tip);
rx = r.min.x - 4.0;
rx -= 10.0;
+12
View File
@@ -81,6 +81,9 @@ pub(crate) fn tr_args(text: &str, args: &[&dyn Display]) -> String {
/// Japanese: the same rows, in the same order, as the Chinese catalogs below (the tests keep the two in step).
const JAPANESE: &[(&str, &str)] = &[
("Appearance Settings…", "外観設定…"),
("Add to favorites", "お気に入りに追加"),
("Remove from favorites", "お気に入りから削除"),
(" OK ", " OK "),
(" Delete ", " 削除 "),
(" Open Auto-Save ", " 自動保存を開く "),
@@ -521,6 +524,9 @@ const JAPANESE: &[(&str, &str)] = &[
];
const SIMPLIFIED_CHINESE: &[(&str, &str)] = &[
("Appearance Settings…", "外观设置…"),
("Add to favorites", "添加到收藏"),
("Remove from favorites", "从收藏中移除"),
(" OK ", " 确定 "),
(" Delete ", " 删除 "),
(" Open Auto-Save ", " 打开自动保存 "),
@@ -1053,6 +1059,9 @@ const SIMPLIFIED_CHINESE: &[(&str, &str)] = &[
];
const TRADITIONAL_CHINESE: &[(&str, &str)] = &[
("Appearance Settings…", "外觀設定…"),
("Add to favorites", "加入最愛"),
("Remove from favorites", "從最愛移除"),
(" OK ", " 確定 "),
(" Delete ", " 刪除 "),
(" Open Auto-Save ", " 開啟自動儲存 "),
@@ -1582,6 +1591,9 @@ const TRADITIONAL_CHINESE: &[(&str, &str)] = &[
/// Ukrainian (uk): original translations of the same interface rows as the Chinese catalogs.
/// Technical names, key names and substituted project content keep their original spelling.
const UKRAINIAN: &[(&str, &str)] = &[
("Appearance Settings…", "Налаштування вигляду…"),
("Add to favorites", "Додати до вибраного"),
("Remove from favorites", "Видалити з вибраного"),
(" OK ", " Гаразд "),
(" Delete ", " Видалити "),
(" Open Auto-Save ", " Відкрити автозбереження "),
+13
View File
@@ -22,6 +22,7 @@ pub enum Icon {
Ellipse,
Polygon,
Star,
StarFilled,
Pen,
PenAdd,
PenDelete,
@@ -271,6 +272,18 @@ pub fn paint(painter: &Painter, rect: Rect, icon: Icon, color: Color32) {
let pts = pen.star(8.0, 8.6, 6.4, 2.7, 5);
pen.closed(&pts);
}
StarFilled => {
// Five triangles fill the concave star without a convex-polygon approximation.
let pts = pen.star(8.0, 8.6, 6.4, 2.7, 5);
for pair in pts.windows(2) {
if let [a, b] = pair {
pen.fill(&[(8.0, 8.6), *a, *b]);
}
}
if let (Some(first), Some(last)) = (pts.first(), pts.last()) {
pen.fill(&[(8.0, 8.6), *last, *first]);
}
}
Pen => {
pen.closed(&[(8.0, 1.8), (12.0, 9.0), (8.0, 14.0), (4.0, 9.0)]);
pen.dot(8.0, 8.6, 1.1);
+33 -5
View File
@@ -333,11 +333,39 @@ fn theme_card(
theme_preview(ui, kind, ui.available_width());
ui.add_space(4.0);
for (label, value) in options {
let r = ui.radio(cur == *value, tr(label));
reg(app, &format!("settings.{key}.{value}"), &r, label);
if r.clicked() && cur != *value {
acts.push(Act::Set(key.into(), json!(value)));
}
let row = egui::Rect::from_min_size(ui.cursor().min, vec2(ui.available_width(), 24.0));
let hovered = ui.ctx().pointer_hover_pos().is_some_and(|p| row.contains(p));
ui.horizontal(|ui| {
let r = ui.radio(cur == *value, tr(label));
reg(app, &format!("settings.{key}.{value}"), &r, label);
if r.clicked() && cur != *value {
acts.push(Act::Set(key.into(), json!(value)));
}
ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {
let mut favorites = app.session.prefs.appearance.favorite_themes.clone();
let favorite = favorites.iter().any(|id| id == value);
let tip = tr(if favorite { "Remove from favorites" } else { "Add to favorites" });
let r = ui.add_visible(favorite || hovered, egui::Button::new("").min_size(vec2(24.0, 24.0)).frame(false)).on_hover_text(tip);
r.widget_info(|| egui::WidgetInfo::labeled(egui::WidgetType::Button, true, format!("{}: {}", tip, tr(label))));
reg(app, &format!("settings.appearance.favoriteThemes.{value}"), &r, tip);
if favorite || hovered {
crate::icons::paint(
ui.painter(),
r.rect.shrink(4.0),
if favorite { crate::icons::Icon::StarFilled } else { crate::icons::Icon::Star },
if favorite { t.accent } else { t.text_dim },
);
}
if r.clicked() {
if favorite {
favorites.retain(|id| id != value);
} else {
favorites.push((*value).into());
}
acts.push(Act::Set("appearance.favoriteThemes".into(), json!(favorites)));
}
});
});
}
});
}