lib: Allow switching themes

This commit is contained in:
Erik Kundt
2026-01-21 13:27:58 +01:00
parent 595f2cc460
commit f3cae9f1f9
7 changed files with 22 additions and 8 deletions
+2 -1
View File
@@ -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(),
+2 -1
View File
@@ -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(),
+2 -1
View File
@@ -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(),
+2 -1
View File
@@ -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),
+5
View File
@@ -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
}
+3 -1
View File
@@ -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,
+6 -3
View File
@@ -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);