mirror of
https://github.com/LGUG2Z/komorebi.git
synced 2026-04-24 09:38:32 +02:00
feat(wm): initial commit
One week of blissful, in-the-zone coding, applying all of the lessons learnt from the development of yatta.
This commit is contained in:
34
komorebi-core/src/cycle_direction.rs
Normal file
34
komorebi-core/src/cycle_direction.rs
Normal file
@@ -0,0 +1,34 @@
|
||||
use clap::Clap;
|
||||
use serde::Deserialize;
|
||||
use serde::Serialize;
|
||||
use strum::Display;
|
||||
use strum::EnumString;
|
||||
|
||||
#[derive(Clone, Copy, Debug, Serialize, Deserialize, Display, EnumString)]
|
||||
#[strum(serialize_all = "snake_case")]
|
||||
#[derive(Clap)]
|
||||
pub enum CycleDirection {
|
||||
Previous,
|
||||
Next,
|
||||
}
|
||||
|
||||
impl CycleDirection {
|
||||
pub fn next_idx(&self, idx: usize, len: usize) -> usize {
|
||||
match self {
|
||||
CycleDirection::Previous => {
|
||||
if idx == 0 {
|
||||
len - 1
|
||||
} else {
|
||||
idx - 1
|
||||
}
|
||||
}
|
||||
CycleDirection::Next => {
|
||||
if idx == len - 1 {
|
||||
0
|
||||
} else {
|
||||
idx + 1
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user