config: fix init config, save flag to show wallet list at dual panel wallets mode
This commit is contained in:
parent
0ec5d415b1
commit
0d00348d15
2 changed files with 30 additions and 11 deletions
|
@ -46,7 +46,7 @@ pub struct WalletsContent {
|
|||
creation_content: WalletCreation,
|
||||
|
||||
/// Flag to show [`Wallet`] list at dual panel mode.
|
||||
show_list_at_dual_panel: bool,
|
||||
show_wallets_at_dual_panel: bool,
|
||||
|
||||
/// [`Modal`] identifiers allowed at this ui container.
|
||||
modal_ids: Vec<&'static str>
|
||||
|
@ -65,7 +65,7 @@ impl Default for WalletsContent {
|
|||
wrong_pass: false,
|
||||
wallet_content: WalletContent::default(),
|
||||
creation_content: WalletCreation::default(),
|
||||
show_list_at_dual_panel: true,
|
||||
show_wallets_at_dual_panel: AppConfig::show_wallets_at_dual_panel(),
|
||||
modal_ids: vec![
|
||||
OPEN_WALLET_MODAL,
|
||||
WalletCreation::NAME_PASS_MODAL
|
||||
|
@ -126,7 +126,7 @@ impl WalletsContent {
|
|||
.min_width(wallet_panel_width)
|
||||
.frame(egui::Frame {
|
||||
fill: if empty_list && !create_wallet
|
||||
|| (dual_panel && !self.show_list_at_dual_panel) {
|
||||
|| (dual_panel && show_wallet && !self.show_wallets_at_dual_panel) {
|
||||
Colors::FILL_DARK
|
||||
} else {
|
||||
Colors::WHITE
|
||||
|
@ -153,7 +153,7 @@ impl WalletsContent {
|
|||
// Setup wallet content width.
|
||||
let mut rect = ui.available_rect_before_wrap();
|
||||
let mut width = ui.available_width();
|
||||
if dual_panel && self.show_list_at_dual_panel {
|
||||
if dual_panel && self.show_wallets_at_dual_panel {
|
||||
width = content_width - Root::SIDE_PANEL_WIDTH;
|
||||
}
|
||||
rect.set_width(width);
|
||||
|
@ -170,7 +170,8 @@ impl WalletsContent {
|
|||
// Show non-empty list if wallet is not creating.
|
||||
if !empty_list && !create_wallet {
|
||||
// Flag to check if wallet list is hidden on the screen.
|
||||
let list_hidden = content_width == 0.0 || (dual_panel && !self.show_list_at_dual_panel)
|
||||
let list_hidden = content_width == 0.0
|
||||
|| (dual_panel && show_wallet && !self.show_wallets_at_dual_panel)
|
||||
|| (!dual_panel && show_wallet);
|
||||
|
||||
// Show wallet list panel.
|
||||
|
@ -245,14 +246,15 @@ impl WalletsContent {
|
|||
self.creation_content.back();
|
||||
});
|
||||
} else if show_wallet && dual_panel {
|
||||
let show_list = self.show_list_at_dual_panel;
|
||||
let show_list = self.show_wallets_at_dual_panel;
|
||||
let list_icon = if show_list {
|
||||
SIDEBAR_SIMPLE
|
||||
} else {
|
||||
SUITCASE
|
||||
};
|
||||
View::title_button(ui, list_icon, || {
|
||||
self.show_list_at_dual_panel = !show_list;
|
||||
self.show_wallets_at_dual_panel = !show_list;
|
||||
AppConfig::toggle_show_wallets_at_dual_panel();
|
||||
});
|
||||
} else if !Root::is_dual_panel_mode(frame) {
|
||||
View::title_button(ui, GLOBE, || {
|
||||
|
@ -276,12 +278,12 @@ impl WalletsContent {
|
|||
) -> f32 {
|
||||
let create_wallet = self.creation_content.can_go_back();
|
||||
let available_width = if list_empty || create_wallet || (show_wallet && !dual_panel)
|
||||
|| !self.show_list_at_dual_panel {
|
||||
|| (show_wallet && !self.show_wallets_at_dual_panel) {
|
||||
ui.available_width()
|
||||
} else {
|
||||
ui.available_width() - Root::SIDE_PANEL_WIDTH
|
||||
};
|
||||
if dual_panel && self.show_list_at_dual_panel {
|
||||
if dual_panel && show_wallet && self.show_wallets_at_dual_panel {
|
||||
let min_width = Root::SIDE_PANEL_WIDTH + View::get_right_inset();
|
||||
f32::max(min_width, available_width)
|
||||
} else {
|
||||
|
|
|
@ -40,13 +40,16 @@ pub struct AppConfig {
|
|||
pub auto_start_node: bool,
|
||||
/// Chain type for node and wallets.
|
||||
chain_type: ChainTypes,
|
||||
/// Flag to show wallet list at dual panel wallets mode.
|
||||
show_wallets_at_dual_panel: bool,
|
||||
}
|
||||
|
||||
impl Default for AppConfig {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
auto_start_node: false,
|
||||
chain_type: ChainTypes::default()
|
||||
chain_type: ChainTypes::default(),
|
||||
show_wallets_at_dual_panel: true,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -96,6 +99,20 @@ impl AppConfig {
|
|||
w_app_config.auto_start_node = !autostart;
|
||||
w_app_config.save();
|
||||
}
|
||||
|
||||
/// Toggle flag to show wallet list at dual panel wallets mode.
|
||||
pub fn show_wallets_at_dual_panel() -> bool {
|
||||
let r_config = Settings::app_config_to_read();
|
||||
r_config.show_wallets_at_dual_panel
|
||||
}
|
||||
|
||||
/// Toggle flag to show wallet list at dual panel wallets mode.
|
||||
pub fn toggle_show_wallets_at_dual_panel() {
|
||||
let show = Self::show_wallets_at_dual_panel();
|
||||
let mut w_app_config = Settings::app_config_to_update();
|
||||
w_app_config.show_wallets_at_dual_panel = !show;
|
||||
w_app_config.save();
|
||||
}
|
||||
}
|
||||
|
||||
/// Main application directory name.
|
||||
|
@ -123,7 +140,7 @@ impl Settings {
|
|||
/// Initialize config from provided file path or set [`Default`] if file not exists.
|
||||
pub fn init_config<T: Default + Serialize + DeserializeOwned>(path: PathBuf) -> T {
|
||||
let parsed = Self::read_from_file::<T>(path.clone());
|
||||
if !path.exists() || !parsed.is_err() {
|
||||
if !path.exists() || parsed.is_err() {
|
||||
let default_config = T::default();
|
||||
Settings::write_to_file(&default_config, path);
|
||||
default_config
|
||||
|
|
Loading…
Reference in a new issue