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 ;
@@ -41,10 +44,44 @@ pub struct SettingsDrawer {
4144 pub bluetooth_details : BluetoothDetails ,
4245 pub open_terminal : bool ,
4346 pub cell_signal : bool ,
47+
48+ pub brightness_value : f32 ,
49+ pub height : f32 ,
50+ pub width : f32 ,
51+
52+ pub brightness_slider_state : Entity < SliderState > ,
53+ pub brightness_slider_value : f32 ,
54+
55+ pub volume_slider_state : Entity < SliderState > ,
56+ pub volume_slider_value : f32 ,
57+ _subscriptions : Vec < Subscription > ,
4458}
4559
4660impl SettingsDrawer {
47- pub fn new ( ) -> Self {
61+ pub fn new ( cx : & mut Context < Self > ) -> Self {
62+ let brightness_slider = cx. new ( |_| SliderState :: new ( ) ) ;
63+ let b_subscription =
64+ cx. subscribe ( & brightness_slider, |this, _, event : & SliderEvent , cx| {
65+ let SliderEvent :: Change ( value) = event;
66+ this. brightness_value = * value;
67+ println ! ( "brightness value: {:?}" , this. brightness_value) ;
68+ cx. notify ( ) ;
69+ } ) ;
70+
71+ let volume_slider = cx. new ( |_| {
72+ SliderState :: new ( )
73+ . default_value ( 20. )
74+ . pattern ( widgets:: SliderPattern :: Bars )
75+ } ) ;
76+ let c_subscription = cx. subscribe ( & volume_slider, |this, _, event : & SliderEvent , cx| {
77+ let SliderEvent :: Change ( value) = event;
78+ this. volume_slider_value = * value;
79+ println ! ( "volume value: {:?}" , this. volume_slider_value) ;
80+ cx. notify ( ) ;
81+ } ) ;
82+
83+ let mut _subscriptions = vec ! [ b_subscription, c_subscription] ;
84+
4885 Self {
4986 settings_active : false ,
5087 battery_percent : 32 ,
@@ -69,6 +106,14 @@ impl SettingsDrawer {
69106 } ,
70107 open_terminal : false ,
71108 cell_signal : false ,
109+ brightness_value : 50. ,
110+ height : 56. ,
111+ width : 172. ,
112+ brightness_slider_state : brightness_slider,
113+ brightness_slider_value : 0.0 ,
114+ volume_slider_state : volume_slider,
115+ volume_slider_value : 0.0 ,
116+ _subscriptions,
72117 }
73118 }
74119}
@@ -168,6 +213,7 @@ impl Render for SettingsDrawer {
168213 . grid_rows ( 2 )
169214 . grid_cols ( 4 )
170215 . h ( px ( 236. ) )
216+ . w ( px ( 476. ) )
171217 . bg ( rgb ( 0x181818 ) )
172218 . p_6 ( )
173219 . gap_5 ( )
@@ -296,32 +342,32 @@ impl Render for SettingsDrawer {
296342 . grid ( )
297343 . grid_cols ( 4 )
298344 . gap_4 ( )
299- . h ( px ( 104. ) )
300- . rounded ( px ( 12. ) )
345+ . h ( px ( 72.0 ) )
301346 . child (
302347 div ( )
303348 . flex ( )
304349 . items_center ( )
305- . justify_center ( )
306350 . w_full ( )
307351 . h_full ( )
308352 . text_color ( rgb ( 0xF4F4F4 ) )
309353 . text_lg ( )
310354 . col_span ( 2 )
311355 . bg ( rgb ( 0x202020 ) )
312- . rounded ( px ( 12 .) )
356+ . rounded ( px ( 8 .) )
313357 . child (
314358 div ( )
315359 . flex ( )
316360 . flex_row ( )
317361 . w_full ( )
318362 . items_center ( )
319- . p_2 ( )
363+ . justify_around ( )
364+ . px_2 ( )
320365 . child (
321366 IconButton :: new ( "id_brightness" )
322367 . icon ( IconName :: BrightnessHigh )
323368 . icon_color ( rgb ( 0xF4F4F4 ) )
324369 . size ( ( px ( 36. ) , px ( 36. ) ) )
370+ . bg_color ( rgb ( 0x202020 ) )
325371 . border ( px ( 0. ) )
326372 . on_click ( cx. listener ( |_, _, _, _| {
327373 println ! ( "brightness clicked" ) ;
@@ -333,10 +379,14 @@ impl Render for SettingsDrawer {
333379 . justify_center ( )
334380 . items_center ( )
335381 . w ( px ( 172.0 ) )
336- . h ( px ( 72.0 ) )
337- . bg ( rgb ( 0x202020 ) )
338- . rounded ( px ( 12. ) )
339- . child ( "sliderrrrr--------rrrrr" ) ,
382+ . child (
383+ Slider :: new (
384+ "brightness-slider" ,
385+ & self . brightness_slider_state ,
386+ )
387+ . width ( 172.0 )
388+ . height ( 56.0 ) ,
389+ ) ,
340390 ) ,
341391 ) ,
342392 )
@@ -351,25 +401,40 @@ impl Render for SettingsDrawer {
351401 . text_lg ( )
352402 . col_span ( 2 )
353403 . bg ( rgb ( 0x202020 ) )
354- . rounded ( px ( 12 .) )
404+ . rounded ( px ( 8 .) )
355405 . child (
356406 div ( )
357407 . flex ( )
358408 . flex_row ( )
359409 . w_full ( )
360410 . items_center ( )
361- . p_2 ( )
411+ . justify_around ( )
412+ . pl_2 ( )
362413 . child (
363414 IconButton :: new ( "id_volume" )
364415 . icon ( IconName :: VolumeMedium )
365416 . icon_color ( rgb ( 0xF4F4F4 ) )
366417 . size ( ( px ( 36. ) , px ( 36. ) ) )
418+ . bg_color ( rgb ( 0x202020 ) )
367419 . border ( px ( 0. ) )
368420 . on_click ( cx. listener ( |_, _, _, _| {
369421 println ! ( "volume clicked" ) ;
370422 } ) ) ,
371423 )
372- . child ( "sliderrrrr--------rrrrr" ) ,
424+ . child (
425+ div ( )
426+ . flex ( )
427+ . justify_center ( )
428+ . items_end ( )
429+ . w ( px ( 172.0 ) )
430+ . child (
431+ Slider :: new (
432+ "volume-slider" ,
433+ & self . volume_slider_state ,
434+ )
435+ . width ( 172.0 ) ,
436+ ) ,
437+ ) ,
373438 ) ,
374439 ) ,
375440 )
@@ -383,7 +448,7 @@ impl Render for SettingsDrawer {
383448 . child (
384449 IconButton :: new ( "id_wireless" )
385450 . icon ( self . wireless_details . icon . clone ( ) )
386- . icon_color ( rgb ( 0x4D4D4D ) ) // changes as per wireless state
451+ . icon_color ( rgb ( 0x4D4D4D ) ) // changes as per wireless state
387452 . size ( ( px ( 104. ) , px ( 104. ) ) )
388453 . active ( self . wireless_details . enalble )
389454 . label ( "Office wifi 1" )
0 commit comments