prelude and transform macro
This commit is contained in:
@@ -1,6 +1,9 @@
|
|||||||
pub mod div;
|
pub mod div;
|
||||||
pub mod flex;
|
pub mod flex;
|
||||||
|
|
||||||
|
pub use div::*;
|
||||||
|
pub use flex::*;
|
||||||
|
|
||||||
use crate::Element;
|
use crate::Element;
|
||||||
|
|
||||||
impl Element for String {
|
impl Element for String {
|
||||||
|
|||||||
@@ -3,6 +3,11 @@ pub mod resources;
|
|||||||
pub mod tick;
|
pub mod tick;
|
||||||
pub mod velocity;
|
pub mod velocity;
|
||||||
|
|
||||||
|
pub use id::*;
|
||||||
|
pub use resources::*;
|
||||||
|
pub use tick::*;
|
||||||
|
pub use velocity::*;
|
||||||
|
|
||||||
use std::{
|
use std::{
|
||||||
any::{type_name, Any},
|
any::{type_name, Any},
|
||||||
fmt::Debug,
|
fmt::Debug,
|
||||||
|
|||||||
@@ -16,6 +16,15 @@ pub mod style;
|
|||||||
pub mod utils;
|
pub mod utils;
|
||||||
pub mod widget;
|
pub mod widget;
|
||||||
|
|
||||||
|
pub mod prelude {
|
||||||
|
pub use crate::{
|
||||||
|
elements::*, extensions::*, frontend::*, render_scope::*, state::*, style::*, utils::*,
|
||||||
|
widget::*, *,
|
||||||
|
};
|
||||||
|
|
||||||
|
pub use crate::style::{Dimension::{Full, Content}, Position::{Center, End}};
|
||||||
|
}
|
||||||
|
|
||||||
pub struct Screen {
|
pub struct Screen {
|
||||||
pub widgets: Mutex<Vec<Arc<Widget>>>,
|
pub widgets: Mutex<Vec<Arc<Widget>>>,
|
||||||
extensions: Mutex<Vec<Arc<Mutex<Box<dyn Extension + Send + Sync>>>>>,
|
extensions: Mutex<Vec<Arc<Mutex<Box<dyn Extension + Send + Sync>>>>>,
|
||||||
|
|||||||
@@ -123,6 +123,15 @@ macro_rules! event_handler {
|
|||||||
}};
|
}};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[macro_export]
|
||||||
|
macro_rules! transform {
|
||||||
|
($($f:ident: $v:expr),* $(,)?) => {{
|
||||||
|
let mut t = Transform::new();
|
||||||
|
$(t.$f = $v.into();)*
|
||||||
|
t
|
||||||
|
}};
|
||||||
|
}
|
||||||
|
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
macro_rules! rsx {
|
macro_rules! rsx {
|
||||||
($($inner:tt)*) => {{
|
($($inner:tt)*) => {{
|
||||||
|
|||||||
+2
-9
@@ -1,11 +1,4 @@
|
|||||||
use osui::{
|
use osui::prelude::*;
|
||||||
elements::{div::Div, flex::FlexCol},
|
|
||||||
frontend::Rsx,
|
|
||||||
rsx,
|
|
||||||
state::use_state,
|
|
||||||
style::Transform,
|
|
||||||
Screen,
|
|
||||||
};
|
|
||||||
|
|
||||||
fn main() -> std::io::Result<()> {
|
fn main() -> std::io::Result<()> {
|
||||||
let screen = Screen::new();
|
let screen = Screen::new();
|
||||||
@@ -39,7 +32,7 @@ fn test(inc: i32) -> Rsx {
|
|||||||
rsx! {
|
rsx! {
|
||||||
@Transform::new().dimensions(40, 3);
|
@Transform::new().dimensions(40, 3);
|
||||||
Div {
|
Div {
|
||||||
@Transform::center().dimensions(8, 1);
|
@transform! { x: Center, y: Center, width: 5 };
|
||||||
Div {
|
Div {
|
||||||
%count
|
%count
|
||||||
"{count}"
|
"{count}"
|
||||||
|
|||||||
@@ -139,3 +139,15 @@ impl Position {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl From<u16> for Position {
|
||||||
|
fn from(value: u16) -> Self {
|
||||||
|
Self::Const(value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<u16> for Dimension {
|
||||||
|
fn from(value: u16) -> Self {
|
||||||
|
Self::Const(value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user