spinners and fmt
This commit is contained in:
+29
-13
@@ -1,15 +1,15 @@
|
||||
use std::cell::RefCell;
|
||||
use std::rc::Rc;
|
||||
use std::time::Duration;
|
||||
use kiln_core::Board;
|
||||
use kiln_core::game::GameState;
|
||||
use crate::animation::Animation;
|
||||
use crate::editor::EditorState;
|
||||
use crate::log::LogState;
|
||||
use crate::menu::{MenuItem, MenuCloseAnimation, MenuOpenAnimation, MenuState};
|
||||
use crate::menu::{MenuCloseAnimation, MenuItem, MenuOpenAnimation, MenuState};
|
||||
use crate::mode::{Mode, PendingMode};
|
||||
use crate::scroll_overlay::{ScrollCloseAnimation, ScrollOpenAnimation, ScrollOverlayState};
|
||||
use crate::transition::TransitionAnimation;
|
||||
use kiln_core::Board;
|
||||
use kiln_core::game::GameState;
|
||||
use std::cell::RefCell;
|
||||
use std::rc::Rc;
|
||||
use std::time::Duration;
|
||||
|
||||
/// A pair of board `Rc`s (old board, new board) queued for transition pre-rendering.
|
||||
type PendingTransition = Option<(Rc<RefCell<Board>>, Rc<RefCell<Board>>)>;
|
||||
@@ -66,8 +66,8 @@ impl Default for Ui {
|
||||
impl Ui {
|
||||
/// Scrolls the scroll overlay by `delta` lines, clamped to the valid range.
|
||||
pub(crate) fn scroll_lines(&mut self, delta: i32) {
|
||||
self.overlay.offset = (self.overlay.offset as i32 + delta)
|
||||
.clamp(0, self.overlay.max_scroll as i32) as u16;
|
||||
self.overlay.offset =
|
||||
(self.overlay.offset as i32 + delta).clamp(0, self.overlay.max_scroll as i32) as u16;
|
||||
}
|
||||
|
||||
/// Scrolls the menu overlay by `delta` lines, clamped to the valid range.
|
||||
@@ -80,14 +80,21 @@ impl Ui {
|
||||
/// Opens a menu: stores the items as [`MenuState`] and starts the open animation.
|
||||
pub(crate) fn open_menu(&mut self, items: Vec<MenuItem>) {
|
||||
self.active_animation = Some(Box::new(MenuOpenAnimation::new(items.clone())));
|
||||
self.menu = Some(MenuState { items, ..Default::default() });
|
||||
self.menu = Some(MenuState {
|
||||
items,
|
||||
..Default::default()
|
||||
});
|
||||
}
|
||||
|
||||
/// Starts the close animation using a snapshot of the current menu items.
|
||||
///
|
||||
/// Called from within a menu item's action closure (e.g. `ui.begin_close_menu()`).
|
||||
pub(crate) fn begin_close_menu(&mut self) {
|
||||
let items = self.menu.as_ref().map(|m| m.items.clone()).unwrap_or_default();
|
||||
let items = self
|
||||
.menu
|
||||
.as_ref()
|
||||
.map(|m| m.items.clone())
|
||||
.unwrap_or_default();
|
||||
self.active_animation = Some(Box::new(MenuCloseAnimation::new(items)));
|
||||
}
|
||||
|
||||
@@ -111,7 +118,9 @@ impl Ui {
|
||||
// Returning to Board mode: eagerly clear scroll and menu state so
|
||||
// neither renders as open for one extra frame before the next tick.
|
||||
if matches!(after, crate::input::InputMode::Board) {
|
||||
if let Mode::Play(game) = mode { game.handle_scroll(); }
|
||||
if let Mode::Play(game) = mode {
|
||||
game.handle_scroll();
|
||||
}
|
||||
self.menu = None;
|
||||
}
|
||||
}
|
||||
@@ -147,7 +156,9 @@ impl Ui {
|
||||
if let Some(scroll) = game.active_scroll.as_mut() {
|
||||
scroll.choice = choice;
|
||||
}
|
||||
let lines = game.active_scroll.as_ref()
|
||||
let lines = game
|
||||
.active_scroll
|
||||
.as_ref()
|
||||
.map(|s| s.lines.clone())
|
||||
.unwrap_or_default();
|
||||
self.active_animation = Some(Box::new(ScrollCloseAnimation::new(lines)));
|
||||
@@ -157,7 +168,12 @@ impl Ui {
|
||||
///
|
||||
/// Called from `draw_board_area` when [`pending_transition`](Ui::pending_transition)
|
||||
/// is set, so the [`TransitionAnimation`] is sized to the exact inner board area.
|
||||
pub(crate) fn start_transition(&mut self, old: &Board, new: &Board, area: ratatui::layout::Rect) {
|
||||
pub(crate) fn start_transition(
|
||||
&mut self,
|
||||
old: &Board,
|
||||
new: &Board,
|
||||
area: ratatui::layout::Rect,
|
||||
) {
|
||||
self.active_animation = Some(Box::new(TransitionAnimation::new(old, new, area)));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user