styles
This commit is contained in:
+1
-1
@@ -112,7 +112,7 @@ pub fn button() -> Component {
|
|||||||
this.clicked = !this.clicked;
|
this.clicked = !this.clicked;
|
||||||
(this.on_click)(this);
|
(this.on_click)(this);
|
||||||
} else {
|
} else {
|
||||||
return UpdateResponse::Tick(vec![1, 140]);
|
return UpdateResponse::Tick(vec![1, 100]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
UpdateResponse::None
|
UpdateResponse::None
|
||||||
|
|||||||
+21
@@ -51,6 +51,25 @@ impl Component {
|
|||||||
pub fn get_active_child(&mut self) -> Option<&mut Component> {
|
pub fn get_active_child(&mut self) -> Option<&mut Component> {
|
||||||
self.children.get_mut(self.active_child)
|
self.children.get_mut(self.active_child)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn set_active_child(&mut self, idx: usize) {
|
||||||
|
let last_active = self.active_child;
|
||||||
|
if let Some(last_child) = self.children.get_mut(last_active) {
|
||||||
|
last_child.style.is_active = false;
|
||||||
|
}
|
||||||
|
if let Some(child) = self.children.get_mut(idx) {
|
||||||
|
self.active_child = idx;
|
||||||
|
if child.width == 0 {
|
||||||
|
child.width = self.width;
|
||||||
|
}
|
||||||
|
if child.height == 0 {
|
||||||
|
child.height = self.height;
|
||||||
|
}
|
||||||
|
child.style.is_active = self.style.is_active;
|
||||||
|
} else if let Some(last_child) = self.children.get_mut(last_active) {
|
||||||
|
last_child.style.is_active = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq)]
|
#[derive(Debug, Clone, PartialEq)]
|
||||||
@@ -69,6 +88,7 @@ impl App {
|
|||||||
/// Sets a component
|
/// Sets a component
|
||||||
pub fn set_component(&mut self, component: Component) {
|
pub fn set_component(&mut self, component: Component) {
|
||||||
let (width, height) = crossterm::terminal::size().unwrap();
|
let (width, height) = crossterm::terminal::size().unwrap();
|
||||||
|
self.component.style.is_active = true;
|
||||||
self.component = component;
|
self.component = component;
|
||||||
if self.component.width == 0 {
|
if self.component.width == 0 {
|
||||||
self.component.width = width as usize;
|
self.component.width = width as usize;
|
||||||
@@ -76,6 +96,7 @@ impl App {
|
|||||||
if self.component.height == 0 {
|
if self.component.height == 0 {
|
||||||
self.component.height = height as usize;
|
self.component.height = height as usize;
|
||||||
}
|
}
|
||||||
|
self.component.style.is_active = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Render to the screen
|
/// Render to the screen
|
||||||
|
|||||||
+30
-10
@@ -2,13 +2,15 @@
|
|||||||
pub struct Style {
|
pub struct Style {
|
||||||
pub bg: Color,
|
pub bg: Color,
|
||||||
pub fg: Color,
|
pub fg: Color,
|
||||||
|
pub outline: Color,
|
||||||
pub font: Font,
|
pub font: Font,
|
||||||
|
|
||||||
pub hover_bg: Color,
|
pub hover_bg: Color,
|
||||||
pub hover_fg: Color,
|
pub hover_fg: Color,
|
||||||
|
pub hover_outline: Color,
|
||||||
pub hover_font: Font,
|
pub hover_font: Font,
|
||||||
|
|
||||||
is_active: bool,
|
pub is_active: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Style {
|
impl Style {
|
||||||
@@ -16,31 +18,33 @@ impl Style {
|
|||||||
Style {
|
Style {
|
||||||
bg: Color::None,
|
bg: Color::None,
|
||||||
fg: Color::None,
|
fg: Color::None,
|
||||||
|
outline: Color::None,
|
||||||
font: Font::None,
|
font: Font::None,
|
||||||
|
|
||||||
hover_bg: Color::None,
|
hover_bg: Color::None,
|
||||||
hover_fg: Color::None,
|
hover_fg: Color::None,
|
||||||
|
hover_outline: Color::None,
|
||||||
hover_font: Font::None,
|
hover_font: Font::None,
|
||||||
|
|
||||||
is_active: false,
|
is_active: false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn update(&mut self, active: bool) {
|
|
||||||
self.is_active = active
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn get(self) -> String {
|
pub fn get(self) -> String {
|
||||||
String::from(self.fg.ansi() + &self.bg.ansi_bg() + &self.font.ansi())
|
if self.is_active {
|
||||||
|
String::from(
|
||||||
|
self.fg.prioritize(self.hover_fg).ansi()
|
||||||
|
+ &self.bg.prioritize(self.hover_bg).ansi_bg()
|
||||||
|
+ &self.font.prioritize(self.hover_font).ansi(),
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
String::from(self.fg.ansi() + &self.bg.ansi_bg() + &self.font.ansi())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_outline(self) -> String {
|
pub fn get_outline(self) -> String {
|
||||||
String::from(self.fg.ansi() + &self.bg.ansi_bg() + &self.font.ansi())
|
String::from(self.fg.ansi() + &self.bg.ansi_bg() + &self.font.ansi())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_hover(self) -> String {
|
|
||||||
String::from(self.hover_fg.ansi() + &self.hover_bg.ansi_bg() + &self.hover_font.ansi())
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq)]
|
#[derive(Debug, Clone, PartialEq)]
|
||||||
@@ -72,6 +76,14 @@ impl Font {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn prioritize(self, secondary: Font) -> Font {
|
||||||
|
if secondary == Font::None {
|
||||||
|
self
|
||||||
|
} else {
|
||||||
|
secondary
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq)]
|
#[derive(Debug, Clone, PartialEq)]
|
||||||
@@ -122,4 +134,12 @@ impl Color {
|
|||||||
Color::White => "\x1b[47m",
|
Color::White => "\x1b[47m",
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn prioritize(self, secondary: Color) -> Color {
|
||||||
|
if secondary == Color::None {
|
||||||
|
self
|
||||||
|
} else {
|
||||||
|
secondary
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user