cushy/examples/manual-tabs.rs
Jonathan Johnson 03e93adb15
Select buttons
2023-11-29 17:14:42 -08:00

34 lines
937 B
Rust

//! This example show show to use a stack of buttons and a switcher to achieve a
//! tab-like widget.
use std::collections::HashMap;
use gooey::value::{Dynamic, Switchable};
use gooey::widget::MakeWidget;
use gooey::Run;
#[derive(Debug, Eq, PartialEq, Clone, Hash)]
enum Tab {
First,
Second,
Missing,
}
fn main() -> gooey::Result {
let mut tab_contents = HashMap::new();
tab_contents.insert(Tab::First, "This is the first tab!".make_widget());
tab_contents.insert(Tab::Second, "This is the second tab!".make_widget());
let selected_tab = Dynamic::new(Tab::First);
let tabs = selected_tab
.new_select(Tab::First, "First")
.and(selected_tab.new_select(Tab::Second, "Second"))
.and(selected_tab.new_select(Tab::Missing, "Missing"))
.into_columns();
tabs.and(selected_tab.switch_between(tab_contents))
.into_rows()
.fit_vertically()
.run()
}