Radish alpha
r
rad:z39mP9rQAaGmERfUMPULfPUi473tY
Radicle terminal user interface
Radicle
Git
lib: Allow switching themes
Erik Kundt committed 3 months ago
commit f3cae9f1f99184ebe64344acc52755550d7c90d6
parent 595f2cc
7 files changed +22 -8
modified README.md
@@ -147,6 +147,7 @@ use radicle_tui as tui;
use tui::event::Key;
use tui::store;
use tui::task::EmptyProcessors;
+
use tui::ui::theme::Theme;
use tui::ui::widget::{Borders, Window};
use tui::ui::{Context, Show};
use tui::{Channel, Exit};
@@ -173,7 +174,7 @@ impl store::Update<Message> for App {

impl Show<Message> for App {
    fn show(&self, ctx: &Context<Message>, frame: &mut Frame) -> Result<()> {
-
        Window::default().show(ctx, |ui| {
+
        Window::default().show(ctx, Theme::default(), |ui| {
            ui.text_view(
                frame,
                self.hello.clone(),
modified examples/hello.rs
@@ -9,6 +9,7 @@ use radicle_tui as tui;
use tui::event::Key;
use tui::store;
use tui::task::EmptyProcessors;
+
use tui::ui::theme::Theme;
use tui::ui::widget::{Borders, Window};
use tui::ui::{Context, Show};
use tui::{Channel, Exit};
@@ -50,7 +51,7 @@ impl store::Update<Message> for App {

impl Show<Message> for App {
    fn show(&self, ctx: &Context<Message>, frame: &mut Frame) -> Result<()> {
-
        Window::default().show(ctx, |ui| {
+
        Window::default().show(ctx, Theme::default(), |ui| {
            ui.text_view(
                frame,
                self.alien.clone(),
modified examples/readme.rs
@@ -8,6 +8,7 @@ use radicle_tui as tui;
use tui::event::Key;
use tui::store;
use tui::task::EmptyProcessors;
+
use tui::ui::theme::Theme;
use tui::ui::widget::{Borders, Window};
use tui::ui::{Context, Show};
use tui::{Channel, Exit};
@@ -34,7 +35,7 @@ impl store::Update<Message> for App {

impl Show<Message> for App {
    fn show(&self, ctx: &Context<Message>, frame: &mut Frame) -> Result<()> {
-
        Window::default().show(ctx, |ui| {
+
        Window::default().show(ctx, Theme::default(), |ui| {
            ui.text_view(
                frame,
                self.hello.clone(),
modified examples/selection.rs
@@ -14,6 +14,7 @@ use tui::event::Key;
use tui::store::Update;
use tui::task::EmptyProcessors;
use tui::ui::layout::Spacing;
+
use tui::ui::theme::Theme;
use tui::ui::widget::{Borders, Column, TableState, Window};
use tui::ui::{Context, Show, ToRow};
use tui::Channel;
@@ -75,7 +76,7 @@ impl Update<Message> for App {

impl Show<Message> for App {
    fn show(&self, ctx: &Context<Message>, frame: &mut Frame) -> Result<()> {
-
        Window::default().show(ctx, |ui| {
+
        Window::default().show(ctx, Theme::default(), |ui| {
            ui.layout(
                Layout::vertical([
                    Constraint::Length(1),
modified src/ui.rs
@@ -397,6 +397,11 @@ impl<M> Ui<M> {
        self
    }

+
    pub fn with_theme(mut self, theme: Theme) -> Self {
+
        self.theme = theme;
+
        self
+
    }
+

    pub fn theme(&self) -> &Theme {
        &self.theme
    }
modified src/ui/theme.rs
@@ -1,6 +1,8 @@
+
use serde::{Deserialize, Serialize};
+

use ratatui::style::{Color, Style, Stylize};

-
#[derive(Clone, Debug)]
+
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct Theme {
    pub border_style: Style,
    pub focus_border_style: Style,
modified src/ui/widget.rs
@@ -15,7 +15,7 @@ use ratatui::{layout::Constraint, widgets::Paragraph};
use crate::event::Key;
use crate::ui::ext::{FooterBlock, FooterBlockType, HeaderBlock};
use crate::ui::layout::Spacing;
-
use crate::ui::theme::style;
+
use crate::ui::theme::{style, Theme};
use crate::ui::ToRow;
use crate::ui::{layout, span, ToTree};

@@ -131,17 +131,19 @@ impl Window {
    pub fn show<M, R>(
        self,
        ctx: &Context<M>,
+
        theme: Theme,
        add_contents: impl FnOnce(&mut Ui<M>) -> R,
    ) -> Option<InnerResponse<Option<R>>>
    where
        M: Clone,
    {
-
        self.show_dyn(ctx, Box::new(add_contents))
+
        self.show_dyn(ctx, theme, Box::new(add_contents))
    }

    fn show_dyn<M, R>(
        self,
        ctx: &Context<M>,
+
        theme: Theme,
        add_contents: Box<AddContentFn<M, R>>,
    ) -> Option<InnerResponse<Option<R>>>
    where
@@ -152,7 +154,8 @@ impl Window {
            .with_area(ctx.frame_size())
            .with_ctx(ctx.clone())
            .with_layout(Layout::horizontal([Constraint::Min(1)]).into())
-
            .with_area_focus(Some(0));
+
            .with_area_focus(Some(0))
+
            .with_theme(theme);

        let inner = add_contents(&mut ui);