removed unecesary params
This commit is contained in:
+7
-7
@@ -4,11 +4,11 @@ use crate::{
|
||||
create_frame,
|
||||
key::{Key, KeyKind},
|
||||
utils::{closest_component, render_to_frame},
|
||||
Component, Params, UpdateResponse,
|
||||
Component, UpdateResponse,
|
||||
};
|
||||
|
||||
pub fn div(params: Params) -> Component {
|
||||
let mut component = Component::new(params);
|
||||
pub fn div() -> Component {
|
||||
let mut component = Component::new();
|
||||
|
||||
component.binds = HashMap::from([
|
||||
(KeyKind::Up, String::from("up")),
|
||||
@@ -80,8 +80,8 @@ pub fn div(params: Params) -> Component {
|
||||
component
|
||||
}
|
||||
|
||||
pub fn text(params: Params) -> Component {
|
||||
let mut component = Component::new(params);
|
||||
pub fn text() -> Component {
|
||||
let mut component = Component::new();
|
||||
|
||||
fn update(_: &mut Component, _: Key) -> UpdateResponse {
|
||||
UpdateResponse::None
|
||||
@@ -96,8 +96,8 @@ pub fn text(params: Params) -> Component {
|
||||
component
|
||||
}
|
||||
|
||||
pub fn button(params: Params) -> Component {
|
||||
let mut component = Component::new(params);
|
||||
pub fn button() -> Component {
|
||||
let mut component = Component::new();
|
||||
|
||||
fn update(this: &mut Component, k: Key) -> UpdateResponse {
|
||||
if k.kind == KeyKind::Enter {
|
||||
|
||||
+4
-13
@@ -13,12 +13,6 @@ pub enum UpdateResponse {
|
||||
None,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Params {
|
||||
pub expr: String,
|
||||
pub children: Vec<Component>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub struct Component {
|
||||
pub render: fn(&mut Component) -> String,
|
||||
@@ -38,7 +32,7 @@ pub struct Component {
|
||||
|
||||
impl Component {
|
||||
/// Creates a new component
|
||||
fn new(params: Params) -> Component {
|
||||
fn new() -> Component {
|
||||
Component {
|
||||
render: |_| String::new(),
|
||||
update: |_, _| UpdateResponse::None,
|
||||
@@ -47,8 +41,8 @@ impl Component {
|
||||
y: 0,
|
||||
width: 0,
|
||||
height: 0,
|
||||
expr: params.expr,
|
||||
children: params.children,
|
||||
expr: String::new(),
|
||||
children: Vec::new(),
|
||||
active_child: 0,
|
||||
clicked: false,
|
||||
toggle: false,
|
||||
@@ -77,10 +71,7 @@ impl App {
|
||||
/// Creates a new screen to render components
|
||||
pub fn new() -> App {
|
||||
App {
|
||||
component: Component::new(Params {
|
||||
expr: "".to_string(),
|
||||
children: vec![],
|
||||
}),
|
||||
component: Component::new(),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+13
-7
@@ -74,7 +74,7 @@ macro_rules! __oml {
|
||||
macro_rules! oml {
|
||||
// Props (P)
|
||||
($tag:ident ($($k:ident = $v:expr),*)) => {{
|
||||
let mut c = $tag(osui::Params { children: Vec::new(), expr: String::new() });
|
||||
let mut c = $tag();
|
||||
$(
|
||||
c.$k = $v;
|
||||
)*
|
||||
@@ -83,7 +83,9 @@ macro_rules! oml {
|
||||
|
||||
// Expression, With components (EC)
|
||||
( $tag:ident ($expr:expr; $($k:ident = $v:expr),* ) {$($inner:tt)*} ) => {{
|
||||
let mut c = $tag(osui::Params { children: osui::__oml!($($inner)*), expr: String::from($expr) });
|
||||
let mut c = $tag();
|
||||
c.children = osui::__oml!($($inner)*);
|
||||
c.params = String::from($expr);
|
||||
$(
|
||||
c.$k = $v;
|
||||
)*
|
||||
@@ -92,7 +94,8 @@ macro_rules! oml {
|
||||
|
||||
// Expression (E)
|
||||
( $tag:ident ($expr:expr; $($k:ident = $v:expr),*) ) => {{
|
||||
let mut c = $tag(osui::Params { children: Vec::new(), expr: String::from($expr) });
|
||||
let mut c = $tag();
|
||||
c.expr = String::from($expr);
|
||||
$(
|
||||
c.$k = $v;
|
||||
)*
|
||||
@@ -100,13 +103,16 @@ macro_rules! oml {
|
||||
}};
|
||||
|
||||
// Components (C)
|
||||
( $tag:ident {$($inner:tt)*} ) => {
|
||||
$tag(osui::Params { children: osui::__oml!($($inner)*), expr: String::new() })
|
||||
};
|
||||
( $tag:ident {$($inner:tt)*} ) => {{
|
||||
let mut c = $tag();
|
||||
c.children = osui::__oml!($($inner)*);
|
||||
c
|
||||
}};
|
||||
|
||||
// Props, With components (PC)
|
||||
( $tag:ident ($($k:ident = $v:expr),*) {$($inner:tt)*} ) => {{
|
||||
let mut c = $tag(osui::Params { children: osui::__oml!($($inner)*), expr: String::new() });
|
||||
let mut c = $tag();
|
||||
c.children = osui::__oml!($($inner)*);
|
||||
$(
|
||||
c.$k = $v;
|
||||
)*
|
||||
|
||||
+5
-8
@@ -1,11 +1,8 @@
|
||||
use osui::{
|
||||
components::{button, div},
|
||||
oml, App, Component, Params,
|
||||
};
|
||||
use osui::{components::*, oml, App, Component};
|
||||
|
||||
fn main() {
|
||||
let mut app = App::new();
|
||||
app.set_component(oml!(app_elem()));
|
||||
app.set_component(app_elem());
|
||||
app.run();
|
||||
}
|
||||
|
||||
@@ -17,11 +14,11 @@ fn onclick(c: &mut Component) {
|
||||
}
|
||||
}
|
||||
|
||||
fn app_elem(_: Params) -> Component {
|
||||
fn app_elem() -> Component {
|
||||
oml!(
|
||||
div {
|
||||
button("click me"; on_click = onclick)
|
||||
button("click me"; y = 2, on_click = onclick)
|
||||
button("click me"; toggle = true, on_click = onclick)
|
||||
button("click me"; toggle = true, y = 2, on_click = onclick)
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user