Skip to content

Menu item width#1099

Open
bhh32 wants to merge 3 commits into
pop-os:masterfrom
bhh32:menu-item-width
Open

Menu item width#1099
bhh32 wants to merge 3 commits into
pop-os:masterfrom
bhh32:menu-item-width

Conversation

@bhh32
Copy link
Copy Markdown
Contributor

@bhh32 bhh32 commented Jan 19, 2026

Summary

Refactors MenuItem from an enum to a struct wrapper, adding a .width() builder method that can be applied to any menu item type. This lets applications control submenu widths without hardcoding values into libcosmic forks/patches.

Problem

Currently, there's no way to set a custom width on menu items. This causes issues when menu content (like file paths) is longer than the default width, resulting is bad looking UI.

Before:
before_cosmic-edit_menu_ui

After:
after_cosmic-viewer_ui

Changes

  • Renamed MenuItem enum to MenuItemKind
  • Created new MenuItem struct wrapping MenuItemKind with optional width field
  • Added .width(u16) builder method
  • Added convenience constructors: button(), button_disabled(), checkbox(), folder(), and divider()
  • Updated menu_items() to apply width to all item types.
  • Updated responsive_menu_bar.rs to use new API

Usage

// Old API
menu::Item::Folder(fl!("recent-folders"), items)

// New API
menu::Item::folder(fl!("recent-folders"), items).width(300)

Migration

Existing code using enum variants (Item::Button(...), Item::Folder(...), etc.) should switch to the method constructors (Item::button(...), Item::folder(...), etc.). The From impl provides backwards compatibility for code that builds MenuItemKind directly.

@mmstick
Copy link
Copy Markdown
Member

mmstick commented Jan 21, 2026

It would be better if we calculate the width in the widget so that they're automatically resized.

/// Kind of menu item.
kind: MenuItemKind<A, L>,
/// Optional width override for this item's submenu.
width: Option<u16>,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A min and max width might be better as the widget should be calculating width automatically. The width will change depending on the language use.

@mmstick
Copy link
Copy Markdown
Member

mmstick commented Jan 21, 2026

This should also update the menu examples, and have examples included in the code docs

@git-f0x
Copy link
Copy Markdown
Contributor

git-f0x commented Jan 21, 2026

Might also be nice if there was a context menu widget that has the same behavior as the menu bar popups, so that it can have nested menus (e.g. Open with... > list of apps in a nested menu in COSMIC Files). Or maybe the same widget and it just differs in the way it's spawned?

@bhh32
Copy link
Copy Markdown
Contributor Author

bhh32 commented Jan 21, 2026

This should also update the menu examples, and have examples included in the code docs

I can definitely update the examples and code docs.

@bhh32
Copy link
Copy Markdown
Contributor Author

bhh32 commented Feb 2, 2026

@mmstick, I've updated the examples and doc comments. I also added min_width and max_width builder options, updated MenuTree, and get_children_layout to ensure that internal auto-resizing occurs and is clamped to the min_width and max_width restrictions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants