mirror of
https://github.com/LGUG2Z/komorebi.git
synced 2026-05-20 18:56:59 +02:00
refactor(layouts): extract independent komorebi-layouts crate
This commit moves layout-related code into a new workspace crate komorebi-layouts, with the intention of re-using it all in komorebi for Mac instead of maintaining two separate implementations.
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
use std::num::NonZeroUsize;
|
||||
|
||||
use clap::ValueEnum;
|
||||
use serde::Deserialize;
|
||||
use serde::Serialize;
|
||||
use strum::Display;
|
||||
use strum::EnumString;
|
||||
|
||||
#[derive(Clone, Copy, Debug, Serialize, Deserialize, Display, EnumString, ValueEnum)]
|
||||
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
|
||||
pub enum CycleDirection {
|
||||
Previous,
|
||||
Next,
|
||||
}
|
||||
|
||||
impl CycleDirection {
|
||||
#[must_use]
|
||||
pub const fn next_idx(&self, idx: usize, len: NonZeroUsize) -> usize {
|
||||
match self {
|
||||
Self::Previous => {
|
||||
if idx == 0 {
|
||||
len.get() - 1
|
||||
} else {
|
||||
idx - 1
|
||||
}
|
||||
}
|
||||
Self::Next => {
|
||||
if idx == len.get() - 1 {
|
||||
0
|
||||
} else {
|
||||
idx + 1
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user