1
- use makepad_widgets:: * ;
2
- use crate :: data:: store:: Store ;
3
1
use super :: chat_history_card:: ChatHistoryCardWidgetRefExt ;
2
+ use crate :: { data:: store:: Store , shared:: toggle_panel:: TogglePanel } ;
3
+ use makepad_widgets:: * ;
4
4
5
5
live_design ! {
6
6
import makepad_widgets:: base:: * ;
7
7
import makepad_widgets:: theme_desktop_dark:: * ;
8
8
9
9
import crate :: shared:: styles:: * ;
10
- import crate :: shared:: widgets:: FadeView ;
11
10
import crate :: shared:: widgets:: MoxinButton ;
12
11
import makepad_draw:: shader:: std:: * ;
13
12
14
13
import crate :: chat:: shared:: ChatAgentAvatar ;
15
14
import crate :: chat:: chat_history_card:: ChatHistoryCard ;
16
15
17
16
ICON_NEW_CHAT = dep( "crate://self/resources/icons/new_chat.svg" )
18
- ICON_CLOSE_PANEL = dep( "crate://self/resources/icons/close_left_panel.svg" )
19
- ICON_OPEN_PANEL = dep( "crate://self/resources/icons/open_left_panel.svg" )
20
-
21
- ChatHistoryActions = <View > {
22
- spacing: 10 ,
23
- height: Fit
24
-
25
- close_panel_button = <MoxinButton > {
26
- width: Fit ,
27
- height: Fit ,
28
- icon_walk: { width: 20 , height: 20 } ,
29
- draw_icon: {
30
- svg_file: ( ICON_CLOSE_PANEL ) ,
31
- fn get_color( self ) -> vec4 {
32
- return #475467 ;
33
- }
34
- }
35
- }
36
-
37
- open_panel_button = <MoxinButton > {
38
- width: Fit ,
39
- height: Fit ,
40
- visible: false ,
41
- icon_walk: { width: 20 , height: 20 } ,
42
- draw_icon: {
43
- svg_file: ( ICON_OPEN_PANEL ) ,
44
- fn get_color( self ) -> vec4 {
45
- return #475467 ;
46
- }
47
- }
48
- }
49
-
50
- new_chat_button = <MoxinButton > {
51
- width: Fit ,
52
- height: Fit ,
53
- icon_walk: { margin: { top: -1 } , width: 21 , height: 21 } ,
54
- draw_icon: {
55
- svg_file: ( ICON_NEW_CHAT ) ,
56
- fn get_color( self ) -> vec4 {
57
- return #475467 ;
58
- }
59
- }
60
- }
61
- }
62
17
63
18
ChatHistory = { { ChatHistory } } {
64
- flow: Overlay
65
- width: Fit
66
- height: Fill
67
-
68
- main_content = <FadeView > {
69
- width: 300
70
- height: Fill ,
19
+ open_content = {
71
20
<View > {
72
21
width: Fill ,
73
22
height: Fill ,
@@ -90,42 +39,36 @@ live_design! {
90
39
}
91
40
}
92
41
93
- <ChatHistoryActions > {
94
- padding: { top: 58 , left: 25 , right: 25 }
95
- }
96
-
97
- animator: {
98
- panel = {
99
- default : show,
100
- show = {
101
- redraw: true ,
102
- from: { all: Forward { duration: 0.3 } }
103
- ease: ExpDecay { d1: 0.80 , d2: 0.97 }
104
- apply: { main_content = { width: 300 , draw_bg: { opacity: 1.0 } } }
105
- }
106
- hide = {
107
- redraw: true ,
108
- from: { all: Forward { duration: 0.3 } }
109
- ease: ExpDecay { d1: 0.80 , d2: 0.97 }
110
- apply: { main_content = { width: 110 , draw_bg: { opacity: 0.0 } } }
42
+ persistent_content = {
43
+ default = {
44
+ after = {
45
+ new_chat_button = <MoxinButton > {
46
+ width: Fit ,
47
+ height: Fit ,
48
+ icon_walk: { margin: { top: -1 } , width: 21 , height: 21 } ,
49
+ draw_icon: {
50
+ svg_file: ( ICON_NEW_CHAT ) ,
51
+ fn get_color( self ) -> vec4 {
52
+ return #475467 ;
53
+ }
54
+ }
55
+ }
111
56
}
112
57
}
113
58
}
59
+
114
60
}
115
61
}
116
62
117
63
#[ derive( Live , LiveHook , Widget ) ]
118
64
pub struct ChatHistory {
119
65
#[ deref]
120
- view : View ,
121
-
122
- #[ animator]
123
- animator : Animator ,
66
+ deref : TogglePanel ,
124
67
}
125
68
126
69
impl Widget for ChatHistory {
127
70
fn handle_event ( & mut self , cx : & mut Cx , event : & Event , scope : & mut Scope ) {
128
- self . view . handle_event ( cx, event, scope) ;
71
+ self . deref . handle_event ( cx, event, scope) ;
129
72
self . widget_match_event ( cx, event, scope) ;
130
73
131
74
// TODO This is a hack to redraw the chat history and reflect the
@@ -134,10 +77,6 @@ impl Widget for ChatHistory {
134
77
if let Event :: Signal = event {
135
78
self . redraw ( cx) ;
136
79
}
137
-
138
- if self . animator_handle_event ( cx, event) . must_redraw ( ) {
139
- self . redraw ( cx) ;
140
- }
141
80
}
142
81
143
82
fn draw_walk ( & mut self , cx : & mut Cx2d , scope : & mut Scope , walk : Walk ) -> DrawStep {
@@ -154,7 +93,7 @@ impl Widget for ChatHistory {
154
93
155
94
let chats_count = chats. saved_chats . len ( ) ;
156
95
157
- while let Some ( view_item) = self . view . draw_walk ( cx, scope, walk) . step ( ) {
96
+ while let Some ( view_item) = self . deref . draw_walk ( cx, scope, walk) . step ( ) {
158
97
if let Some ( mut list) = view_item. as_portal_list ( ) . borrow_mut ( ) {
159
98
list. set_item_range ( cx, 0 , chats_count) ;
160
99
while let Some ( item_id) = list. next_visible_item ( cx) {
@@ -186,13 +125,13 @@ impl WidgetMatchEvent for ChatHistory {
186
125
if self . button ( id ! ( close_panel_button) ) . clicked ( & actions) {
187
126
self . button ( id ! ( close_panel_button) ) . set_visible ( false ) ;
188
127
self . button ( id ! ( open_panel_button) ) . set_visible ( true ) ;
189
- self . animator_play ( cx, id ! ( panel . hide ) ) ;
128
+ self . deref . set_open ( cx, false ) ;
190
129
}
191
130
192
131
if self . button ( id ! ( open_panel_button) ) . clicked ( & actions) {
193
132
self . button ( id ! ( open_panel_button) ) . set_visible ( false ) ;
194
133
self . button ( id ! ( close_panel_button) ) . set_visible ( true ) ;
195
- self . animator_play ( cx, id ! ( panel . show ) ) ;
134
+ self . deref . set_open ( cx, true ) ;
196
135
}
197
136
}
198
137
}
0 commit comments