mirror of
https://github.com/jwinterm/grim.git
synced 2026-11-24 23:03:57 +01:00
config + ui: fix connections dir, add wallet tabs, initial wallet loading content, fix wallet content width, update translations
This commit is contained in:
@@ -12,21 +12,26 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
use egui::Margin;
|
||||
use crate::gui::Colors;
|
||||
use egui::{Margin, RichText};
|
||||
|
||||
use crate::gui::Colors;
|
||||
use crate::gui::icons::{DOWNLOAD, UPLOAD, WALLET, WRENCH};
|
||||
use crate::gui::platform::PlatformCallbacks;
|
||||
use crate::gui::views::View;
|
||||
use crate::wallet::Wallet;
|
||||
use crate::gui::views::wallets::{WalletInfo, WalletReceive, WalletSend, WalletSettings};
|
||||
use crate::gui::views::wallets::types::{WalletTab, WalletTabType};
|
||||
use crate::node::Node;
|
||||
use crate::wallet::{Wallet, Wallets};
|
||||
|
||||
/// Selected and opened wallet content.
|
||||
pub struct WalletContent {
|
||||
|
||||
/// Current tab content to show.
|
||||
current_tab: Box<dyn WalletTab>,
|
||||
}
|
||||
|
||||
impl Default for WalletContent {
|
||||
fn default() -> Self {
|
||||
Self {}
|
||||
Self { current_tab: Box::new(WalletInfo::default()) }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,7 +41,23 @@ impl WalletContent {
|
||||
frame: &mut eframe::Frame,
|
||||
wallet: &mut Wallet,
|
||||
cb: &dyn PlatformCallbacks) {
|
||||
// Show wallet content.
|
||||
// Show bottom tabs.
|
||||
egui::TopBottomPanel::bottom("wallet_tabs")
|
||||
.frame(egui::Frame {
|
||||
fill: Colors::FILL,
|
||||
inner_margin: Margin {
|
||||
left: View::far_left_inset_margin(ui) + 4.0,
|
||||
right: View::get_right_inset() + 4.0,
|
||||
top: 4.0,
|
||||
bottom: View::get_bottom_inset() + 4.0,
|
||||
},
|
||||
..Default::default()
|
||||
})
|
||||
.show_inside(ui, |ui| {
|
||||
self.tabs_ui(ui);
|
||||
});
|
||||
|
||||
// Show tab content.
|
||||
egui::CentralPanel::default()
|
||||
.frame(egui::Frame {
|
||||
stroke: View::DEFAULT_STROKE,
|
||||
@@ -50,10 +71,80 @@ impl WalletContent {
|
||||
..Default::default()
|
||||
})
|
||||
.show_inside(ui, |ui| {
|
||||
ui.label(&wallet.config.name);
|
||||
//TODO: wallet content
|
||||
});
|
||||
|
||||
// Refresh content after delay for loaded wallet.
|
||||
if wallet.is_loaded() {
|
||||
ui.ctx().request_repaint_after(Wallets::INFO_UPDATE_DELAY);
|
||||
} else {
|
||||
ui.ctx().request_repaint();
|
||||
}
|
||||
}
|
||||
|
||||
/// Draw tab buttons in the bottom of the screen.
|
||||
fn tabs_ui(&mut self, ui: &mut egui::Ui) {
|
||||
ui.scope(|ui| {
|
||||
// Setup spacing between tabs.
|
||||
ui.style_mut().spacing.item_spacing = egui::vec2(4.0, 0.0);
|
||||
// Setup vertical padding inside tab button.
|
||||
ui.style_mut().spacing.button_padding = egui::vec2(0.0, 8.0);
|
||||
|
||||
// Draw tab buttons.
|
||||
let current_type = self.current_tab.get_type();
|
||||
ui.columns(4, |columns| {
|
||||
columns[0].vertical_centered_justified(|ui| {
|
||||
View::tab_button(ui, WALLET, current_type == WalletTabType::Info, || {
|
||||
self.current_tab = Box::new(WalletInfo::default());
|
||||
});
|
||||
});
|
||||
columns[1].vertical_centered_justified(|ui| {
|
||||
View::tab_button(ui, DOWNLOAD, current_type == WalletTabType::Receive, || {
|
||||
self.current_tab = Box::new(WalletReceive::default());
|
||||
});
|
||||
});
|
||||
columns[2].vertical_centered_justified(|ui| {
|
||||
View::tab_button(ui, UPLOAD, current_type == WalletTabType::Send, || {
|
||||
self.current_tab = Box::new(WalletSend::default());
|
||||
});
|
||||
});
|
||||
columns[3].vertical_centered_justified(|ui| {
|
||||
View::tab_button(ui, WRENCH, current_type == WalletTabType::Settings, || {
|
||||
self.current_tab = Box::new(WalletSettings::default());
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/// Content to draw when wallet is loading.
|
||||
fn loading_ui(ui: &mut egui::Ui, wallet: &Wallet) {
|
||||
if wallet.config.external_node_url.is_none() && !Node::is_running() {
|
||||
|
||||
} else {
|
||||
if let Some(error) = &wallet.loading_error {
|
||||
// View::center_content(ui, 162.0, |ui| {
|
||||
// let text = t!("wallets.enable_node", "settings" => WRENCH);
|
||||
// View::big_loading_spinner(ui);
|
||||
// ui.add_space(18.0);
|
||||
// let text = if wallet.loading_progress == 0 {
|
||||
// t!("wallet_loading")
|
||||
// } else {
|
||||
// format!("{}: {}%", t!("wallet_loading"), wallet.loading_progress)
|
||||
// };
|
||||
// ui.label(RichText::new(text).size(16.0).color(Colors::INACTIVE_TEXT));
|
||||
// });
|
||||
} else if !wallet.is_loaded() {
|
||||
View::center_content(ui, 162.0, |ui| {
|
||||
View::big_loading_spinner(ui);
|
||||
ui.add_space(18.0);
|
||||
let text = if wallet.loading_progress == 0 {
|
||||
t!("wallets.wallet_loading")
|
||||
} else {
|
||||
format!("{}: {}%", t!("wallets.wallet_loading"), wallet.loading_progress)
|
||||
};
|
||||
ui.label(RichText::new(text).size(16.0).color(Colors::INACTIVE_TEXT));
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
// Copyright 2023 The Grim Developers
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
use crate::gui::platform::PlatformCallbacks;
|
||||
use crate::gui::views::wallets::types::WalletTab;
|
||||
use crate::gui::views::wallets::wallet::types::WalletTabType;
|
||||
|
||||
/// Wallet info tab content.
|
||||
#[derive(Default)]
|
||||
pub struct WalletInfo;
|
||||
|
||||
impl WalletTab for WalletInfo {
|
||||
fn get_type(&self) -> WalletTabType {
|
||||
WalletTabType::Info
|
||||
}
|
||||
|
||||
fn ui(&mut self, ui: &mut egui::Ui, frame: &mut eframe::Frame, cb: &dyn PlatformCallbacks) {
|
||||
}
|
||||
}
|
||||
@@ -12,10 +12,19 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
mod content;
|
||||
mod txs;
|
||||
mod send;
|
||||
mod settings;
|
||||
mod receive;
|
||||
pub mod types;
|
||||
|
||||
mod info;
|
||||
pub use info::WalletInfo;
|
||||
|
||||
mod receive;
|
||||
pub use receive::WalletReceive;
|
||||
|
||||
mod send;
|
||||
pub use send::WalletSend;
|
||||
|
||||
mod settings;
|
||||
pub use settings::WalletSettings;
|
||||
|
||||
mod content;
|
||||
pub use content::WalletContent;
|
||||
@@ -10,4 +10,20 @@
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
// limitations under the License.
|
||||
|
||||
use crate::gui::platform::PlatformCallbacks;
|
||||
use crate::gui::views::wallets::wallet::types::{WalletTab, WalletTabType};
|
||||
|
||||
/// Receive funds tab content.
|
||||
#[derive(Default)]
|
||||
pub struct WalletReceive;
|
||||
|
||||
impl WalletTab for WalletReceive {
|
||||
fn get_type(&self) -> WalletTabType {
|
||||
WalletTabType::Receive
|
||||
}
|
||||
|
||||
fn ui(&mut self, ui: &mut egui::Ui, frame: &mut eframe::Frame, cb: &dyn PlatformCallbacks) {
|
||||
}
|
||||
}
|
||||
@@ -11,3 +11,19 @@
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
use crate::gui::platform::PlatformCallbacks;
|
||||
use crate::gui::views::wallets::wallet::types::{WalletTab, WalletTabType};
|
||||
|
||||
/// Send funds tab content.
|
||||
#[derive(Default)]
|
||||
pub struct WalletSend;
|
||||
|
||||
impl WalletTab for WalletSend {
|
||||
fn get_type(&self) -> WalletTabType {
|
||||
WalletTabType::Send
|
||||
}
|
||||
|
||||
fn ui(&mut self, ui: &mut egui::Ui, frame: &mut eframe::Frame, cb: &dyn PlatformCallbacks) {
|
||||
}
|
||||
}
|
||||
@@ -10,4 +10,20 @@
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
// limitations under the License.
|
||||
|
||||
use crate::gui::platform::PlatformCallbacks;
|
||||
use crate::gui::views::wallets::wallet::types::{WalletTab, WalletTabType};
|
||||
|
||||
/// Wallet settings tab content.
|
||||
#[derive(Default)]
|
||||
pub struct WalletSettings;
|
||||
|
||||
impl WalletTab for WalletSettings {
|
||||
fn get_type(&self) -> WalletTabType {
|
||||
WalletTabType::Settings
|
||||
}
|
||||
|
||||
fn ui(&mut self, ui: &mut egui::Ui, frame: &mut eframe::Frame, cb: &dyn PlatformCallbacks) {
|
||||
}
|
||||
}
|
||||
@@ -11,3 +11,20 @@
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
use crate::gui::platform::PlatformCallbacks;
|
||||
|
||||
/// Wallet tab content interface.
|
||||
pub trait WalletTab {
|
||||
fn get_type(&self) -> WalletTabType;
|
||||
fn ui(&mut self, ui: &mut egui::Ui, frame: &mut eframe::Frame, cb: &dyn PlatformCallbacks);
|
||||
}
|
||||
|
||||
/// Type of [`WalletTab`] content.
|
||||
#[derive(PartialEq)]
|
||||
pub enum WalletTabType {
|
||||
Info,
|
||||
Receive,
|
||||
Send,
|
||||
Settings
|
||||
}
|
||||
Reference in New Issue
Block a user