Skip to content

Commit 9dd76ba

Browse files
committed
add(settings drawer): add slider widget
1 parent 33f080d commit 9dd76ba

File tree

4 files changed

+444
-16
lines changed

4 files changed

+444
-16
lines changed

shell/crates/settings_drawer/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ fn main() {
1313
window_bounds: Some(window_bounds),
1414
..Default::default()
1515
},
16-
|_window, cx| cx.new(|_cx| SettingsDrawer::new()),
16+
|_window, cx| cx.new(|cx| SettingsDrawer::new(cx)),
1717
)
1818
.unwrap();
1919
cx.activate(true);

shell/crates/settings_drawer/src/ui/mod.rs

Lines changed: 80 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
mod icon;
22
mod widgets;
3-
use crate::ui::icon::Icon;
3+
use crate::ui::{
4+
icon::Icon,
5+
widgets::{Slider, SliderEvent, SliderState},
6+
};
47
use gpui::*;
58
use icon::IconName;
69
use 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

4660
impl 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")
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
mod icon_button;
2+
mod slider;
23

34
pub use icon_button::*;
5+
pub use slider::*;

0 commit comments

Comments
 (0)