2023-12-12 12:44:16 +00:00
|
|
|
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::*;
|
|
|
|
|
2023-12-13 00:53:09 +00:00
|
|
|
import crate::shared::helpers::*;
|
2023-12-12 12:44:16 +00:00
|
|
|
import crate::shared::helpers::Divider;
|
|
|
|
import crate::shared::styles::*;
|
|
|
|
import crate::shared::clickable_view::ClickableView
|
2023-12-12 17:45:11 +00:00
|
|
|
import crate::shared::search_bar::SearchBar;
|
|
|
|
import crate::shared::custom_button::CustomButton;
|
2023-12-12 12:44:16 +00:00
|
|
|
|
|
|
|
Counter = {{Counter}} {
|
2023-12-15 11:51:54 +00:00
|
|
|
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
|
2023-12-12 12:44:16 +00:00
|
|
|
draw_bg: {
|
2023-12-15 11:51:54 +00:00
|
|
|
color: #fff
|
2023-12-12 12:44:16 +00:00
|
|
|
}
|
2023-12-15 11:51:54 +00:00
|
|
|
<View> {
|
|
|
|
width: Fit
|
|
|
|
height: Fill
|
|
|
|
show_bg: false
|
|
|
|
align: {x: 0.5, y: 0.5}
|
|
|
|
container = <RoundedView> {
|
|
|
|
width: 360
|
|
|
|
height: 400
|
2023-12-13 00:53:09 +00:00
|
|
|
align: {x: 0.5, y: 0.5}
|
2023-12-15 11:51:54 +00:00
|
|
|
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.
|
2023-12-13 00:53:09 +00:00
|
|
|
|
2023-12-15 11:51:54 +00:00
|
|
|
avatar = <Image> {
|
|
|
|
source: (LOGO_MAKEPAD),
|
|
|
|
width: 300., height: 80.
|
|
|
|
}
|
|
|
|
button1 = <CustomButton> {
|
|
|
|
button = {
|
|
|
|
text: "Hello world"
|
2023-12-13 00:53:09 +00:00
|
|
|
}
|
2023-12-15 11:51:54 +00:00
|
|
|
}
|
|
|
|
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,
|
2023-12-13 00:53:09 +00:00
|
|
|
}
|
|
|
|
}
|
2023-12-15 11:51:54 +00:00
|
|
|
}
|
|
|
|
label1 = <Label> {
|
|
|
|
draw_text: {
|
|
|
|
color: #000
|
|
|
|
},
|
|
|
|
text: "Counter: 0"
|
2023-12-12 17:45:11 +00:00
|
|
|
}
|
|
|
|
}
|
2023-12-12 12:44:16 +00:00
|
|
|
}
|
|
|
|
}
|
2023-12-15 11:51:54 +00:00
|
|
|
|
2023-12-12 12:44:16 +00:00
|
|
|
}
|
|
|
|
}
|
2023-12-13 00:53:09 +00:00
|
|
|
|
2023-12-12 12:44:16 +00:00
|
|
|
CounterScreen = <View> {
|
|
|
|
width: Fill, height: Fill
|
|
|
|
<Counter> {}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-12-15 11:51:54 +00:00
|
|
|
#[derive(Live, LiveHook, Widget)]
|
2023-12-12 12:44:16 +00:00
|
|
|
pub struct Counter {
|
2023-12-15 11:51:54 +00:00
|
|
|
#[deref] view: View,
|
2023-12-12 12:44:16 +00:00
|
|
|
#[rust] counter: usize,
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Widget for Counter {
|
2023-12-15 11:51:54 +00:00
|
|
|
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);
|
|
|
|
// }
|
2023-12-12 12:44:16 +00:00
|
|
|
|
2023-12-15 11:51:54 +00:00
|
|
|
// 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);
|
|
|
|
// }
|
2023-12-13 00:53:09 +00:00
|
|
|
if self.view.button(id!(button1)).clicked(&actions)
|
2023-12-12 12:44:16 +00:00
|
|
|
{
|
|
|
|
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));
|
|
|
|
}
|
|
|
|
}
|
2023-12-15 11:51:54 +00:00
|
|
|
|
|
|
|
fn draw_walk(&mut self, cx: &mut Cx2d, scope: &mut Scope, walk: Walk) -> DrawStep {
|
|
|
|
self.view.draw_walk(cx, scope, walk)
|
|
|
|
}
|
2023-12-12 12:44:16 +00:00
|
|
|
}
|
2023-12-15 11:51:54 +00:00
|
|
|
|
|
|
|
// 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));
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// }
|