Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 40 additions & 1 deletion src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,30 @@ pub type AppResult<T> = anyhow::Result<T>;

const STAR_SYMBOL: &str = "★";

#[derive(Debug, Clone, Copy, PartialEq)]
pub enum HelpAction {
ScrollUp,
ScrollDown,
ToggleConnect,
Unpair,
ToggleTrust,
ToggleFavorite,
Rename,
ToggleScan,
Pair,
TogglePairing,
TogglePower,
ToggleDiscovery,
}

#[derive(Debug, Clone)]
pub struct ClickableHelpItem {
pub x_start: u16,
pub x_end: u16,
pub y: u16,
pub action: Option<HelpAction>,
}

#[derive(Debug, Clone, Copy, PartialEq)]
pub enum FocusedBlock {
Adapter,
Expand Down Expand Up @@ -68,6 +92,11 @@ pub struct App {
pub config: Arc<Config>,
pub requests: Requests,
pub auth_agent: AuthAgent,
pub adapter_block_bounds: Option<Rect>,
pub paired_devices_block_bounds: Option<Rect>,
pub new_devices_block_bounds: Option<Rect>,
pub help_block_bounds: Option<Rect>,
pub help_sections: Vec<ClickableHelpItem>,
}

impl App {
Expand Down Expand Up @@ -130,6 +159,11 @@ impl App {
config,
requests: Requests::default(),
auth_agent,
adapter_block_bounds: None,
paired_devices_block_bounds: None,
new_devices_block_bounds: None,
help_block_bounds: None,
Comment on lines +162 to +165
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't love introducing partial initialization to App.

Do you think we could get with initializing them as Rect::ZERO instead, then resizing once we know?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes looks like a good switch. At first glance I thought it might make it less explicit but after a little thought I think you're right. Using zero for default bounds shouldn't be hard to swap in.

help_sections: Vec::new(),
})
}

Expand Down Expand Up @@ -308,6 +342,10 @@ impl App {
(chunks[0], chunks[1], chunks[2], chunks[3])
};

self.adapter_block_bounds = Some(controller_block);
self.paired_devices_block_bounds = Some(paired_devices_block);
self.new_devices_block_bounds = render_new_devices.then_some(new_devices_block);

//Adapters
let rows: Vec<Row> = self
.controllers
Expand Down Expand Up @@ -697,7 +735,8 @@ impl App {
let area = self.area(frame);

// Help
Help::render(
self.help_block_bounds = Some(help_block);
self.help_sections = Help::render(
frame,
area,
self.focused_block,
Expand Down
Loading