Skip to content

Commit

Permalink
Rework a bit the themed view example
Browse files Browse the repository at this point in the history
  • Loading branch information
gyscos committed Sep 29, 2023
1 parent 7a7d586 commit c798fe4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
3 changes: 3 additions & 0 deletions cursive-core/src/views/button.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,13 @@ impl View for Button {
}

let style = if !(self.enabled && printer.enabled) {
// Disabled button goes blue
PaletteStyle::Secondary
} else if printer.focused {
// Selected button is highlighted
PaletteStyle::Highlight
} else {
// Looks like regular text if not selected
PaletteStyle::Primary
};

Expand Down
16 changes: 10 additions & 6 deletions cursive/examples/themed_view.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use cursive::{self, theme, views, With};
use cursive::{views, With};

fn main() {
let mut cursive = cursive::default();
Expand All @@ -15,13 +15,17 @@ fn main() {
fn show_dialog(s: &mut cursive::Cursive) {
// Let's build a green theme
let theme = s.current_theme().clone().with(|theme| {
theme.palette[theme::PaletteColor::View] = theme::Color::Dark(theme::BaseColor::Black);
theme.palette[theme::PaletteColor::Primary] = theme::Color::Light(theme::BaseColor::Green);
theme.palette[theme::PaletteColor::TitlePrimary] =
theme::Color::Light(theme::BaseColor::Green);
theme.palette[theme::PaletteColor::Highlight] = theme::Color::Dark(theme::BaseColor::Green);
// Just for this function, import all color names for convenience.
use cursive::theme::{BaseColor::*, PaletteColor::*};

theme.palette[View] = Black.dark();
theme.palette[Primary] = Green.light();
theme.palette[TitlePrimary] = Green.light();
theme.palette[Highlight] = Green.dark();
theme.palette[HighlightText] = Green.light();
});

// We wrap the `Dialog` inside a `Layer` so it fills the entire view with the new `View` color.
s.add_layer(views::ThemedView::new(
theme,
views::Layer::new(views::Dialog::info("Colors!").title("Themed Dialog")),
Expand Down

0 comments on commit c798fe4

Please sign in to comment.