Skip to content

Commit 76c03e7

Browse files
committed
add slider methods
1 parent 62d7a4a commit 76c03e7

File tree

5 files changed

+46
-2
lines changed

5 files changed

+46
-2
lines changed

lvgl/src/support.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,9 @@ pub enum Event<T> {
139139
/// case, `Event<_>::PressLost` is sent.
140140
Released,
141141

142+
/// Called when an underlying value is changed e.g. position of a `Slider`.
143+
ValueChanged,
144+
142145
/// Pointer-like input devices events (E.g. mouse or touchpad)
143146
Pointer(PointerEvent),
144147

@@ -159,6 +162,7 @@ impl<S> TryFrom<lvgl_sys::lv_event_code_t> for Event<S> {
159162
const LV_EVENT_LONG_PRESSED_REPEAT: u32 =
160163
lvgl_sys::lv_event_code_t_LV_EVENT_LONG_PRESSED_REPEAT;
161164
const LV_EVENT_RELEASED: u32 = lvgl_sys::lv_event_code_t_LV_EVENT_RELEASED;
165+
const LV_EVENT_VALUE_CHANGED: u32 = lvgl_sys::lv_event_code_t_LV_EVENT_VALUE_CHANGED;
162166

163167
match value {
164168
LV_EVENT_PRESSED => Ok(Event::Pressed),
@@ -169,6 +173,7 @@ impl<S> TryFrom<lvgl_sys::lv_event_code_t> for Event<S> {
169173
LV_EVENT_LONG_PRESSED => Ok(Event::LongPressed),
170174
LV_EVENT_LONG_PRESSED_REPEAT => Ok(Event::LongPressedRepeat),
171175
LV_EVENT_RELEASED => Ok(Event::Released),
176+
LV_EVENT_VALUE_CHANGED => Ok(Event::ValueChanged),
172177
_ => Err(()),
173178
}
174179
}
@@ -185,6 +190,7 @@ impl<S> From<Event<S>> for lvgl_sys::lv_event_code_t {
185190
Event::LongPressed => lvgl_sys::lv_event_code_t_LV_EVENT_LONG_PRESSED,
186191
Event::LongPressedRepeat => lvgl_sys::lv_event_code_t_LV_EVENT_LONG_PRESSED_REPEAT,
187192
Event::Released => lvgl_sys::lv_event_code_t_LV_EVENT_RELEASED,
193+
Event::ValueChanged => lvgl_sys::lv_event_code_t_LV_EVENT_VALUE_CHANGED,
188194
// TODO: handle all types...
189195
_ => lvgl_sys::lv_event_code_t_LV_EVENT_CLICKED,
190196
};

lvgl/src/widgets/arc.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
use crate::widgets::Arc;
2+
use crate::LvResult;
3+
use crate::lv_core::obj::NativeObject;
24

35
impl Arc {
46
// /// Set the start angle, for the given arc part.
@@ -36,6 +38,13 @@ impl Arc {
3638
// }
3739
// Ok(())
3840
// }
41+
42+
/// Gets the current value of the arc
43+
pub fn get_value(&self) -> LvResult<i32> {
44+
unsafe {
45+
Ok(lvgl_sys::lv_bar_get_value(self.core.raw()?.as_ptr()))
46+
}
47+
}
3948
}
4049
/*
4150
/// The different parts, of an arc object.

lvgl/src/widgets/bar.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,13 @@ impl Bar {
1818
}
1919
Ok(())
2020
}
21+
22+
/// Gets the current value of the bar
23+
pub fn get_value(&self) -> LvResult<i32> {
24+
unsafe {
25+
Ok(lvgl_sys::lv_bar_get_value(self.core.raw()?.as_ptr()))
26+
}
27+
}
2128
}
2229
/*
2330
/// The different parts, of a bar object.

lvgl/src/widgets/mod.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,19 @@
55
//! widget with no parent will have a screen as its parent. Style data is
66
//! inherited from parent objects by default.
77
8-
//mod arc;
8+
mod arc;
99
mod bar;
1010
mod keyboard;
1111
mod label;
1212
mod meter;
13+
mod slider;
1314

1415
include!(concat!(env!("OUT_DIR"), "/generated.rs"));
1516

1617
use crate::NativeObject;
17-
//pub use arc::*;
18+
pub use arc::*;
1819
pub use bar::*;
1920
pub use keyboard::*;
2021
pub use label::*;
2122
pub use meter::*;
23+
pub use slider::*;

lvgl/src/widgets/slider.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
use crate::widgets::Slider;
2+
use crate::{LvResult, Animation};
3+
use crate::lv_core::obj::NativeObject;
4+
5+
impl Slider {
6+
/// Set a new value on the slider
7+
pub fn set_value(&self, value: i32, anim: Animation) -> LvResult<()> {
8+
unsafe {
9+
lvgl_sys::lv_bar_set_value(self.core.raw()?.as_ptr(), value, anim.into())
10+
}
11+
Ok(())
12+
}
13+
14+
/// Gets the current value of the slider
15+
pub fn get_value(&self) -> LvResult<i32> {
16+
unsafe {
17+
Ok(lvgl_sys::lv_bar_get_value(self.core.raw()?.as_ptr()))
18+
}
19+
}
20+
}

0 commit comments

Comments
 (0)