Skip to content

Commit

Permalink
wip - notification panel
Browse files Browse the repository at this point in the history
  • Loading branch information
aspect committed Jan 13, 2024
1 parent e93412f commit db99b30
Show file tree
Hide file tree
Showing 16 changed files with 279 additions and 24 deletions.
18 changes: 16 additions & 2 deletions core/src/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ pub struct Core {
pub window_frame: bool,
callback_map: CallbackMap,
network_load_samples: VecDeque<f32>,
notifications: Notifications,
}

impl Core {
Expand Down Expand Up @@ -192,6 +193,7 @@ impl Core {
window_frame,
callback_map: CallbackMap::default(),
network_load_samples: VecDeque::default(),
notifications: Notifications::default(),
};

modules.values().for_each(|module| {
Expand Down Expand Up @@ -310,6 +312,10 @@ impl Core {
&mut self.device
}

pub fn notifications(&mut self) -> &mut Notifications {
&mut self.notifications
}

pub fn module(&self) -> &Module {
&self.module
}
Expand Down Expand Up @@ -572,7 +578,8 @@ impl Core {
user_notification: UserNotification::success(format!(
"Capture saved to\n{}",
path.to_string_lossy()
)),
))
.as_toast(),
})
.unwrap()
})
Expand Down Expand Up @@ -680,7 +687,11 @@ impl Core {
Events::Notify {
user_notification: notification,
} => {
notification.render(&mut self.toasts);
if notification.is_toast() {
notification.toast(&mut self.toasts);
} else {
self.notifications.push(notification);
}
}
Events::Close { .. } => {}
Events::UnlockSuccess => {}
Expand All @@ -693,13 +704,16 @@ impl Core {
Events::Wallet { event } => {
match *event {
CoreWallet::Error { message } => {
// runtime().notify(UserNotification::error(message.as_str()));
println!("{message}");
}
CoreWallet::UtxoProcStart => {
self.state.error = None;
}
CoreWallet::UtxoProcStop => {}
CoreWallet::UtxoProcError { message } => {
runtime().notify(UserNotification::error(message.as_str()));

if message.contains("network type") {
self.state.error = Some(message);
}
Expand Down
2 changes: 1 addition & 1 deletion core/src/egui/mnemonic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ impl<'render> MnemonicPresenter<'render> {

if ui.medium_button(format!("{CLIPBOARD_TEXT} Copy to clipboard")).clicked() {
ui.output_mut(|o| o.copied_text = self.phrase.to_string());
runtime().notify(UserNotification::info(format!("{CLIPBOARD_TEXT} {}", i18n("Copied to clipboard"))).short());
runtime().notify_clipboard(i18n("Copied to clipboard"));
}
}
});
Expand Down
12 changes: 11 additions & 1 deletion core/src/egui/popup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,16 @@ pub struct PopupPanel<'panel> {
caption: Option<String>,
with_close_button: bool,
close_on_interaction: bool,
close_on_escape: bool,
above_or_below: AboveOrBelow,
with_padding: bool,
}

impl<'panel> PopupPanel<'panel> {
pub fn id(ui: &mut Ui, id: impl Into<String>) -> Id {
ui.make_persistent_id(id.into())
}

pub fn new(
ui: &mut Ui,
id: impl Into<String>,
Expand All @@ -34,6 +39,7 @@ impl<'panel> PopupPanel<'panel> {
caption: None,
with_close_button: false,
close_on_interaction: false,
close_on_escape: true,
above_or_below: AboveOrBelow::Below,
with_padding: true,
}
Expand Down Expand Up @@ -90,6 +96,7 @@ impl<'panel> PopupPanel<'panel> {
&response,
self.above_or_below,
self.close_on_interaction,
self.close_on_escape,
|ui| {
if let Some(width) = self.min_width {
ui.set_min_width(width);
Expand Down Expand Up @@ -152,6 +159,7 @@ pub fn popup_above_or_below_widget_local<R>(
widget_response: &Response,
above_or_below: AboveOrBelow,
close_on_interaction: bool,
close_on_escape: bool,
add_contents: impl FnOnce(&mut Ui) -> R,
) -> Option<R> {
if ui.memory(|mem| mem.is_popup_open(popup_id)) {
Expand Down Expand Up @@ -186,7 +194,9 @@ pub fn popup_above_or_below_widget_local<R>(
if ui.input(|i| i.key_pressed(Key::Escape)) || widget_response.clicked_elsewhere() {
close_popup = true;
}
} else if ui.input(|i| i.key_pressed(Key::Escape)) || widget_response.clicked_elsewhere() {
} else if close_on_escape
&& (ui.input(|i| i.key_pressed(Key::Escape)) || widget_response.clicked_elsewhere())
{
let response = inner.response;
ui.ctx().input(|i| {
let pointer = &i.pointer;
Expand Down
3 changes: 3 additions & 0 deletions core/src/egui/theme/color.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ pub struct ThemeColor {
pub error_color: Color32,
pub alert_color: Color32,
pub warning_color: Color32,
pub info_color: Color32,
pub icon_syncing_color: Color32,
pub icon_connected_color: Color32,
pub icon_color_default: Color32,
Expand Down Expand Up @@ -84,6 +85,7 @@ impl ThemeColor {
error_color: Color32::from_rgb(255, 136, 136),
alert_color: Color32::from_rgb(255, 136, 136),
warning_color: egui::Color32::from_rgb(255, 255, 136),
info_color: egui::Color32::from_rgb(66, 178, 252),
icon_syncing_color: egui::Color32::from_rgb(255, 255, 136),
icon_connected_color: egui::Color32::from_rgb(85, 233, 136),
icon_color_default: Color32::from_rgb(240, 240, 240),
Expand Down Expand Up @@ -152,6 +154,7 @@ impl ThemeColor {
error_color: Color32::from_rgb(77, 41, 41),
alert_color: Color32::from_rgb(77, 41, 41),
warning_color: egui::Color32::from_rgb(77, 77, 41),
info_color: egui::Color32::from_rgb(41, 56, 77),
icon_syncing_color: egui::Color32::from_rgb(117, 117, 4),
icon_connected_color: egui::Color32::from_rgb(8, 110, 65),
icon_color_default: Color32::from_rgb(32, 32, 32),
Expand Down
10 changes: 10 additions & 0 deletions core/src/egui/theme/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,16 @@ pub fn warning_color() -> Color32 {
theme_color().warning_color
}

#[inline(always)]
pub fn info_color() -> Color32 {
theme_color().info_color
}

#[inline(always)]
pub fn strong_color() -> Color32 {
theme_color().strong_color
}

// ~

pub trait MetricGroupExtension {
Expand Down
2 changes: 1 addition & 1 deletion core/src/imports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ pub use crate::menu::Menu;
pub use crate::modules;
pub use crate::modules::{Module, ModuleCaps, ModuleStyle, ModuleT};
pub use crate::network::Network;
pub use crate::notifications::{UserNotification, UserNotifyKind};
pub use crate::notifications::{Notifications, UserNotification, UserNotifyKind};
pub use crate::primitives::{
Account, AccountCollection, AccountSelectorButtonExtension, BlockDagGraphSettings, DaaBucket,
DagBlock, Transaction, TransactionCollection,
Expand Down
5 changes: 5 additions & 0 deletions core/src/menu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,11 @@ impl<'core> Menu<'core> {
)
.with_min_width(64.)
.build(ui);

if self.core.notifications().has_some() {
ui.separator();
self.core.notifications().render(ui);
}
});
});
});
Expand Down
2 changes: 1 addition & 1 deletion core/src/modules/account_manager/address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ impl<'context> AddressPane<'context> {
// })
.clicked() {
ui.output_mut(|o| o.copied_text = rc.context.address().to_string());
runtime().notify(UserNotification::info(format!("{CLIPBOARD_TEXT} {}", i18n("Copied to clipboard"))).short())
runtime().notify_clipboard(i18n("Copied to clipboard"));
}
}
}
2 changes: 1 addition & 1 deletion core/src/modules/donations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ impl Donations {

if response.clicked() {
ui.output_mut(|o| o.copied_text = Self::ADDRESS_KASPA_NG_FUND.to_owned());
runtime().notify(UserNotification::info(format!("{CLIPBOARD_TEXT} {}", i18n("Copied to clipboard"))).short());
runtime().notify_clipboard(i18n("Copied to clipboard"));
}

ui.label(" ");
Expand Down
2 changes: 1 addition & 1 deletion core/src/modules/logs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ impl ModuleT for Logs {
.clicked() {
let logs = self.runtime.kaspa_service().logs().iter().map(|log| log.to_string()).collect::<Vec<String>>().join("\n");
ui.output_mut(|o| o.copied_text = logs);
runtime().notify(UserNotification::info(format!("{CLIPBOARD_TEXT} {}",i18n("Copied to clipboard"))).short())
runtime().notify_clipboard(i18n("Copied to clipboard"));
}
}
}
4 changes: 2 additions & 2 deletions core/src/modules/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ impl Request {

if response.clicked() {
ui.output_mut(|o| o.copied_text = address.to_owned());
runtime().notify(UserNotification::info(format!("{CLIPBOARD_TEXT} {}", i18n("Address copied to clipboard"))).short());
runtime().notify_clipboard(i18n("Address copied to clipboard"));
}

ui.label(" ");
Expand All @@ -104,7 +104,7 @@ impl Request {

if response.clicked() {
ui.output_mut(|o| o.copied_text = request_uri.to_owned());
runtime().notify(UserNotification::info(format!("{CLIPBOARD_TEXT} {}", i18n("URI copied to clipboard"))).short());
runtime().notify_clipboard(i18n("URI copied to clipboard"));
}

ui.label(" ");
Expand Down
36 changes: 34 additions & 2 deletions core/src/modules/testing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ pub struct Testing {
// text : String,
// graph_data: Vec<PlotPoint>,

#[allow(dead_code)]
mnemonic_presenter_context : MnemonicPresenterContext,
}

Expand Down Expand Up @@ -74,6 +75,39 @@ impl ModuleT for Testing {
_frame: &mut eframe::Frame,
ui: &mut egui::Ui,
) {

if ui.large_button("notify regular").clicked() {
runtime().notify(UserNotification::info("This is a regular notification").short());
}

if ui.large_button("notify error").clicked() {
runtime().notify(UserNotification::error("This is an error notification").short());
}

if ui.large_button("notify warning").clicked() {
runtime().notify(UserNotification::warning("Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.").short());
}

if ui.large_button("notify success").clicked() {
runtime().notify(UserNotification::success("This is a success notification").short());
}

if ui.large_button("notify info").clicked() {
runtime().notify(UserNotification::info("Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, ").short());
}

}
}

impl Testing {

fn _render_mnemonic_presenter(
&mut self,
_core: &mut Core,
_ctx: &egui::Context,
_frame: &mut eframe::Frame,
ui: &mut egui::Ui,
) {
egui::ScrollArea::vertical()
.id_source("test_mnemonic_size_scroll")
.auto_shrink([true; 2])
Expand All @@ -96,8 +130,6 @@ impl ModuleT for Testing {
});
// self.mnemonic_presenter_context.render(ui);
}
}
impl Testing {
fn _render_v1(
&mut self,
_core: &mut Core,
Expand Down
Loading

0 comments on commit db99b30

Please sign in to comment.