161 lines
5.2 KiB
Rust
161 lines
5.2 KiB
Rust
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::*;
|
|
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;
|
|
|
|
IMG_DEFAULT_AVATAR = dep("crate://self/resources/img/default_avatar.png")
|
|
IMG_FAVORITES = dep("crate://self/resources/img/favorites.png")
|
|
IMG_MY_POSTS = dep("crate://self/resources/img/my-posts.png")
|
|
IMG_STICKER_GALLERY = dep("crate://self/resources/img/sticker-gallery.png")
|
|
IMG_SETTINGS = dep("crate://self/resources/img/settings.png")
|
|
IMG_QR = dep("crate://self/resources/img/qr_icon.png")
|
|
|
|
Counter = {{Counter}} {
|
|
view: {
|
|
width: Fill, height: Fit
|
|
spacing: 10.
|
|
draw_bg: {
|
|
color: #000
|
|
}
|
|
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)]
|
|
pub struct Counter {
|
|
#[live]
|
|
view:View,
|
|
#[rust] counter: usize,
|
|
}
|
|
|
|
impl LiveHook for Counter {
|
|
fn before_live_design(cx: &mut Cx) {
|
|
register_widget!(cx, Counter);
|
|
}
|
|
}
|
|
|
|
impl Widget for Counter {
|
|
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));
|
|
});
|
|
}
|
|
|
|
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,
|
|
_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));
|
|
}
|
|
}
|
|
}
|