Ribbon: an option to fold it to its tab row (#10112) (#10214)

* Ribbon: an option to fold it to its tab row (#10112)

Preferences > Layout > "Show only the ribbon's tabs" (off by default), the
Ribbon Tabs Only command (view.ribbon_tabs_only), and its settings-profile key.
Rebuilt on main's redesigned Layout page.

* Ribbon Tabs Only: switching tabs with a panel menu open no longer keeps the overlay open (#10112)

A tab click now forgets the open panel drop-down of the previous tab, so the pointer leaving or Escape still closes the overlay.

* Ribbon Tabs Only: count its settings-profile key in the profile membership test (#10112)
This commit is contained in:
raykholo authored and GitHub committed 2026-11-05 03:42:58 +00:00
1 parent 733f0b2254
commit b916f9bf33
17 files changed
+381 -26

No files matched your search

@@ -0,0 +1,38 @@
{
"en": {
"cmd.view_ribbon_tabs_only": "Ribbon Tabs Only",
"help.view.ribbon_tabs_only": "Folds the ribbon to its tab row, so the view gets the room its panels took. Click a tab to show its panels over the view; choose this again to keep the whole ribbon shown.",
"prefs.ribbon_tabs_only": "Show only the ribbon's tabs",
"prefs.ribbon_tabs_only_note": "The ribbon folds to its tab row. Clicking a tab shows its panels over the view until a command starts or the pointer leaves them. Ribbon Tabs Only in the View tab, or its shortcut, switches this."
},
"ar": {
"cmd.view_ribbon_tabs_only": "علامات تبويب الشريط فقط",
"help.view.ribbon_tabs_only": "يطوي الشريط إلى صف علامات التبويب، فتحصل منطقة العرض على المساحة التي كانت تشغلها لوحاته. انقر علامة تبويب لإظهار لوحاتها فوق منطقة العرض؛ واختر هذا الأمر مرة أخرى لإبقاء الشريط كاملًا ظاهرًا.",
"prefs.ribbon_tabs_only": "إظهار علامات تبويب الشريط فقط",
"prefs.ribbon_tabs_only_note": "يُطوى الشريط إلى صف علامات التبويب. يؤدي النقر على علامة تبويب إلى إظهار لوحاتها فوق منطقة العرض حتى يبدأ أمر أو يغادرها المؤشر. يبدّل الأمر «علامات تبويب الشريط فقط» في تبويب العرض، أو اختصاره، هذا الخيار."
},
"he": {
"cmd.view_ribbon_tabs_only": "רק לשוניות הסרט",
"help.view.ribbon_tabs_only": "מקפל את הסרט לשורת הלשוניות שלו, כך שחלון התצוגה מקבל את המקום שתפסו הלוחות. לחיצה על לשונית מציגה את הלוחות שלה מעל התצוגה; בחירה חוזרת בפקודה משאירה את הסרט כולו מוצג.",
"prefs.ribbon_tabs_only": "הצגת לשוניות הסרט בלבד",
"prefs.ribbon_tabs_only_note": "הסרט מתקפל לשורת הלשוניות שלו. לחיצה על לשונית מציגה את הלוחות שלה מעל התצוגה עד שפקודה מתחילה או שהמצביע עוזב אותם. הפקודה ״רק לשוניות הסרט״ בלשונית תצוגה, או קיצור המקשים שלה, מחליפה הגדרה זו."
},
"ja": {
"cmd.view_ribbon_tabs_only": "リボンのタブのみ",
"help.view.ribbon_tabs_only": "リボンをタブの行だけに折りたたみ、パネルが使っていた場所をビューに充てます。タブをクリックするとそのパネルがビューの上に表示されます。もう一度選ぶとリボン全体を表示したままにします。",
"prefs.ribbon_tabs_only": "リボンのタブだけを表示",
"prefs.ribbon_tabs_only_note": "リボンをタブの行だけに折りたたみます。タブをクリックすると、コマンドが始まるかポインターが離れるまで、そのパネルがビューの上に表示されます。表示タブの「リボンのタブのみ」またはそのショートカットで切り替えます。"
},
"vi": {
"cmd.view_ribbon_tabs_only": "Chỉ các thẻ ribbon",
"help.view.ribbon_tabs_only": "Thu gọn ribbon chỉ còn hàng thẻ, để khung nhìn có thêm chỗ mà các bảng từng chiếm. Bấm một thẻ để hiện các bảng của nó đè lên khung nhìn; chọn lại lệnh này để luôn hiện toàn bộ ribbon.",
"prefs.ribbon_tabs_only": "Chỉ hiện các thẻ của ribbon",
"prefs.ribbon_tabs_only_note": "Ribbon thu gọn chỉ còn hàng thẻ. Bấm một thẻ sẽ hiện các bảng của nó đè lên khung nhìn cho đến khi một lệnh bắt đầu hoặc con trỏ rời khỏi chúng. Lệnh Chỉ các thẻ ribbon trong thẻ Xem, hoặc phím tắt của nó, bật tắt tùy chọn này."
},
"zh": {
"cmd.view_ribbon_tabs_only": "仅功能区选项卡",
"help.view.ribbon_tabs_only": "将功能区折叠为选项卡行,让视图得到面板原先占用的空间。单击选项卡可在视图上方显示其面板;再次选择此命令则始终显示完整的功能区。",
"prefs.ribbon_tabs_only": "仅显示功能区的选项卡",
"prefs.ribbon_tabs_only_note": "功能区折叠为选项卡行。单击选项卡会在视图上方显示其面板,直到命令开始或指针离开面板。“视图”选项卡中的“仅功能区选项卡”或其快捷键可切换此项。"
}
}
+32 -1
View File
@@ -6,7 +6,8 @@ use solidcraft_render::{Camera, StandardView};
use super::CommandSpec;
use crate::params::{bad, num, req_vec2, req_vec3, vec3};
use crate::schema::view_navigation::{
CameraReply, NavigatorParams, NormalToParams, RenderBrowser, RenderFocus, RenderSelect, StandardViewParams, TabStep, TabStepParams,
CameraReply, NavigatorParams, NormalToParams, RenderBrowser, RenderFocus, RenderSelect, RibbonTabsOnly, RibbonTabsOnlyParams, StandardViewParams,
TabStep, TabStepParams,
};
use crate::schema::{TypedContract, output_schema_for};
use crate::{Result, Sel, Session};
@@ -17,6 +18,7 @@ const BROWSER_CONTRACT: TypedContract<RenderBrowserRequest> = TypedContract::new
const TAB_STEP_CONTRACT: TypedContract<TabStepParams> = TypedContract::new();
const STANDARD_VIEW_CONTRACT: TypedContract<StandardViewParams> = TypedContract::new();
const NORMAL_TO_CONTRACT: TypedContract<NormalToParams> = TypedContract::new();
const RIBBON_TABS_ONLY_CONTRACT: TypedContract<RibbonTabsOnlyParams> = TypedContract::new();
// Both existing request forms share the Browser command and its published schema.
#[derive(serde::Deserialize, serde::Serialize, schemars::JsonSchema)]
@@ -69,6 +71,9 @@ CommandSpec::new("view.navigator", "Custom View Navigator", crate::checked!("vie
.icon("nav_settings").noundo().doc_only()
.contract(&NAVIGATOR_CONTRACT).output(output_schema_for::<NavigatorParams>)
.params("style?: axes|cube|custom; body?: body name|null; texture?: themed|modeled; arrows?, home?: bool → the navigator as set; the app's view navigator, never saved in the design; never opens a dialog (a toolbar start opens the Custom View Navigator panel)"),
CommandSpec::new("view.ribbon_tabs_only", "Ribbon Tabs Only", crate::checked!("view.ribbon_tabs_only", ribbon_tabs_only))
.icon("chevron").noundo().doc_only().contract(&RIBBON_TABS_ONLY_CONTRACT).output(output_schema_for::<RibbonTabsOnly>)
.params("on?: bool (omitted: switch) → on?; fold the ribbon to its tab row, a tab click shows its panels over the view (window setting)"),
CommandSpec::new("view.render_focus", "Render Focus View", crate::checked!("view.render_focus", render_focus))
.icon("render_scene").noundo().doc_only()
.contract(&FOCUS_CONTRACT).output(output_schema_for::<RenderFocus>)
@@ -320,6 +325,17 @@ fn navigation_bar(_s: &mut Session, p: &Value) -> Result<Value> {
view_toggle(p, "view.navigation_bar", "visible")
}
fn ribbon_tabs_only(_s: &mut Session, p: &Value) -> Result<Value> {
let cmd = "view.ribbon_tabs_only";
let p = match p {
Value::Null => json!({}),
Value::Object(_) => p.clone(),
_ => return Err(bad(cmd, "parameters must be an object")),
};
let request: RibbonTabsOnlyParams = serde_json::from_value(p).map_err(|e| bad(cmd, e.to_string()))?;
serde_json::to_value(RibbonTabsOnly { on: request.on, param_warnings: Vec::new() }).map_err(|e| crate::EngineError::Other(e.to_string()))
}
fn status_items(s: &mut Session, p: &Value) -> Result<Value> {
if !p.is_object() {
return Err(bad("view.status_items", "parameters must be an empty object"));
@@ -645,6 +661,21 @@ mod tests {
assert!(s.camera.is_none());
}
#[test]
fn ribbon_tabs_only_echoes_the_request_without_editing_the_design() {
let mut s = Session::default();
let before = s.doc.to_json();
assert_eq!(s.execute("view.ribbon_tabs_only", &json!({})).unwrap(), json!({}));
for on in [false, true] {
assert_eq!(s.execute("view.ribbon_tabs_only", &json!({"on":on})).unwrap(), json!({"on":on}));
}
for params in [json!({"on":0}), json!({"on":"true"}), json!({"on":[]}), json!({"unexpected":true}), json!(true), json!([])] {
assert!(s.execute("view.ribbon_tabs_only", &params).is_err(), "{params}");
}
assert_eq!(s.doc.to_json(), before);
assert!(s.undo.is_empty());
}
#[test]
fn look_at_planes_uses_the_first_supported_selection_and_flips_on_repeat() {
let original = Camera { yaw: 0.3, pitch: 0.4, roll: 0.7, fov: 0.6, distance: 123.0, ..Default::default() };
@@ -131,6 +131,27 @@ pub struct TabStep {
pub param_warnings: Vec<String>,
}
/// `view.ribbon_tabs_only`: fold the ribbon to its tab row, or show it whole (#10112).
#[derive(Debug, Deserialize, JsonSchema)]
#[serde(deny_unknown_fields)]
pub struct RibbonTabsOnlyParams {
/// True folds the ribbon to its tab row, false shows it whole; omitted switches between the two.
#[serde(default)]
pub on: Option<bool>,
}
/// What `view.ribbon_tabs_only` returns: the request echoed. The window applies it to its
/// preference; the design is not changed and nothing is added to undo.
#[derive(Debug, Serialize, JsonSchema)]
pub struct RibbonTabsOnly {
/// The requested state; absent when the call asked to switch.
#[serde(skip_serializing_if = "Option::is_none")]
pub on: Option<bool>,
/// In the warn parameter-check mode: what the call's parameters got wrong.
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub param_warnings: Vec<String>,
}
/// Validated request and echoed result of `view.render_select`.
#[derive(Debug, Serialize)]
pub struct RenderSelect {
+1
View File
@@ -316,6 +316,7 @@ pub const DOCUMENTED: &[&str] = &[
"view.navigate",
"view.navigation_bar",
"view.rename",
"view.ribbon_tabs_only",
"view.save",
"view.spin",
"view.tool",
+1
View File
@@ -312,6 +312,7 @@ fn execute(app: &mut SolveApp, id: &str, params: Value) -> Result<Value, String>
| "view.grid"
| "view.ground_shadow"
| "view.navigation_bar"
| "view.ribbon_tabs_only"
| "view.next_tab"
| "view.previous_tab"
| "view.layout"
+17
View File
@@ -349,6 +349,10 @@ pub struct UiState {
/// Not saved: it only lives while a sketch is open.
#[serde(skip)]
pub sketch_return_tab: Option<String>,
/// The folded ribbon's panels are open over the view (`ribbon_tabs_only`, #10112). Not saved:
/// a tab click opens them, and a command starting or the pointer leaving closes them.
#[serde(skip)]
pub ribbon_open: bool,
/// Last contextual body/sketch, only used to select on entry.
#[serde(skip)]
pub ribbon_context: Option<String>,
@@ -411,6 +415,7 @@ impl Default for UiState {
tab: "MODEL".into(),
ribbon_context: None,
sketch_return_tab: None,
ribbon_open: false,
show_browser: true,
show_timeline: true,
show_grid: true,
@@ -1300,6 +1305,11 @@ impl SolveApp {
self.ui.show_navigation_bar = v.get("visible").and_then(Value::as_bool).unwrap_or(!self.ui.show_navigation_bar)
}
"view.next_tab" | "view.previous_tab" => documents::cycle(self, id == "view.next_tab"),
"view.ribbon_tabs_only" => {
let on = v.get("on").and_then(Value::as_bool).unwrap_or(!self.preferences.ribbon_tabs_only);
self.preferences.ribbon_tabs_only = on;
self.ui.ribbon_open = false;
}
// An edit OK'd on a feature behind the history marker changes nothing in the view:
// say why, or the edit looks as if it had silently failed (#8100).
"timeline.redefine" if v.get("rolled_back").and_then(Value::as_bool) == Some(true) => {
@@ -1615,6 +1625,13 @@ impl SolveApp {
return;
}
self.tree.clear_folder_pick();
// A command started from the folded ribbon's open panels closes them (#10112).
self.ui.ribbon_open = false;
// Folding the ribbon, or showing it whole, keeps the tab it shows (no switch to VIEW).
if id == "view.ribbon_tabs_only" {
let _ = self.run(id, json!({}));
return;
}
if id == "timeline.play" {
if let Err(why) = self.run(id, json!({})) {
self.set_status(why, true);
+4
View File
@@ -1301,6 +1301,10 @@ preference_settings! {
/// blinks there, and a running command that sits in a drop-down marks its section label. Off
/// by default: the ribbon stays as it was.
ribbon_reveal: bool = false, PAGE_LAYOUT;
/// Fold the ribbon to its tab row, so the view has the room its panels took (#10112). A tab's
/// click shows its panels over the view until a command starts or the pointer leaves them.
/// Off by default: the whole ribbon shows. `view.ribbon_tabs_only` switches it.
ribbon_tabs_only: bool = false, PAGE_LAYOUT;
/// Where a dialog's OK and Cancel sit: under its inputs (the default) or in its title row (#6708).
dialog_buttons: crate::ui_kit::DialogButtons = Default::default(), PAGE_LAYOUT;
/// Where notices and offers stack: the view's bottom-right corner (the default) or the bottom
+11 -1
View File
@@ -498,6 +498,7 @@ pub(super) fn layout(app: &mut SolveApp, ui: &mut egui::Ui) {
app.tr("prefs.sketch_tab_always"),
app.tr("prefs.layout_page.active_commands"),
app.tr("prefs.ribbon_reveal"),
app.tr("prefs.ribbon_tabs_only"),
app.tr("prefs.layout_page.pinned_menus"),
app.tr("prefs.layout_page.hover_panel_menus"),
];
@@ -543,6 +544,15 @@ pub(super) fn layout(app: &mut SolveApp, ui: &mut egui::Ui) {
);
}
3 => {
layout_check(
ui,
app.tr("prefs.ribbon_tabs_only"),
app.tr("prefs.ribbon_tabs_only_note"),
&mut app.preferences.ribbon_tabs_only,
"ribbon_tabs_only",
);
}
4 => {
layout_check(
ui,
app.tr("prefs.layout_page.pinned_menus"),
@@ -551,7 +561,7 @@ pub(super) fn layout(app: &mut SolveApp, ui: &mut egui::Ui) {
"ribbon_menus_skip_pinned",
);
}
4 => {
5 => {
layout_check(
ui,
app.tr("prefs.layout_page.hover_panel_menus"),
+1
View File
@@ -96,6 +96,7 @@ const PROFILE_KEYS: &[&str] = &[
"ribbon_menus_follow_hover",
"ribbon_menus_skip_pinned",
"ribbon_reveal",
"ribbon_tabs_only",
"right_drag_orbits",
"select_other_hidden",
"selection_shift_add_only",
@@ -17,7 +17,7 @@ fn error(h: &mut Harness, id: &str, params: Value) -> String {
#[test]
fn a_profile_holds_input_and_interface_settings_but_not_the_machine() {
let keys: Vec<&str> = keys().collect();
assert_eq!(keys.len(), 99, "page presentation must not alter profile membership");
assert_eq!(keys.len(), 100, "page presentation must not alter profile membership");
for key in [
"nav",
"mouse_gestures",
@@ -795,6 +795,7 @@ fn profile_keys_preserve_the_baseline_and_explicit_additions() {
"ribbon_menus_follow_hover",
"ribbon_menus_skip_pinned",
"ribbon_reveal",
"ribbon_tabs_only",
"right_drag_orbits",
"select_other_hidden",
"selection_shift_add_only",
@@ -843,7 +844,7 @@ fn profile_keys_preserve_the_baseline_and_explicit_additions() {
];
let mut actual: Vec<_> = keys().collect();
actual.sort_unstable();
assert_eq!(expected.len(), 99);
assert_eq!(expected.len(), 100);
assert_eq!(actual, expected);
}
+3 -2
View File
@@ -434,8 +434,9 @@ pub fn show(app: &mut SolveApp, ctx: &egui::Context) {
let mut design = Vec::new();
let mut mode = None;
// Closed, the field is part of the ribbon and belongs under the system windows the rest of
// the ribbon goes under (Preferences, say); open, its sheet floats over everything.
let floating = open || progress > 0.0;
// the ribbon goes under (Preferences, say); open, its sheet floats over everything. The
// folded ribbon's panels, open over the view (#10112), keep it on top of them too.
let floating = open || progress > 0.0 || app.ui.ribbon_open;
let response = Container::new(ctx, Surface::Popup)
.area(egui::Id::new("sc_sbox"))
.fixed_pos(pos)
+230 -20
View File
@@ -1357,7 +1357,8 @@ fn ribbon_tab_style(t: &Tokens, tab: &str, contextual: bool, active: bool, hover
RibbonTabStyle { fill, ink, outline }
}
fn ribbon_tabs(app: &mut SolveApp, ui: &mut egui::Ui, row: Rect) {
/// Returns `Some(already shown)` when a tab was clicked.
fn ribbon_tabs(app: &mut SolveApp, ui: &mut egui::Ui, row: Rect) -> Option<bool> {
let t = Tokens::get();
let tabs = crate::workspace::visible_tabs(app);
let widths: Vec<_> = tabs
@@ -1425,6 +1426,7 @@ fn ribbon_tabs(app: &mut SolveApp, ui: &mut egui::Ui, row: Rect) {
});
let end = if in_ribbon { search.left() - 6.0 } else { row.right() - inset };
let span = Rect::from_min_max(row.left_top() + vec2(inset, 0.0), pos2(end.max(row.left() + inset), row.bottom()));
let mut clicked = None;
ui.scope_builder(egui::UiBuilder::new().max_rect(span), |ui| {
ui.set_clip_rect(span);
egui::ScrollArea::horizontal()
@@ -1464,6 +1466,7 @@ fn ribbon_tabs(app: &mut SolveApp, ui: &mut egui::Ui, row: Rect) {
}
}
if response.clicked() {
clicked = Some(active);
app.ui.tab = tab.to_string();
// Floating ribbons draw after the viewport. An instant surface switch
// needs one more pass too; settled tabs never schedule their own frames.
@@ -1509,6 +1512,7 @@ fn ribbon_tabs(app: &mut SolveApp, ui: &mut egui::Ui, row: Rect) {
t.toolbar.lerp_to_gamma(t.border, 0.5),
);
}
clicked
}
/// The dropdown chevron every ribbon menu shares.
@@ -1524,29 +1528,130 @@ pub(crate) fn shell_cards(app: &SolveApp, available: Rect) -> crate::shell::Card
if crate::render_workspace::active(app) {
crate::ui_kit::StageBar::cards(available)
} else {
crate::shell::Cards::new(available, shell_layout(app), ribbon_height(app.preferences.ribbon_labels))
crate::shell::Cards::new(available, shell_layout(app), reserved_height(app))
}
}
/// The ribbon is folded to its tab row (`ribbon_tabs_only`, #10112). The Render workspace keeps
/// its own stage bar whole.
pub(crate) fn tabs_only(app: &SolveApp) -> bool {
app.preferences.ribbon_tabs_only && !crate::render_workspace::active(app)
}
/// The height the ribbon keeps from the view: the tab row alone while it is folded, whose panels
/// then open over the view.
pub(crate) fn reserved_height(app: &SolveApp) -> f32 {
if tabs_only(app) { TAB_ROW_HEIGHT + 1.0 } else { ribbon_height(app.preferences.ribbon_labels) }
}
/// Where one pass of the ribbon draws: the folded tab row, the whole ribbon, or the whole ribbon
/// opened over the view from the folded row.
#[derive(Clone, Copy)]
struct RibbonShape {
floating: bool,
cards: crate::shell::Cards,
r: Rect,
ws: Rect,
folded: bool,
}
pub fn toolbar(app: &mut SolveApp, ui: &mut egui::Ui) {
let t = Tokens::get();
crate::workspace::sync_context(app);
let layout = shell_layout(app);
let floating = Container::for_layout(layout, Surface::Panel).floating();
let labels = app.preferences.ribbon_labels;
let button_height = if labels { BUTTON_HEIGHT } else { ICON_BUTTON_HEIGHT };
let group_height = if labels { GROUP_HEIGHT } else { ICON_GROUP_HEIGHT };
let ribbon_height = ribbon_height(labels);
let gallery_width = if labels { CONSTRAINT_GRID_WIDTH } else { 6.0 * 27.0 };
let cards = shell_cards(app, ui.available_rect_before_wrap());
let height = if floating { cards.bottom - ui.available_rect_before_wrap().top() } else { ribbon_height };
let folded = tabs_only(app);
if !folded {
app.ui.ribbon_open = false;
}
let available = ui.available_rect_before_wrap();
let cards = shell_cards(app, available);
let height = if floating { cards.bottom - available.top() } else { reserved_height(app) };
let fill = if floating { Color32::TRANSPARENT } else { t.toolbar };
let host = Container::for_layout(layout, Surface::Chrome);
let ribbon = host.edge("sc_toolbar", Edge::Top);
let frame = host.edge_frame(fill);
let mut tab_click = None;
let chrome = host.show_edge(ui, ribbon.exact_size(height).show_separator_line(false), frame, |ui| {
let r = if floating { Rect::from_min_max(cards.workspace.min, cards.ribbon.max) } else { frame.outer_rect(ui.max_rect()) };
let ws = if floating { cards.workspace } else { Rect::from_min_size(r.left_top(), vec2(WORKSPACE_WIDTH, ribbon_height - 1.0)) };
let ws = if floating { cards.workspace } else { Rect::from_min_size(r.left_top(), vec2(WORKSPACE_WIDTH, height - 1.0)) };
tab_click = ribbon_contents(app, ui, RibbonShape { floating, cards, r, ws, folded });
});
if floating {
let frame = host.frame(ui.ctx(), t.toolbar, crate::frame::Side::Left);
for card in [cards.workspace, cards.ribbon] {
Container::paint_inset(ui.painter(), frame.widget_rect(card), frame);
}
} else {
Container::paint_inset(ui.painter(), chrome.response.rect - frame.outer_margin, frame);
}
if folded && (app.ui.ribbon_open || tab_click.is_some()) {
app.ui.ribbon_open = true;
open_ribbon(app, ui, available, chrome.response.rect);
}
}
/// The folded ribbon's tab, clicked: its panels open over the view, as the whole ribbon would
/// show them, until a command starts (`SolveApp::start` closes it), the pointer leaves them,
/// Escape is pressed or the open tab is clicked again (#10112).
fn open_ribbon(app: &mut SolveApp, ui: &mut egui::Ui, available: Rect, folded: Rect) {
let t = Tokens::get();
let layout = shell_layout(app);
let floating = Container::for_layout(layout, Surface::Panel).floating();
let full = ribbon_height(app.preferences.ribbon_labels);
let cards = crate::shell::Cards::new(available, layout, full);
let r = if floating {
Rect::from_min_max(cards.workspace.min, cards.ribbon.max)
} else {
Rect::from_min_size(folded.min, vec2(folded.width(), full))
};
let ws = if floating { cards.workspace } else { Rect::from_min_size(r.left_top(), vec2(WORKSPACE_WIDTH, full - 1.0)) };
let host = Container::for_layout(layout, Surface::Chrome);
let mut tab_click = None;
host.area(egui::Id::new("sc_ribbon_open")).fixed_pos(r.min).show(ui.ctx(), |ui| {
ui.set_min_size(r.size());
if !floating {
let frame = host.frame(ui.ctx(), t.toolbar, crate::frame::Side::Left);
Container::paint_frame(ui.painter(), frame, r);
}
tab_click = ribbon_contents(app, ui, RibbonShape { floating, cards, r, ws, folded: false });
if tab_click.is_some() {
// The other tab's panels are drawn now; the old tab's open drop-down is gone with them.
ui.ctx().data_mut(|d| d.remove::<egui::Id>(egui::Id::new("sc_panel_open")));
}
if floating {
let frame = host.frame(ui.ctx(), t.toolbar, crate::frame::Side::Left);
for card in [cards.workspace, cards.ribbon] {
Container::paint_inset(ui.painter(), frame.widget_rect(card), frame);
}
}
});
crate::scenario::publish_rect("ribbon:open", r);
let ctx = ui.ctx().clone();
// A panel's drop-down, a menu or a dragged button keep the panels open while the pointer is
// on them, away from the panels.
let busy = ctx.data(|d| d.get_temp::<egui::Id>(egui::Id::new("sc_panel_open")).is_some())
|| app.viewport.context_menu.is_some()
|| egui::DragAndDrop::payload::<ToolbarDrag>(&ctx).is_some();
let left = ctx.input(|i| i.pointer.latest_pos()).is_none_or(|p| !r.expand(t.space_4).contains(p));
let escape = ctx.input(|i| i.key_pressed(egui::Key::Escape));
if tab_click == Some(true) || (!busy && (left || escape)) {
app.ui.ribbon_open = false;
ctx.request_repaint();
}
}
/// One pass of the ribbon in `shape`. Returns `Some(already shown)` when a tab was clicked.
fn ribbon_contents(app: &mut SolveApp, ui: &mut egui::Ui, shape: RibbonShape) -> Option<bool> {
let t = Tokens::get();
let layout = shell_layout(app);
let host = Container::for_layout(layout, Surface::Chrome);
let labels = app.preferences.ribbon_labels;
let button_height = if labels { BUTTON_HEIGHT } else { ICON_BUTTON_HEIGHT };
let group_height = if labels { GROUP_HEIGHT } else { ICON_GROUP_HEIGHT };
let gallery_width = if labels { CONSTRAINT_GRID_WIDTH } else { 6.0 * 27.0 };
let RibbonShape { floating, cards, r, ws, folded } = shape;
{
let ribbon_left = if floating { cards.ribbon.left() } else { ws.right() };
if floating {
for card in [ws, cards.ribbon] {
@@ -1594,6 +1699,17 @@ pub fn toolbar(app: &mut SolveApp, ui: &mut egui::Ui) {
let render = crate::render_workspace::active(app);
if render {
crate::ui_kit::StageBar::workspace(ui, ws, "ws_render", app.tr("ui.render"), app.tr("ui.ribbon_workspace"));
} else if folded {
// Folded to the tab row: the workspace's name and its arrow, on one line.
let galley = egui::WidgetText::from(egui::RichText::new(app.tr("ui.design")).size(t.font_button).color(t.text)).into_galley(
ui,
Some(egui::TextWrapMode::Truncate),
(ws.width() - 2.0 * t.space_8 - t.space_12).max(0.0),
egui::TextStyle::Button,
);
let label_width = galley.size().x;
ribbon_galley(ui, pos2(ws.center().x - 6.0, ws.center().y + 1.0), galley, t.text);
dropdown_arrow(&painter, pos2(ws.center().x - 6.0 + label_width / 2.0 + 7.0, ws.center().y + 1.5), t.text_dim);
} else {
let workspace_icon = if render { "ws_render" } else { "ws_design" };
icons::paint_icon(
@@ -1630,9 +1746,13 @@ pub fn toolbar(app: &mut SolveApp, ui: &mut egui::Ui) {
crate::scenario::publish_target("ribbon:workspace", ws);
if render {
crate::render_ui::stage_bar(app, ui, cards.ribbon);
return;
return None;
}
let tab_click = ribbon_tabs(app, ui, Rect::from_min_max(pos2(ribbon_left, r.top()), pos2(r.right(), r.top() + TAB_ROW_HEIGHT)));
if folded {
crate::scenario::publish_rect("ribbon:folded", r);
return tab_click;
}
ribbon_tabs(app, ui, Rect::from_min_max(pos2(ribbon_left, r.top()), pos2(r.right(), r.top() + TAB_ROW_HEIGHT)));
// Panels.
let tab = app.ui.tab.clone();
// The command whose tool or dialog is open right now, shown pressed in the toolbar.
@@ -2318,14 +2438,7 @@ pub fn toolbar(app: &mut SolveApp, ui: &mut egui::Ui) {
ui.ctx().data_mut(|d| d.remove::<egui::Id>(egui::Id::new("sc_panel_open")));
crate::context_menu::open_for(app, at, crate::context_menu::Target::ToolbarCommand { id: id.to_string() });
}
});
if floating {
let frame = host.frame(ui.ctx(), t.toolbar, crate::frame::Side::Left);
for card in [cards.workspace, cards.ribbon] {
Container::paint_inset(ui.painter(), frame.widget_rect(card), frame);
}
} else {
Container::paint_inset(ui.painter(), chrome.response.rect - frame.outer_margin, frame);
tab_click
}
}
@@ -5306,6 +5419,103 @@ mod dropdown_toggle_tests {
}
}
/// Ribbon Tabs Only folds the ribbon to its tab row (#10112) in both layouts: a tab's click
/// opens its panels over the view, a command starting or the pointer leaving closes them, and
/// the command again keeps the whole ribbon shown.
#[test]
fn ribbon_tabs_only_folds_to_the_tab_row_and_a_tab_opens_over_the_view() {
for layout in ["compact", "floating"] {
let mut h = Harness::new();
h.app.home.open = false;
h.app.run("view.layout", json!({ "mode": layout })).unwrap();
h.frames(3);
assert!(!h.app.preferences.ribbon_tabs_only, "off by default");
let whole = rect_of("toolbar").unwrap();
let whole_view = h.app.viewport.rect.unwrap();
assert!(rect_of("ribbon:folded").is_none());
h.app.start("view.ribbon_tabs_only");
h.frames(3);
assert!(h.app.preferences.ribbon_tabs_only, "{layout}: the command folds the ribbon");
let folded = rect_of("ribbon:folded").unwrap();
assert!(folded.height() <= super::TAB_ROW_HEIGHT + 1.0, "{layout}: only the tab row is left: {folded:?}");
assert!(rect_of("panel:MODEL:CREATE").is_none(), "{layout}: no panels while folded");
if layout == "compact" {
assert!(h.app.viewport.rect.unwrap().top() < whole_view.top() - 50.0, "{layout}: the view takes the panels' room");
}
// A tab's click opens its panels over the view, as tall as the whole ribbon.
let tab = rect_of("toolbar_tab:SURFACE").unwrap().center();
h.step(&json!({"click": [tab.x, tab.y]})).unwrap();
h.frames(2);
assert_eq!(h.app.ui.tab, "SURFACE");
assert!(h.app.ui.ribbon_open, "{layout}: the tab's panels open");
let open = rect_of("ribbon:open").unwrap();
assert!((open.height() - whole.height()).abs() <= 2.0 * crate::shell::SHELL_GAP + 1.0, "{layout}: {open:?} vs {whole:?}");
assert!(rect_of("panel:SURFACE:CREATE").is_some(), "{layout}: the panels are drawn");
if layout == "compact" {
let top = h.app.viewport.rect.unwrap().top();
assert!((top - folded.bottom()).abs() <= 2.0, "{layout}: over the view, not pushing it down: {top} {folded:?}");
}
// The pointer leaving the panels closes them.
let away = h.app.viewport.rect.unwrap().center() + egui::vec2(0.0, 150.0);
h.step(&json!({"move": [away.x, away.y]})).unwrap();
h.frames(2);
assert!(!h.app.ui.ribbon_open, "{layout}: leaving closes the panels");
assert!(rect_of("ribbon:open").is_none());
// A command started from them closes them too.
h.step(&json!({"click": [tab.x, tab.y]})).unwrap();
h.frames(2);
assert!(h.app.ui.ribbon_open);
h.app.start("view.grid");
h.frames(2);
assert!(!h.app.ui.ribbon_open, "{layout}: a command closes the panels");
// The command again keeps the whole ribbon shown.
h.app.ui.tab = "SURFACE".into();
h.app.start("view.ribbon_tabs_only");
h.frames(3);
assert!(!h.app.preferences.ribbon_tabs_only);
assert_eq!(h.app.ui.tab, "SURFACE", "{layout}: the ribbon keeps its tab");
assert!(rect_of("ribbon:folded").is_none());
assert_eq!(rect_of("toolbar").unwrap().height(), whole.height(), "{layout}");
assert!(h.app.run("view.ribbon_tabs_only", json!({"on": true})).is_ok());
assert!(h.app.preferences.ribbon_tabs_only, "{layout}: `on` sets it");
assert!(h.app.session.undo.is_empty(), "{layout}: a window setting, not a design change");
}
}
/// Switching tabs with a panel's drop-down open forgets that drop-down, so the pointer leaving
/// the overlay still closes it (#10112).
#[test]
fn ribbon_tabs_only_closes_after_a_tab_switch_with_a_panel_menu_open() {
let mut h = Harness::new();
h.app.home.open = false;
h.frames(3);
h.app.start("view.ribbon_tabs_only");
h.frames(3);
let tab = rect_of("toolbar_tab:MODEL").unwrap().center();
h.step(&json!({"click": [tab.x, tab.y]})).unwrap();
h.frames(2);
h.step(&json!({"click": {"handle": "panel:MODEL:MODIFY"}})).unwrap();
h.frames(2);
let key = egui::Id::new("sc_panel_open");
assert!(h.app.ui.ribbon_open);
assert!(h.ctx.data(|d| d.get_temp::<egui::Id>(key)).is_some(), "the panel menu is open");
let other = rect_of("toolbar_tab:SURFACE").unwrap().center();
h.step(&json!({"click": [other.x, other.y]})).unwrap();
h.frames(2);
assert_eq!(h.app.ui.tab, "SURFACE");
assert!(h.app.ui.ribbon_open, "the other tab's panels are shown");
assert!(h.ctx.data(|d| d.get_temp::<egui::Id>(key)).is_none(), "the old menu is forgotten");
let away = h.app.viewport.rect.unwrap().center() + egui::vec2(0.0, 150.0);
h.step(&json!({"move": [away.x, away.y]})).unwrap();
h.frames(2);
assert!(!h.app.ui.ribbon_open, "leaving still closes the overlay");
}
/// A drop-down row's help tooltip names the key the command runs from now, not its default.
#[test]
fn a_drop_down_row_tooltip_names_a_rebound_key() {
+5
View File
@@ -398,6 +398,11 @@ pub fn toolbar_items(app: &SolveApp) -> Vec<Item> {
v.push(if on { item.key("current") } else { item });
}
// With every tab hidden there is no tab to customise.
v.push(Item::sep());
// Fold the ribbon to its tab row, or show it whole again (#10112).
let on = app.preferences.ribbon_tabs_only;
let item = crate::context_menu::cmd(app, "view.ribbon_tabs_only", "Ribbon Tabs Only").with(json!({ "on": !on }));
v.push(if on { item.key("current") } else { item });
if !crate::workspace::visible_tabs(app).contains(&app.ui.tab.as_str()) {
return v;
}
+1
View File
@@ -247,6 +247,7 @@ pub const SECTIONS: &[Section] = &[
"view.grid",
"view.ground_shadow",
"view.navigation_bar",
"view.ribbon_tabs_only",
],
},
Section { tab: "VIEW", panel: "SELECT", promoted: 0, ids: &[] },
+8
View File
@@ -221,6 +221,14 @@ The bar is empty, and so not shown, until a command is added, and holds up to 24
windows hide it with Undo and Redo. It is saved with the toolbar's customisations, so it is
exported with the keyboard shortcuts and carried by settings profiles.
Layout › **Show only the ribbon's tabs** (off by default) folds the ribbon to its tab
row, so the view gets the room its panels took. Click a tab to show its panels over the view; they
close again when a command starts, when the pointer leaves them, when Escape is pressed or when the
open tab is clicked again. The command **Ribbon Tabs Only** (VIEW tab, the toolbar's right-click
menu and command search) switches the option, so it can be given a key in Keyboard Shortcuts:
choose it again to keep the whole ribbon shown. Scripts run `view.ribbon_tabs_only` with
`{"on": true}` or `{"on": false}`, or with no parameters to switch.
Interface › Layout › **Show origin and bodies at the top** (off by default) puts the active
component's Bodies folder and the Origin (planes, axes and point) at the top of the History when
it sits on the left or under the browser and is wide enough for names. They are the browser's own
+4
View File
@@ -152,6 +152,10 @@ Sketch's Finish group reserves space at the far right even when other groups col
Additional handles: `ribbon:workspace`, `ribbon:search`, and `ribbon:section:<TAB>:<SECTION>`. Existing workspace, tab, panel, collapsed, family and command handles remain available. Layout evidence also publishes rectangles for these handles, `button:<command id>`, and the open `ribbon:search_popup`.
## Folded ribbon
`ribbon_tabs_only` (Preferences › Layout, off by default; `view.ribbon_tabs_only` switches it) keeps only the 30 px tab row, plus its 1 px line, from the view: `toolbar::reserved_height` gives the shell that height, in both layouts. The workspace column shows its name and arrow on one line. A tab's click opens the whole ribbon of that tab over the view in a Chrome area at the same place and size it has when not folded; nothing below it moves. It closes when a command starts (`SolveApp::start`), when the pointer leaves it (an open section list, a menu or a dragged button keep it open), on Escape, or when the open tab is clicked again. Render keeps its stage bar whole. Rectangles: `ribbon:folded` while folded, `ribbon:open` while open; the handles inside are the usual ones.
## Workspace and section lists
The workspace popup is 470 px wide, anchored below the workspace column. Design and Render keep their existing menu actions and enablement; planned workspaces cannot be selected. Each row also publishes `workspace:menu:<design|render|animation|simulation|manufacture|drawing>`. The constraint cells publish `ribbon:constraint:<command id>` alongside their existing `button:` and `toolbar:` handles. No icon assets or command ids were added.
+1
View File
@@ -342,6 +342,7 @@ view.render_frame the view: camera, layout, display
view.render_inspector the view: camera, layout, display
view.render_select the view: camera, layout, display
view.render_stage the view: camera, layout, display
view.ribbon_tabs_only the view: camera, layout, display
view.right the view: camera, layout, display
view.save the view: camera, layout, display
view.shots_strip the view: camera, layout, display