slint icon indicating copy to clipboard operation
slint copied to clipboard

Menu: Add icon property

Open redstrate opened this issue 8 months ago • 5 comments

This adds an icon that is displayed to the left of the title, and is also shown for Menus are inside of a parent menu.

image

Closes #7791

redstrate avatar Apr 16 '25 14:04 redstrate

Thanks for this much appreciated patch. Looks good to me, but I'm not the right person to judge the aesthetics, but I think it is ok for now. Could you make sure that the gallery has at least one menu entry with one icon? (Also a disabled entry would be nice)

Looks like the CI is failing in the C++ tests.

   Error: /Users/runner/work/slint/cppbuild/api/cpp/generated_include/slint_builtin_structs_internal.h:139:5: error: unknown type name 'Image'
      Image icon;
      ^

This is because the builtin struct now contain an image. This header is generated in https://github.com/slint-ui/slint/blob/ec1e125e8007e0c3fa086bf354e3e39b1d7a3c1b/api/cpp/cbindgen.rs#L119 , and it should be sufficient to add an #include <slint_image.h> there.

Also the muda implementation in muda.rs is missing.

ogoffart avatar Apr 17 '25 06:04 ogoffart

Looking at the PR again, it looks like there are still some issue in the generated headers. Is that something you need help with?

ogoffart avatar May 19 '25 13:05 ogoffart

Looking at the PR again, it looks like there are still some issue in the generated headers. Is that something you need help with?

Absolutely! I have no idea what I'm doing in the C++ part of Slint, so I'm just putting in stuff blind

redstrate avatar May 19 '25 15:05 redstrate

I've fixed the include issue, but there is still an error in C++ 32bit (esp-idf):

 /__w/slint/slint/api/cpp/include/slint_sharedvector.h: In instantiation of 'struct slint::SharedVector<slint::cbindgen_private::MenuEntry>':
/__w/slint/slint/api/cpp/include/slint_window.h:106:31:   required from here
/__w/slint/slint/api/cpp/include/slint_sharedvector.h:227:30: error: static assertion failed: Not yet supported because we would need to add padding
  227 |     static_assert(alignof(T) <= alignof(SharedVectorHeader),
      |                   ~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/__w/slint/slint/api/cpp/include/slint_sharedvector.h:227:30: note: the comparison reduces to '(8 <= 4)'

The problem is because Image constains a CacheKey which contains a u64, and so can't be put in a SharedVector because struct for which alignment is bigger than the alignment of the helper data.

https://github.com/slint-ui/slint/blob/a176a553522adb052aa7c50b7e23ef2f9f3ce604/internal/core/graphics/image.rs#L293

Option include:

  1. Fix SharedVector to support higher alignment of its data
  2. Use a usize instead of a u64 for this field
  3. Something else.

Option 2. is the easier, @tronical: do you think it is safe? Otherwise I think Option 1. (fixing SharedVector) should actually be the most correct.

ogoffart avatar May 20 '25 06:05 ogoffart

The usize holds a pointer, so u64 is ok for now.

tronical avatar May 20 '25 09:05 tronical

(Rebased to fix conflicts)

ogoffart avatar Jun 26 '25 14:06 ogoffart