mirror of
https://github.com/aljazceru/notedeck.git
synced 2026-02-23 01:14:20 +01:00
refactor: move galley_centered_pos to notedeck_ui
Signed-off-by: kernelkind <kernelkind@gmail.com>
This commit is contained in:
@@ -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(
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user