notedeck

One damus client to rule them all
git clone git://jb55.com/notedeck
Log | Files | Refs | README | LICENSE

commit 9b1f7680aac0d1fbdab203a28a951b89bfa48e9d
parent 54485843d06b1bb5a9ff7871a706cdb76ba8dbc1
Author: kernelkind <kernelkind@gmail.com>
Date:   Mon, 13 Oct 2025 19:43:06 -0400

refactor: move `galley_centered_pos` to notedeck_ui

Signed-off-by: kernelkind <kernelkind@gmail.com>

Diffstat:
Mcrates/notedeck_columns/src/ui/repost.rs | 15+++------------
Mcrates/notedeck_ui/src/lib.rs | 12+++++++++++-
2 files changed, 14 insertions(+), 13 deletions(-)

diff --git a/crates/notedeck_columns/src/ui/repost.rs b/crates/notedeck_columns/src/ui/repost.rs @@ -1,13 +1,12 @@ use std::f32::consts::PI; use egui::{ - epaint::PathShape, pos2, vec2, CornerRadius, Layout, Margin, Pos2, RichText, Sense, Shape, - Stroke, + epaint::PathShape, pos2, vec2, CornerRadius, Layout, Margin, RichText, Sense, Shape, Stroke, }; use egui_extras::StripBuilder; use enostr::NoteId; use notedeck::{fonts::get_font_size, NotedeckTextStyle}; -use notedeck_ui::app_images; +use notedeck_ui::{app_images, galley_centered_pos}; use crate::repost::RepostAction; @@ -91,7 +90,7 @@ impl<'a> RepostDecisionView<'a> { ); painter.galley( - galley_top_left_from_center(&galley, resp.rect.center()), + galley_centered_pos(&galley, resp.rect.center()), galley, ui.visuals().text_color(), ); @@ -107,14 +106,6 @@ impl<'a> RepostDecisionView<'a> { } } -fn galley_top_left_from_center(galley: &std::sync::Arc<egui::Galley>, center: Pos2) -> Pos2 { - let mut top_left = center; - top_left.x -= galley.rect.width() / 2.0; - top_left.y -= galley.rect.height() / 2.0; - - top_left -} - fn repost_item_text(text: &str) -> impl egui::Widget + use<'_> { move |ui: &mut egui::Ui| -> egui::Response { ui.add(egui::Label::new( diff --git a/crates/notedeck_ui/src/lib.rs b/crates/notedeck_ui/src/lib.rs @@ -20,7 +20,7 @@ pub use note::{NoteContents, NoteOptions, NoteView}; pub use profile::{ProfilePic, ProfilePreview}; pub use username::Username; -use egui::{Label, Margin, RichText}; +use egui::{Label, Margin, Pos2, RichText}; /// This is kind of like the Widget trait but is meant for larger top-level /// views that are typically stateful. @@ -93,3 +93,13 @@ pub fn input_rect(ui: &mut egui::Ui) -> Option<egui::Rect> { pub fn clear_input_rect(ui: &mut egui::Ui) { ui.data_mut(|d| d.remove::<egui::Rect>(egui::Id::new(INPUT_RECT_KEY))) } + +/// Center the galley on the center pos, returning the position of the top left position of the galley, +/// for the `painter.galley(..)` +pub fn galley_centered_pos(galley: &std::sync::Arc<egui::Galley>, center: Pos2) -> Pos2 { + let mut top_left = center; + top_left.x -= galley.rect.width() / 2.0; + top_left.y -= galley.rect.height() / 2.0; + + top_left +}