fix note context menu placement inside rect
Signed-off-by: kernelkind <kernelkind@gmail.com>
This commit is contained in:
@@ -310,36 +310,19 @@ impl<'a> NoteView<'a> {
|
|||||||
note_cache: &mut NoteCache,
|
note_cache: &mut NoteCache,
|
||||||
note: &Note,
|
note: &Note,
|
||||||
profile: &Result<nostrdb::ProfileRecord<'_>, nostrdb::Error>,
|
profile: &Result<nostrdb::ProfileRecord<'_>, nostrdb::Error>,
|
||||||
options: NoteOptions,
|
) {
|
||||||
container_right: Pos2,
|
|
||||||
) -> NoteResponse {
|
|
||||||
#[cfg(feature = "profiling")]
|
#[cfg(feature = "profiling")]
|
||||||
puffin::profile_function!();
|
puffin::profile_function!();
|
||||||
|
|
||||||
let note_key = note.key().unwrap();
|
let note_key = note.key().unwrap();
|
||||||
|
|
||||||
let inner_response = ui.horizontal(|ui| {
|
ui.horizontal(|ui| {
|
||||||
ui.spacing_mut().item_spacing.x = 2.0;
|
ui.spacing_mut().item_spacing.x = 2.0;
|
||||||
ui.add(ui::Username::new(profile.as_ref().ok(), note.pubkey()).abbreviated(20));
|
ui.add(ui::Username::new(profile.as_ref().ok(), note.pubkey()).abbreviated(20));
|
||||||
|
|
||||||
let cached_note = note_cache.cached_note_or_insert_mut(note_key, note);
|
let cached_note = note_cache.cached_note_or_insert_mut(note_key, note);
|
||||||
render_reltime(ui, cached_note, true);
|
render_reltime(ui, cached_note, true);
|
||||||
|
|
||||||
if options.has_options_button() {
|
|
||||||
let context_pos = {
|
|
||||||
let size = NoteContextButton::max_width();
|
|
||||||
let min = Pos2::new(container_right.x - size, container_right.y);
|
|
||||||
Rect::from_min_size(min, egui::vec2(size, size))
|
|
||||||
};
|
|
||||||
|
|
||||||
let resp = ui.add(NoteContextButton::new(note_key).place_at(context_pos));
|
|
||||||
NoteContextButton::menu(ui, resp.clone())
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
NoteResponse::new(inner_response.response).select_option(inner_response.inner)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn show_standard(&mut self, ui: &mut egui::Ui) -> NoteResponse {
|
fn show_standard(&mut self, ui: &mut egui::Ui) -> NoteResponse {
|
||||||
@@ -354,12 +337,6 @@ impl<'a> NoteView<'a> {
|
|||||||
let hitbox_id = note_hitbox_id(note_key, self.options(), self.parent);
|
let hitbox_id = note_hitbox_id(note_key, self.options(), self.parent);
|
||||||
let profile = self.ndb.get_profile_by_pubkey(txn, self.note.pubkey());
|
let profile = self.ndb.get_profile_by_pubkey(txn, self.note.pubkey());
|
||||||
let maybe_hitbox = maybe_note_hitbox(ui, hitbox_id);
|
let maybe_hitbox = maybe_note_hitbox(ui, hitbox_id);
|
||||||
let container_right = {
|
|
||||||
let r = ui.available_rect_before_wrap();
|
|
||||||
let x = r.max.x;
|
|
||||||
let y = r.min.y;
|
|
||||||
Pos2::new(x, y)
|
|
||||||
};
|
|
||||||
|
|
||||||
// wide design
|
// wide design
|
||||||
let response = if self.options().has_wide() {
|
let response = if self.options().has_wide() {
|
||||||
@@ -375,15 +352,7 @@ impl<'a> NoteView<'a> {
|
|||||||
ui.vertical(|ui| {
|
ui.vertical(|ui| {
|
||||||
ui.add_sized([size.x, self.options().pfp_size()], |ui: &mut egui::Ui| {
|
ui.add_sized([size.x, self.options().pfp_size()], |ui: &mut egui::Ui| {
|
||||||
ui.horizontal_centered(|ui| {
|
ui.horizontal_centered(|ui| {
|
||||||
selected_option = NoteView::note_header(
|
NoteView::note_header(ui, self.note_cache, self.note, &profile);
|
||||||
ui,
|
|
||||||
self.note_cache,
|
|
||||||
self.note,
|
|
||||||
&profile,
|
|
||||||
self.options(),
|
|
||||||
container_right,
|
|
||||||
)
|
|
||||||
.context_selection;
|
|
||||||
})
|
})
|
||||||
.response
|
.response
|
||||||
});
|
});
|
||||||
@@ -449,15 +418,7 @@ impl<'a> NoteView<'a> {
|
|||||||
};
|
};
|
||||||
|
|
||||||
ui.with_layout(egui::Layout::top_down(egui::Align::LEFT), |ui| {
|
ui.with_layout(egui::Layout::top_down(egui::Align::LEFT), |ui| {
|
||||||
selected_option = NoteView::note_header(
|
NoteView::note_header(ui, self.note_cache, self.note, &profile);
|
||||||
ui,
|
|
||||||
self.note_cache,
|
|
||||||
self.note,
|
|
||||||
&profile,
|
|
||||||
self.options(),
|
|
||||||
container_right,
|
|
||||||
)
|
|
||||||
.context_selection;
|
|
||||||
ui.horizontal(|ui| {
|
ui.horizontal(|ui| {
|
||||||
ui.spacing_mut().item_spacing.x = 2.0;
|
ui.spacing_mut().item_spacing.x = 2.0;
|
||||||
|
|
||||||
@@ -510,6 +471,18 @@ impl<'a> NoteView<'a> {
|
|||||||
.response
|
.response
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if self.options().has_options_button() {
|
||||||
|
let context_pos = {
|
||||||
|
let size = NoteContextButton::max_width();
|
||||||
|
let top_right = response.rect.right_top();
|
||||||
|
let min = Pos2::new(top_right.x - size, top_right.y);
|
||||||
|
Rect::from_min_size(min, egui::vec2(size, size))
|
||||||
|
};
|
||||||
|
|
||||||
|
let resp = ui.add(NoteContextButton::new(note_key).place_at(context_pos));
|
||||||
|
selected_option = NoteContextButton::menu(ui, resp.clone());
|
||||||
|
}
|
||||||
|
|
||||||
let note_action = if note_hitbox_clicked(ui, hitbox_id, &response.rect, maybe_hitbox) {
|
let note_action = if note_hitbox_clicked(ui, hitbox_id, &response.rect, maybe_hitbox) {
|
||||||
if let Ok(selection) = ThreadSelection::from_note_id(
|
if let Ok(selection) = ThreadSelection::from_note_id(
|
||||||
self.ndb,
|
self.ndb,
|
||||||
|
|||||||
@@ -323,8 +323,9 @@ impl<'a> PostView<'a> {
|
|||||||
context_selection = Frame::none()
|
context_selection = Frame::none()
|
||||||
.show(ui, |ui| {
|
.show(ui, |ui| {
|
||||||
ui.vertical(|ui| {
|
ui.vertical(|ui| {
|
||||||
ui.set_max_width(avail_size.x * 0.8);
|
let set_width = avail_size.x * 0.8;
|
||||||
render_note_preview(
|
ui.set_max_width(set_width);
|
||||||
|
let resp = render_note_preview(
|
||||||
ui,
|
ui,
|
||||||
self.ndb,
|
self.ndb,
|
||||||
self.note_cache,
|
self.note_cache,
|
||||||
@@ -333,7 +334,8 @@ impl<'a> PostView<'a> {
|
|||||||
id.bytes(),
|
id.bytes(),
|
||||||
nostrdb::NoteKey::new(0),
|
nostrdb::NoteKey::new(0),
|
||||||
self.note_options,
|
self.note_options,
|
||||||
)
|
);
|
||||||
|
resp
|
||||||
})
|
})
|
||||||
.inner
|
.inner
|
||||||
.context_selection
|
.context_selection
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ impl<'a> QuoteRepostView<'a> {
|
|||||||
let id = self.id();
|
let id = self.id();
|
||||||
let quoting_note_id = self.quoting_note.id();
|
let quoting_note_id = self.quoting_note.id();
|
||||||
|
|
||||||
ui::PostView::new(
|
let post_resp = ui::PostView::new(
|
||||||
self.ndb,
|
self.ndb,
|
||||||
self.draft,
|
self.draft,
|
||||||
PostType::Quote(NoteId::new(quoting_note_id.to_owned())),
|
PostType::Quote(NoteId::new(quoting_note_id.to_owned())),
|
||||||
@@ -62,7 +62,8 @@ impl<'a> QuoteRepostView<'a> {
|
|||||||
self.note_options,
|
self.note_options,
|
||||||
)
|
)
|
||||||
.id_source(id)
|
.id_source(id)
|
||||||
.ui(self.quoting_note.txn().unwrap(), ui)
|
.ui(self.quoting_note.txn().unwrap(), ui);
|
||||||
|
post_resp
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn id_source(mut self, id: egui::Id) -> Self {
|
pub fn id_source(mut self, id: egui::Id) -> Self {
|
||||||
|
|||||||
Reference in New Issue
Block a user