removed unecesary params

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