11mod icon;
22mod widgets;
3- use crate :: ui:: icon:: Icon ;
3+ use crate :: ui:: {
4+ icon:: Icon ,
5+ widgets:: { Slider , SliderEvent , SliderState } ,
6+ } ;
47use gpui:: * ;
58use icon:: IconName ;
69use widgets:: IconButton ;
@@ -34,17 +37,45 @@ pub struct SettingsDrawer {
3437 pub power_mode : PowerMode ,
3538 pub mincrophone_recoding : bool ,
3639 pub screen_recording : bool ,
37- pub calc_active : bool ,
38- pub camera_active : bool ,
3940
4041 pub wireless_details : WirelessDetails ,
4142 pub bluetooth_details : BluetoothDetails ,
4243 pub open_terminal : bool ,
4344 pub cell_signal : bool ,
45+
46+ pub brightness_slider_state : Entity < SliderState > ,
47+ pub brightness_slider_value : f32 ,
48+
49+ pub volume_slider_state : Entity < SliderState > ,
50+ pub volume_slider_value : f32 ,
51+ _subscriptions : Vec < Subscription > ,
4452}
4553
4654impl SettingsDrawer {
47- pub fn new ( ) -> Self {
55+ pub fn new ( cx : & mut Context < Self > ) -> Self {
56+ let brightness_slider = cx. new ( |_| SliderState :: new ( ) ) ;
57+ let b_subscription =
58+ cx. subscribe ( & brightness_slider, |this, _, event : & SliderEvent , cx| {
59+ let SliderEvent :: Change ( value) = event;
60+ this. brightness_slider_value = * value;
61+ println ! ( "brightness value: {:?}" , this. brightness_slider_value) ;
62+ cx. notify ( ) ;
63+ } ) ;
64+
65+ let volume_slider = cx. new ( |_| {
66+ SliderState :: new ( )
67+ . default_value ( 20. )
68+ . pattern ( widgets:: SliderPattern :: Bars )
69+ } ) ;
70+ let c_subscription = cx. subscribe ( & volume_slider, |this, _, event : & SliderEvent , cx| {
71+ let SliderEvent :: Change ( value) = event;
72+ this. volume_slider_value = * value;
73+ println ! ( "volume value: {:?}" , this. volume_slider_value) ;
74+ cx. notify ( ) ;
75+ } ) ;
76+
77+ let mut _subscriptions = vec ! [ b_subscription, c_subscription] ;
78+
4879 Self {
4980 settings_active : false ,
5081 battery_percent : 32 ,
@@ -55,8 +86,6 @@ impl SettingsDrawer {
5586 power_mode : PowerMode :: Low ,
5687 mincrophone_recoding : false ,
5788 screen_recording : false ,
58- calc_active : true ,
59- camera_active : false ,
6089 wireless_details : WirelessDetails {
6190 enalble : true ,
6291 icon : IconName :: WirelessHigh ,
@@ -69,6 +98,11 @@ impl SettingsDrawer {
6998 } ,
7099 open_terminal : false ,
71100 cell_signal : false ,
101+ brightness_slider_state : brightness_slider,
102+ brightness_slider_value : 0.0 ,
103+ volume_slider_state : volume_slider,
104+ volume_slider_value : 0.0 ,
105+ _subscriptions,
72106 }
73107 }
74108}
@@ -168,6 +202,7 @@ impl Render for SettingsDrawer {
168202 . grid_rows ( 2 )
169203 . grid_cols ( 4 )
170204 . h ( px ( 236. ) )
205+ . w ( px ( 476. ) )
171206 . bg ( rgb ( 0x181818 ) )
172207 . p_6 ( )
173208 . gap_5 ( )
@@ -176,6 +211,8 @@ impl Render for SettingsDrawer {
176211 IconButton :: new ( "id_rotation" )
177212 . icon ( rotation_icon)
178213 . active ( self . rotation_on )
214+ . active_icon_color ( rgb ( 0x4892F1 ) )
215+ . active_bg_color ( rgb ( 0x202020 ) )
179216 . on_click ( cx. listener (
180217 |this : & mut SettingsDrawer ,
181218 _event : & ClickEvent ,
@@ -208,6 +245,8 @@ impl Render for SettingsDrawer {
208245 IconButton :: new ( "id_screen_mirroring" )
209246 . icon ( screen_mirroring_icon)
210247 . active ( self . screen_mirrorring )
248+ . active_icon_color ( rgb ( 0x4892F1 ) )
249+ . active_bg_color ( rgb ( 0x202020 ) )
211250 . on_click ( cx. listener (
212251 |this : & mut SettingsDrawer ,
213252 _event : & ClickEvent ,
@@ -230,6 +269,7 @@ impl Render for SettingsDrawer {
230269 IconButton :: new ( "id_microphone" )
231270 . icon ( IconName :: MicroPhoneOff )
232271 . active ( self . mincrophone_recoding )
272+ . active_bg_color ( rgb ( 0x202020 ) )
233273 . active_icon_color ( rgb ( 0xFF6560 ) )
234274 . on_click ( cx. listener (
235275 |this : & mut SettingsDrawer ,
@@ -245,6 +285,7 @@ impl Render for SettingsDrawer {
245285 IconButton :: new ( "id_screen_recording" )
246286 . icon ( IconName :: ScreenRecordingOff )
247287 . active ( self . screen_recording )
288+ . active_bg_color ( rgb ( 0x202020 ) )
248289 . active_icon_color ( rgb ( 0xFF6560 ) )
249290 . on_click ( cx. listener (
250291 |this : & mut SettingsDrawer ,
@@ -260,15 +301,12 @@ impl Render for SettingsDrawer {
260301 IconButton :: new ( "id_calc" )
261302 . icon ( IconName :: Calculator )
262303 . icon_color ( rgb ( 0xF4F4F4 ) )
263- . active ( self . calc_active )
264- . active_icon_color ( rgb ( 0xF4F4F4 ) )
265304 . on_click ( cx. listener (
266305 |this : & mut SettingsDrawer ,
267306 _event : & ClickEvent ,
268307 _window : & mut Window ,
269308 cx : & mut Context < Self > | {
270309 println ! ( "calc clicked" ) ;
271- this. calc_active = !this. calc_active ;
272310 cx. notify ( ) ;
273311 } ,
274312 ) ) ,
@@ -277,15 +315,13 @@ impl Render for SettingsDrawer {
277315 IconButton :: new ( "id_camera" )
278316 . icon ( IconName :: Camera )
279317 . icon_color ( rgb ( 0xF4F4F4 ) )
280- . active ( self . camera_active )
281318 . active_icon_color ( rgb ( 0xF4F4F4 ) )
282319 . on_click ( cx. listener (
283320 |this : & mut SettingsDrawer ,
284321 _event : & ClickEvent ,
285322 _window : & mut Window ,
286323 cx : & mut Context < Self > | {
287324 println ! ( "camera clicked" ) ;
288- this. camera_active = !this. camera_active ;
289325 cx. notify ( ) ;
290326 } ,
291327 ) ) ,
@@ -296,32 +332,32 @@ impl Render for SettingsDrawer {
296332 . grid ( )
297333 . grid_cols ( 4 )
298334 . gap_4 ( )
299- . h ( px ( 104. ) )
300- . rounded ( px ( 12. ) )
335+ . h ( px ( 72.0 ) )
301336 . child (
302337 div ( )
303338 . flex ( )
304339 . items_center ( )
305- . justify_center ( )
306340 . w_full ( )
307341 . h_full ( )
308342 . text_color ( rgb ( 0xF4F4F4 ) )
309343 . text_lg ( )
310344 . col_span ( 2 )
311345 . bg ( rgb ( 0x202020 ) )
312- . rounded ( px ( 12 .) )
346+ . rounded ( px ( 8 .) )
313347 . child (
314348 div ( )
315349 . flex ( )
316350 . flex_row ( )
317351 . w_full ( )
318352 . items_center ( )
319- . p_2 ( )
353+ . justify_around ( )
354+ . px_2 ( )
320355 . child (
321356 IconButton :: new ( "id_brightness" )
322357 . icon ( IconName :: BrightnessHigh )
323358 . icon_color ( rgb ( 0xF4F4F4 ) )
324359 . size ( ( px ( 36. ) , px ( 36. ) ) )
360+ . bg_color ( rgb ( 0x202020 ) )
325361 . border ( px ( 0. ) )
326362 . on_click ( cx. listener ( |_, _, _, _| {
327363 println ! ( "brightness clicked" ) ;
@@ -333,10 +369,14 @@ impl Render for SettingsDrawer {
333369 . justify_center ( )
334370 . items_center ( )
335371 . w ( px ( 172.0 ) )
336- . h ( px ( 72.0 ) )
337- . bg ( rgb ( 0x202020 ) )
338- . rounded ( px ( 12. ) )
339- . child ( "sliderrrrr--------rrrrr" ) ,
372+ . child (
373+ Slider :: new (
374+ "brightness-slider" ,
375+ & self . brightness_slider_state ,
376+ )
377+ . width ( 172.0 )
378+ . height ( 56.0 ) ,
379+ ) ,
340380 ) ,
341381 ) ,
342382 )
@@ -351,25 +391,40 @@ impl Render for SettingsDrawer {
351391 . text_lg ( )
352392 . col_span ( 2 )
353393 . bg ( rgb ( 0x202020 ) )
354- . rounded ( px ( 12 .) )
394+ . rounded ( px ( 8 .) )
355395 . child (
356396 div ( )
357397 . flex ( )
358398 . flex_row ( )
359399 . w_full ( )
360400 . items_center ( )
361- . p_2 ( )
401+ . justify_around ( )
402+ . pl_2 ( )
362403 . child (
363404 IconButton :: new ( "id_volume" )
364405 . icon ( IconName :: VolumeMedium )
365406 . icon_color ( rgb ( 0xF4F4F4 ) )
366407 . size ( ( px ( 36. ) , px ( 36. ) ) )
408+ . bg_color ( rgb ( 0x202020 ) )
367409 . border ( px ( 0. ) )
368410 . on_click ( cx. listener ( |_, _, _, _| {
369411 println ! ( "volume clicked" ) ;
370412 } ) ) ,
371413 )
372- . child ( "sliderrrrr--------rrrrr" ) ,
414+ . child (
415+ div ( )
416+ . flex ( )
417+ . justify_center ( )
418+ . items_end ( )
419+ . w ( px ( 172.0 ) )
420+ . child (
421+ Slider :: new (
422+ "volume-slider" ,
423+ & self . volume_slider_state ,
424+ )
425+ . width ( 172.0 ) ,
426+ ) ,
427+ ) ,
373428 ) ,
374429 ) ,
375430 )
@@ -380,13 +435,13 @@ impl Render for SettingsDrawer {
380435 . gap_5 ( )
381436 . h ( px ( 104. ) )
382437 . rounded ( px ( 4. ) )
383- . bg ( rgb ( 0x181818 ) )
384438 . child (
385439 IconButton :: new ( "id_wireless" )
386440 . icon ( self . wireless_details . icon . clone ( ) )
387- . icon_color ( rgb ( 0x4D4D4D ) ) // changes as per wireless state
441+ . icon_color ( rgb ( 0x4D4D4D ) ) // changes as per wireless state
388442 . size ( ( px ( 104. ) , px ( 104. ) ) )
389443 . active ( self . wireless_details . enalble )
444+ . active_bg_color ( rgb ( 0x202020 ) )
390445 . label ( "Office wifi 1" )
391446 . on_click ( cx. listener ( |_, _, _, _| {
392447 println ! ( "wireless clicked" ) ;
@@ -398,6 +453,7 @@ impl Render for SettingsDrawer {
398453 . size ( ( px ( 104. ) , px ( 104. ) ) )
399454 . label ( "OFF" )
400455 . active ( self . bluetooth_details . enalble )
456+ . active_bg_color ( rgb ( 0x202020 ) )
401457 . on_click ( cx. listener ( |_, _, _, _| {
402458 println ! ( "bluetooth clicked" ) ;
403459 } ) ) ,
@@ -408,15 +464,13 @@ impl Render for SettingsDrawer {
408464 . size ( ( px ( 104. ) , px ( 104. ) ) )
409465 . label ( "Terminal" )
410466 . icon_color ( rgb ( 0xF4F4F4 ) )
411- . active ( self . open_terminal )
412467 . active_icon_color ( rgb ( 0xF4F4F4 ) )
413468 . on_click ( cx. listener (
414469 |this : & mut SettingsDrawer ,
415470 _event : & ClickEvent ,
416471 _window : & mut Window ,
417472 cx : & mut Context < Self > | {
418473 println ! ( "terminal clicked" ) ;
419- this. open_terminal = !this. open_terminal ;
420474 cx. notify ( ) ;
421475 } ,
422476 ) ) ,
@@ -428,6 +482,7 @@ impl Render for SettingsDrawer {
428482 . label ( "No SIM" )
429483 . active ( self . cell_signal )
430484 . active_icon_color ( rgb ( 0xF4F4F4 ) )
485+ . active_bg_color ( rgb ( 0x202020 ) )
431486 . on_click ( cx. listener (
432487 |this : & mut SettingsDrawer ,
433488 _event : & ClickEvent ,
0 commit comments