mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 16:07:46 +00:00
StringViewize a bunch of things -- mostly LibGUI
This commit is contained in:
parent
f9ba7adae2
commit
1024dfa81a
59 changed files with 129 additions and 139 deletions
|
@ -66,7 +66,7 @@ RetainPtr<Font> Font::clone() const
|
|||
return adopt(*new Font(m_name, new_rows, new_widths, m_fixed_width, m_glyph_width, m_glyph_height));
|
||||
}
|
||||
|
||||
Font::Font(const String& name, unsigned* rows, byte* widths, bool is_fixed_width, byte glyph_width, byte glyph_height)
|
||||
Font::Font(const StringView& name, unsigned* rows, byte* widths, bool is_fixed_width, byte glyph_width, byte glyph_height)
|
||||
: m_name(name)
|
||||
, m_rows(rows)
|
||||
, m_glyph_widths(widths)
|
||||
|
@ -113,7 +113,7 @@ RetainPtr<Font> Font::load_from_memory(const byte* data)
|
|||
return adopt(*new Font(String(header.name), rows, widths, !header.is_variable_width, header.glyph_width, header.glyph_height));
|
||||
}
|
||||
|
||||
RetainPtr<Font> Font::load_from_file(const String& path)
|
||||
RetainPtr<Font> Font::load_from_file(const StringView& path)
|
||||
{
|
||||
MappedFile mapped_file(path);
|
||||
if (!mapped_file.is_valid())
|
||||
|
@ -124,7 +124,7 @@ RetainPtr<Font> Font::load_from_file(const String& path)
|
|||
return font;
|
||||
}
|
||||
|
||||
bool Font::write_to_file(const String& path)
|
||||
bool Font::write_to_file(const StringView& path)
|
||||
{
|
||||
int fd = creat(path.characters(), 0644);
|
||||
if (fd < 0) {
|
||||
|
@ -158,22 +158,17 @@ bool Font::write_to_file(const String& path)
|
|||
return true;
|
||||
}
|
||||
|
||||
int Font::width(const String& string) const
|
||||
int Font::width(const StringView& string) const
|
||||
{
|
||||
return width(string.characters(), string.length());
|
||||
}
|
||||
|
||||
int Font::width(const char* characters, int length) const
|
||||
{
|
||||
if (!length)
|
||||
if (!string.length())
|
||||
return 0;
|
||||
|
||||
if (m_fixed_width)
|
||||
return length * m_glyph_width;
|
||||
return string.length() * m_glyph_width;
|
||||
|
||||
int width = 0;
|
||||
for (int i = 0; i < length; ++i)
|
||||
width += glyph_width(characters[i]) + 1;
|
||||
for (int i = 0; i < string.length(); ++i)
|
||||
width += glyph_width(string.characters()[i]) + 1;
|
||||
|
||||
return width - 1;
|
||||
}
|
||||
|
|
|
@ -48,8 +48,8 @@ public:
|
|||
|
||||
RetainPtr<Font> clone() const;
|
||||
|
||||
static RetainPtr<Font> load_from_file(const String& path);
|
||||
bool write_to_file(const String& path);
|
||||
static RetainPtr<Font> load_from_file(const StringView& path);
|
||||
bool write_to_file(const StringView& path);
|
||||
|
||||
~Font();
|
||||
|
||||
|
@ -60,11 +60,10 @@ public:
|
|||
byte min_glyph_width() const { return m_min_glyph_width; }
|
||||
byte max_glyph_width() const { return m_max_glyph_width; }
|
||||
byte glyph_spacing() const { return m_fixed_width ? 0 : 1; }
|
||||
int width(const String& string) const;
|
||||
int width(const char*, int) const;
|
||||
int width(const StringView& string) const;
|
||||
|
||||
String name() const { return m_name; }
|
||||
void set_name(const String& name) { m_name = name; }
|
||||
void set_name(const StringView& name) { m_name = name; }
|
||||
|
||||
bool is_fixed_width() const { return m_fixed_width; }
|
||||
void set_fixed_width(bool b) { m_fixed_width = b; }
|
||||
|
@ -76,7 +75,7 @@ public:
|
|||
}
|
||||
|
||||
private:
|
||||
Font(const String& name, unsigned* rows, byte* widths, bool is_fixed_width, byte glyph_width, byte glyph_height);
|
||||
Font(const StringView& name, unsigned* rows, byte* widths, bool is_fixed_width, byte glyph_width, byte glyph_height);
|
||||
|
||||
static RetainPtr<Font> load_from_memory(const byte*);
|
||||
|
||||
|
|
|
@ -29,12 +29,12 @@ Retained<GraphicsBitmap> GraphicsBitmap::create_wrapper(Format format, const Siz
|
|||
return adopt(*new GraphicsBitmap(format, size, data));
|
||||
}
|
||||
|
||||
RetainPtr<GraphicsBitmap> GraphicsBitmap::load_from_file(const String& path)
|
||||
RetainPtr<GraphicsBitmap> GraphicsBitmap::load_from_file(const StringView& path)
|
||||
{
|
||||
return load_png(path);
|
||||
}
|
||||
|
||||
RetainPtr<GraphicsBitmap> GraphicsBitmap::load_from_file(Format format, const String& path, const Size& size)
|
||||
RetainPtr<GraphicsBitmap> GraphicsBitmap::load_from_file(Format format, const StringView& path, const Size& size)
|
||||
{
|
||||
MappedFile mapped_file(path);
|
||||
if (!mapped_file.is_valid())
|
||||
|
@ -86,7 +86,7 @@ GraphicsBitmap::~GraphicsBitmap()
|
|||
delete [] m_palette;
|
||||
}
|
||||
|
||||
void GraphicsBitmap::set_mmap_name(const String& name)
|
||||
void GraphicsBitmap::set_mmap_name(const StringView& name)
|
||||
{
|
||||
ASSERT(m_needs_munmap);
|
||||
::set_mmap_name(m_data, size_in_bytes(), name.characters());
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
#include <AK/Retainable.h>
|
||||
#include <AK/RetainPtr.h>
|
||||
#include <AK/AKString.h>
|
||||
#include <AK/StringView.h>
|
||||
#include <AK/MappedFile.h>
|
||||
#include <SharedBuffer.h>
|
||||
|
||||
|
@ -15,8 +16,8 @@ public:
|
|||
|
||||
static Retained<GraphicsBitmap> create(Format, const Size&);
|
||||
static Retained<GraphicsBitmap> create_wrapper(Format, const Size&, RGBA32*);
|
||||
static RetainPtr<GraphicsBitmap> load_from_file(const String& path);
|
||||
static RetainPtr<GraphicsBitmap> load_from_file(Format, const String& path, const Size&);
|
||||
static RetainPtr<GraphicsBitmap> load_from_file(const StringView& path);
|
||||
static RetainPtr<GraphicsBitmap> load_from_file(Format, const StringView& path, const Size&);
|
||||
static Retained<GraphicsBitmap> create_with_shared_buffer(Format, Retained<SharedBuffer>&&, const Size&);
|
||||
~GraphicsBitmap();
|
||||
|
||||
|
@ -36,7 +37,7 @@ public:
|
|||
bool has_alpha_channel() const { return m_format == Format::RGBA32; }
|
||||
Format format() const { return m_format; }
|
||||
|
||||
void set_mmap_name(const String&);
|
||||
void set_mmap_name(const StringView&);
|
||||
|
||||
size_t size_in_bytes() const { return m_pitch * m_size.height(); }
|
||||
|
||||
|
|
|
@ -101,7 +101,7 @@ private:
|
|||
static RetainPtr<GraphicsBitmap> load_png_impl(const byte*, int);
|
||||
static bool process_chunk(Streamer&, PNGLoadingContext& context);
|
||||
|
||||
RetainPtr<GraphicsBitmap> load_png(const String& path)
|
||||
RetainPtr<GraphicsBitmap> load_png(const StringView& path)
|
||||
{
|
||||
MappedFile mapped_file(path);
|
||||
if (!mapped_file.is_valid())
|
||||
|
|
|
@ -2,4 +2,4 @@
|
|||
|
||||
#include <SharedGraphics/GraphicsBitmap.h>
|
||||
|
||||
RetainPtr<GraphicsBitmap> load_png(const String& path);
|
||||
RetainPtr<GraphicsBitmap> load_png(const StringView& path);
|
||||
|
|
|
@ -512,8 +512,8 @@ void Painter::draw_text(const Rect& rect, const char* text, int length, const Fo
|
|||
{
|
||||
String elided_text;
|
||||
if (elision == TextElision::Right) {
|
||||
int text_width = font.width(text, length);
|
||||
if (font.width(text, length) > rect.width()) {
|
||||
int text_width = font.width(StringView(text, length));
|
||||
if (font.width(StringView(text, length)) > rect.width()) {
|
||||
int glyph_spacing = font.glyph_spacing();
|
||||
int new_length = 0;
|
||||
int new_width = font.width("...");
|
||||
|
@ -546,10 +546,10 @@ void Painter::draw_text(const Rect& rect, const char* text, int length, const Fo
|
|||
} else if (alignment == TextAlignment::CenterLeft) {
|
||||
point = { rect.x(), rect.center().y() - (font.glyph_height() / 2) };
|
||||
} else if (alignment == TextAlignment::CenterRight) {
|
||||
int text_width = font.width(text);
|
||||
int text_width = font.width(StringView(text, length));
|
||||
point = { rect.right() - text_width, rect.center().y() - (font.glyph_height() / 2) };
|
||||
} else if (alignment == TextAlignment::Center) {
|
||||
int text_width = font.width(text);
|
||||
int text_width = font.width(StringView(text, length));
|
||||
point = rect.center();
|
||||
point.move_by(-(text_width / 2), -(font.glyph_height() / 2));
|
||||
} else {
|
||||
|
@ -568,12 +568,12 @@ void Painter::draw_text(const Rect& rect, const char* text, int length, const Fo
|
|||
}
|
||||
}
|
||||
|
||||
void Painter::draw_text(const Rect& rect, const String& text, TextAlignment alignment, Color color, TextElision elision)
|
||||
void Painter::draw_text(const Rect& rect, const StringView& text, TextAlignment alignment, Color color, TextElision elision)
|
||||
{
|
||||
draw_text(rect, text.characters(), text.length(), alignment, color, elision);
|
||||
}
|
||||
|
||||
void Painter::draw_text(const Rect& rect, const String& text, const Font& font, TextAlignment alignment, Color color, TextElision elision)
|
||||
void Painter::draw_text(const Rect& rect, const StringView& text, const Font& font, TextAlignment alignment, Color color, TextElision elision)
|
||||
{
|
||||
draw_text(rect, text.characters(), text.length(), font, alignment, color, elision);
|
||||
}
|
||||
|
|
|
@ -32,8 +32,8 @@ public:
|
|||
void blit_scaled(const Point&, const GraphicsBitmap&, const Rect& src_rect, const Size&);
|
||||
void draw_text(const Rect&, const char* text, int length, const Font&, TextAlignment = TextAlignment::TopLeft, Color = Color::Black, TextElision = TextElision::None);
|
||||
void draw_text(const Rect&, const char* text, int length, TextAlignment = TextAlignment::TopLeft, Color = Color::Black, TextElision = TextElision::None);
|
||||
void draw_text(const Rect&, const String&, const Font&, TextAlignment = TextAlignment::TopLeft, Color = Color::Black, TextElision = TextElision::None);
|
||||
void draw_text(const Rect&, const String&, TextAlignment = TextAlignment::TopLeft, Color = Color::Black, TextElision = TextElision::None);
|
||||
void draw_text(const Rect&, const StringView&, const Font&, TextAlignment = TextAlignment::TopLeft, Color = Color::Black, TextElision = TextElision::None);
|
||||
void draw_text(const Rect&, const StringView&, TextAlignment = TextAlignment::TopLeft, Color = Color::Black, TextElision = TextElision::None);
|
||||
void draw_glyph(const Point&, char, Color);
|
||||
void draw_glyph(const Point&, char, const Font&, Color);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue