Extract cursor proportion calculations
This commit is contained in:
parent
eeb350aef4
commit
bec12917d6
3 changed files with 19 additions and 6 deletions
|
|
@ -1,7 +1,7 @@
|
|||
//! Constants and helper functions.
|
||||
|
||||
use crossterm::style::{ContentStyle, Stylize};
|
||||
use toss::frame::Frame;
|
||||
use toss::frame::{Frame, Size};
|
||||
|
||||
pub const TIME_FORMAT: &str = "%H:%M ";
|
||||
pub const TIME_EMPTY: &str = " ";
|
||||
|
|
@ -42,3 +42,15 @@ pub fn after_indent(indent: usize) -> i32 {
|
|||
pub fn after_nick(frame: &mut Frame, indent: usize, nick: &str) -> i32 {
|
||||
after_indent(indent) + 1 + frame.width(nick) as i32 + 2
|
||||
}
|
||||
|
||||
pub fn proportion_to_line(height: u16, proportion: f32) -> i32 {
|
||||
((height - 1) as f32 * proportion).ceil() as i32
|
||||
}
|
||||
|
||||
pub fn line_to_proportion(height: u16, line: i32) -> f32 {
|
||||
if height > 1 {
|
||||
line as f32 / (height - 1) as f32
|
||||
} else {
|
||||
0.0
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue