mirror of
https://github.com/FliegendeWurst/cursive.git
synced 2024-11-13 20:53:07 +00:00
Add macro'd Default implementations
This commit is contained in:
parent
d4afdf024f
commit
05f66b8e1b
16
src/lib.rs
16
src/lib.rs
@ -61,6 +61,16 @@ macro_rules! println_stderr(
|
||||
} }
|
||||
);
|
||||
|
||||
macro_rules! new_default(
|
||||
($c:ident) => {
|
||||
impl Default for $c {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
pub mod event;
|
||||
pub mod view;
|
||||
@ -119,11 +129,7 @@ pub struct Cursive {
|
||||
running: bool,
|
||||
}
|
||||
|
||||
impl Default for Cursive {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
new_default!(Cursive);
|
||||
|
||||
// Use the Ncurses backend.
|
||||
// TODO: make this feature-driven
|
||||
|
@ -34,11 +34,7 @@ pub struct Menubar {
|
||||
state: State,
|
||||
}
|
||||
|
||||
impl Default for Menubar {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
new_default!(Menubar);
|
||||
|
||||
impl Menubar {
|
||||
pub fn new() -> Self {
|
||||
|
@ -12,12 +12,12 @@ pub struct Checkbox {
|
||||
checked: bool,
|
||||
}
|
||||
|
||||
new_default!(Checkbox);
|
||||
|
||||
impl Checkbox {
|
||||
/// Creates a new, unchecked checkbox.
|
||||
pub fn new() -> Self {
|
||||
Checkbox {
|
||||
checked: false,
|
||||
}
|
||||
Checkbox { checked: false }
|
||||
}
|
||||
|
||||
/// Toggles the checkbox state.
|
||||
@ -66,7 +66,7 @@ impl View for Checkbox {
|
||||
|
||||
fn draw(&self, printer: &Printer) {
|
||||
printer.with_selection(printer.focused, |printer| {
|
||||
printer.print((0,0), "[ ]");
|
||||
printer.print((0, 0), "[ ]");
|
||||
if self.checked {
|
||||
printer.print((1, 0), "X");
|
||||
}
|
||||
|
@ -27,11 +27,7 @@ pub struct EditView {
|
||||
* TODO: add a max text length? */
|
||||
}
|
||||
|
||||
impl Default for EditView {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
new_default!(EditView);
|
||||
|
||||
impl EditView {
|
||||
/// Creates a new, empty edit view.
|
||||
|
@ -44,11 +44,7 @@ pub struct ListView {
|
||||
focus: usize,
|
||||
}
|
||||
|
||||
impl Default for ListView {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
new_default!(ListView);
|
||||
|
||||
impl ListView {
|
||||
/// Creates a new, empty `ListView`.
|
||||
|
@ -22,11 +22,7 @@ struct Layer {
|
||||
virgin: bool,
|
||||
}
|
||||
|
||||
impl Default for StackView {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
new_default!(StackView);
|
||||
|
||||
impl StackView {
|
||||
/// Creates a new empty StackView
|
||||
|
@ -5,11 +5,7 @@ pub struct ViewPath {
|
||||
pub path: Vec<usize>,
|
||||
}
|
||||
|
||||
impl Default for ViewPath {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
new_default!(ViewPath);
|
||||
|
||||
impl ViewPath {
|
||||
/// Creates a new empty path.
|
||||
|
Loading…
Reference in New Issue
Block a user