mirror of
https://github.com/FliegendeWurst/cursive.git
synced 2024-11-24 01:46:31 +00:00
Derive more stuff
This commit is contained in:
parent
96919c6561
commit
d31d0d0d76
@ -1,7 +1,7 @@
|
|||||||
//! Tools to control view alignment.
|
//! Tools to control view alignment.
|
||||||
|
|
||||||
/// Specifies the alignment along both horizontal and vertical directions.
|
/// Specifies the alignment along both horizontal and vertical directions.
|
||||||
#[derive(Debug, Clone, Copy)]
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||||
pub struct Align {
|
pub struct Align {
|
||||||
/// Horizontal alignment policy
|
/// Horizontal alignment policy
|
||||||
pub h: HAlign,
|
pub h: HAlign,
|
||||||
@ -62,7 +62,7 @@ impl Align {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Horizontal alignment
|
/// Horizontal alignment
|
||||||
#[derive(Debug, Clone, Copy)]
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||||
pub enum HAlign {
|
pub enum HAlign {
|
||||||
/// Place the element to the left of available space
|
/// Place the element to the left of available space
|
||||||
Left,
|
Left,
|
||||||
@ -73,7 +73,7 @@ pub enum HAlign {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Vertical alignment
|
/// Vertical alignment
|
||||||
#[derive(Debug, Clone, Copy)]
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||||
pub enum VAlign {
|
pub enum VAlign {
|
||||||
/// Place the element at the top of available space
|
/// Place the element at the top of available space
|
||||||
Top,
|
Top,
|
||||||
|
@ -30,7 +30,7 @@ use crate::Vec2;
|
|||||||
use crate::XY;
|
use crate::XY;
|
||||||
|
|
||||||
/// Describes a vertical or horizontal orientation for a view.
|
/// Describes a vertical or horizontal orientation for a view.
|
||||||
#[derive(Clone, Copy, Debug, PartialEq)]
|
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
|
||||||
pub enum Orientation {
|
pub enum Orientation {
|
||||||
/// Horizontal orientation
|
/// Horizontal orientation
|
||||||
Horizontal,
|
Horizontal,
|
||||||
@ -126,7 +126,7 @@ impl Orientation {
|
|||||||
///
|
///
|
||||||
/// * Absolute directions are Up, Down, Left, and Right.
|
/// * Absolute directions are Up, Down, Left, and Right.
|
||||||
/// * Relative directions are Front and Back.
|
/// * Relative directions are Front and Back.
|
||||||
#[derive(Debug, Clone, Copy, PartialEq)]
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||||
pub enum Direction {
|
pub enum Direction {
|
||||||
/// An absolute direction.
|
/// An absolute direction.
|
||||||
Abs(Absolute),
|
Abs(Absolute),
|
||||||
@ -199,7 +199,7 @@ impl Direction {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Direction relative to an orientation.
|
/// Direction relative to an orientation.
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||||
pub enum Relative {
|
pub enum Relative {
|
||||||
// TODO: handle right-to-left? (Arabic, ...)
|
// TODO: handle right-to-left? (Arabic, ...)
|
||||||
/// Front relative direction.
|
/// Front relative direction.
|
||||||
@ -261,7 +261,7 @@ impl Relative {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Absolute direction (up, down, left, right).
|
/// Absolute direction (up, down, left, right).
|
||||||
#[derive(Debug, Clone, Copy, PartialEq)]
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||||
pub enum Absolute {
|
pub enum Absolute {
|
||||||
/// Left
|
/// Left
|
||||||
Left,
|
Left,
|
||||||
|
@ -5,7 +5,7 @@ use crate::Vec2;
|
|||||||
use std::ops::Add;
|
use std::ops::Add;
|
||||||
|
|
||||||
/// A non-empty rectangle on the 2D grid.
|
/// A non-empty rectangle on the 2D grid.
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||||
pub struct Rect {
|
pub struct Rect {
|
||||||
/// Top-left corner, inclusive
|
/// Top-left corner, inclusive
|
||||||
top_left: Vec2,
|
top_left: Vec2,
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
use enumset::EnumSetType;
|
use enumset::EnumSetType;
|
||||||
|
|
||||||
/// Text effect
|
/// Text effect
|
||||||
#[derive(EnumSetType, Debug)]
|
#[derive(EnumSetType, Debug, Hash)]
|
||||||
pub enum Effect {
|
pub enum Effect {
|
||||||
/// No effect
|
/// No effect
|
||||||
Simple,
|
Simple,
|
||||||
|
@ -4,7 +4,7 @@ use enumset::{enum_set, EnumSet};
|
|||||||
/// Combine a color and an effect.
|
/// Combine a color and an effect.
|
||||||
///
|
///
|
||||||
/// Represents any transformation that can be applied to text.
|
/// Represents any transformation that can be applied to text.
|
||||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
|
||||||
pub struct Style {
|
pub struct Style {
|
||||||
/// Effect to apply.
|
/// Effect to apply.
|
||||||
///
|
///
|
||||||
|
@ -4,7 +4,7 @@ use crate::With;
|
|||||||
///
|
///
|
||||||
/// A row is made of offsets into a parent `String`.
|
/// A row is made of offsets into a parent `String`.
|
||||||
/// The corresponding substring should take `width` cells when printed.
|
/// The corresponding substring should take `width` cells when printed.
|
||||||
#[derive(Debug, Clone, Copy)]
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||||
pub struct Row {
|
pub struct Row {
|
||||||
/// Beginning of the row in the parent `String`.
|
/// Beginning of the row in the parent `String`.
|
||||||
pub start: usize,
|
pub start: usize,
|
||||||
|
@ -3,7 +3,7 @@ use super::segment::Segment;
|
|||||||
/// Non-splittable piece of text.
|
/// Non-splittable piece of text.
|
||||||
///
|
///
|
||||||
/// It is made of a list of segments of text.
|
/// It is made of a list of segments of text.
|
||||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||||
pub struct Chunk {
|
pub struct Chunk {
|
||||||
/// Total width of this chunk.
|
/// Total width of this chunk.
|
||||||
pub width: usize,
|
pub width: usize,
|
||||||
@ -81,7 +81,7 @@ impl Chunk {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default, Hash)]
|
||||||
/// Describes a part of a chunk.
|
/// Describes a part of a chunk.
|
||||||
///
|
///
|
||||||
/// Includes both length and width to ease some computations.
|
/// Includes both length and width to ease some computations.
|
||||||
|
@ -2,7 +2,7 @@ use super::Segment;
|
|||||||
use crate::utils::span::{IndexedCow, Span, SpannedStr};
|
use crate::utils::span::{IndexedCow, Span, SpannedStr};
|
||||||
|
|
||||||
/// A list of segments representing a row of text
|
/// A list of segments representing a row of text
|
||||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||||
pub struct Row {
|
pub struct Row {
|
||||||
/// List of segments
|
/// List of segments
|
||||||
pub segments: Vec<Segment>,
|
pub segments: Vec<Segment>,
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
use crate::utils::span::{IndexedCow, Span, SpannedStr, SpannedText};
|
use crate::utils::span::{IndexedCow, Span, SpannedStr, SpannedText};
|
||||||
|
|
||||||
/// Refers to a part of a span
|
/// Refers to a part of a span
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||||
pub struct Segment {
|
pub struct Segment {
|
||||||
/// ID of the span this segment refers to
|
/// ID of the span this segment refers to
|
||||||
pub span_id: usize,
|
pub span_id: usize,
|
||||||
|
@ -8,14 +8,14 @@ use unicode_width::UnicodeWidthStr;
|
|||||||
/// A string with associated spans.
|
/// A string with associated spans.
|
||||||
///
|
///
|
||||||
/// Each span has an associated attribute `T`.
|
/// Each span has an associated attribute `T`.
|
||||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||||
pub struct SpannedString<T> {
|
pub struct SpannedString<T> {
|
||||||
source: String,
|
source: String,
|
||||||
spans: Vec<IndexedSpan<T>>,
|
spans: Vec<IndexedSpan<T>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The immutable, borrowed equivalent of `SpannedString`.
|
/// The immutable, borrowed equivalent of `SpannedString`.
|
||||||
#[derive(Debug, PartialEq, Eq)]
|
#[derive(Debug, PartialEq, Eq, Hash)]
|
||||||
pub struct SpannedStr<'a, T> {
|
pub struct SpannedStr<'a, T> {
|
||||||
source: &'a str,
|
source: &'a str,
|
||||||
spans: &'a [IndexedSpan<T>],
|
spans: &'a [IndexedSpan<T>],
|
||||||
@ -261,7 +261,7 @@ impl<'a, T> From<&'a SpannedString<T>> for SpannedStr<'a, T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// An indexed span with an associated attribute.
|
/// An indexed span with an associated attribute.
|
||||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||||
pub struct IndexedSpan<T> {
|
pub struct IndexedSpan<T> {
|
||||||
/// Content of the span.
|
/// Content of the span.
|
||||||
pub content: IndexedCow,
|
pub content: IndexedCow,
|
||||||
@ -280,7 +280,7 @@ impl<T> AsRef<IndexedCow> for IndexedSpan<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// A resolved span borrowing its source string.
|
/// A resolved span borrowing its source string.
|
||||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||||
pub struct Span<'a, T> {
|
pub struct Span<'a, T> {
|
||||||
/// Content of this span.
|
/// Content of this span.
|
||||||
pub content: &'a str,
|
pub content: &'a str,
|
||||||
@ -334,7 +334,7 @@ impl<T> IndexedSpan<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// A span of text that can be either owned, or indexed in another String.
|
/// A span of text that can be either owned, or indexed in another String.
|
||||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||||
pub enum IndexedCow {
|
pub enum IndexedCow {
|
||||||
/// Indexes content in a separate string.
|
/// Indexes content in a separate string.
|
||||||
Borrowed {
|
Borrowed {
|
||||||
|
@ -2,7 +2,7 @@ use crate::Vec2;
|
|||||||
use std::ops::{Add, Div, Mul, Sub};
|
use std::ops::{Add, Div, Mul, Sub};
|
||||||
|
|
||||||
/// Four values representing each direction.
|
/// Four values representing each direction.
|
||||||
#[derive(Clone, Copy)]
|
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
|
||||||
pub struct Margins {
|
pub struct Margins {
|
||||||
/// Left margin
|
/// Left margin
|
||||||
pub left: usize,
|
pub left: usize,
|
||||||
|
@ -52,7 +52,7 @@ impl Position {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Single-dimensional offset policy.
|
/// Single-dimensional offset policy.
|
||||||
#[derive(PartialEq, Debug, Clone)]
|
#[derive(PartialEq, Eq, Debug, Clone, Copy, Hash)]
|
||||||
pub enum Offset {
|
pub enum Offset {
|
||||||
/// In the center of the screen
|
/// In the center of the screen
|
||||||
Center,
|
Center,
|
||||||
|
@ -5,7 +5,7 @@ use std::cmp::min;
|
|||||||
/// This describes a possible behaviour for a [`ResizedView`].
|
/// This describes a possible behaviour for a [`ResizedView`].
|
||||||
///
|
///
|
||||||
/// [`ResizedView`]: crate::views::ResizedView
|
/// [`ResizedView`]: crate::views::ResizedView
|
||||||
#[derive(Debug, Clone, Copy)]
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||||
pub enum SizeConstraint {
|
pub enum SizeConstraint {
|
||||||
/// No constraint imposed, the child view's response is used.
|
/// No constraint imposed, the child view's response is used.
|
||||||
Free,
|
Free,
|
||||||
|
@ -14,7 +14,7 @@ use std::cmp::max;
|
|||||||
use unicode_width::UnicodeWidthStr;
|
use unicode_width::UnicodeWidthStr;
|
||||||
|
|
||||||
/// Identifies currently focused element in [`Dialog`].
|
/// Identifies currently focused element in [`Dialog`].
|
||||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
|
||||||
pub enum DialogFocus {
|
pub enum DialogFocus {
|
||||||
/// Content element focused
|
/// Content element focused
|
||||||
Content,
|
Content,
|
||||||
|
@ -32,7 +32,7 @@ enum Placement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Identifies a layer in a `StackView`.
|
/// Identifies a layer in a `StackView`.
|
||||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
|
||||||
pub enum LayerPosition {
|
pub enum LayerPosition {
|
||||||
/// Starts from the back (bottom) of the stack.
|
/// Starts from the back (bottom) of the stack.
|
||||||
FromBack(usize),
|
FromBack(usize),
|
||||||
|
Loading…
Reference in New Issue
Block a user