mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-21 23:20:20 +00:00
Documentation: Replace TRY()
example in Patterns.md
The `Menubar::add_menu()` call used in the previous code snippet no longer returns `ErrorOr`, which defeats the purpose of the example.
This commit is contained in:
parent
dcf3bdcb9a
commit
d054116012
Notes:
sideshowbarker
2024-07-18 01:43:16 +09:00
Author: https://github.com/tcl3 Commit: https://github.com/SerenityOS/serenity/commit/d054116012 Pull-request: https://github.com/SerenityOS/serenity/pull/21262 Reviewed-by: https://github.com/AtkinsSJ ✅
1 changed files with 11 additions and 8 deletions
|
@ -18,21 +18,24 @@ result of the contents of the TRY will be the result of the macro's execution.
|
|||
|
||||
### Examples:
|
||||
|
||||
Example from LibGUI:
|
||||
Example from LibGfx:
|
||||
|
||||
```cpp
|
||||
#include <AK/Try.h>
|
||||
|
||||
... snip ...
|
||||
|
||||
ErrorOr<NonnullRefPtr<Menu>> Window::try_add_menu(String name)
|
||||
ErrorOr<NonnullRefPtr<Bitmap>> Bitmap::create_shareable(BitmapFormat format, IntSize size, int scale_factor)
|
||||
{
|
||||
auto menu = m_menubar->add_menu({}, move(name));
|
||||
if (m_window_id) {
|
||||
menu->realize_menu_if_needed();
|
||||
ConnectionToWindowServer::the().async_add_menu(m_window_id, menu->menu_id());
|
||||
}
|
||||
return menu;
|
||||
if (size_would_overflow(format, size, scale_factor))
|
||||
return Error::from_string_literal("Gfx::Bitmap::create_shareable size overflow");
|
||||
|
||||
auto const pitch = minimum_pitch(size.width() * scale_factor, format);
|
||||
auto const data_size = size_in_bytes(pitch, size.height() * scale_factor);
|
||||
|
||||
auto buffer = TRY(Core::AnonymousBuffer::create_with_size(round_up_to_power_of_two(data_size, PAGE_SIZE)));
|
||||
auto bitmap = TRY(Bitmap::create_with_anonymous_buffer(format, buffer, size, scale_factor, {}));
|
||||
return bitmap;
|
||||
}
|
||||
```
|
||||
|
||||
|
|
Loading…
Reference in a new issue