Add macro'd Default implementations

This commit is contained in:
Alexandre Bury 2016-07-16 17:28:42 -07:00
parent d4afdf024f
commit 05f66b8e1b
7 changed files with 20 additions and 34 deletions

View File

@ -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

View File

@ -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 {

View File

@ -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");
}

View File

@ -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.

View File

@ -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`.

View File

@ -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

View File

@ -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.