Simple velocity example
This commit is contained in:
+2
-2
@@ -64,7 +64,7 @@ pub fn app(screen: Arc<Screen>) -> Rsx {
|
|||||||
FlexRow
|
FlexRow
|
||||||
{
|
{
|
||||||
"Username"
|
"Username"
|
||||||
@Transform::new().padding(1, 1).dimensions(40, 1);
|
@Transform::new().padding(1, 1).dimensions_const(40, 1);
|
||||||
@Style { foreground: Some(0xffffff), background: Background::RoundedOutline(0xff0000) };
|
@Style { foreground: Some(0xffffff), background: Background::RoundedOutline(0xff0000) };
|
||||||
@Focused;
|
@Focused;
|
||||||
Input { }
|
Input { }
|
||||||
@@ -73,7 +73,7 @@ pub fn app(screen: Arc<Screen>) -> Rsx {
|
|||||||
FlexRow
|
FlexRow
|
||||||
{
|
{
|
||||||
"Password"
|
"Password"
|
||||||
@Transform::new().padding(1, 1).dimensions(40, 1);
|
@Transform::new().padding(1, 1).dimensions_const(40, 1);
|
||||||
@Style { foreground: Some(0xffffff), background: Background::RoundedOutline(0xffff00) };
|
@Style { foreground: Some(0xffffff), background: Background::RoundedOutline(0xffff00) };
|
||||||
Input { }
|
Input { }
|
||||||
}
|
}
|
||||||
|
|||||||
+37
-5
@@ -1,20 +1,52 @@
|
|||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
use osui::prelude::*;
|
use osui::prelude::*;
|
||||||
|
|
||||||
fn main() -> std::io::Result<()> {
|
fn main() -> std::io::Result<()> {
|
||||||
let screen = Screen::new();
|
let screen = Screen::new();
|
||||||
|
screen.extension(InputExtension);
|
||||||
|
|
||||||
app().draw(&screen);
|
app(screen.clone()).draw(&screen);
|
||||||
|
|
||||||
screen.run()
|
screen.run()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn app() -> Rsx {
|
pub fn app(screen: Arc<Screen>) -> Rsx {
|
||||||
rsx! {
|
rsx! {
|
||||||
|
@Handler::new({
|
||||||
|
let screen = screen.clone();
|
||||||
|
move |_, e: &crossterm::event::Event| {
|
||||||
|
if let crossterm::event::Event::Key(e) = e {
|
||||||
|
if e.code == crossterm::event::KeyCode::Esc {
|
||||||
|
screen.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
@Style { foreground: None, background: Background::Outline(0xff0000) };
|
@Style { foreground: None, background: Background::Outline(0xff0000) };
|
||||||
@Transform::new().padding(1, 1);
|
|
||||||
VelocityHandler {
|
VelocityHandler {
|
||||||
@Velocity(200, 100);
|
@Velocity(700, 0);
|
||||||
"test"
|
@Handler::new({
|
||||||
|
move |w, e: &crossterm::event::Event| {
|
||||||
|
if let crossterm::event::Event::Key(e) = e {
|
||||||
|
if e.code == crossterm::event::KeyCode::Char(' ') {
|
||||||
|
if let Some(Velocity(v, _)) = w.get() {
|
||||||
|
w.set_component(Velocity(-v, 0));
|
||||||
|
} else {
|
||||||
|
w.component(Velocity(700, 0));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
"(•_•)"
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transform::new().dimensions(Dimension::Full, Dimension::Full);
|
||||||
|
VelocityHandler {
|
||||||
|
@Velocity(0, -150);
|
||||||
|
@Transform::center().bottom();
|
||||||
|
"^"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+8
-1
@@ -139,12 +139,19 @@ impl Transform {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Sets constant dimensions.
|
/// Sets constant dimensions.
|
||||||
pub fn dimensions(mut self, width: u16, height: u16) -> Self {
|
pub fn dimensions_const(mut self, width: u16, height: u16) -> Self {
|
||||||
self.width = Dimension::Const(width);
|
self.width = Dimension::Const(width);
|
||||||
self.height = Dimension::Const(height);
|
self.height = Dimension::Const(height);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Sets constant dimensions.
|
||||||
|
pub fn dimensions(mut self, width: Dimension, height: Dimension) -> Self {
|
||||||
|
self.width = width;
|
||||||
|
self.height = height;
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
/// Resolves `Dimension` rules into absolute values for the given parent size.
|
/// Resolves `Dimension` rules into absolute values for the given parent size.
|
||||||
pub fn use_dimensions(&self, parent_transform: &RawTransform, raw: &mut RawTransform) {
|
pub fn use_dimensions(&self, parent_transform: &RawTransform, raw: &mut RawTransform) {
|
||||||
self.width
|
self.width
|
||||||
|
|||||||
Reference in New Issue
Block a user