egui/emigui/src/types.rs

122 lines
2.7 KiB
Rust
Raw Normal View History

use serde_derive::Serialize;
2019-01-12 23:55:56 +00:00
use crate::{
2019-04-25 16:07:36 +00:00
color::Color,
2019-01-12 23:55:56 +00:00
fonts::TextStyle,
2020-05-03 11:28:47 +00:00
math::{Pos2, Rect},
2020-04-19 21:34:34 +00:00
mesher::{Mesh, Path},
2019-01-12 23:55:56 +00:00
};
2018-12-23 19:06:40 +00:00
2018-12-26 09:46:23 +00:00
// ----------------------------------------------------------------------------
2020-04-23 17:15:17 +00:00
#[derive(Clone, Default, Serialize)]
pub struct Output {
pub cursor_icon: CursorIcon,
2020-04-29 19:25:49 +00:00
2020-04-23 17:15:17 +00:00
/// If set, open this url.
pub open_url: Option<String>,
2020-04-29 19:25:49 +00:00
/// Response to Event::Copy or Event::Cut. Ignore if empty.
pub copied_text: String,
2020-04-23 17:15:17 +00:00
}
#[derive(Clone, Copy, Serialize)]
#[serde(rename_all = "snake_case")]
pub enum CursorIcon {
Default,
/// Pointing hand, used for e.g. web links
PointingHand,
ResizeNwSe,
2020-04-29 19:25:49 +00:00
Text,
2020-04-23 17:15:17 +00:00
}
impl Default for CursorIcon {
fn default() -> Self {
Self::Default
2020-04-23 17:15:17 +00:00
}
}
2018-12-26 09:46:23 +00:00
// ----------------------------------------------------------------------------
2018-12-26 13:38:46 +00:00
#[derive(Clone, Copy, Debug, Default, Serialize)]
pub struct InteractInfo {
/// The mouse is hovering above this thing
2018-12-26 13:38:46 +00:00
pub hovered: bool,
2018-12-26 14:28:38 +00:00
/// The mouse pressed this thing ealier, and now released on this thing too.
2018-12-26 13:38:46 +00:00
pub clicked: bool,
2018-12-26 14:28:38 +00:00
/// The mouse is interacting with this thing (e.g. dragging it or holding it)
2018-12-26 14:28:38 +00:00
pub active: bool,
2019-01-14 13:26:02 +00:00
/// The region of the screen we are talking about
pub rect: Rect,
2018-12-26 13:38:46 +00:00
}
// ----------------------------------------------------------------------------
2018-12-26 16:32:58 +00:00
#[derive(Clone, Debug, Serialize)]
pub struct Outline {
pub width: f32,
2018-12-27 16:47:32 +00:00
pub color: Color,
2018-12-26 16:32:58 +00:00
}
2020-04-19 09:11:41 +00:00
impl Outline {
pub fn new(width: impl Into<f32>, color: impl Into<Color>) -> Self {
Self {
width: width.into(),
color: color.into(),
}
}
}
2020-04-19 21:34:34 +00:00
#[derive(Clone, Debug)]
2018-12-23 19:06:40 +00:00
pub enum PaintCmd {
2018-12-26 21:26:15 +00:00
Circle {
center: Pos2,
2018-12-27 16:47:32 +00:00
fill_color: Option<Color>,
2018-12-26 21:26:15 +00:00
outline: Option<Outline>,
radius: f32,
},
2018-12-26 21:17:33 +00:00
Line {
points: Vec<Pos2>,
2018-12-27 16:47:32 +00:00
color: Color,
2018-12-26 21:17:33 +00:00
width: f32,
},
2020-04-19 21:34:34 +00:00
Path {
path: Path,
closed: bool,
fill_color: Option<Color>,
outline: Option<Outline>,
},
2018-12-26 16:32:58 +00:00
Rect {
2020-04-20 22:17:02 +00:00
rect: Rect,
2018-12-26 16:32:58 +00:00
corner_radius: f32,
2018-12-27 16:47:32 +00:00
fill_color: Option<Color>,
2018-12-26 16:32:58 +00:00
outline: Option<Outline>,
2018-12-23 19:06:40 +00:00
},
2019-01-05 14:28:07 +00:00
/// Paint a single line of text
2018-12-23 19:06:40 +00:00
Text {
2019-01-05 14:28:07 +00:00
color: Color,
/// Top left corner of the first character.
pos: Pos2,
2018-12-23 19:06:40 +00:00
text: String,
2019-01-12 23:55:56 +00:00
text_style: TextStyle,
2019-01-05 14:28:07 +00:00
/// Start each character in the text, as offset from pos.
x_offsets: Vec<f32>,
// TODO: font info
2018-12-23 19:06:40 +00:00
},
2019-03-11 14:30:32 +00:00
/// Low-level triangle mesh
Mesh(Mesh),
2018-12-23 19:06:40 +00:00
}
2020-04-25 12:37:39 +00:00
impl PaintCmd {
pub fn line_segment(seg: (Pos2, Pos2), color: Color, width: f32) -> Self {
Self::Line {
points: vec![seg.0, seg.1],
color,
width,
}
}
}