Generalize `draw_image_switch` to `draw_image_segmented_control`
This commit is contained in:
parent
940605fbb5
commit
5a2c716688
|
@ -449,28 +449,37 @@ impl<D> UIPresenter<D> where D: Device {
|
||||||
value
|
value
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn draw_image_switch(&mut self,
|
pub fn draw_image_segmented_control(&mut self,
|
||||||
device: &D,
|
device: &D,
|
||||||
mut origin: Point2DI32,
|
mut origin: Point2DI32,
|
||||||
segment_textures: &[&D::Texture],
|
segment_textures: &[&D::Texture],
|
||||||
mut value: u8)
|
mut value: Option<u8>)
|
||||||
-> u8 {
|
-> Option<u8> {
|
||||||
if let Some(new_value) = self.draw_segmented_control(device,
|
let mut clicked_segment = None;
|
||||||
origin,
|
if let Some(segment_index) = self.draw_segmented_control(device,
|
||||||
Some(value),
|
origin,
|
||||||
segment_textures.len() as u8) {
|
value,
|
||||||
value = new_value;
|
segment_textures.len() as u8) {
|
||||||
|
if let Some(ref mut value) = value {
|
||||||
|
*value = segment_index;
|
||||||
|
}
|
||||||
|
clicked_segment = Some(segment_index);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (segment_index, segment_texture) in segment_textures.iter().enumerate() {
|
for (segment_index, segment_texture) in segment_textures.iter().enumerate() {
|
||||||
let texture_width = device.texture_size(segment_texture).x();
|
let texture_width = device.texture_size(segment_texture).x();
|
||||||
let offset = SEGMENT_SIZE / 2 - texture_width / 2;
|
let offset = Point2DI32::new(SEGMENT_SIZE / 2 - texture_width / 2, PADDING);
|
||||||
let color = if segment_index as u8 == value { TEXT_COLOR } else { WINDOW_COLOR };
|
let color = if Some(segment_index as u8) == value {
|
||||||
self.draw_texture(device, origin + Point2DI32::new(offset, 0), segment_texture, color);
|
WINDOW_COLOR
|
||||||
|
} else {
|
||||||
|
TEXT_COLOR
|
||||||
|
};
|
||||||
|
|
||||||
|
self.draw_texture(device, origin + offset, segment_texture, color);
|
||||||
origin += Point2DI32::new(SEGMENT_SIZE + 1, 0);
|
origin += Point2DI32::new(SEGMENT_SIZE + 1, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
value
|
clicked_segment
|
||||||
}
|
}
|
||||||
|
|
||||||
fn draw_segmented_control(&mut self,
|
fn draw_segmented_control(&mut self,
|
||||||
|
|
Loading…
Reference in New Issue