feat: enhance settings dialog with close button and hover effects

This commit is contained in:
2026-03-29 03:43:05 +02:00
parent 318928ded3
commit 9afb4adaca
5 changed files with 48 additions and 10 deletions

View File

@@ -7,13 +7,8 @@
"text_editor": "msedit",
"custom_menu_items": [
{
"name": "Nytt kommando",
"command": "echo $[path]",
"applies_to": "Both"
},
{
"name": "Nytt kommando",
"command": "echo $[path]",
"name": "Open In VS Code",
"command": "code $[path]",
"applies_to": "Both"
}
]

Binary file not shown.

View File

@@ -103,6 +103,8 @@ pub struct App {
pub settings_editing_field: Option<SettingsField>, // which field is being edited
pub settings_editing_buf: String, // current text in the edited field
pub settings_custom_selected: usize, // which custom item row is selected
/// Which button on the action-button row is hovered: 0 = [+ Ny], 1 = [Ta bort], None = neither
pub settings_hover_button: Option<u8>,
// Terminal capabilities
pub unicode_support: bool,
}
@@ -177,6 +179,7 @@ impl App {
settings_editing_field: None,
settings_editing_buf: String::new(),
settings_custom_selected: 0,
settings_hover_button: None,
unicode_support: detect_unicode_support(),
}
}

View File

@@ -542,6 +542,17 @@ fn settings_activate(app: &mut App) {
pub fn settings_click(app: &mut App, col: u16, row: u16, dlg: ratatui::layout::Rect) {
if col < dlg.x || col >= dlg.x + dlg.width { return; }
if row < dlg.y || row >= dlg.y + dlg.height { return; }
// [X] close button on the top border row
if row == dlg.y {
let close_x = dlg.x + dlg.width.saturating_sub(5);
if col >= close_x && col < close_x + 3 {
app.dialog = DialogMode::None;
return;
}
return;
}
let inner_y = dlg.y + 1; // top border
let inner_x = dlg.x + 1;
let inner_w = dlg.width.saturating_sub(2);
@@ -914,19 +925,36 @@ fn handle_mouse_move(app: &mut App, col: u16, row: u16) {
&& row > dlg.y && row < dlg.y + dlg.height.saturating_sub(1)
{
let inner_y = dlg.y + 1;
let inner_x = dlg.x + 1;
let list_row = (row - inner_y) as usize;
let custom_count = app.config.custom_menu_items.len();
let btn_lr = if custom_count == 0 { 7 } else { 6 + custom_count };
let save_lr = btn_lr + 1;
if list_row == 1 {
app.settings_selected_row = 1;
app.settings_hover_button = None;
} else if list_row >= 5 && custom_count > 0 && list_row < 5 + custom_count {
app.settings_selected_row = 4 + (list_row - 5);
app.settings_hover_button = None;
} else if list_row == btn_lr {
app.settings_selected_row = 4 + custom_count;
// Determine which button the mouse is over
let col_rel = col.saturating_sub(inner_x) as usize;
if col_rel < 10 {
app.settings_hover_button = Some(0); // [+ Ny]
} else if col_rel < 22 {
app.settings_hover_button = Some(1); // [Ta bort]
} else {
app.settings_hover_button = None;
}
} else if list_row == save_lr {
app.settings_selected_row = 5 + custom_count;
app.settings_hover_button = None;
} else {
app.settings_hover_button = None;
}
} else {
app.settings_hover_button = None;
}
return;
}

View File

@@ -678,6 +678,16 @@ fn draw_settings(f: &mut Frame, app: &App, right_edge: u16) {
let inner = block.inner(area);
f.render_widget(block, area);
// ── [X] close button in top-right corner of the border ───────────────────
let close_label = "[X]";
let close_x = area.x + area.width.saturating_sub(close_label.len() as u16 + 2);
f.render_widget(
Paragraph::new(close_label).style(
Style::default().fg(Color::Red).add_modifier(Modifier::BOLD)
),
Rect::new(close_x, area.y, close_label.len() as u16, 1),
);
let sel = app.settings_selected_row;
let editing = &app.settings_editing_field;
let buf = &app.settings_editing_buf;
@@ -815,14 +825,16 @@ fn draw_settings(f: &mut Frame, app: &App, right_edge: u16) {
// ── Action buttons row ────────────────────────────────────────────────────
if row_y < inner.y + inner.height.saturating_sub(2) {
let is_btn_sel = sel == 4 + custom_count;
let is_btn_row = sel == 4 + custom_count;
let hover_add = is_btn_row && app.settings_hover_button == Some(0);
let hover_del = is_btn_row && app.settings_hover_button == Some(1);
let btn_add_s = if is_btn_sel {
let btn_add_s = if hover_add {
Style::default().fg(Color::Black).bg(Color::Green).add_modifier(Modifier::BOLD)
} else {
Style::default().fg(Color::Green).add_modifier(Modifier::BOLD)
};
let btn_del_s = if is_btn_sel {
let btn_del_s = if hover_del {
Style::default().fg(Color::White).bg(Color::Red).add_modifier(Modifier::BOLD)
} else {
Style::default().fg(Color::Red)