2023-12-12 12:44:16 +00:00
|
|
|
use crate::shared::clickable_view::*;
|
|
|
|
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::FillerX;
|
|
|
|
import crate::shared::helpers::Divider;
|
|
|
|
import crate::shared::styles::*;
|
|
|
|
import crate::shared::clickable_view::ClickableView
|
|
|
|
// import crate::shared::header::HeaderDropDownMenu;
|
|
|
|
|
2023-12-12 17:45:11 +00:00
|
|
|
import crate::shared::search_bar::SearchBar;
|
|
|
|
import crate::shared::custom_button::CustomButton;
|
|
|
|
import crate::shared::cbutton::CButton;
|
2023-12-12 12:44:16 +00:00
|
|
|
|
|
|
|
|
|
|
|
Counter = {{Counter}} {
|
|
|
|
view: {
|
|
|
|
width: Fill, height: Fit
|
|
|
|
flow: Down, spacing: 10.
|
|
|
|
|
|
|
|
show_bg: true,
|
|
|
|
draw_bg: {
|
|
|
|
color: #ddd
|
|
|
|
}
|
|
|
|
// <CounterHeader> {}
|
|
|
|
|
|
|
|
body = <View>{
|
|
|
|
|
|
|
|
flow: Down,
|
|
|
|
spacing: 20,
|
|
|
|
align: {
|
|
|
|
x: 0.5,
|
|
|
|
y: 0.5
|
|
|
|
},
|
|
|
|
|
|
|
|
avatar = <Image> {
|
|
|
|
source: (LOGO_MAKEPAD),
|
|
|
|
width: 300., height: 80.
|
|
|
|
}
|
2023-12-12 17:45:11 +00:00
|
|
|
button1 = <CButton> {
|
|
|
|
button = {
|
|
|
|
width: Fit, height: Fit, margin: 0
|
2023-12-12 12:44:16 +00:00
|
|
|
text: "Hello world"
|
2023-12-12 17:45:11 +00:00
|
|
|
// draw_bg: {
|
|
|
|
// border_radius: 0.
|
|
|
|
// }
|
|
|
|
}
|
2023-12-12 12:44:16 +00:00
|
|
|
}
|
2023-12-12 17:45:11 +00:00
|
|
|
// button1 = <Button> {
|
|
|
|
// text: "Hello world"
|
|
|
|
// }
|
|
|
|
// input1 = <TextInput> {
|
|
|
|
// width: 100, height: 30
|
|
|
|
// text: "Click to count"
|
|
|
|
// }
|
|
|
|
input1 = <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-12 12:44:16 +00:00
|
|
|
}
|
|
|
|
label1 = <Label> {
|
|
|
|
draw_text: {
|
|
|
|
color: #f
|
|
|
|
},
|
|
|
|
text: "Counter: 0"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
CounterScreen = <View> {
|
|
|
|
width: Fill, height: Fill
|
|
|
|
|
|
|
|
<Counter> {}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Live)]
|
|
|
|
pub struct Counter {
|
2023-12-12 17:45:11 +00:00
|
|
|
#[live] view:View,
|
2023-12-12 12:44:16 +00:00
|
|
|
#[rust] counter: usize,
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
impl LiveHook for Counter {
|
|
|
|
fn before_live_design(cx: &mut Cx) {
|
|
|
|
register_widget!(cx, Counter);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Widget for Counter {
|
2023-12-12 17:45:11 +00:00
|
|
|
// fn handle_widget_event_with(
|
|
|
|
// &mut self,
|
|
|
|
// cx: &mut Cx,
|
|
|
|
// event: &Event,
|
|
|
|
// dispatch_action: &mut dyn FnMut(&mut Cx, WidgetActionItem),
|
|
|
|
// ) {
|
|
|
|
// let uid = self.widget_uid();
|
|
|
|
// self.handle_event_with(cx, event, &mut |cx, action: StackViewAction| {
|
|
|
|
// dispatch_action(cx, WidgetActionItem::new(action.into(), uid));
|
|
|
|
// });
|
|
|
|
// }
|
2023-12-12 12:44:16 +00:00
|
|
|
|
|
|
|
fn redraw(&mut self, cx: &mut Cx) {
|
|
|
|
self.view.redraw(cx);
|
|
|
|
}
|
|
|
|
|
|
|
|
fn find_widgets(&mut self, path: &[LiveId], cached: WidgetCache, results: &mut WidgetSet) {
|
|
|
|
self.view.find_widgets(path, cached, results);
|
|
|
|
}
|
|
|
|
|
|
|
|
fn draw_walk_widget(&mut self, cx: &mut Cx2d, walk: Walk) -> WidgetDraw {
|
|
|
|
self.view.draw_walk_widget(cx, walk)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Counter {
|
|
|
|
fn handle_event_with(
|
|
|
|
&mut self,
|
|
|
|
cx: &mut Cx,
|
|
|
|
event: &Event,
|
2023-12-12 17:45:11 +00:00
|
|
|
// dispatch_action: &mut dyn FnMut(&mut Cx, StackViewAction),
|
2023-12-12 12:44:16 +00:00
|
|
|
) {
|
|
|
|
|
|
|
|
let actions = self.view.handle_widget_event(cx, event);
|
|
|
|
|
2023-12-12 17:45:11 +00:00
|
|
|
// if self
|
|
|
|
// .view
|
|
|
|
// .clickable_view(id!(my_profile_frame))
|
|
|
|
// .clicked(&actions)
|
|
|
|
// {
|
|
|
|
// dispatch_action(cx, StackViewAction::ShowCounterScreen);
|
|
|
|
// }
|
|
|
|
|
|
|
|
// if self
|
|
|
|
// .view
|
|
|
|
// .clickable_view(id!(button1.button))
|
|
|
|
// .clicked(&actions)
|
|
|
|
// {
|
|
|
|
// log!("BUTTON CLICKED {}", self.counter);
|
|
|
|
// self.counter += 1;
|
|
|
|
// let label = self.view.clickable_view(id!(label1));
|
|
|
|
// label.set_text_and_redraw(cx,&format!("Counter: {}", self.counter));
|
|
|
|
// }
|
|
|
|
|
|
|
|
if self.view.button(id!(button1.button)).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-12 17:45:11 +00:00
|
|
|
|
|
|
|
async fn _do_network_request(_cx:CxRef, _ui:WidgetRef, _url:&str)->String{
|
|
|
|
"".to_string()
|
|
|
|
}
|
2023-12-12 12:44:16 +00:00
|
|
|
}
|