mirror of
https://github.com/mikedilger/gossip.git
synced 2024-09-29 00:11:01 +00:00
My Relay Page: Move "Advertise" button to action menu top right
This commit is contained in:
parent
a1ed904bd4
commit
0f12bcc9b5
@ -3,10 +3,8 @@ use crate::ui::{widgets, Page};
|
||||
use eframe::egui;
|
||||
use egui::{Context, Ui};
|
||||
use egui_winit::egui::Id;
|
||||
use gossip_lib::comms::ToOverlordMessage;
|
||||
use gossip_lib::Relay;
|
||||
use gossip_lib::GLOBALS;
|
||||
use std::sync::atomic::Ordering;
|
||||
|
||||
pub(super) fn update(app: &mut GossipUi, _ctx: &Context, _frame: &mut eframe::Frame, ui: &mut Ui) {
|
||||
let is_editing = app.relays.edit.is_some();
|
||||
@ -30,26 +28,7 @@ pub(super) fn update(app: &mut GossipUi, _ctx: &Context, _frame: &mut eframe::Fr
|
||||
super::start_entry_dialog(app);
|
||||
}
|
||||
|
||||
let advertise_remaining = GLOBALS.advertise_jobs_remaining.load(Ordering::Relaxed);
|
||||
if advertise_remaining == 0 {
|
||||
if widgets::Button::secondary(&app.theme,"Advertise Relay List")
|
||||
.show(ui)
|
||||
.on_hover_text("Advertise my relays. Will send your relay usage information to every relay that seems to be working well so that other people know how to follow and contact you.")
|
||||
.clicked()
|
||||
{
|
||||
let _ = GLOBALS
|
||||
.to_overlord
|
||||
.send(ToOverlordMessage::AdvertiseRelayList);
|
||||
}
|
||||
} else {
|
||||
ui.add_enabled(
|
||||
false,
|
||||
widgets::Button::secondary(
|
||||
&app.theme,
|
||||
format!("Advertising, {} to go", advertise_remaining),
|
||||
),
|
||||
);
|
||||
}
|
||||
// let advertise_remaining = GLOBALS.advertise_jobs_remaining.load(Ordering::Relaxed);
|
||||
});
|
||||
|
||||
let relays = if !is_editing {
|
||||
|
@ -464,6 +464,20 @@ pub(super) fn configure_list_btn(app: &mut GossipUi, ui: &mut Ui) {
|
||||
}),
|
||||
)));
|
||||
|
||||
if app.page == Page::RelaysMine {
|
||||
items.push(MoreMenuItem::Button(MoreMenuButton::new("Advertise Relay List",
|
||||
Box::new(|_ui, _app| {
|
||||
let _ = GLOBALS
|
||||
.to_overlord
|
||||
.send(ToOverlordMessage::AdvertiseRelayList);
|
||||
|
||||
}))
|
||||
.enabled(GLOBALS.identity.is_unlocked())
|
||||
.on_disabled_hover_text("Add or unlock your private key to advertise your relays")
|
||||
.on_hover_text("Advertise my relays. Will send your relay usage information to every relay that seems to be working well so that other people know how to follow and contact you.")
|
||||
));
|
||||
}
|
||||
|
||||
menu.show_entries(ui, app, response, items);
|
||||
});
|
||||
}
|
||||
|
@ -33,6 +33,8 @@ pub(in crate::ui) enum MoreMenuItem<'a> {
|
||||
#[allow(clippy::type_complexity)]
|
||||
pub(in crate::ui) struct MoreMenuButton<'a> {
|
||||
text: WidgetText,
|
||||
on_hover_text: Option<WidgetText>,
|
||||
on_disabled_hover_text: Option<WidgetText>,
|
||||
action: Box<dyn FnOnce(&mut Ui, &mut GossipUi) + 'a>,
|
||||
enabled: bool,
|
||||
}
|
||||
@ -45,11 +47,26 @@ impl<'a> MoreMenuButton<'a> {
|
||||
) -> Self {
|
||||
Self {
|
||||
text: text.into(),
|
||||
on_hover_text: None,
|
||||
on_disabled_hover_text: None,
|
||||
action,
|
||||
enabled: true,
|
||||
}
|
||||
}
|
||||
|
||||
/// Set an optional `on_hover_text`
|
||||
pub fn on_hover_text(mut self, text: impl Into<WidgetText>) -> Self {
|
||||
self.on_hover_text = Some(text.into());
|
||||
self
|
||||
}
|
||||
|
||||
/// Set an optional `on_disabled_hover_text`
|
||||
pub fn on_disabled_hover_text(mut self, text: impl Into<WidgetText>) -> Self {
|
||||
self.on_disabled_hover_text = Some(text.into());
|
||||
self
|
||||
}
|
||||
|
||||
/// Set `enabled` state of this button
|
||||
pub fn enabled(mut self, enabled: bool) -> Self {
|
||||
self.enabled = enabled;
|
||||
self
|
||||
@ -71,7 +88,14 @@ impl<'a> MoreMenuButton<'a> {
|
||||
ui.disable();
|
||||
}
|
||||
|
||||
let response = draw_menu_button(ui, &app.theme, self.text, None);
|
||||
let response = draw_menu_button(
|
||||
ui,
|
||||
&app.theme,
|
||||
self.text,
|
||||
None,
|
||||
self.on_hover_text,
|
||||
self.on_disabled_hover_text,
|
||||
);
|
||||
|
||||
// process action
|
||||
if response.clicked() {
|
||||
@ -141,7 +165,7 @@ impl<'a> MoreMenuSubMenu<'a> {
|
||||
|
||||
let mut open = load_state(ui, &self.id);
|
||||
|
||||
let response = draw_menu_button(ui, &app.theme, self.title, Some(open));
|
||||
let response = draw_menu_button(ui, &app.theme, self.title, Some(open), None, None);
|
||||
|
||||
// TODO paint open/close arrow, use animation
|
||||
|
||||
@ -779,12 +803,14 @@ fn draw_menu_button(
|
||||
theme: &Theme,
|
||||
title: WidgetText,
|
||||
force_hover: Option<bool>,
|
||||
on_hover_text: Option<WidgetText>,
|
||||
on_disabled_hover_text: Option<WidgetText>,
|
||||
) -> Response {
|
||||
// layout
|
||||
let desired_size = vec2(ui.available_width(), 32.0);
|
||||
|
||||
// interact
|
||||
let (rect, response) = ui.allocate_at_least(desired_size, Sense::click());
|
||||
let (rect, mut response) = ui.allocate_at_least(desired_size, Sense::click());
|
||||
response.widget_info(|| WidgetInfo::labeled(WidgetType::Button, ui.is_enabled(), title.text()));
|
||||
let state = super::interact_widget_state(ui, &response);
|
||||
let state = match state {
|
||||
@ -902,5 +928,12 @@ fn draw_menu_button(
|
||||
);
|
||||
painter.add(shapes);
|
||||
|
||||
if let Some(text) = on_hover_text {
|
||||
response = response.on_hover_text(text);
|
||||
}
|
||||
if let Some(text) = on_disabled_hover_text {
|
||||
response = response.on_disabled_hover_text(text);
|
||||
}
|
||||
|
||||
response
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user