mirror of
https://github.com/RGBCube/serenity
synced 2025-05-14 06:24:58 +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
|
@ -9,11 +9,10 @@
|
|||
|
||||
namespace AK {
|
||||
|
||||
MappedFile::MappedFile(const String& file_name)
|
||||
: m_file_name(file_name)
|
||||
MappedFile::MappedFile(const StringView& file_name)
|
||||
{
|
||||
m_size = PAGE_SIZE;
|
||||
m_fd = open(m_file_name.characters(), O_RDONLY | O_CLOEXEC);
|
||||
m_fd = open(file_name.characters(), O_RDONLY | O_CLOEXEC);
|
||||
|
||||
if (m_fd != -1) {
|
||||
struct stat st;
|
||||
|
@ -26,7 +25,7 @@ MappedFile::MappedFile(const String& file_name)
|
|||
}
|
||||
|
||||
#ifdef DEBUG_MAPPED_FILE
|
||||
dbgprintf("MappedFile{%s} := { m_fd=%d, m_size=%u, m_map=%p }\n", m_file_name.characters(), m_fd, m_size, m_map);
|
||||
dbgprintf("MappedFile{%s} := { m_fd=%d, m_size=%u, m_map=%p }\n", file_name.characters(), m_fd, m_size, m_map);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -44,15 +43,13 @@ void MappedFile::unmap()
|
|||
ASSERT(rc == 0);
|
||||
rc = close(m_fd);
|
||||
ASSERT(rc == 0);
|
||||
m_file_name = {};
|
||||
m_size = 0;
|
||||
m_fd = -1;
|
||||
m_map = (void*)-1;
|
||||
}
|
||||
|
||||
MappedFile::MappedFile(MappedFile&& other)
|
||||
: m_file_name(move(other.m_file_name))
|
||||
, m_size(other.m_size)
|
||||
: m_size(other.m_size)
|
||||
, m_fd(other.m_fd)
|
||||
, m_map(other.m_map)
|
||||
{
|
||||
|
@ -66,7 +63,6 @@ MappedFile& MappedFile::operator=(MappedFile&& other)
|
|||
if (this == &other)
|
||||
return *this;
|
||||
unmap();
|
||||
swap(m_file_name, other.m_file_name);
|
||||
swap(m_size, other.m_size);
|
||||
swap(m_fd, other.m_fd);
|
||||
swap(m_map, other.m_map);
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
#pragma once
|
||||
|
||||
#include "AKString.h"
|
||||
#include "StringView.h"
|
||||
|
||||
namespace AK {
|
||||
|
||||
class MappedFile {
|
||||
public:
|
||||
MappedFile() {}
|
||||
explicit MappedFile(const String& file_name);
|
||||
explicit MappedFile(const StringView& file_name);
|
||||
MappedFile(MappedFile&&);
|
||||
~MappedFile();
|
||||
|
||||
|
@ -21,7 +21,6 @@ public:
|
|||
size_t size() const { return m_size; }
|
||||
|
||||
private:
|
||||
String m_file_name;
|
||||
size_t m_size { 0 };
|
||||
int m_fd { -1 };
|
||||
void* m_map { (void*)-1 };
|
||||
|
|
|
@ -184,7 +184,7 @@ int main(int argc, char** argv)
|
|||
menubar->add_menu(move(app_menu));
|
||||
|
||||
auto font_menu = make<GMenu>("Font");
|
||||
GFontDatabase::the().for_each_fixed_width_font([&] (const String& font_name) {
|
||||
GFontDatabase::the().for_each_fixed_width_font([&] (const StringView& font_name) {
|
||||
font_menu->add_action(GAction::create(font_name, [&terminal, &config] (const GAction& action) {
|
||||
terminal.set_font(GFontDatabase::the().get_by_name(action.text()));
|
||||
auto metadata = GFontDatabase::the().get_metadata_by_name(action.text());
|
||||
|
|
|
@ -99,7 +99,7 @@ int main(int argc, char** argv)
|
|||
menubar->add_menu(move(edit_menu));
|
||||
|
||||
auto font_menu = make<GMenu>("Font");
|
||||
GFontDatabase::the().for_each_fixed_width_font([&] (const String& font_name) {
|
||||
GFontDatabase::the().for_each_fixed_width_font([&] (const StringView& font_name) {
|
||||
font_menu->add_action(GAction::create(font_name, [text_editor] (const GAction& action) {
|
||||
text_editor->set_font(GFontDatabase::the().get_by_name(action.text()));
|
||||
text_editor->update();
|
||||
|
|
|
@ -6,7 +6,7 @@ GAbstractButton::GAbstractButton(GWidget* parent)
|
|||
{
|
||||
}
|
||||
|
||||
GAbstractButton::GAbstractButton(const String& text, GWidget* parent)
|
||||
GAbstractButton::GAbstractButton(const StringView& text, GWidget* parent)
|
||||
: GWidget(parent)
|
||||
, m_text(text)
|
||||
{
|
||||
|
@ -16,7 +16,7 @@ GAbstractButton::~GAbstractButton()
|
|||
{
|
||||
}
|
||||
|
||||
void GAbstractButton::set_text(const String& text)
|
||||
void GAbstractButton::set_text(const StringView& text)
|
||||
{
|
||||
if (m_text == text)
|
||||
return;
|
||||
|
|
|
@ -11,7 +11,7 @@ public:
|
|||
|
||||
Function<void(bool)> on_checked;
|
||||
|
||||
void set_text(const String&);
|
||||
void set_text(const StringView&);
|
||||
const String& text() const { return m_text; }
|
||||
|
||||
bool is_checked() const { return m_checked; }
|
||||
|
@ -29,7 +29,7 @@ public:
|
|||
|
||||
protected:
|
||||
explicit GAbstractButton(GWidget* parent);
|
||||
GAbstractButton(const String&, GWidget* parent);
|
||||
GAbstractButton(const StringView&, GWidget* parent);
|
||||
|
||||
virtual void mousedown_event(GMouseEvent&) override;
|
||||
virtual void mousemove_event(GMouseEvent&) override;
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
#include <LibGUI/GButton.h>
|
||||
#include <LibGUI/GMenuItem.h>
|
||||
|
||||
GAction::GAction(const String& text, const String& custom_data, Function<void(GAction&)> on_activation_callback, GWidget* widget)
|
||||
GAction::GAction(const StringView& text, const StringView& custom_data, Function<void(GAction&)> on_activation_callback, GWidget* widget)
|
||||
: on_activation(move(on_activation_callback))
|
||||
, m_text(text)
|
||||
, m_custom_data(custom_data)
|
||||
|
@ -11,12 +11,12 @@ GAction::GAction(const String& text, const String& custom_data, Function<void(GA
|
|||
{
|
||||
}
|
||||
|
||||
GAction::GAction(const String& text, Function<void(GAction&)> on_activation_callback, GWidget* widget)
|
||||
GAction::GAction(const StringView& text, Function<void(GAction&)> on_activation_callback, GWidget* widget)
|
||||
: GAction(text, String(), move(on_activation_callback), widget)
|
||||
{
|
||||
}
|
||||
|
||||
GAction::GAction(const String& text, RetainPtr<GraphicsBitmap>&& icon, Function<void(GAction&)> on_activation_callback, GWidget* widget)
|
||||
GAction::GAction(const StringView& text, RetainPtr<GraphicsBitmap>&& icon, Function<void(GAction&)> on_activation_callback, GWidget* widget)
|
||||
: on_activation(move(on_activation_callback))
|
||||
, m_text(text)
|
||||
, m_icon(move(icon))
|
||||
|
@ -24,13 +24,13 @@ GAction::GAction(const String& text, RetainPtr<GraphicsBitmap>&& icon, Function<
|
|||
{
|
||||
}
|
||||
|
||||
GAction::GAction(const String& text, const GShortcut& shortcut, Function<void(GAction&)> on_activation_callback, GWidget* widget)
|
||||
GAction::GAction(const StringView& text, const GShortcut& shortcut, Function<void(GAction&)> on_activation_callback, GWidget* widget)
|
||||
: GAction(text, shortcut, nullptr, move(on_activation_callback), widget)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
GAction::GAction(const String& text, const GShortcut& shortcut, RetainPtr<GraphicsBitmap>&& icon, Function<void(GAction&)> on_activation_callback, GWidget* widget)
|
||||
GAction::GAction(const StringView& text, const GShortcut& shortcut, RetainPtr<GraphicsBitmap>&& icon, Function<void(GAction&)> on_activation_callback, GWidget* widget)
|
||||
: on_activation(move(on_activation_callback))
|
||||
, m_text(text)
|
||||
, m_icon(move(icon))
|
||||
|
|
|
@ -24,23 +24,23 @@ public:
|
|||
ApplicationGlobal,
|
||||
WidgetLocal,
|
||||
};
|
||||
static Retained<GAction> create(const String& text, Function<void(GAction&)> callback, GWidget* widget = nullptr)
|
||||
static Retained<GAction> create(const StringView& text, Function<void(GAction&)> callback, GWidget* widget = nullptr)
|
||||
{
|
||||
return adopt(*new GAction(text, move(callback), widget));
|
||||
}
|
||||
static Retained<GAction> create(const String& text, const String& custom_data, Function<void(GAction&)> callback, GWidget* widget = nullptr)
|
||||
static Retained<GAction> create(const StringView& text, const StringView& custom_data, Function<void(GAction&)> callback, GWidget* widget = nullptr)
|
||||
{
|
||||
return adopt(*new GAction(text, custom_data, move(callback), widget));
|
||||
}
|
||||
static Retained<GAction> create(const String& text, RetainPtr<GraphicsBitmap>&& icon, Function<void(GAction&)> callback, GWidget* widget = nullptr)
|
||||
static Retained<GAction> create(const StringView& text, RetainPtr<GraphicsBitmap>&& icon, Function<void(GAction&)> callback, GWidget* widget = nullptr)
|
||||
{
|
||||
return adopt(*new GAction(text, move(icon), move(callback), widget));
|
||||
}
|
||||
static Retained<GAction> create(const String& text, const GShortcut& shortcut, Function<void(GAction&)> callback, GWidget* widget = nullptr)
|
||||
static Retained<GAction> create(const StringView& text, const GShortcut& shortcut, Function<void(GAction&)> callback, GWidget* widget = nullptr)
|
||||
{
|
||||
return adopt(*new GAction(text, shortcut, move(callback), widget));
|
||||
}
|
||||
static Retained<GAction> create(const String& text, const GShortcut& shortcut, RetainPtr<GraphicsBitmap>&& icon, Function<void(GAction&)> callback, GWidget* widget = nullptr)
|
||||
static Retained<GAction> create(const StringView& text, const GShortcut& shortcut, RetainPtr<GraphicsBitmap>&& icon, Function<void(GAction&)> callback, GWidget* widget = nullptr)
|
||||
{
|
||||
return adopt(*new GAction(text, shortcut, move(icon), move(callback), widget));
|
||||
}
|
||||
|
@ -77,11 +77,11 @@ public:
|
|||
void unregister_menu_item(Badge<GMenuItem>, GMenuItem&);
|
||||
|
||||
private:
|
||||
GAction(const String& text, Function<void(GAction&)> = nullptr, GWidget* = nullptr);
|
||||
GAction(const String& text, const GShortcut&, Function<void(GAction&)> = nullptr, GWidget* = nullptr);
|
||||
GAction(const String& text, const GShortcut&, RetainPtr<GraphicsBitmap>&& icon, Function<void(GAction&)> = nullptr, GWidget* = nullptr);
|
||||
GAction(const String& text, RetainPtr<GraphicsBitmap>&& icon, Function<void(GAction&)> = nullptr, GWidget* = nullptr);
|
||||
GAction(const String& text, const String& custom_data = String(), Function<void(GAction&)> = nullptr, GWidget* = nullptr);
|
||||
GAction(const StringView& text, Function<void(GAction&)> = nullptr, GWidget* = nullptr);
|
||||
GAction(const StringView& text, const GShortcut&, Function<void(GAction&)> = nullptr, GWidget* = nullptr);
|
||||
GAction(const StringView& text, const GShortcut&, RetainPtr<GraphicsBitmap>&& icon, Function<void(GAction&)> = nullptr, GWidget* = nullptr);
|
||||
GAction(const StringView& text, RetainPtr<GraphicsBitmap>&& icon, Function<void(GAction&)> = nullptr, GWidget* = nullptr);
|
||||
GAction(const StringView& text, const StringView& custom_data = StringView(), Function<void(GAction&)> = nullptr, GWidget* = nullptr);
|
||||
|
||||
template<typename Callback>
|
||||
void for_each_toolbar_button(Callback);
|
||||
|
|
|
@ -84,7 +84,7 @@ public:
|
|||
set_main_widget(m_label);
|
||||
}
|
||||
|
||||
void set_tooltip(const String& tooltip)
|
||||
void set_tooltip(const StringView& tooltip)
|
||||
{
|
||||
// FIXME: Add some kind of GLabel auto-sizing feature.
|
||||
int text_width = m_label->font().width(tooltip);
|
||||
|
@ -95,7 +95,7 @@ public:
|
|||
GLabel* m_label { nullptr };
|
||||
};
|
||||
|
||||
void GApplication::show_tooltip(const String& tooltip, const Point& screen_location)
|
||||
void GApplication::show_tooltip(const StringView& tooltip, const Point& screen_location)
|
||||
{
|
||||
if (!m_tooltip_window) {
|
||||
m_tooltip_window = new TooltipWindow;
|
||||
|
|
|
@ -26,7 +26,7 @@ public:
|
|||
void register_global_shortcut_action(Badge<GAction>, GAction&);
|
||||
void unregister_global_shortcut_action(Badge<GAction>, GAction&);
|
||||
|
||||
void show_tooltip(const String&, const Point& screen_location);
|
||||
void show_tooltip(const StringView&, const Point& screen_location);
|
||||
void hide_tooltip();
|
||||
|
||||
private:
|
||||
|
|
|
@ -10,7 +10,7 @@ GButton::GButton(GWidget* parent)
|
|||
{
|
||||
}
|
||||
|
||||
GButton::GButton(const String& text, GWidget* parent)
|
||||
GButton::GButton(const StringView& text, GWidget* parent)
|
||||
: GAbstractButton(text, parent)
|
||||
{
|
||||
}
|
||||
|
|
|
@ -11,7 +11,7 @@ class GAction;
|
|||
|
||||
class GButton : public GAbstractButton {
|
||||
public:
|
||||
GButton(const String& text, GWidget* parent);
|
||||
GButton(const StringView& text, GWidget* parent);
|
||||
explicit GButton(GWidget* parent);
|
||||
virtual ~GButton() override;
|
||||
|
||||
|
|
|
@ -27,7 +27,7 @@ GCheckBox::GCheckBox(GWidget* parent)
|
|||
{
|
||||
}
|
||||
|
||||
GCheckBox::GCheckBox(const String& text, GWidget* parent)
|
||||
GCheckBox::GCheckBox(const StringView& text, GWidget* parent)
|
||||
: GAbstractButton(text, parent)
|
||||
{
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
|
||||
class GCheckBox : public GAbstractButton {
|
||||
public:
|
||||
GCheckBox(const String&, GWidget* parent);
|
||||
GCheckBox(const StringView&, GWidget* parent);
|
||||
explicit GCheckBox(GWidget* parent);
|
||||
virtual ~GCheckBox() override;
|
||||
|
||||
|
|
|
@ -34,7 +34,7 @@ String GClipboard::data() const
|
|||
return String((const char*)shared_buffer->data(), response.clipboard.contents_size);
|
||||
}
|
||||
|
||||
void GClipboard::set_data(const String& data)
|
||||
void GClipboard::set_data(const StringView& data)
|
||||
{
|
||||
WSAPI_ClientMessage request;
|
||||
request.type = WSAPI_ClientMessage::Type::SetClipboardContents;
|
||||
|
|
|
@ -7,7 +7,7 @@ public:
|
|||
static GClipboard& the();
|
||||
|
||||
String data() const;
|
||||
void set_data(const String&);
|
||||
void set_data(const StringView&);
|
||||
|
||||
private:
|
||||
GClipboard();
|
||||
|
|
|
@ -24,7 +24,7 @@ void GDesktop::did_receive_screen_rect(Badge<GEventLoop>, const Rect& rect)
|
|||
on_rect_change(rect);
|
||||
}
|
||||
|
||||
bool GDesktop::set_wallpaper(const String& path)
|
||||
bool GDesktop::set_wallpaper(const StringView& path)
|
||||
{
|
||||
WSAPI_ClientMessage message;
|
||||
message.type = WSAPI_ClientMessage::Type::SetWallpaper;
|
||||
|
|
|
@ -13,7 +13,7 @@ public:
|
|||
GDesktop();
|
||||
|
||||
String wallpaper() const;
|
||||
bool set_wallpaper(const String& path);
|
||||
bool set_wallpaper(const StringView& path);
|
||||
|
||||
Rect rect() const { return m_rect; }
|
||||
void did_receive_screen_rect(Badge<GEventLoop>, const Rect&);
|
||||
|
|
|
@ -272,7 +272,7 @@ void GDirectoryModel::update()
|
|||
did_update();
|
||||
}
|
||||
|
||||
void GDirectoryModel::open(const String& a_path)
|
||||
void GDirectoryModel::open(const StringView& a_path)
|
||||
{
|
||||
FileSystemPath canonical_path(a_path);
|
||||
auto path = canonical_path.string();
|
||||
|
|
|
@ -31,7 +31,7 @@ public:
|
|||
virtual void update() override;
|
||||
|
||||
String path() const { return m_path; }
|
||||
void open(const String& path);
|
||||
void open(const StringView& path);
|
||||
size_t bytes_in_files() const { return m_bytes_in_files; }
|
||||
|
||||
Function<void(int done, int total)> on_thumbnail_progress;
|
||||
|
|
|
@ -82,7 +82,7 @@ public:
|
|||
|
||||
class GWMWindowStateChangedEvent : public GWMEvent {
|
||||
public:
|
||||
GWMWindowStateChangedEvent(int client_id, int window_id, const String& title, const Rect& rect, bool is_active, GWindowType window_type, bool is_minimized)
|
||||
GWMWindowStateChangedEvent(int client_id, int window_id, const StringView& title, const Rect& rect, bool is_active, GWindowType window_type, bool is_minimized)
|
||||
: GWMEvent(GEvent::Type::WM_WindowStateChanged, client_id, window_id)
|
||||
, m_title(title)
|
||||
, m_rect(rect)
|
||||
|
@ -122,7 +122,7 @@ private:
|
|||
|
||||
class GWMWindowIconChangedEvent : public GWMEvent {
|
||||
public:
|
||||
GWMWindowIconChangedEvent(int client_id, int window_id, const String& icon_path)
|
||||
GWMWindowIconChangedEvent(int client_id, int window_id, const StringView& icon_path)
|
||||
: GWMEvent(GEvent::Type::WM_WindowIconChanged, client_id, window_id)
|
||||
, m_icon_path(icon_path)
|
||||
{
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
#include <LibGUI/GToolBar.h>
|
||||
#include <SharedGraphics/PNGLoader.h>
|
||||
|
||||
GFilePicker::GFilePicker(const String& path, CObject* parent)
|
||||
GFilePicker::GFilePicker(const StringView& path, CObject* parent)
|
||||
: GDialog(parent)
|
||||
, m_model(GDirectoryModel::create())
|
||||
{
|
||||
|
|
|
@ -7,7 +7,7 @@ class GLabel;
|
|||
|
||||
class GFilePicker final : public GDialog {
|
||||
public:
|
||||
GFilePicker(const String& path = "/", CObject* parent = nullptr);
|
||||
GFilePicker(const StringView& path = "/", CObject* parent = nullptr);
|
||||
virtual ~GFilePicker() override;
|
||||
|
||||
FileSystemPath selected_file() const { return m_selected_file; }
|
||||
|
|
|
@ -92,7 +92,7 @@ struct GFileSystemModel::Node {
|
|||
}
|
||||
};
|
||||
|
||||
GModelIndex GFileSystemModel::index(const String& path) const
|
||||
GModelIndex GFileSystemModel::index(const StringView& path) const
|
||||
{
|
||||
FileSystemPath canonical_path(path);
|
||||
const Node* node = m_root;
|
||||
|
@ -125,7 +125,7 @@ String GFileSystemModel::path(const GModelIndex& index) const
|
|||
return node.full_path(*this);
|
||||
}
|
||||
|
||||
GFileSystemModel::GFileSystemModel(const String& root_path, Mode mode)
|
||||
GFileSystemModel::GFileSystemModel(const StringView& root_path, Mode mode)
|
||||
: m_root_path(FileSystemPath(root_path).string())
|
||||
, m_mode(mode)
|
||||
{
|
||||
|
|
|
@ -13,7 +13,7 @@ public:
|
|||
FilesAndDirectories
|
||||
};
|
||||
|
||||
static Retained<GFileSystemModel> create(const String& root_path = "/", Mode mode = Mode::FilesAndDirectories)
|
||||
static Retained<GFileSystemModel> create(const StringView& root_path = "/", Mode mode = Mode::FilesAndDirectories)
|
||||
{
|
||||
return adopt(*new GFileSystemModel(root_path, mode));
|
||||
}
|
||||
|
@ -21,7 +21,7 @@ public:
|
|||
|
||||
String root_path() const { return m_root_path; }
|
||||
String path(const GModelIndex&) const;
|
||||
GModelIndex index(const String& path) const;
|
||||
GModelIndex index(const StringView& path) const;
|
||||
|
||||
virtual int row_count(const GModelIndex& = GModelIndex()) const override;
|
||||
virtual int column_count(const GModelIndex& = GModelIndex()) const override;
|
||||
|
@ -31,7 +31,7 @@ public:
|
|||
virtual GModelIndex index(int row, int column = 0, const GModelIndex& parent = GModelIndex()) const override;
|
||||
|
||||
private:
|
||||
GFileSystemModel(const String& root_path, Mode);
|
||||
GFileSystemModel(const StringView& root_path, Mode);
|
||||
|
||||
String m_root_path;
|
||||
Mode m_mode { Invalid };
|
||||
|
|
|
@ -38,14 +38,14 @@ GFontDatabase::~GFontDatabase()
|
|||
{
|
||||
}
|
||||
|
||||
void GFontDatabase::for_each_font(Function<void(const String&)> callback)
|
||||
void GFontDatabase::for_each_font(Function<void(const StringView&)> callback)
|
||||
{
|
||||
for (auto& it : m_name_to_metadata) {
|
||||
callback(it.key);
|
||||
}
|
||||
}
|
||||
|
||||
void GFontDatabase::for_each_fixed_width_font(Function<void(const String&)> callback)
|
||||
void GFontDatabase::for_each_fixed_width_font(Function<void(const StringView&)> callback)
|
||||
{
|
||||
for (auto& it : m_name_to_metadata) {
|
||||
if (it.value.is_fixed_width)
|
||||
|
@ -53,7 +53,7 @@ void GFontDatabase::for_each_fixed_width_font(Function<void(const String&)> call
|
|||
}
|
||||
}
|
||||
|
||||
RetainPtr<Font> GFontDatabase::get_by_name(const String& name)
|
||||
RetainPtr<Font> GFontDatabase::get_by_name(const StringView& name)
|
||||
{
|
||||
auto it = m_name_to_metadata.find(name);
|
||||
if (it == m_name_to_metadata.end())
|
||||
|
|
|
@ -16,11 +16,11 @@ class GFontDatabase {
|
|||
public:
|
||||
static GFontDatabase& the();
|
||||
|
||||
RetainPtr<Font> get_by_name(const String&);
|
||||
void for_each_font(Function<void(const String&)>);
|
||||
void for_each_fixed_width_font(Function<void(const String&)>);
|
||||
RetainPtr<Font> get_by_name(const StringView&);
|
||||
void for_each_font(Function<void(const StringView&)>);
|
||||
void for_each_fixed_width_font(Function<void(const StringView&)>);
|
||||
|
||||
Metadata get_metadata_by_name(const String& name) const
|
||||
Metadata get_metadata_by_name(const StringView& name) const
|
||||
{
|
||||
return m_name_to_metadata.get(name);
|
||||
};
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
#include <LibGUI/GPainter.h>
|
||||
#include <SharedGraphics/StylePainter.h>
|
||||
|
||||
GGroupBox::GGroupBox(const String& title, GWidget* parent)
|
||||
GGroupBox::GGroupBox(const StringView& title, GWidget* parent)
|
||||
: GWidget(parent)
|
||||
, m_title(title)
|
||||
{
|
||||
|
@ -30,7 +30,7 @@ void GGroupBox::paint_event(GPaintEvent& event)
|
|||
painter.draw_text(text_rect, m_title, TextAlignment::Center, foreground_color());
|
||||
}
|
||||
|
||||
void GGroupBox::set_title(const String& title)
|
||||
void GGroupBox::set_title(const StringView& title)
|
||||
{
|
||||
if (m_title == title)
|
||||
return;
|
||||
|
|
|
@ -4,11 +4,11 @@
|
|||
|
||||
class GGroupBox : public GWidget {
|
||||
public:
|
||||
GGroupBox(const String& title, GWidget* parent);
|
||||
GGroupBox(const StringView& title, GWidget* parent);
|
||||
virtual ~GGroupBox() override;
|
||||
|
||||
String title() const { return m_title; }
|
||||
void set_title(const String&);
|
||||
void set_title(const StringView&);
|
||||
|
||||
virtual const char* class_name() const override { return "GGroupBox"; }
|
||||
|
||||
|
|
|
@ -62,7 +62,7 @@ void GIconImpl::set_bitmap_for_size(int size, RetainPtr<GraphicsBitmap>&& bitmap
|
|||
m_bitmaps.set(size, move(bitmap));
|
||||
}
|
||||
|
||||
GIcon GIcon::default_icon(const String& name)
|
||||
GIcon GIcon::default_icon(const StringView& name)
|
||||
{
|
||||
auto bitmap16 = GraphicsBitmap::load_from_file(String::format("/res/icons/16x16/%s.png", name.characters()));
|
||||
auto bitmap32 = GraphicsBitmap::load_from_file(String::format("/res/icons/32x32/%s.png", name.characters()));
|
||||
|
|
|
@ -25,7 +25,7 @@ public:
|
|||
GIcon(const GIcon&);
|
||||
~GIcon() {}
|
||||
|
||||
static GIcon default_icon(const String&);
|
||||
static GIcon default_icon(const StringView&);
|
||||
|
||||
GIcon& operator=(const GIcon& other)
|
||||
{
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
#include <LibGUI/GTextEditor.h>
|
||||
#include <stdio.h>
|
||||
|
||||
GInputBox::GInputBox(const String& prompt, const String& title, CObject* parent)
|
||||
GInputBox::GInputBox(const StringView& prompt, const StringView& title, CObject* parent)
|
||||
: GDialog(parent)
|
||||
, m_prompt(prompt)
|
||||
{
|
||||
|
|
|
@ -7,7 +7,7 @@ class GTextEditor;
|
|||
|
||||
class GInputBox : public GDialog {
|
||||
public:
|
||||
explicit GInputBox(const String& prompt, const String& title, CObject* parent = nullptr);
|
||||
explicit GInputBox(const StringView& prompt, const StringView& title, CObject* parent = nullptr);
|
||||
virtual ~GInputBox() override;
|
||||
|
||||
String text_value() const { return m_text_value; }
|
||||
|
|
|
@ -7,7 +7,7 @@ GLabel::GLabel(GWidget* parent)
|
|||
{
|
||||
}
|
||||
|
||||
GLabel::GLabel(const String& text, GWidget* parent)
|
||||
GLabel::GLabel(const StringView& text, GWidget* parent)
|
||||
: GFrame(parent)
|
||||
, m_text(text)
|
||||
{
|
||||
|
@ -22,7 +22,7 @@ void GLabel::set_icon(RetainPtr<GraphicsBitmap>&& icon)
|
|||
m_icon = move(icon);
|
||||
}
|
||||
|
||||
void GLabel::set_text(const String& text)
|
||||
void GLabel::set_text(const StringView& text)
|
||||
{
|
||||
if (text == m_text)
|
||||
return;
|
||||
|
|
|
@ -8,11 +8,11 @@ class GraphicsBitmap;
|
|||
class GLabel : public GFrame {
|
||||
public:
|
||||
explicit GLabel(GWidget* parent = nullptr);
|
||||
GLabel(const String& text, GWidget* parent = nullptr);
|
||||
GLabel(const StringView& text, GWidget* parent = nullptr);
|
||||
virtual ~GLabel() override;
|
||||
|
||||
String text() const { return m_text; }
|
||||
void set_text(const String&);
|
||||
void set_text(const StringView&);
|
||||
|
||||
void set_icon(RetainPtr<GraphicsBitmap>&&);
|
||||
const GraphicsBitmap* icon() const { return m_icon.ptr(); }
|
||||
|
|
|
@ -21,7 +21,7 @@ GMenu* GMenu::from_menu_id(int menu_id)
|
|||
return (*it).value;
|
||||
}
|
||||
|
||||
GMenu::GMenu(const String& name)
|
||||
GMenu::GMenu(const StringView& name)
|
||||
: m_name(name)
|
||||
{
|
||||
}
|
||||
|
|
|
@ -11,7 +11,7 @@ class Point;
|
|||
|
||||
class GMenu {
|
||||
public:
|
||||
explicit GMenu(const String& name);
|
||||
explicit GMenu(const StringView& name);
|
||||
~GMenu();
|
||||
|
||||
static GMenu* from_menu_id(int);
|
||||
|
|
|
@ -4,13 +4,13 @@
|
|||
#include <LibGUI/GButton.h>
|
||||
#include <stdio.h>
|
||||
|
||||
void GMessageBox::show(const String& text, const String& title, Type type, CObject* parent)
|
||||
void GMessageBox::show(const StringView& text, const StringView& title, Type type, CObject* parent)
|
||||
{
|
||||
GMessageBox box(text, title, type, parent);
|
||||
box.exec();
|
||||
}
|
||||
|
||||
GMessageBox::GMessageBox(const String& text, const String& title, Type type, CObject* parent)
|
||||
GMessageBox::GMessageBox(const StringView& text, const StringView& title, Type type, CObject* parent)
|
||||
: GDialog(parent)
|
||||
, m_text(text)
|
||||
, m_type(type)
|
||||
|
|
|
@ -12,10 +12,10 @@ public:
|
|||
Error,
|
||||
};
|
||||
|
||||
explicit GMessageBox(const String& text, const String& title, Type type = Type::None, CObject* parent = nullptr);
|
||||
explicit GMessageBox(const StringView& text, const StringView& title, Type type = Type::None, CObject* parent = nullptr);
|
||||
virtual ~GMessageBox() override;
|
||||
|
||||
static void show(const String& text, const String& title, Type type = Type::None, CObject* parent = nullptr);
|
||||
static void show(const StringView& text, const StringView& title, Type type = Type::None, CObject* parent = nullptr);
|
||||
|
||||
virtual const char* class_name() const override { return "GMessageBox"; }
|
||||
|
||||
|
|
|
@ -17,7 +17,7 @@ public:
|
|||
int max() const { return m_max; }
|
||||
|
||||
String caption() const { return m_caption; }
|
||||
void set_caption(const String& caption) { m_caption = caption; }
|
||||
void set_caption(const StringView& caption) { m_caption = caption; }
|
||||
|
||||
enum Format
|
||||
{
|
||||
|
|
|
@ -7,7 +7,7 @@ static RetainPtr<GraphicsBitmap> s_filled_circle_bitmap;
|
|||
static RetainPtr<GraphicsBitmap> s_changing_filled_circle_bitmap;
|
||||
static RetainPtr<GraphicsBitmap> s_changing_unfilled_circle_bitmap;
|
||||
|
||||
GRadioButton::GRadioButton(const String& text, GWidget* parent)
|
||||
GRadioButton::GRadioButton(const StringView& text, GWidget* parent)
|
||||
: GAbstractButton(text, parent)
|
||||
{
|
||||
if (!s_unfilled_circle_bitmap) {
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
class GRadioButton : public GAbstractButton {
|
||||
public:
|
||||
GRadioButton(const String& text, GWidget* parent);
|
||||
GRadioButton(const StringView& text, GWidget* parent);
|
||||
virtual ~GRadioButton() override;
|
||||
|
||||
virtual const char* class_name() const override { return "GRadioButton"; }
|
||||
|
|
|
@ -26,7 +26,7 @@ GStatusBar::~GStatusBar()
|
|||
{
|
||||
}
|
||||
|
||||
void GStatusBar::set_text(const String& text)
|
||||
void GStatusBar::set_text(const StringView& text)
|
||||
{
|
||||
m_label->set_text(text);
|
||||
}
|
||||
|
|
|
@ -11,7 +11,7 @@ public:
|
|||
virtual ~GStatusBar() override;
|
||||
|
||||
String text() const;
|
||||
void set_text(const String&);
|
||||
void set_text(const StringView&);
|
||||
|
||||
virtual const char* class_name() const override { return "GStatusBar"; }
|
||||
|
||||
|
|
|
@ -14,7 +14,7 @@ GTabWidget::~GTabWidget()
|
|||
{
|
||||
}
|
||||
|
||||
void GTabWidget::add_widget(const String& title, GWidget* widget)
|
||||
void GTabWidget::add_widget(const StringView& title, GWidget* widget)
|
||||
{
|
||||
m_tabs.append({ title, widget });
|
||||
add_child(*widget);
|
||||
|
|
|
@ -13,7 +13,7 @@ public:
|
|||
int bar_height() const { return 21; }
|
||||
int container_padding() const { return 2; }
|
||||
|
||||
void add_widget(const String&, GWidget*);
|
||||
void add_widget(const StringView&, GWidget*);
|
||||
|
||||
virtual const char* class_name() const override { return "GTabWidget"; }
|
||||
|
||||
|
|
|
@ -58,7 +58,7 @@ void GTextEditor::create_actions()
|
|||
}, this);
|
||||
}
|
||||
|
||||
void GTextEditor::set_text(const String& text)
|
||||
void GTextEditor::set_text(const StringView& text)
|
||||
{
|
||||
if (is_single_line() && text.length() == m_lines[0]->length() && !memcmp(text.characters(), m_lines[0]->characters(), text.length()))
|
||||
return;
|
||||
|
@ -71,7 +71,7 @@ void GTextEditor::set_text(const String& text)
|
|||
int line_length = current_position - start_of_current_line;
|
||||
auto line = make<Line>();
|
||||
if (line_length)
|
||||
line->set_text(text.substring(start_of_current_line, current_position - start_of_current_line));
|
||||
line->set_text(text.substring_view(start_of_current_line, current_position - start_of_current_line));
|
||||
m_lines.append(move(line));
|
||||
start_of_current_line = current_position + 1;
|
||||
};
|
||||
|
@ -574,7 +574,7 @@ void GTextEditor::do_delete()
|
|||
}
|
||||
}
|
||||
|
||||
void GTextEditor::insert_at_cursor(const String& text)
|
||||
void GTextEditor::insert_at_cursor(const StringView& text)
|
||||
{
|
||||
// FIXME: This should obviously not be implemented this way.
|
||||
for (int i = 0; i < text.length(); ++i) {
|
||||
|
@ -756,7 +756,7 @@ GTextEditor::Line::Line()
|
|||
clear();
|
||||
}
|
||||
|
||||
GTextEditor::Line::Line(const String& text)
|
||||
GTextEditor::Line::Line(const StringView& text)
|
||||
{
|
||||
set_text(text);
|
||||
}
|
||||
|
@ -767,7 +767,7 @@ void GTextEditor::Line::clear()
|
|||
m_text.append(0);
|
||||
}
|
||||
|
||||
void GTextEditor::Line::set_text(const String& text)
|
||||
void GTextEditor::Line::set_text(const StringView& text)
|
||||
{
|
||||
if (text.length() == length() && !memcmp(text.characters(), characters(), length()))
|
||||
return;
|
||||
|
@ -828,7 +828,7 @@ void GTextEditor::Line::truncate(int length)
|
|||
m_text.last() = 0;
|
||||
}
|
||||
|
||||
bool GTextEditor::write_to_file(const String& path)
|
||||
bool GTextEditor::write_to_file(const StringView& path)
|
||||
{
|
||||
int fd = open(path.characters(), O_WRONLY | O_CREAT | O_TRUNC, 0666);
|
||||
if (fd < 0) {
|
||||
|
@ -952,7 +952,7 @@ void GTextEditor::delete_selection()
|
|||
update();
|
||||
}
|
||||
|
||||
void GTextEditor::insert_at_cursor_or_replace_selection(const String& text)
|
||||
void GTextEditor::insert_at_cursor_or_replace_selection(const StringView& text)
|
||||
{
|
||||
ASSERT(!is_readonly());
|
||||
if (has_selection())
|
||||
|
|
|
@ -105,7 +105,7 @@ public:
|
|||
Function<void()> on_cursor_change;
|
||||
Function<void()> on_selection_change;
|
||||
|
||||
void set_text(const String&);
|
||||
void set_text(const StringView&);
|
||||
void scroll_cursor_into_view();
|
||||
int line_count() const { return m_lines.size(); }
|
||||
int line_spacing() const { return m_line_spacing; }
|
||||
|
@ -115,7 +115,7 @@ public:
|
|||
// FIXME: This should take glyph spacing into account, no?
|
||||
int glyph_width() const { return font().glyph_width('x'); }
|
||||
|
||||
bool write_to_file(const String& path);
|
||||
bool write_to_file(const StringView& path);
|
||||
|
||||
bool has_selection() const { return m_selection.is_valid(); }
|
||||
String selected_text() const;
|
||||
|
@ -168,12 +168,12 @@ private:
|
|||
|
||||
public:
|
||||
Line();
|
||||
explicit Line(const String&);
|
||||
explicit Line(const StringView&);
|
||||
|
||||
const char* characters() const { return m_text.data(); }
|
||||
int length() const { return m_text.size() - 1; }
|
||||
int width(const Font&) const;
|
||||
void set_text(const String&);
|
||||
void set_text(const StringView&);
|
||||
void append(char);
|
||||
void prepend(char);
|
||||
void insert(int index, char);
|
||||
|
@ -197,11 +197,11 @@ private:
|
|||
const Line& current_line() const { return *m_lines[m_cursor.line()]; }
|
||||
GTextPosition text_position_at(const Point&) const;
|
||||
void insert_at_cursor(char);
|
||||
void insert_at_cursor(const String&);
|
||||
void insert_at_cursor(const StringView&);
|
||||
int ruler_width() const;
|
||||
Rect ruler_content_rect(int line) const;
|
||||
void toggle_selection_if_needed_for_event(const GKeyEvent&);
|
||||
void insert_at_cursor_or_replace_selection(const String&);
|
||||
void insert_at_cursor_or_replace_selection(const StringView&);
|
||||
void delete_selection();
|
||||
void did_update_selection();
|
||||
int content_x_for_position(const GTextPosition&) const;
|
||||
|
|
|
@ -56,7 +56,7 @@ public:
|
|||
|
||||
bool has_tooltip() const { return !m_tooltip.is_empty(); }
|
||||
String tooltip() const { return m_tooltip; }
|
||||
void set_tooltip(const String& tooltip) { m_tooltip = tooltip; }
|
||||
void set_tooltip(const StringView& tooltip) { m_tooltip = tooltip; }
|
||||
|
||||
bool is_enabled() const { return m_enabled; }
|
||||
void set_enabled(bool);
|
||||
|
|
|
@ -104,7 +104,7 @@ void GWindow::hide()
|
|||
m_front_bitmap = nullptr;
|
||||
}
|
||||
|
||||
void GWindow::set_title(const String& title)
|
||||
void GWindow::set_title(const StringView& title)
|
||||
{
|
||||
m_title_when_windowless = title;
|
||||
if (!m_window_id)
|
||||
|
@ -502,7 +502,7 @@ void GWindow::wm_event(GWMEvent&)
|
|||
{
|
||||
}
|
||||
|
||||
void GWindow::set_icon_path(const String& path)
|
||||
void GWindow::set_icon_path(const StringView& path)
|
||||
{
|
||||
if (m_icon_path == path)
|
||||
return;
|
||||
|
|
|
@ -45,7 +45,7 @@ public:
|
|||
int window_id() const { return m_window_id; }
|
||||
|
||||
String title() const;
|
||||
void set_title(const String&);
|
||||
void set_title(const StringView&);
|
||||
|
||||
bool show_titlebar() const { return m_show_titlebar; };
|
||||
void set_show_titlebar(bool show) { m_show_titlebar = show; };
|
||||
|
@ -119,7 +119,7 @@ public:
|
|||
void set_override_cursor(GStandardCursor);
|
||||
|
||||
String icon_path() const { return m_icon_path; }
|
||||
void set_icon_path(const String&);
|
||||
void set_icon_path(const StringView&);
|
||||
|
||||
Vector<GWidget*> focusable_widgets() const;
|
||||
|
||||
|
|
|
@ -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