Settings
A settings view: searchable pages in a sidebar, titled groups of rows, each with a title, a description and a control on the right that moves under the text when there is no room.
Settings
// The groups are group boxes, so they take the group box style
// set around the view.
ui.group_box_style(group_box_styles::Outline, |ui| settings_view(ui, state));
Settings::new("story-settings").show(ui, |settings| {
settings.page("General", |page| {
page.icon(general.clone());
page.description("How the gallery looks and reads.");
page.group("Appearance", |group| {
group.item(
SettingItem::new("Dark mode")
.description("Switch between light and dark themes.")
.keywords(["theme"]),
|ui| {
ui.add(Toggle::without_label(&mut state.dark));
},
);
group.item(
SettingItem::new("Follow the system")
.description("Switch theme with the system's setting."),
|ui| {
ui.add(
Toggle::new(&mut state.follow_system, "")
.style(&toggle_styles::Checkbox),
);
},
);
});
page.group("Font", |group| {
group.item(
SettingItem::new("Font size")
.description("The size of text everywhere, in points.")
.keywords(["zoom"]),
|ui| {
ui.add(Slider::new(&mut state.font_size, 10.0..=24.0));
},
);
group.item(
SettingItem::new("Line height")
.description("The space between lines, as a multiple of the size."),
|ui| {
ui.add(Slider::new(&mut state.line_height, 1.0..=2.0));
},
);
});
page.group("Other", |group| {
group.item(
SettingItem::new("Lock settings")
.description("Keep the settings below from changing."),
|ui| {
ui.add(Toggle::without_label(&mut state.locked));
},
);
group.item(
SettingItem::new("Display name")
.description("The name others see.")
.disabled(state.locked)
.stacked(),
|ui| {
ui.add(egui::TextEdit::singleline(&mut state.name).desired_width(240.0));
},
);
});
});
settings.page("About", |page| {
page.icon(about.clone());
page.group("", |group| {
group.note(
SettingItem::new("fastframe gallery")
.description("Every component in every state, in the browser."),
);
group.item(
SettingItem::new("Licence").description("MIT and Apache-2.0"),
|ui| {
ui.add(Button::new("View").small());
},
);
});
});
});
The story above is gallery/src/stories/settings.rs, running in your browser. Every snippet on this page is cut from it.