Skip to content

Commit cef70fb

Browse files
authored
Merge branch 'main' into fix/repaint-on-tab-close
2 parents 995deed + 2bb89d2 commit cef70fb

9 files changed

Lines changed: 278 additions & 399 deletions

File tree

Cargo.lock

Lines changed: 121 additions & 278 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.lock

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

frontends/rioterm/src/application.rs

Lines changed: 19 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -432,11 +432,10 @@ impl ApplicationHandler<EventPayload> for Application<'_> {
432432
}
433433
}
434434
}
435-
RioEventType::Rio(RioEvent::Exit) => {
435+
RioEventType::Rio(RioEvent::Exit | RioEvent::Quit) => {
436436
if let Some(route) = self.router.routes.get_mut(&window_id) {
437437
if self.config.confirm_before_quit {
438438
route.confirm_quit();
439-
route.request_redraw();
440439
} else {
441440
route.quit();
442441
}
@@ -994,7 +993,6 @@ impl ApplicationHandler<EventPayload> for Application<'_> {
994993

995994
if self.config.confirm_before_quit {
996995
route.confirm_quit();
997-
route.request_redraw();
998996
return;
999997
} else {
1000998
self.router.routes.remove(&window_id);
@@ -1010,7 +1008,9 @@ impl ApplicationHandler<EventPayload> for Application<'_> {
10101008
}
10111009

10121010
WindowEvent::MouseInput { state, button, .. } => {
1013-
if route.path != RoutePath::Terminal {
1011+
if route.path != RoutePath::Terminal
1012+
|| route.window.screen.renderer.confirm_quit.is_active()
1013+
{
10141014
#[cfg(target_os = "macos")]
10151015
if state == ElementState::Pressed
10161016
&& button == MouseButton::Left
@@ -1316,7 +1316,9 @@ impl ApplicationHandler<EventPayload> for Application<'_> {
13161316
route.window.screen.mouse.y = y;
13171317
route.window.screen.mouse.raw_y = position.y;
13181318

1319-
if route.path != RoutePath::Terminal {
1319+
if route.path != RoutePath::Terminal
1320+
|| route.window.screen.renderer.confirm_quit.is_active()
1321+
{
13201322
route.window.winit_window.set_cursor(CursorIcon::Default);
13211323
return;
13221324
}
@@ -1624,7 +1626,9 @@ impl ApplicationHandler<EventPayload> for Application<'_> {
16241626
}
16251627

16261628
WindowEvent::MouseWheel { delta, phase, .. } => {
1627-
if route.path != RoutePath::Terminal {
1629+
if route.path != RoutePath::Terminal
1630+
|| route.window.screen.renderer.confirm_quit.is_active()
1631+
{
16281632
return;
16291633
}
16301634

@@ -1838,18 +1842,7 @@ impl ApplicationHandler<EventPayload> for Application<'_> {
18381842
RoutePath::Welcome => {
18391843
route.window.screen.render_welcome();
18401844
}
1841-
RoutePath::Terminal | RoutePath::ConfirmQuit => {
1842-
if route.path == RoutePath::ConfirmQuit {
1843-
let dim = route.window.screen.ctx().current().dimension;
1844-
crate::router::routes::dialog::screen(
1845-
&mut route.window.screen.sugarloaf,
1846-
&dim,
1847-
"want to quit?",
1848-
"yes (y)",
1849-
"no (n)",
1850-
);
1851-
}
1852-
1845+
RoutePath::Terminal => {
18531846
if let Some(window_update) = route.window.screen.render() {
18541847
use crate::context::renderable::{
18551848
BackgroundState, WindowUpdate,
@@ -1910,16 +1903,14 @@ impl ApplicationHandler<EventPayload> for Application<'_> {
19101903
route.request_redraw();
19111904
event_loop.set_control_flow(ControlFlow::Poll);
19121905
} else {
1913-
if route.path == RoutePath::Welcome
1914-
|| route.path == RoutePath::ConfirmQuit
1915-
|| route
1916-
.window
1917-
.screen
1918-
.ctx()
1919-
.current()
1920-
.renderable_content
1921-
.pending_update
1922-
.is_dirty()
1906+
if route
1907+
.window
1908+
.screen
1909+
.ctx()
1910+
.current()
1911+
.renderable_content
1912+
.pending_update
1913+
.is_dirty()
19231914
{
19241915
route.request_redraw();
19251916
}
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
// Copyright (c) 2023-present, Raphael Amorim.
2+
//
3+
// This source code is licensed under the MIT license found in the
4+
// LICENSE file in the root directory of this source tree.
5+
6+
use rio_backend::sugarloaf::text::DrawOpts;
7+
use rio_backend::sugarloaf::Sugarloaf;
8+
9+
const HEADING: &str = "want to quit?";
10+
const CONFIRM: &str = "yes (y)";
11+
const DISMISS: &str = "no (n)";
12+
13+
#[derive(Default)]
14+
pub struct ConfirmQuit {
15+
active: bool,
16+
}
17+
18+
impl ConfirmQuit {
19+
#[inline]
20+
pub fn is_active(&self) -> bool {
21+
self.active
22+
}
23+
24+
#[inline]
25+
pub fn set_active(&mut self, active: bool) {
26+
self.active = active;
27+
}
28+
29+
/// `dimensions` is `(window_width, window_height, scale_factor)`,
30+
/// matching the other overlays' `render` signature.
31+
pub fn render(&self, sugarloaf: &mut Sugarloaf, dimensions: (f32, f32, f32)) {
32+
if !self.active {
33+
return;
34+
}
35+
36+
let (width, height, scale) = dimensions;
37+
let win_w = width / scale;
38+
let win_h = height / scale;
39+
40+
let full_text = format!("{} {} / {}", HEADING, CONFIRM, DISMISS);
41+
let padding_x = 12.0;
42+
let padding_y = 6.0;
43+
let text_h = 16.0;
44+
let box_w = full_text.len() as f32 * 7.5 + padding_x * 2.0;
45+
let box_h = text_h + padding_y * 2.0;
46+
let box_x = (win_w - box_w) / 2.0;
47+
let box_y = (win_h - box_h) / 2.0;
48+
49+
sugarloaf.rect(
50+
None,
51+
box_x,
52+
box_y,
53+
box_w,
54+
box_h,
55+
[0.0, 0.0, 0.0, 1.0],
56+
0.0,
57+
20,
58+
);
59+
60+
let heading_opts = DrawOpts {
61+
font_size: 13.0,
62+
color: [255, 255, 255, 255],
63+
..DrawOpts::default()
64+
};
65+
let gray_opts = DrawOpts {
66+
font_size: 13.0,
67+
color: [166, 166, 166, 255],
68+
..DrawOpts::default()
69+
};
70+
71+
let text_x = box_x + padding_x;
72+
let text_y = box_y + padding_y + 2.0;
73+
74+
let ui = sugarloaf.text_mut();
75+
let heading_w = ui.draw(text_x, text_y, HEADING, &heading_opts);
76+
ui.draw(
77+
text_x + heading_w,
78+
text_y,
79+
&format!(" {} / {}", CONFIRM, DISMISS),
80+
&gray_opts,
81+
);
82+
}
83+
}

frontends/rioterm/src/renderer/mod.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
pub mod assistant;
22
pub mod command_palette;
3+
pub mod confirm_quit;
34
pub mod custom_cursor;
45
pub mod helpers;
56
pub mod island;
@@ -66,6 +67,7 @@ pub struct Renderer {
6667
pub(crate) ignore_selection_fg_color: bool,
6768
pub search: search::SearchOverlay,
6869
pub assistant: assistant::AssistantOverlay,
70+
pub confirm_quit: confirm_quit::ConfirmQuit,
6971
pub scrollbar: scrollbar::Scrollbar,
7072
#[allow(unused)]
7173
pub option_as_alt: String,
@@ -153,6 +155,7 @@ impl Renderer {
153155
window_bg_alpha: target_bg_alpha,
154156
search: search::SearchOverlay::default(),
155157
assistant: assistant::AssistantOverlay::default(),
158+
confirm_quit: confirm_quit::ConfirmQuit::default(),
156159
scrollbar: scrollbar::Scrollbar::new(config.enable_scroll_bar),
157160
is_game_mode_enabled: config.renderer.strategy.is_game(),
158161
custom_mouse_cursor: config.effects.custom_mouse_cursor,
@@ -597,6 +600,11 @@ impl Renderer {
597600
(window_size.width, window_size.height, scale_factor),
598601
);
599602

603+
self.confirm_quit.render(
604+
sugarloaf,
605+
(window_size.width, window_size.height, scale_factor),
606+
);
607+
600608
// Render scrollbars for each panel
601609
let grid_scaled_margin_sb = context_manager.get_current_grid_scaled_margin();
602610
let grid_margin_sb = (grid_scaled_margin_sb.left, grid_scaled_margin_sb.top);

frontends/rioterm/src/router/mod.rs

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,8 @@ impl Route<'_> {
131131

132132
#[inline]
133133
pub fn confirm_quit(&mut self) {
134-
self.path = RoutePath::ConfirmQuit;
134+
self.window.screen.renderer.confirm_quit.set_active(true);
135+
self.request_overlay_redraw();
135136
}
136137

137138
#[inline]
@@ -313,30 +314,16 @@ impl Route<'_> {
313314
return true; // Block all input when command palette is active
314315
}
315316

316-
if self.path == RoutePath::Terminal {
317-
return false;
318-
}
319-
320-
let is_enter = key_event.logical_key == Key::Named(NamedKey::Enter);
321-
322-
// Handle assistant overlay dismiss
323-
if self.window.screen.renderer.assistant.is_active() {
324-
if is_enter {
325-
self.assistant.clear();
326-
self.window.screen.renderer.assistant.clear();
327-
self.request_overlay_redraw();
328-
}
329-
return true;
330-
}
331-
332-
if self.path == RoutePath::ConfirmQuit {
317+
if self.window.screen.renderer.confirm_quit.is_active() {
333318
if key_event.state == rio_window::event::ElementState::Pressed {
334319
match &key_event.logical_key {
335320
Key::Character(c) if c.as_str() == "n" || c.as_str() == "N" => {
336-
self.path = RoutePath::Terminal;
321+
self.window.screen.renderer.confirm_quit.set_active(false);
322+
self.request_overlay_redraw();
337323
}
338324
Key::Named(NamedKey::Escape) => {
339-
self.path = RoutePath::Terminal;
325+
self.window.screen.renderer.confirm_quit.set_active(false);
326+
self.request_overlay_redraw();
340327
}
341328
Key::Character(c) if c.as_str() == "y" || c.as_str() == "Y" => {
342329
self.quit();
@@ -348,6 +335,22 @@ impl Route<'_> {
348335
return true;
349336
}
350337

338+
if self.path == RoutePath::Terminal {
339+
return false;
340+
}
341+
342+
let is_enter = key_event.logical_key == Key::Named(NamedKey::Enter);
343+
344+
// Handle assistant overlay dismiss
345+
if self.window.screen.renderer.assistant.is_active() {
346+
if is_enter {
347+
self.assistant.clear();
348+
self.window.screen.renderer.assistant.clear();
349+
self.request_overlay_redraw();
350+
}
351+
return true;
352+
}
353+
351354
if self.path == RoutePath::Welcome && is_enter {
352355
rio_backend::config::create_config_file(None);
353356
self.path = RoutePath::Terminal;

frontends/rioterm/src/router/routes/dialog.rs

Lines changed: 0 additions & 64 deletions
This file was deleted.
Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
pub mod assistant;
2-
pub mod dialog;
32
pub mod welcome;
43

54
#[derive(PartialEq)]
65
pub enum RoutePath {
76
Terminal,
87
Welcome,
9-
ConfirmQuit,
108
}

0 commit comments

Comments
 (0)