simplestacknavigation/src/counter/counter_screen.rs

158 lines
5.1 KiB
Rust

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;
Counter = {{Counter}} {
width: Fill, height: Fill
flow: Down,
spacing: 10.
draw_bg: {
color: #000
}
// draw_bg: {
// fn pixel(self) -> vec4 {
// return mix(#3, #1, self.pos.y);
// }
// }
CounterInfo = <View> {
width: Fill, height: Fill
flow: Right,
spacing: 10.,
align: {
x: 0.5,
y: 0.5
},
show_bg: true
draw_bg: {
color: #fff
}
<View> {
width: Fit
height: Fill
show_bg: false
align: {x: 0.5, y: 0.5}
container = <RoundedView> {
width: 360
height: 400
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.5, y: 0.5},
padding: {top: 5., left: 10., right: 10.}, spacing: 20.
avatar = <Image> {
source: (LOGO_MAKEPAD),
width: 300., height: 80.
}
button1 = <CustomButton> {
button = {
text: "Hello world"
}
}
message_input = <SearchBar> {
show_bg: false
input = {
width: Fill, height: Fit, margin: 0
empty_message: "Click to count"
draw_bg: {
color: #fff
border_width: 0.5,
border_color: #b4b4b4,
}
}
}
label1 = <Label> {
draw_text: {
color: #000
},
text: "Counter: 0"
}
}
}
}
}
}
CounterScreen = <View> {
width: Fill, height: Fill
<Counter> {}
}
}
#[derive(Live, LiveHook, Widget)]
pub struct Counter {
#[deref] view: View,
#[rust] counter: usize,
}
impl Widget for Counter {
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);
// }
if self.view.button(id!(button1)).clicked(&actions)
{
log!("BUTTON CLICKED {}", self.counter);
self.counter += 1;
let label = self.view.label(id!(label1));
label.set_text_and_redraw(cx,&format!("Counter: {}", self.counter));
}
}
fn draw_walk(&mut self, cx: &mut Cx2d, scope: &mut Scope, walk: Walk) -> DrawStep {
self.view.draw_walk(cx, scope, walk)
}
}
// impl Counter {
// fn handle_event_with(
// &mut self,
// cx: &mut Cx,
// event: &Event,
// _dispatch_action: &mut dyn FnMut(&mut Cx, StackViewAction),
// ) {
// let actions = self.view.handle_widget_event(cx, event);
// if self.view.button(id!(button1)).clicked(&actions)
// {
// log!("BUTTON CLICKED {}", self.counter);
// self.counter += 1;
// let label = self.view.label(id!(label1));
// label.set_text_and_redraw(cx,&format!("Counter: {}", self.counter));
// }
// }
// }