compactify the slider layout

this saves some empty vertical space allowing for more info
on the screen while sliders happen
This commit is contained in:
bunnie 2025-05-23 12:56:32 +08:00
parent f8bbf97724
commit 0b07c58336
3 changed files with 10 additions and 7 deletions

View file

@ -721,7 +721,7 @@ impl Gfx {
let buf = match Buffer::into_buf(list) { let buf = match Buffer::into_buf(list) {
Ok(b) => b, Ok(b) => b,
Err(e) => { Err(e) => {
log::info!("size {}", size); log::info!("Size {} won't fit", size);
log::error!("err: {:?}", e); log::error!("err: {:?}", e);
panic!("error") panic!("error")
} }

View file

@ -111,6 +111,7 @@ impl<'a> Modal<'a> {
self.gfx.clear().unwrap(); self.gfx.clear().unwrap();
} }
let mut cur_height = self.margin; let mut cur_height = self.margin;
log::debug!("start {}", cur_height);
if let Some(mut tv) = self.top_text.as_mut() { if let Some(mut tv) = self.top_text.as_mut() {
if do_redraw { if do_redraw {
self.gfx.draw_textview(&mut tv).expect("couldn't draw text"); self.gfx.draw_textview(&mut tv).expect("couldn't draw text");
@ -123,7 +124,7 @@ impl<'a> Modal<'a> {
y y
}; };
cur_height += y_clip; cur_height += y_clip;
log::trace!("top_tv height: {}", y_clip); log::debug!(" top_tv height: {}", y_clip);
self.top_memoized_height = Some(y_clip); self.top_memoized_height = Some(y_clip);
} else { } else {
log::warn!("text bounds didn't compute setting to max"); log::warn!("text bounds didn't compute setting to max");
@ -138,6 +139,7 @@ impl<'a> Modal<'a> {
self.top_dirty = false; self.top_dirty = false;
} }
log::debug!(" action @ {}", self.line_height);
let action_height = self.action.height(self.line_height, self.margin, &self); let action_height = self.action.height(self.line_height, self.margin, &self);
let action_resolver: Box<&dyn ActionApi> = Box::new(&self.action); let action_resolver: Box<&dyn ActionApi> = Box::new(&self.action);

View file

@ -91,6 +91,7 @@ impl ActionApi for Slider {
fn set_action_opcode(&mut self, op: u32) { self.action_opcode = op } fn set_action_opcode(&mut self, op: u32) { self.action_opcode = op }
fn redraw(&self, at_height: isize, modal: &Modal) { fn redraw(&self, at_height: isize, modal: &Modal) {
log::debug!(" slider @ {}", at_height);
let color = PixelColor::Light; let color = PixelColor::Light;
let fill_color = PixelColor::Dark; let fill_color = PixelColor::Dark;
@ -130,7 +131,7 @@ impl ActionApi for Slider {
// render current setting // render current setting
tv.bounds_computed = None; tv.bounds_computed = None;
tv.bounds_hint = TextBounds::GrowableFromTl( tv.bounds_hint = TextBounds::GrowableFromTl(
Point::new(offset, at_height + modal.margin + modal.line_height * 2 + modal.margin), Point::new(offset, at_height + modal.margin + modal.line_height * 1),
maxwidth, maxwidth,
); );
modal.gfx.draw_textview(&mut tv).expect("couldn't draw legend"); modal.gfx.draw_textview(&mut tv).expect("couldn't draw legend");
@ -139,10 +140,10 @@ impl ActionApi for Slider {
// the actual slider // the actual slider
let mut draw_list = ObjectList::new(); let mut draw_list = ObjectList::new();
let outer_rect = Rectangle::new_with_style( let outer_rect = Rectangle::new_with_style(
Point::new(modal.margin * 2, modal.margin + modal.line_height + at_height), Point::new(modal.margin * 2, modal.margin + modal.line_height * 0 + at_height),
Point::new( Point::new(
modal.canvas_width - modal.margin * 2, modal.canvas_width - modal.margin * 2,
modal.margin + modal.line_height * 2 + at_height, modal.margin + modal.line_height * 1 + at_height,
), ),
DrawStyle::new(fill_color, color, 2), DrawStyle::new(fill_color, color, 2),
); );
@ -151,8 +152,8 @@ impl ActionApi for Slider {
let slider_point = let slider_point =
(total_width * (self.action_payload - self.min) as isize) / (self.max - self.min) as isize; (total_width * (self.action_payload - self.min) as isize) / (self.max - self.min) as isize;
let inner_rect = Rectangle::new_with_style( let inner_rect = Rectangle::new_with_style(
Point::new(modal.margin * 2, modal.margin + modal.line_height + at_height), Point::new(modal.margin * 2, modal.margin + modal.line_height * 0 + at_height),
Point::new(modal.margin * 2 + slider_point, modal.margin + modal.line_height * 2 + at_height), Point::new(modal.margin * 2 + slider_point, modal.margin + modal.line_height * 1 + at_height),
DrawStyle::new(color, color, 1), DrawStyle::new(color, color, 1),
); );
draw_list.push(ClipObjectType::Rect(inner_rect)).unwrap(); draw_list.push(ClipObjectType::Rect(inner_rect)).unwrap();