diff --git a/gossip-bin/src/ui/feed/note/mod.rs b/gossip-bin/src/ui/feed/note/mod.rs index b3ef6873..2d62acd3 100644 --- a/gossip-bin/src/ui/feed/note/mod.rs +++ b/gossip-bin/src/ui/feed/note/mod.rs @@ -420,9 +420,14 @@ pub fn render_note_inner( let mut next_page = None; ui.with_layout(Layout::right_to_left(Align::TOP), |ui| { - widgets::MoreMenu::simple(&app.theme, &app.assets, ui.next_auto_id()) - .small_button() - .show(ui, |ui, keep_open| { + let text = egui::RichText::new("=").size(13.0); + let response = widgets::Button::primary(&app.theme, text) + .small(true) + .show(ui); + widgets::MoreMenu::simple(ui.next_auto_id()).show( + ui, + response, + |ui, keep_open| { let relays: Vec = note .seen_on .iter() @@ -562,7 +567,8 @@ pub fn render_note_inner( app.notes.cache_invalidate_note(¬e.event.id); *keep_open = false; } - }); + }, + ); ui.add_space(4.0); let is_thread_view: bool = { diff --git a/gossip-bin/src/ui/feed/post.rs b/gossip-bin/src/ui/feed/post.rs index 016b9524..ff66b596 100644 --- a/gossip-bin/src/ui/feed/post.rs +++ b/gossip-bin/src/ui/feed/post.rs @@ -229,11 +229,12 @@ fn dm_posting_area( ui.add_space(8.0); ui.horizontal(|ui| { - widgets::MoreMenu::bubble(&app.theme, &app.assets, ui.next_auto_id()) + let response = widgets::options_menu_button(ui, &app.theme, &app.assets); + widgets::MoreMenu::bubble(ui.next_auto_id()) .with_max_size(vec2(190.0, 40.0)) .with_min_size(vec2(190.0, 40.0)) .place_above(!read_setting!(posting_area_at_top)) - .show(ui, |ui, is_open| { + .show(ui, response, |ui, is_open| { ui.vertical_centered_justified(|ui| { if app.dm_draft_data.include_subject { if widgets::Button::primary(&app.theme, "Remove Subject") @@ -530,11 +531,12 @@ fn real_posting_area(app: &mut GossipUi, ctx: &Context, ui: &mut Ui) { if app.draft_data.raw.is_empty() { // show advanced action menu if app.draft_data.repost.is_none() { - widgets::MoreMenu::bubble(&app.theme, &app.assets, ui.next_auto_id()) + let response = widgets::options_menu_button(ui, &app.theme, &app.assets); + widgets::MoreMenu::bubble(ui.next_auto_id()) .with_max_size(vec2(180.0, 80.0)) .with_min_size(vec2(180.0, 80.0)) .place_above(!read_setting!(posting_area_at_top)) - .show(ui, |ui, is_open| { + .show(ui, response, |ui, is_open| { ui.vertical_centered_justified(|ui| { if app.draft_data.include_subject { if widgets::Button::primary(&app.theme, "Remove Subject") diff --git a/gossip-bin/src/ui/people/list.rs b/gossip-bin/src/ui/people/list.rs index 97ac674a..5d9e3e7b 100644 --- a/gossip-bin/src/ui/people/list.rs +++ b/gossip-bin/src/ui/people/list.rs @@ -293,22 +293,25 @@ pub(super) fn update( egui::Layout::right_to_left(egui::Align::Min) .with_cross_align(egui::Align::Center), |ui| { - widgets::MoreMenu::simple( - &app.theme, - &app.assets, - ui.next_auto_id(), - ) - .show(ui, |ui, is_open| { - // actions - if ui.button("Remove").clicked() { - let _ = GLOBALS.storage.remove_person_from_list( - &person.pubkey, - list, - None, - ); - *is_open = false; - } - }); + let text = egui::RichText::new("=").size(13.0); + let response = widgets::Button::primary(&app.theme, text) + .small(true) + .show(ui); + widgets::MoreMenu::simple(ui.next_auto_id()).show( + ui, + response, + |ui, is_open| { + // actions + if ui.button("Remove").clicked() { + let _ = GLOBALS.storage.remove_person_from_list( + &person.pubkey, + list, + None, + ); + *is_open = false; + } + }, + ); ui.add_space(20.0); @@ -768,11 +771,16 @@ pub(super) fn render_more_list_actions( return; } - let menu = widgets::MoreMenu::simple(&app.theme, &app.assets, ui.next_auto_id()) + let text = egui::RichText::new("=").size(13.0); + let response = widgets::Button::primary(&app.theme, text) + .small(true) + .show(ui); + + let menu = widgets::MoreMenu::simple(ui.next_auto_id()) .with_min_size(vec2(100.0, 0.0)) .with_max_size(vec2(160.0, f32::INFINITY)); - menu.show(ui, |ui, is_open| { + menu.show(ui, response, |ui, is_open| { ui.with_layout(egui::Layout::top_down_justified(egui::Align::LEFT), |ui| { if on_list { app.theme.primary_button_style(ui.style_mut()); diff --git a/gossip-bin/src/ui/relays/mod.rs b/gossip-bin/src/ui/relays/mod.rs index 87402ba1..61a2ebfe 100644 --- a/gossip-bin/src/ui/relays/mod.rs +++ b/gossip-bin/src/ui/relays/mod.rs @@ -471,10 +471,11 @@ pub(super) fn configure_list_btn(app: &mut GossipUi, ui: &mut Ui) { ui.add_enabled_ui(true, |ui| { let min_size = vec2(180.0, 20.0); - widgets::MoreMenu::bubble(&app.theme, &app.assets, ui.next_auto_id()) + let response = widgets::options_menu_button(ui, &app.theme, &app.assets); + widgets::MoreMenu::bubble(ui.next_auto_id()) .with_min_size(min_size) .with_hover_text("Configure List View".to_owned()) - .show(ui, |ui, is_open| { + .show(ui, response, |ui, is_open| { ui.horizontal(|ui| { if widgets::Switch::small(&app.theme, &mut app.relays.show_details) .show(ui) diff --git a/gossip-bin/src/ui/widgets/mod.rs b/gossip-bin/src/ui/widgets/mod.rs index 91981491..62ee1c9b 100644 --- a/gossip-bin/src/ui/widgets/mod.rs +++ b/gossip-bin/src/ui/widgets/mod.rs @@ -14,7 +14,7 @@ pub(crate) mod list_entry; pub use copy_button::{CopyButton, COPY_SYMBOL_SIZE}; mod nav_item; -use eframe::egui::{FontId, Galley}; +use eframe::egui::{vec2, FontId, Galley, Rect}; use egui_winit::egui::text::LayoutJob; use egui_winit::egui::{ self, Align, FontSelection, Response, RichText, Rounding, Sense, Ui, WidgetText, @@ -42,6 +42,7 @@ pub use switch::Switch; mod textedit; pub use textedit::TextEdit; +use super::assets::Assets; use super::{GossipUi, Theme}; pub const DROPDOWN_DISTANCE: f32 = 10.0; @@ -162,6 +163,24 @@ pub fn break_anywhere_hyperlink_to(ui: &mut Ui, text: impl Into, url ui.hyperlink_to(job, url); } +pub fn options_menu_button(ui: &mut Ui, theme: &Theme, assets: &Assets) -> Response { + let (response, painter) = ui.allocate_painter(vec2(20.0, 20.0), egui::Sense::click()); + let btn_rect = response.rect; + let color = if response.hovered() { + theme.accent_color() + } else { + ui.visuals().text_color() + }; + let mut mesh = egui::Mesh::with_texture((&assets.options_symbol).into()); + mesh.add_rect_with_uv( + btn_rect.shrink(2.0), + Rect::from_min_max(egui::pos2(0.0, 0.0), egui::pos2(1.0, 1.0)), + color, + ); + painter.add(egui::Shape::mesh(mesh)); + response +} + pub(super) fn set_important_button_visuals(ui: &mut Ui, app: &GossipUi) { let visuals = ui.visuals_mut(); visuals.widgets.inactive.weak_bg_fill = app.theme.accent_color(); diff --git a/gossip-bin/src/ui/widgets/more_menu.rs b/gossip-bin/src/ui/widgets/more_menu.rs index fe0b5374..89f849a4 100644 --- a/gossip-bin/src/ui/widgets/more_menu.rs +++ b/gossip-bin/src/ui/widgets/more_menu.rs @@ -1,9 +1,5 @@ -use eframe::epaint::PathShape; -use egui_winit::egui::{ - self, vec2, AboveOrBelow, Align2, Color32, Id, Rect, TextureHandle, Ui, Vec2, -}; - -use crate::ui::{assets::Assets, Theme}; +use eframe::{egui::Response, epaint::PathShape}; +use egui_winit::egui::{self, vec2, AboveOrBelow, Align2, Id, Ui, Vec2}; static POPUP_MARGIN: Vec2 = Vec2 { x: 20.0, y: 16.0 }; @@ -13,21 +9,17 @@ enum MoreMenuStyle { Bubble, } -pub(in crate::ui) struct MoreMenu<'a> { +pub(in crate::ui) struct MoreMenu { id: Id, min_size: Vec2, max_size: Vec2, above_or_below: Option, hover_text: Option, - small_button: bool, - accent_color: Color32, - options_symbol: TextureHandle, style: MoreMenuStyle, - theme: &'a Theme, } -impl<'a> MoreMenu<'a> { - pub fn simple(theme: &'a Theme, assets: &'a Assets, id: Id) -> Self { +impl MoreMenu { + pub fn simple(id: Id) -> Self { Self { id, min_size: Vec2 { x: 0.0, y: 0.0 }, @@ -37,15 +29,11 @@ impl<'a> MoreMenu<'a> { }, above_or_below: None, hover_text: None, - small_button: false, - accent_color: theme.accent_color(), - options_symbol: assets.options_symbol.clone(), style: MoreMenuStyle::Simple, - theme, } } - pub fn bubble(theme: &'a Theme, assets: &'a Assets, id: Id) -> Self { + pub fn bubble(id: Id) -> Self { Self { id, min_size: Vec2 { x: 0.0, y: 0.0 }, @@ -55,20 +43,10 @@ impl<'a> MoreMenu<'a> { }, above_or_below: None, hover_text: None, - small_button: false, - accent_color: theme.accent_color(), - options_symbol: assets.options_symbol.clone(), style: MoreMenuStyle::Bubble, - theme, } } - #[allow(unused)] - pub fn small_button(mut self) -> Self { - self.small_button = true; - self - } - #[allow(unused)] pub fn with_id(mut self, id: impl Into) -> Self { self.id = id.into(); @@ -103,37 +81,36 @@ impl<'a> MoreMenu<'a> { self } - pub fn show(&self, ui: &mut Ui, content: impl FnOnce(&mut Ui, &mut bool)) { + pub fn show(&self, ui: &mut Ui, response: Response, content: impl FnOnce(&mut Ui, &mut bool)) { let mut active = self.load_state(ui); - let response = match self.style { - MoreMenuStyle::Simple => { - let text = egui::RichText::new("=").size(13.0); - super::Button::primary(self.theme, text) - .small(self.small_button) - .show(ui) - } - MoreMenuStyle::Bubble => { - let (response, painter) = - ui.allocate_painter(vec2(20.0, 20.0), egui::Sense::click()); - let btn_rect = response.rect; - let color = if response.hovered() { - self.accent_color - } else { - ui.visuals().text_color() - }; - let mut mesh = egui::Mesh::with_texture((&self.options_symbol).into()); - mesh.add_rect_with_uv( - btn_rect.shrink(2.0), - Rect::from_min_max(egui::pos2(0.0, 0.0), egui::pos2(1.0, 1.0)), - color, - ); - painter.add(egui::Shape::mesh(mesh)); - response - } - }; + // let response = match self.style { + // MoreMenuStyle::Simple => { + // let text = egui::RichText::new("=").size(13.0); + // super::Button::primary(self.theme, text) + // .small(self.small_button) + // .show(ui) + // } + // MoreMenuStyle::Bubble => { + // let (response, painter) = + // ui.allocate_painter(vec2(20.0, 20.0), egui::Sense::click()); + // let btn_rect = response.rect; + // let color = if response.hovered() { + // self.accent_color + // } else { + // ui.visuals().text_color() + // }; + // let mut mesh = egui::Mesh::with_texture((&self.options_symbol).into()); + // mesh.add_rect_with_uv( + // btn_rect.shrink(2.0), + // Rect::from_min_max(egui::pos2(0.0, 0.0), egui::pos2(1.0, 1.0)), + // color, + // ); + // painter.add(egui::Shape::mesh(mesh)); + // response + // } + // }; - let response = response.on_hover_cursor(egui::CursorIcon::PointingHand); let response = if let Some(text) = &self.hover_text { if !active { response.on_hover_text(text) diff --git a/gossip-bin/src/ui/wizard/follow_people.rs b/gossip-bin/src/ui/wizard/follow_people.rs index f79d39eb..877aebc1 100644 --- a/gossip-bin/src/ui/wizard/follow_people.rs +++ b/gossip-bin/src/ui/wizard/follow_people.rs @@ -136,13 +136,13 @@ pub(super) fn update(app: &mut GossipUi, ctx: &Context, _frame: &mut eframe::Fra egui::Layout::right_to_left(egui::Align::Min) .with_cross_align(egui::Align::Center), |ui| { - widgets::MoreMenu::simple( - &app.theme, - &app.assets, - ui.next_auto_id(), - ) - .show( + let text = egui::RichText::new("=").size(13.0); + let response = widgets::Button::primary(&app.theme, text) + .small(true) + .show(ui); + widgets::MoreMenu::simple(ui.next_auto_id()).show( ui, + response, |ui, is_open| { // actions if ui.button("Remove").clicked() {