parent
8471e0c455
commit
65178a6a36
@ -0,0 +1,79 @@
|
||||
use crate::{
|
||||
strutil::TString,
|
||||
ui::{
|
||||
component::{Component, Event, EventCtx, Never, Pad},
|
||||
display::{self, Color, Font},
|
||||
geometry::{Offset, Rect},
|
||||
},
|
||||
};
|
||||
|
||||
pub struct Connect {
|
||||
fg: Color,
|
||||
bg: Pad,
|
||||
message: TString<'static>,
|
||||
}
|
||||
|
||||
impl Connect {
|
||||
pub fn new<T>(message: T, fg: Color, bg: Color) -> Self
|
||||
where
|
||||
T: Into<TString<'static>>,
|
||||
{
|
||||
let mut instance = Self {
|
||||
fg,
|
||||
bg: Pad::with_background(bg),
|
||||
message: message.into(),
|
||||
};
|
||||
|
||||
instance.bg.clear();
|
||||
instance
|
||||
}
|
||||
}
|
||||
|
||||
impl Component for Connect {
|
||||
type Msg = Never;
|
||||
|
||||
fn place(&mut self, bounds: Rect) -> Rect {
|
||||
self.bg.place(bounds);
|
||||
bounds
|
||||
}
|
||||
|
||||
fn event(&mut self, _ctx: &mut EventCtx, _event: Event) -> Option<Self::Msg> {
|
||||
None
|
||||
}
|
||||
|
||||
fn paint(&mut self) {
|
||||
let font = Font::NORMAL;
|
||||
|
||||
self.bg.paint();
|
||||
self.message.map(|t| {
|
||||
display::text_center(
|
||||
self.bg.area.center() + Offset::y(font.text_height() / 2),
|
||||
t,
|
||||
font,
|
||||
self.fg,
|
||||
self.bg.color,
|
||||
)
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "micropython")]
|
||||
mod micropython {
|
||||
use crate::{error::Error, micropython::obj::Obj, ui::layout::obj::ComponentMsgObj};
|
||||
|
||||
use super::Connect;
|
||||
|
||||
impl ComponentMsgObj for Connect {
|
||||
fn msg_try_into_obj(&self, _msg: Self::Msg) -> Result<Obj, Error> {
|
||||
unreachable!()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "ui_debug")]
|
||||
impl crate::trace::Trace for Connect {
|
||||
fn trace(&self, t: &mut dyn crate::trace::Tracer) {
|
||||
t.component("Connect");
|
||||
t.string("message", self.message);
|
||||
}
|
||||
}
|
@ -1,47 +0,0 @@
|
||||
use crate::ui::{
|
||||
component::{Component, Event, EventCtx, Never, Pad},
|
||||
display::{self, Font},
|
||||
geometry::{Offset, Rect},
|
||||
};
|
||||
|
||||
use super::super::theme::bootloader::{BLD_BG, BLD_FG};
|
||||
|
||||
pub struct Connect {
|
||||
bg: Pad,
|
||||
message: &'static str,
|
||||
}
|
||||
|
||||
impl Connect {
|
||||
pub fn new(message: &'static str) -> Self {
|
||||
Self {
|
||||
bg: Pad::with_background(BLD_BG).with_clear(),
|
||||
message,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Component for Connect {
|
||||
type Msg = Never;
|
||||
|
||||
fn place(&mut self, bounds: Rect) -> Rect {
|
||||
self.bg.place(bounds);
|
||||
bounds
|
||||
}
|
||||
|
||||
fn event(&mut self, _ctx: &mut EventCtx, _event: Event) -> Option<Self::Msg> {
|
||||
None
|
||||
}
|
||||
|
||||
fn paint(&mut self) {
|
||||
let font = Font::NORMAL;
|
||||
|
||||
self.bg.paint();
|
||||
display::text_center(
|
||||
self.bg.area.center() + Offset::y(font.text_height() / 2),
|
||||
self.message,
|
||||
font,
|
||||
BLD_FG,
|
||||
BLD_BG,
|
||||
);
|
||||
}
|
||||
}
|
@ -1,52 +0,0 @@
|
||||
use crate::ui::{
|
||||
component::{Component, Event, EventCtx, Never, Pad},
|
||||
constant::screen,
|
||||
display::{self, Color, Font},
|
||||
geometry::{Offset, Rect},
|
||||
model_tt::theme::bootloader::BLD_TITLE_COLOR,
|
||||
};
|
||||
|
||||
pub struct Connect {
|
||||
fg: Color,
|
||||
bg: Pad,
|
||||
message: &'static str,
|
||||
}
|
||||
|
||||
impl Connect {
|
||||
pub fn new(message: &'static str, fg: Color, bg: Color) -> Self {
|
||||
let mut instance = Self {
|
||||
fg,
|
||||
bg: Pad::with_background(bg),
|
||||
message,
|
||||
};
|
||||
|
||||
instance.bg.clear();
|
||||
instance
|
||||
}
|
||||
}
|
||||
|
||||
impl Component for Connect {
|
||||
type Msg = Never;
|
||||
|
||||
fn place(&mut self, bounds: Rect) -> Rect {
|
||||
self.bg.place(screen());
|
||||
bounds
|
||||
}
|
||||
|
||||
fn event(&mut self, _ctx: &mut EventCtx, _event: Event) -> Option<Self::Msg> {
|
||||
None
|
||||
}
|
||||
|
||||
fn paint(&mut self) {
|
||||
let font = Font::NORMAL;
|
||||
|
||||
self.bg.paint();
|
||||
display::text_center(
|
||||
screen().center() + Offset::y(font.text_height() / 2),
|
||||
self.message,
|
||||
Font::NORMAL,
|
||||
BLD_TITLE_COLOR,
|
||||
self.bg.color,
|
||||
);
|
||||
}
|
||||
}
|
Loading…
Reference in new issue