simplestacknavigation/src/welcome/welcome_screen.rs

104 lines
3.4 KiB
Rust

use crate::shared::stack_view_action::StackViewAction;
use makepad_widgets::widget::WidgetCache;
use makepad_widgets::*;
live_design! {
import makepad_draw::shader::std::*;
import makepad_widgets::base::*;
import makepad_widgets::theme_desktop_dark::*;
import crate::shared::helpers::*;
import crate::shared::helpers::Divider;
import crate::shared::styles::*;
import crate::shared::clickable_view::ClickableView
import crate::shared::search_bar::SearchBar;
import crate::shared::custom_button::CustomButton;
Welcome = {{Welcome}} {
// show_bg: true
draw_bg: {
color: #f00 //Color Red
}
<View> {
align: {x: 0.5, y: 0.5}
container = <RoundedView> {
width: 360
height: 400
flow: Down
align: {x: 0.5, y: 0.5}
spacing: 2.0
draw_bg: {
color: #ddd,
radius: (CARD_CORNER_RADIUS)
}
<View> {
width: Fit, height: Fill
flow: Down,
align: {x: 0, y: 0.5},
padding: {top: 5., left: 10., right: 10.}, spacing: 20.
username = <Label> {
draw_text:{
color: #000,
text_style: <TEXT_SUB>{font_size: 20.},
}
text:"Welcome To Simple Nav"
}
message_input = <SearchBar> {
show_bg: false
input = {
width: Fill, height: Fit, margin: 0
empty_message: "Enter Your Name"
draw_bg: {
color: #fff
border_width: 0.5,
border_color: #b4b4b4,
}
}
}
welcome_frame = <CustomButton> {
button = {
text: "Welcome"
}
}
}
}
}
}
WelcomeScreen = <View> {
width: Fill, height: Fill
<Welcome> {}
}
}
#[derive(Live, LiveHook, Widget)]
pub struct Welcome {
#[deref] view: View
}
impl Widget for Welcome {
fn handle_event(&mut self, cx: &mut Cx, event: &Event, scope: &mut Scope) {
let actions = cx.capture_actions(|cx| self.view.handle_event(cx, event, scope));
// if self
// .view
// .clickable_view(id!(my_profile_frame))
// .clicked(&actions)
// {
// let uid = self.widget_uid();
// cx.widget_action(uid, &scope.path, StackViewAction::ShowMyProfile);
// }
if self.view.button(id!(welcome_frame)).clicked(&actions)
{
let uid = self.widget_uid();
cx.widget_action(uid, &scope.path, StackViewAction::ShowCounterScreen);
// dispatch_action(cx, StackViewAction::ShowCounterScreen);
let user_prompt1 = self.view.text_input(id!(message_input.input)).text();
log!("WELCOME BUTTON CLICKED: {}", user_prompt1);
}
}
fn draw_walk(&mut self, cx: &mut Cx2d, scope: &mut Scope, walk: Walk) -> DrawStep {
self.view.draw_walk(cx, scope, walk)
}
}