use crate::{model::settings::Feature, view::settings::SettingsWindow};
use bezel::{
gpui::{AnyElement, Context, div, prelude::*, px},
theme::{TextStyle, Theme, Typeset},
ui::{
icons,
widgets::{Content, Controls, Scaffolding},
},
};
fn copy(
feature: Feature,
) -> (
&'static [u8],
&'static str,
&'static str,
Option<&'static str>,
) {
match feature {
Feature::Sessions => (
icons::social::MessageCircle,
"Sessions",
"Runs an agent — a package this machine downloads and executes.",
None,
),
Feature::Boards => (
icons::text::List,
"Boards",
"Cards in columns, one board to a file.",
Some("Preview"),
),
Feature::Tables => (
icons::layout::LayoutGrid,
"Tables",
"Structured records in the project's store.",
Some("Preview"),
),
}
}
impl SettingsWindow {
pub(super) fn features_body(&self, cx: &Context<Self>) -> AnyElement {
let theme = Theme::of(cx).clone();
theme
.group_box()
.children(
Feature::ALL
.into_iter()
.enumerate()
.map(|(ix, feature)| self.feature_row(ix, feature, cx)),
)
.into_any_element()
}
fn feature_row(&self, ix: usize, feature: Feature, cx: &Context<Self>) -> AnyElement {
let theme = Theme::of(cx).clone();
let (glyph, title, blurb, badge) = copy(feature);
let on = feature.on(&self.workspace.read(cx).settings.features);
theme
.card_row(ix == 0)
.child(
div()
.flex_none()
.size(px(18.))
.flex()
.items_center()
.justify_center()
.child(
icons::icon(glyph)
.size(px(16.))
.flex_none()
.text_color(theme.text_muted),
),
)
.child(
div()
.flex_1()
.min_w_0()
.flex()
.flex_col()
.child(theme.row_title(title))
.child(
div()
.mt(px(4.))
.truncate()
.text_style(TextStyle::Subheadline)
.text_color(theme.text_muted)
.child(blurb),
),
)
.children(badge.map(|label| theme.badge(label)))
.child(
div()
.id(("feature", ix))
.cursor_pointer()
.child(theme.toggle(on))
.on_click(cx.listener(move |this, _, _, cx| {
this.workspace
.update(cx, |workspace, cx| workspace.set_feature(feature, !on, cx));
cx.notify();
})),
)
.into_any_element()
}
}