mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 07:30:19 +00:00
LibGUI: Use String::formatted() and String::number() more
This commit is contained in:
parent
f181ddb56a
commit
7bb18215cb
Notes:
sideshowbarker
2024-07-19 00:10:08 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/7bb18215cbe
15 changed files with 48 additions and 24 deletions
|
@ -184,7 +184,7 @@ RefPtr<Gfx::Bitmap> load_bmp(const StringView& path)
|
|||
return nullptr;
|
||||
auto bitmap = load_bmp_impl((const u8*)mapped_file.data(), mapped_file.size());
|
||||
if (bitmap)
|
||||
bitmap->set_mmap_name(String::format("Gfx::Bitmap [%dx%d] - Decoded BMP: %s", bitmap->width(), bitmap->height(), LexicalPath::canonicalized_path(path).characters()));
|
||||
bitmap->set_mmap_name(String::formatted("Gfx::Bitmap [{}] - Decoded BMP: {}", bitmap->size(), LexicalPath::canonicalized_path(path)));
|
||||
return bitmap;
|
||||
}
|
||||
|
||||
|
@ -192,7 +192,7 @@ RefPtr<Gfx::Bitmap> load_bmp_from_memory(const u8* data, size_t length)
|
|||
{
|
||||
auto bitmap = load_bmp_impl(data, length);
|
||||
if (bitmap)
|
||||
bitmap->set_mmap_name(String::format("Gfx::Bitmap [%dx%d] - Decoded BMP: <memory>", bitmap->width(), bitmap->height()));
|
||||
bitmap->set_mmap_name(String::formatted("Gfx::Bitmap [{}] - Decoded BMP: <memory>", bitmap->size()));
|
||||
return bitmap;
|
||||
}
|
||||
|
||||
|
|
|
@ -113,7 +113,7 @@ RefPtr<Gfx::Bitmap> load_gif(const StringView& path)
|
|||
GIFImageDecoderPlugin gif_decoder((const u8*)mapped_file.data(), mapped_file.size());
|
||||
auto bitmap = gif_decoder.bitmap();
|
||||
if (bitmap)
|
||||
bitmap->set_mmap_name(String::format("Gfx::Bitmap [%dx%d] - Decoded GIF: %s", bitmap->width(), bitmap->height(), LexicalPath::canonicalized_path(path).characters()));
|
||||
bitmap->set_mmap_name(String::formatted("Gfx::Bitmap [{}] - Decoded GIF: {}", bitmap->size(), LexicalPath::canonicalized_path(path)));
|
||||
return bitmap;
|
||||
}
|
||||
|
||||
|
@ -122,7 +122,7 @@ RefPtr<Gfx::Bitmap> load_gif_from_memory(const u8* data, size_t length)
|
|||
GIFImageDecoderPlugin gif_decoder(data, length);
|
||||
auto bitmap = gif_decoder.bitmap();
|
||||
if (bitmap)
|
||||
bitmap->set_mmap_name(String::format("Gfx::Bitmap [%dx%d] - Decoded GIF: <memory>", bitmap->width(), bitmap->height()));
|
||||
bitmap->set_mmap_name(String::formatted("Gfx::Bitmap [{}] - Decoded GIF: <memory>", bitmap->size()));
|
||||
return bitmap;
|
||||
}
|
||||
|
||||
|
|
|
@ -122,7 +122,7 @@ RefPtr<Gfx::Bitmap> load_ico(const StringView& path)
|
|||
ICOImageDecoderPlugin decoder((const u8*)mapped_file.data(), mapped_file.size());
|
||||
auto bitmap = decoder.bitmap();
|
||||
if (bitmap)
|
||||
bitmap->set_mmap_name(String::format("Gfx::Bitmap [%dx%d] - Decoded ICO: %s", bitmap->width(), bitmap->height(), LexicalPath::canonicalized_path(path).characters()));
|
||||
bitmap->set_mmap_name(String::formatted("Gfx::Bitmap [{}] - Decoded ICO: {}", bitmap->size(), LexicalPath::canonicalized_path(path)));
|
||||
return bitmap;
|
||||
}
|
||||
|
||||
|
@ -131,7 +131,7 @@ RefPtr<Gfx::Bitmap> load_ico_from_memory(const u8* data, size_t length)
|
|||
ICOImageDecoderPlugin decoder(data, length);
|
||||
auto bitmap = decoder.bitmap();
|
||||
if (bitmap)
|
||||
bitmap->set_mmap_name(String::format("Gfx::Bitmap [%dx%d] - Decoded ICO: <memory>", bitmap->width(), bitmap->height()));
|
||||
bitmap->set_mmap_name(String::formatted("Gfx::Bitmap [{}] - Decoded ICO: <memory>", bitmap->size()));
|
||||
return bitmap;
|
||||
}
|
||||
|
||||
|
|
|
@ -1327,7 +1327,7 @@ RefPtr<Gfx::Bitmap> load_jpg(const StringView& path)
|
|||
|
||||
auto bitmap = load_jpg_impl((const u8*)mapped_file.data(), mapped_file.size());
|
||||
if (bitmap)
|
||||
bitmap->set_mmap_name(String::format("Gfx::Bitmap [%dx%d] - Decoded JPG: %s", bitmap->width(), bitmap->height(), LexicalPath::canonicalized_path(path).characters()));
|
||||
bitmap->set_mmap_name(String::formatted("Gfx::Bitmap [{}] - Decoded JPG: {}", bitmap->size(), LexicalPath::canonicalized_path(path)));
|
||||
return bitmap;
|
||||
}
|
||||
|
||||
|
@ -1335,7 +1335,7 @@ RefPtr<Gfx::Bitmap> load_jpg_from_memory(const u8* data, size_t length)
|
|||
{
|
||||
auto bitmap = load_jpg_impl(data, length);
|
||||
if (bitmap)
|
||||
bitmap->set_mmap_name(String::format("Gfx::Bitmap [%dx%d] - Decoded jpg: <memory>", bitmap->width(), bitmap->height()));
|
||||
bitmap->set_mmap_name(String::formatted("Gfx::Bitmap [{}] - Decoded jpg: <memory>", bitmap->size()));
|
||||
return bitmap;
|
||||
}
|
||||
|
||||
|
|
|
@ -120,7 +120,7 @@ RefPtr<Gfx::Bitmap> load_pbm_from_memory(const u8* data, size_t length)
|
|||
{
|
||||
auto bitmap = load_impl<PBMLoadingContext>(data, length);
|
||||
if (bitmap)
|
||||
bitmap->set_mmap_name(String::format("Gfx::Bitmap [%dx%d] - Decoded PBM: <memory>", bitmap->width(), bitmap->height()));
|
||||
bitmap->set_mmap_name(String::formatted("Gfx::Bitmap [{}] - Decoded PBM: <memory>", bitmap->size()));
|
||||
return bitmap;
|
||||
}
|
||||
|
||||
|
|
|
@ -109,7 +109,7 @@ RefPtr<Gfx::Bitmap> load_pgm_from_memory(const u8* data, size_t length)
|
|||
{
|
||||
auto bitmap = load_impl<PGMLoadingContext>(data, length);
|
||||
if (bitmap)
|
||||
bitmap->set_mmap_name(String::format("Gfx::Bitmap [%dx%d] - Decoded PGM: <memory>", bitmap->width(), bitmap->height()));
|
||||
bitmap->set_mmap_name(String::formatted("Gfx::Bitmap [{}] - Decoded PGM: <memory>", bitmap->size()));
|
||||
return bitmap;
|
||||
}
|
||||
|
||||
|
|
|
@ -198,7 +198,7 @@ RefPtr<Gfx::Bitmap> load_png(const StringView& path)
|
|||
return nullptr;
|
||||
auto bitmap = load_png_impl((const u8*)mapped_file.data(), mapped_file.size());
|
||||
if (bitmap)
|
||||
bitmap->set_mmap_name(String::format("Gfx::Bitmap [%dx%d] - Decoded PNG: %s", bitmap->width(), bitmap->height(), LexicalPath::canonicalized_path(path).characters()));
|
||||
bitmap->set_mmap_name(String::formatted("Gfx::Bitmap [{}] - Decoded PNG: {}", bitmap->size(), LexicalPath::canonicalized_path(path)));
|
||||
return bitmap;
|
||||
}
|
||||
|
||||
|
@ -206,7 +206,7 @@ RefPtr<Gfx::Bitmap> load_png_from_memory(const u8* data, size_t length)
|
|||
{
|
||||
auto bitmap = load_png_impl(data, length);
|
||||
if (bitmap)
|
||||
bitmap->set_mmap_name(String::format("Gfx::Bitmap [%dx%d] - Decoded PNG: <memory>", bitmap->width(), bitmap->height()));
|
||||
bitmap->set_mmap_name(String::formatted("Gfx::Bitmap [{}] - Decoded PNG: <memory>", bitmap->size()));
|
||||
return bitmap;
|
||||
}
|
||||
|
||||
|
|
|
@ -131,7 +131,7 @@ RefPtr<Gfx::Bitmap> load_ppm_from_memory(const u8* data, size_t length)
|
|||
{
|
||||
auto bitmap = load_impl<PPMLoadingContext>(data, length);
|
||||
if (bitmap)
|
||||
bitmap->set_mmap_name(String::format("Gfx::Bitmap [%dx%d] - Decoded PPM: <memory>", bitmap->width(), bitmap->height()));
|
||||
bitmap->set_mmap_name(String::formatted("Gfx::Bitmap [{}] - Decoded PPM: <memory>", bitmap->size()));
|
||||
return bitmap;
|
||||
}
|
||||
|
||||
|
|
|
@ -1532,7 +1532,7 @@ void Painter::fill_path(Path& path, Color color, WindingRule winding_rule)
|
|||
});
|
||||
#ifdef FILL_PATH_DEBUG
|
||||
if ((int)scanline % 10 == 0) {
|
||||
draw_text(IntRect(active_list.last().x - 20, scanline, 20, 10), String::format("%d", (int)scanline));
|
||||
draw_text(IntRect(active_list.last().x - 20, scanline, 20, 10), String::number((int)scanline));
|
||||
}
|
||||
#endif
|
||||
|
||||
|
|
|
@ -51,13 +51,13 @@ void Point<T>::constrain(const Rect<T>& rect)
|
|||
template<>
|
||||
String IntPoint::to_string() const
|
||||
{
|
||||
return String::format("[%d,%d]", x(), y());
|
||||
return String::formatted("[{},{}]", x(), y());
|
||||
}
|
||||
|
||||
template<>
|
||||
String FloatPoint::to_string() const
|
||||
{
|
||||
return String::format("[%f,%f]", x(), y());
|
||||
return String::formatted("[{},{}]", x(), y());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -26,7 +26,7 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <AK/Forward.h>
|
||||
#include <AK/Format.h>
|
||||
#include <AK/StdLibExtras.h>
|
||||
#include <LibGfx/Forward.h>
|
||||
#include <LibGfx/Orientation.h>
|
||||
|
@ -237,6 +237,18 @@ using FloatPoint = Point<float>;
|
|||
|
||||
}
|
||||
|
||||
namespace AK {
|
||||
|
||||
template<typename T>
|
||||
struct Formatter<Gfx::Point<T>> : Formatter<StringView> {
|
||||
void format(FormatBuilder& builder, const Gfx::Point<T>& value)
|
||||
{
|
||||
Formatter<StringView>::format(builder, value.to_string());
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
namespace IPC {
|
||||
|
||||
bool encode(Encoder&, const Gfx::IntPoint&);
|
||||
|
|
|
@ -317,10 +317,10 @@ static RefPtr<Gfx::Bitmap> load(const StringView& path)
|
|||
|
||||
auto bitmap = load_impl<TContext>((const u8*)mapped_file.data(), mapped_file.size());
|
||||
if (bitmap)
|
||||
bitmap->set_mmap_name(String::format("Gfx::Bitmap [%dx%d] - Decoded %s: %s",
|
||||
bitmap->width(), bitmap->height(),
|
||||
bitmap->set_mmap_name(String::formatted("Gfx::Bitmap [{}] - Decoded {}: {}",
|
||||
bitmap->size(),
|
||||
TContext::image_type,
|
||||
LexicalPath::canonicalized_path(path).characters()));
|
||||
LexicalPath::canonicalized_path(path)));
|
||||
return bitmap;
|
||||
}
|
||||
|
||||
|
|
|
@ -34,13 +34,13 @@ namespace Gfx {
|
|||
template<>
|
||||
String IntSize::to_string() const
|
||||
{
|
||||
return String::format("[%dx%d]", m_width, m_height);
|
||||
return String::formatted("[{}x{}]", m_width, m_height);
|
||||
}
|
||||
|
||||
template<>
|
||||
String FloatSize::to_string() const
|
||||
{
|
||||
return String::format("[%fx%f]", m_width, m_height);
|
||||
return String::formatted("[{}x{}]", m_width, m_height);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -26,7 +26,7 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <AK/Forward.h>
|
||||
#include <AK/Format.h>
|
||||
#include <LibGfx/Orientation.h>
|
||||
#include <LibIPC/Forward.h>
|
||||
|
||||
|
@ -159,6 +159,18 @@ using FloatSize = Size<float>;
|
|||
|
||||
}
|
||||
|
||||
namespace AK {
|
||||
|
||||
template<typename T>
|
||||
struct Formatter<Gfx::Size<T>> : Formatter<StringView> {
|
||||
void format(FormatBuilder& builder, const Gfx::Size<T>& value)
|
||||
{
|
||||
Formatter<StringView>::format(builder, value.to_string());
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
namespace IPC {
|
||||
|
||||
bool encode(Encoder&, const Gfx::IntSize&);
|
||||
|
|
|
@ -31,7 +31,7 @@ namespace Gfx {
|
|||
|
||||
String Triangle::to_string() const
|
||||
{
|
||||
return String::format("(%s,%s,%s)", m_a.to_string().characters(), m_b.to_string().characters(), m_c.to_string().characters());
|
||||
return String::format("({},{},{})", m_a, m_b, m_c);
|
||||
}
|
||||
|
||||
const LogStream& operator<<(const LogStream& stream, const Triangle& value)
|
||||
|
|
Loading…
Reference in a new issue