Skip to content

Commit

Permalink
ui: Give dialogs a title bar of sorts.
Browse files Browse the repository at this point in the history
This saves one row of space in dialogs that have both a title and a
close/back button.
  • Loading branch information
kpreid committed Nov 29, 2024
1 parent 8a3df8c commit 73c1e27
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 33 deletions.
8 changes: 6 additions & 2 deletions all-is-cubes-ui/src/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ pub fn inspect_block_at_cursor(
let contents = Arc::new(vui::LayoutTree::Stack {
direction: Face6::NY,
children: vec![
back_button(inputs),
vui::leaf_widget(hit.block.clone().with_modifier(block::Quote::new())),
Arc::new(vui::LayoutTree::Stack {
direction: Face6::PX,
Expand All @@ -43,7 +42,12 @@ pub fn inspect_block_at_cursor(
],
});

vui::Page::new_modal_dialog(&inputs.hud_blocks.widget_theme, contents)
vui::Page::new_modal_dialog(
&inputs.hud_blocks.widget_theme,
literal!("Inspect Block"),
Some(back_button(inputs)),
contents,
)
}

fn inspect_block_definition(block: &Block) -> vui::WidgetTree {
Expand Down
53 changes: 25 additions & 28 deletions all-is-cubes-ui/src/ui_content/pages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,11 @@ pub(super) fn new_paused_page(
u: &mut Universe,
hud_inputs: &HudInputs,
) -> Result<vui::Page, InstallVuiError> {
use parts::{heading, shrink};
use parts::shrink;

let mut children = vec![
// TODO: establish standard resolutions for logo etc
vui::leaf_widget(shrink(u, R16, &vui::leaf_widget(logo_text()))?),
heading("Paused"),
vui::leaf_widget(open_page_button(
hud_inputs,
VuiPageState::AboutText,
Expand Down Expand Up @@ -66,6 +65,11 @@ pub(super) fn new_paused_page(
});
Ok(vui::Page::new_modal_dialog(
&hud_inputs.hud_blocks.widget_theme,
literal!("Paused"),
Some(vui::leaf_widget(pause_toggle_button(
hud_inputs,
OptionsStyle::CompactRow,
))),
contents,
))
}
Expand All @@ -86,36 +90,28 @@ pub(super) fn new_progress_page(
)),
];

// TODO: should have at least a title giving context
// TODO: should have a title sourced from the notification data
let contents = Arc::new(LayoutTree::Stack {
direction: Face6::NY,
children,
});
vui::Page::new_modal_dialog(theme, contents)
vui::Page::new_modal_dialog(theme, literal!("Progress"), None, contents)
}

pub(super) fn new_options_widget_tree(
u: &mut Universe,
hud_inputs: &HudInputs,
) -> Result<vui::Page, InstallVuiError> {
use parts::{heading, shrink};

pub(super) fn new_options_widget_tree(hud_inputs: &HudInputs) -> vui::Page {
let contents = Arc::new(LayoutTree::Stack {
direction: Face6::NY,
children: vec![
vui::leaf_widget(shrink(u, R32, &vui::leaf_widget(logo_text()))?),
heading("Options"),
back_button(hud_inputs),
Arc::new(LayoutTree::Stack {
direction: Face6::NY,
children: graphics_options_widgets(hud_inputs, OptionsStyle::LabeledColumn),
}),
],
children: vec![Arc::new(LayoutTree::Stack {
direction: Face6::NY,
children: graphics_options_widgets(hud_inputs, OptionsStyle::LabeledColumn),
})],
});
Ok(vui::Page::new_modal_dialog(
vui::Page::new_modal_dialog(
&hud_inputs.hud_blocks.widget_theme,
literal!("Options"),
Some(back_button(hud_inputs)),
contents,
))
)
}

/// TODO: The content of the about page should be customizable in the final build or
Expand Down Expand Up @@ -152,7 +148,6 @@ pub(super) fn new_about_page(
direction: Face6::NY,
children: vec![
vui::leaf_widget(shrink(u, R8, &vui::leaf_widget(logo_text()))?),
back_button(hud_inputs),
heading("Controls"),
paragraph(controls_text),
heading("About"),
Expand All @@ -164,6 +159,8 @@ pub(super) fn new_about_page(

Ok(vui::Page::new_modal_dialog(
&hud_inputs.hud_blocks.widget_theme,
literal!("About All is Cubes"),
Some(back_button(hud_inputs)),
contents,
))
}
Expand All @@ -172,12 +169,12 @@ pub(super) fn new_about_page(
pub(super) fn new_message_page(message: ArcStr, hud_inputs: &HudInputs) -> vui::Page {
use parts::paragraph;

let contents = Arc::new(LayoutTree::Stack {
direction: Face6::NY,
children: vec![paragraph(message), back_button(hud_inputs)],
});

vui::Page::new_modal_dialog(&hud_inputs.hud_blocks.widget_theme, contents)
vui::Page::new_modal_dialog(
&hud_inputs.hud_blocks.widget_theme,
literal!(""), // TODO:
Some(back_button(hud_inputs)),
paragraph(message),
)
}

/// Make a button that sends [`VuiMessage::Open`].
Expand Down
2 changes: 1 addition & 1 deletion all-is-cubes-ui/src/ui_content/vui_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ impl Vui {
);

let paused_page = pages::new_paused_page(&mut universe, &hud_inputs).unwrap();
let options_page = pages::new_options_widget_tree(&mut universe, &hud_inputs).unwrap();
let options_page = pages::new_options_widget_tree(&hud_inputs);
let about_page = pages::new_about_page(&mut universe, &hud_inputs).unwrap();
let progress_page =
pages::new_progress_page(&hud_inputs.hud_blocks.widget_theme, &notif_hub);
Expand Down
27 changes: 25 additions & 2 deletions all-is-cubes-ui/src/vui/page.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,13 @@ impl Page {
}

/// Wrap the given widget tree in a dialog box and a transparent screen-filling background.
pub fn new_modal_dialog(theme: &widgets::WidgetTheme, contents: WidgetTree) -> Self {
pub fn new_modal_dialog(
theme: &widgets::WidgetTheme,
title: ArcStr,
corner_button: Option<WidgetTree>,
contents: WidgetTree,
) -> Self {
let title_widget = vui::leaf_widget(widgets::Label::new(title));
let tree = Arc::new(LayoutTree::Stack {
direction: Face6::PZ,
children: vec![
Expand All @@ -138,7 +144,24 @@ impl Page {
})),
vui::leaf_widget(widgets::Frame::with_block(color_block!(0., 0., 0., 0.7))),
Arc::new(LayoutTree::Shrink(
theme.dialog_background().as_background_of(contents),
theme
.dialog_background()
.as_background_of(Arc::new(LayoutTree::Stack {
direction: Face6::NY,
children: vec![
Arc::new(LayoutTree::Stack {
direction: Face6::PX,
children: if let Some(corner_button) = corner_button {
// TODO: arrange so that title text is centered if possible
// (need a new LayoutTree variant or to generalize Stack, but it might help with our HUD too)
vec![corner_button, title_widget]
} else {
vec![title_widget]
},
}),
contents,
],
})),
)),
],
});
Expand Down
Binary file modified test-renderers/expected/ui/session_modal-all.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test-renderers/expected/ui/session_page_pause-all.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test-renderers/expected/ui/session_page_progress-all.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 73c1e27

Please sign in to comment.