Skip to main content

dear_imgui_rs/style/
direction.rs

1#![allow(
2    clippy::cast_possible_truncation,
3    clippy::cast_sign_loss,
4    clippy::as_conversions
5)]
6
7use crate::sys;
8
9/// A cardinal direction
10#[repr(i32)]
11#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)]
12pub enum Direction {
13    None = sys::ImGuiDir_None as i32,
14    Left = sys::ImGuiDir_Left as i32,
15    Right = sys::ImGuiDir_Right as i32,
16    Up = sys::ImGuiDir_Up as i32,
17    Down = sys::ImGuiDir_Down as i32,
18}
19
20impl From<sys::ImGuiDir> for Direction {
21    fn from(d: sys::ImGuiDir) -> Self {
22        match d as i32 {
23            x if x == sys::ImGuiDir_Left as i32 => Direction::Left,
24            x if x == sys::ImGuiDir_Right as i32 => Direction::Right,
25            x if x == sys::ImGuiDir_Up as i32 => Direction::Up,
26            x if x == sys::ImGuiDir_Down as i32 => Direction::Down,
27            _ => Direction::None,
28        }
29    }
30}
31
32impl From<Direction> for sys::ImGuiDir {
33    fn from(d: Direction) -> Self {
34        match d {
35            Direction::None => sys::ImGuiDir_None,
36            Direction::Left => sys::ImGuiDir_Left,
37            Direction::Right => sys::ImGuiDir_Right,
38            Direction::Up => sys::ImGuiDir_Up,
39            Direction::Down => sys::ImGuiDir_Down,
40        }
41    }
42}