fixup! chore(core/rust): Add dynamic place system

mmilata/dynamic_place
Martin Milata 2 years ago
parent d51fdf4487
commit 48ac54d17e

@ -1,4 +1,3 @@
use core::ops::{Range, RangeFrom};
use heapless::Vec;
use crate::ui::{
@ -7,7 +6,7 @@ use crate::ui::{
geometry::{Dimensions, Insets, LinearPlacement, Rect},
};
use super::layout::{DefaultTextTheme, LayoutFit, TextLayout, TextNoOp, TextRenderer};
use super::layout::{DefaultTextTheme, LayoutFit, TextLayout};
pub const MAX_PARAGRAPHS: usize = 6;
/// Maximum space between paragraphs. Actual result may be smaller (even 0) if

@ -54,8 +54,10 @@ where
let (content_area, button_area) = bounds.split_bottom(button_height);
let (content_area, scrollbar_area) = content_area.split_right(ScrollBar::WIDTH);
let content_area = content_area.inset(Insets::top(1));
self.pad.place(content_area);
self.pad.place(bounds);
self.content.place(content_area);
let page_count = self.content.page_count();
self.scrollbar.set_count_and_active_page(page_count, 0);
self.scrollbar.place(scrollbar_area);
self.prev.place(button_area);
self.next.place(button_area);

@ -92,7 +92,11 @@ mod tests {
use crate::{
error::Error,
trace::Trace,
ui::model_t1::component::{Dialog, DialogMsg},
ui::{
component::Component,
display,
model_t1::component::{Dialog, DialogMsg},
},
};
use super::*;
@ -121,7 +125,7 @@ mod tests {
#[test]
fn trace_example_layout() {
let layout = Dialog::new(
let mut layout = Dialog::new(
FormattedText::new::<theme::T1DefaultText>(
"Testing text layout, with some text, and some more text. And {param}",
)
@ -137,6 +141,7 @@ mod tests {
theme::button_default(),
)),
);
layout.place(display::screen());
assert_eq!(
trace(&layout),
r#"<Dialog content:<Text content:Testing text layout,
@ -148,7 +153,7 @@ arameters! > left:<Button text:Left > right:<Button text:Right > >"#
#[test]
fn trace_layout_title() {
let layout = Frame::new(
let mut layout = Frame::new(
"Please confirm",
Dialog::new(
FormattedText::new::<theme::T1DefaultText>(
@ -167,6 +172,7 @@ arameters! > left:<Button text:Left > right:<Button text:Right > >"#
)),
),
);
layout.place(display::screen());
assert_eq!(
trace(&layout),
r#"<Frame title:Please confirm content:<Dialog content:<Text content:Testing text layout,

@ -36,7 +36,9 @@ where
// Same as PageLayout::BUTTON_SPACE.
const TITLE_SPACE: i32 = 6;
let (title_area, content_area) = bounds.split_top(theme::FONT_BOLD.text_height());
let (title_area, content_area) = bounds
.inset(theme::borders_scroll())
.split_top(theme::FONT_BOLD.text_height());
let title_area = title_area.inset(Insets::left(theme::CONTENT_BORDER));
let content_area = content_area.inset(Insets::top(TITLE_SPACE));

@ -75,6 +75,7 @@ where
fn place(&mut self, bounds: Rect) -> Rect {
let layout = PageLayout::new(bounds);
self.pad.place(bounds);
self.swipe.place(bounds);
self.buttons.place(layout.buttons);
self.scrollbar.place(layout.scrollbar);

@ -1,7 +1,7 @@
use crate::ui::{
component::{label::LabelStyle, text::layout::DefaultTextTheme},
display::{self, Color, Font},
geometry::{Insets, Rect},
display::{Color, Font},
geometry::Insets,
};
use super::component::{ButtonStyle, ButtonStyleSheet, LoaderStyle, LoaderStyleSheet};
@ -165,6 +165,6 @@ pub const CONTENT_BORDER: i32 = 5;
/// | +----+ |
/// | 14 |
/// +----------+
pub fn borders() -> Rect {
display::screen().inset(Insets::new(13, 5, 14, 10))
pub fn borders_scroll() -> Insets {
Insets::new(13, 5, 14, 10)
}

Loading…
Cancel
Save