working dialog now better
This commit is contained in:
@@ -5,12 +5,12 @@ use common::proto::multieko2::table_definition::ProfileTreeResponse;
|
||||
use crate::components::IntroState;
|
||||
use crate::modes::handlers::mode_manager::AppMode;
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct DialogState {
|
||||
pub show_dialog: bool,
|
||||
pub dialog_show: bool,
|
||||
pub dialog_title: String,
|
||||
pub dialog_message: String,
|
||||
pub dialog_button_active: bool,
|
||||
pub dialog_buttons: Vec<String>,
|
||||
pub dialog_active_button_index: usize,
|
||||
}
|
||||
|
||||
pub struct UiState {
|
||||
@@ -77,21 +77,55 @@ impl AppState {
|
||||
}
|
||||
|
||||
// Add dialog helper methods
|
||||
pub fn show_dialog(&mut self, title: &str, message: &str) {
|
||||
self.ui.dialog.show_dialog = true;
|
||||
/// Shows a dialog with the given title, message, and buttons.
|
||||
/// The first button (index 0) is active by default.
|
||||
pub fn show_dialog(
|
||||
&mut self,
|
||||
title: &str,
|
||||
message: &str,
|
||||
buttons: Vec<String>,
|
||||
) {
|
||||
self.ui.dialog.dialog_title = title.to_string();
|
||||
self.ui.dialog.dialog_message = message.to_string();
|
||||
self.ui.dialog.dialog_button_active = true;
|
||||
self.ui.dialog.dialog_buttons = buttons;
|
||||
self.ui.dialog.dialog_active_button_index = 0; // Default to first button
|
||||
self.ui.dialog.dialog_show = true; // Use new name
|
||||
}
|
||||
|
||||
/// Hides the dialog and clears its content.
|
||||
pub fn hide_dialog(&mut self) {
|
||||
self.ui.dialog.show_dialog = false;
|
||||
self.ui.dialog.dialog_show = false; // Use new name
|
||||
self.ui.dialog.dialog_title.clear();
|
||||
self.ui.dialog.dialog_message.clear();
|
||||
self.ui.dialog.dialog_buttons.clear();
|
||||
self.ui.dialog.dialog_active_button_index = 0;
|
||||
}
|
||||
|
||||
pub fn set_dialog_button_active(&mut self, active: bool) {
|
||||
self.ui.dialog.dialog_button_active = active;
|
||||
/// Sets the active button index, wrapping around if necessary.
|
||||
pub fn next_dialog_button(&mut self) {
|
||||
if !self.ui.dialog.dialog_buttons.is_empty() {
|
||||
let next_index = (self.ui.dialog.dialog_active_button_index + 1)
|
||||
% self.ui.dialog.dialog_buttons.len();
|
||||
self.ui.dialog.dialog_active_button_index = next_index; // Use new name
|
||||
}
|
||||
}
|
||||
|
||||
/// Sets the active button index, wrapping around if necessary.
|
||||
pub fn previous_dialog_button(&mut self) {
|
||||
if !self.ui.dialog.dialog_buttons.is_empty() {
|
||||
let len = self.ui.dialog.dialog_buttons.len();
|
||||
let prev_index =
|
||||
(self.ui.dialog.dialog_active_button_index + len - 1) % len;
|
||||
self.ui.dialog.dialog_active_button_index = prev_index; // Use new name
|
||||
}
|
||||
}
|
||||
|
||||
/// Gets the label of the currently active button, if any.
|
||||
pub fn get_active_dialog_button_label(&self) -> Option<&str> {
|
||||
self.ui.dialog
|
||||
.dialog_buttons // Use new name
|
||||
.get(self.ui.dialog.dialog_active_button_index) // Use new name
|
||||
.map(|s| s.as_str())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -109,3 +143,16 @@ impl Default for UiState {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Update the Default implementation for DialogState itself
|
||||
impl Default for DialogState {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
dialog_show: false, // Use new name
|
||||
dialog_title: String::new(), // Use new name
|
||||
dialog_message: String::new(), // Use new name
|
||||
dialog_buttons: Vec::new(), // Use new name
|
||||
dialog_active_button_index: 0, // Use new name
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user