Skip to content

PhotoCraft: An open-source, photo editor written by scratch in pure Rust

feat(ui): derive transform anchor from pivot and add missing i18n catalogs

Ahmed Tammamfb99255513e7
diff --git a/crates/ui-egui/src/i18n/cs.tsv b/crates/ui-egui/src/i18n/cs.tsv
index f3fb8c8c4..5f906a3f5 100644
--- a/crates/ui-egui/src/i18n/cs.tsv
+++ b/crates/ui-egui/src/i18n/cs.tsv
@@ -3805,6 +3805,7 @@ navigator Zoom Zvětšení
{shortcut} is reserved by the system and can't be assigned. {shortcut} je vyhrazena systémem a nelze ji přiřadit.
Low-Latency Drawing (vsync off, applies at next launch) Kreslení s nízkou latencí (bez vertikální synchronizace, platí po dalším spuštění)
# Free Transform: a new layer while the box is open (#5859)
+ Reference point location Umístění referenčního bodu
Free Transform is still being applied; try again when it has finished. Volná transformace se stále použije; zkuste to znovu, až skončí.
The transform couldn't be applied. Transformaci nelze použít.
# Preferences › Performance › GPU Memory; the status bar and slow-redraw notice
diff --git a/crates/ui-egui/src/i18n/de.tsv b/crates/ui-egui/src/i18n/de.tsv
index 48ebfba67..e98111e9e 100644
--- a/crates/ui-egui/src/i18n/de.tsv
+++ b/crates/ui-egui/src/i18n/de.tsv
@@ -3199,6 +3199,7 @@ curves Smooth Glätten
{shortcut} is reserved by the system and can't be assigned. {shortcut} ist vom System reserviert und kann nicht zugewiesen werden.
Low-Latency Drawing (vsync off, applies at next launch) Zeichnen mit geringer Latenz (ohne VSync, gilt ab dem nächsten Start)
# Free Transform: a new layer while the box is open (#5859)
+ Reference point location Position des Referenzpunkts
Free Transform is still being applied; try again when it has finished. Frei transformieren wird noch angewendet; versuchen Sie es erneut, wenn es fertig ist.
The transform couldn't be applied. Die Transformation konnte nicht angewendet werden.
# Preferences › Performance › GPU Memory; the status bar and slow-redraw notice
diff --git a/crates/ui-egui/src/i18n/ko.tsv b/crates/ui-egui/src/i18n/ko.tsv
index 361cef2e9..a52eeb237 100644
--- a/crates/ui-egui/src/i18n/ko.tsv
+++ b/crates/ui-egui/src/i18n/ko.tsv
@@ -3375,6 +3375,7 @@ curves Smooth 매끄럽게
{shortcut} is reserved by the system and can't be assigned. {shortcut}은(는) 시스템에서 예약되어 할당할 수 없습니다.
Low-Latency Drawing (vsync off, applies at next launch) 저지연 그리기(수직 동기화 끔, 다음 실행 시 적용)
# Free Transform: a new layer while the box is open (#5859)
+ Reference point location 기준점 위치
Free Transform is still being applied; try again when it has finished. 자유 변형을 아직 적용하는 중입니다. 완료된 후 다시 시도하세요.
The transform couldn't be applied. 변형을 적용할 수 없습니다.
# Preferences › Performance › GPU Memory; the status bar and slow-redraw notice
diff --git a/crates/ui-egui/src/i18n/vi.tsv b/crates/ui-egui/src/i18n/vi.tsv
index e2e55ab1b..bbb083f81 100644
--- a/crates/ui-egui/src/i18n/vi.tsv
+++ b/crates/ui-egui/src/i18n/vi.tsv
@@ -3683,6 +3683,7 @@ curves Smooth Làm mượt
{shortcut} is reserved by the system and can't be assigned. {shortcut} được hệ thống dành riêng và không thể gán.
Low-Latency Drawing (vsync off, applies at next launch) Vẽ độ trễ thấp (tắt vsync, áp dụng ở lần khởi động sau)
# Free Transform: a new layer while the box is open (#5859)
+ Reference point location Vị trí điểm tham chiếu
Free Transform is still being applied; try again when it has finished. Biến đổi tự do vẫn đang được áp dụng; hãy thử lại khi hoàn tất.
The transform couldn't be applied. Không thể áp dụng phép biến đổi.
# Preferences › Performance › GPU Memory; the status bar and slow-redraw notice
diff --git a/crates/ui-egui/src/i18n/zh-hans.tsv b/crates/ui-egui/src/i18n/zh-hans.tsv
index eebeabaa6..4352a5ffc 100644
--- a/crates/ui-egui/src/i18n/zh-hans.tsv
+++ b/crates/ui-egui/src/i18n/zh-hans.tsv
@@ -2813,6 +2813,7 @@ curves Smooth 平滑
{shortcut} is reserved by the system and can't be assigned. {shortcut} 由系统保留,无法指定。
Low-Latency Drawing (vsync off, applies at next launch) 低延迟绘画(关闭垂直同步,下次启动时生效)
# Free Transform: a new layer while the box is open (#5859)
+ Reference point location 参考点位置
Free Transform is still being applied; try again when it has finished. 自由变换仍在应用中;请在完成后重试。
The transform couldn't be applied. 无法应用变换。
# Preferences › Performance › GPU Memory; the status bar and slow-redraw notice
diff --git a/crates/ui-egui/src/i18n/zh-hant.tsv b/crates/ui-egui/src/i18n/zh-hant.tsv
index b35556b6f..6c951d09c 100644
--- a/crates/ui-egui/src/i18n/zh-hant.tsv
+++ b/crates/ui-egui/src/i18n/zh-hant.tsv
@@ -2798,6 +2798,7 @@ curves Smooth 平滑
{shortcut} is reserved by the system and can't be assigned. {shortcut} 由系統保留,無法指定。
Low-Latency Drawing (vsync off, applies at next launch) 低延遲繪圖(關閉垂直同步,下次啟動時生效)
# Free Transform: a new layer while the box is open (#5859)
+ Reference point location 參考點位置
Free Transform is still being applied; try again when it has finished. 任意變形仍在套用中;請在完成後再試一次。
The transform couldn't be applied. 無法套用變形。
# Preferences › Performance › GPU Memory; the status bar and slow-redraw notice
diff --git a/crates/ui-egui/src/transform_tool.rs b/crates/ui-egui/src/transform_tool.rs
index 03c8fc6a6..0be1f59f5 100644
--- a/crates/ui-egui/src/transform_tool.rs
+++ b/crates/ui-egui/src/transform_tool.rs
@@ -2846,7 +2846,14 @@ fn transform_fields(app: &mut PhotocraftApp, ui: &mut egui::Ui, t: &TransformSes
}
}
-fn anchor_grid_widget(ui: &mut egui::Ui, current_anchor: usize) -> Option<usize> {
+fn matching_anchor(quad: [[f64; 2]; 4], pivot: [f64; 2]) -> Option<usize> {
+ (0..9).find(|&i| {
+ let p = point_on_quad(quad, i);
+ (p[0] - pivot[0]).abs() <= 0.05 && (p[1] - pivot[1]).abs() <= 0.05
+ })
+}
+
+fn anchor_grid_widget(ui: &mut egui::Ui, current_anchor: Option<usize>) -> Option<usize> {
let size = egui::vec2(16.0, 16.0);
let (rect, resp) = ui.allocate_exact_size(size, egui::Sense::click());
let tk = crate::theme::Tokens::get(ui.ctx());
@@ -2863,7 +2870,7 @@ fn anchor_grid_widget(ui: &mut egui::Ui, current_anchor: usize) -> Option<usize>
if resp.clicked() && pointer.is_some_and(|p| (p.x - cx).abs() <= 3.0 && (p.y - cy).abs() <= 3.0) {
clicked = Some(idx);
}
- if idx == current_anchor {
+ if current_anchor == Some(idx) {
painter.rect_filled(pt_rect, 0.5, tk.accent);
} else {
painter.rect_filled(pt_rect, 0.5, tk.text_dim);
@@ -2881,17 +2888,18 @@ pub(crate) fn position_size_fields(app: &mut PhotocraftApp, ui: &mut egui::Ui, t
let lbl = |ui: &mut egui::Ui, s: &str| {
ui.label(egui::RichText::new(s).color(tk.text_dim).size(12.0));
};
- let anchor_id = egui::Id::new("transform-anchor");
- let current_anchor: usize = ui.data(|d| d.get_temp(anchor_id)).unwrap_or(4);
+ let current_anchor = matching_anchor(t.quad, t.pivot);
+ let mut pivot = t.pivot;
if let Some(new_anchor) = anchor_grid_widget(ui, current_anchor) {
- ui.data_mut(|d| d.insert_temp(anchor_id, new_anchor));
+ let new_p = point_on_quad(t.quad, new_anchor);
if let Some(s) = app.ui.transform.as_mut() {
- s.pivot = point_on_quad(s.quad, new_anchor);
+ s.pivot = new_p;
}
+ pivot = new_p;
}
ui.add_space(4.0);
- let mut px = t.pivot[0] as f32;
- let mut py = t.pivot[1] as f32;
+ let mut px = pivot[0] as f32;
+ let mut py = pivot[1] as f32;
lbl(ui, "X:");
let rx = crate::widgets::value_field(ui, &mut px, -POSITION_LIMIT_PX..=POSITION_LIMIT_PX, "px", 72.0);
lbl(ui, "Y:");
@@ -5433,5 +5441,11 @@ mod tests {
assert_eq!(p_top_right, [200.0, 0.0]);
let p_center = carry_pivot(quad, quad_scaled, [50.0, 25.0]);
assert_eq!(p_center, [100.0, 50.0]);
+
+ for anchor in 0..9 {
+ assert_eq!(matching_anchor(quad, point_on_quad(quad, anchor)), Some(anchor));
+ }
+ assert_eq!(matching_anchor(quad, [12.3, 45.6]), None);
+ assert_eq!(matching_anchor(quad, [50.0, 30.0]), None);
}
}