mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 16:37:35 +00:00
LibGUI+FontEditor: Move GlyphMapWidget to LibGUI
This will allow us to use this in other apps, such as the upcoming Character Map. :^)
This commit is contained in:
parent
dd17df76e9
commit
8175cd0a28
6 changed files with 28 additions and 21 deletions
94
Userland/Libraries/LibGUI/GlyphMapWidget.h
Normal file
94
Userland/Libraries/LibGUI/GlyphMapWidget.h
Normal file
|
@ -0,0 +1,94 @@
|
|||
/*
|
||||
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
||||
* Copyright (c) 2022, Sam Atkins <atkinssj@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <AK/Vector.h>
|
||||
#include <LibGUI/AbstractScrollableWidget.h>
|
||||
#include <LibGUI/TextRange.h>
|
||||
#include <LibGfx/BitmapFont.h>
|
||||
|
||||
namespace GUI {
|
||||
|
||||
class GlyphMapWidget final : public AbstractScrollableWidget {
|
||||
C_OBJECT(GlyphMapWidget)
|
||||
public:
|
||||
virtual ~GlyphMapWidget() override;
|
||||
|
||||
void initialize(Gfx::BitmapFont&);
|
||||
|
||||
class Selection {
|
||||
public:
|
||||
Selection() = default;
|
||||
Selection(int start, int size)
|
||||
: m_start(start)
|
||||
, m_size(size)
|
||||
{
|
||||
}
|
||||
|
||||
int size() const { return m_size; }
|
||||
void set_size(int i) { m_size = i; }
|
||||
int start() const { return m_start; }
|
||||
void set_start(int i) { m_start = i; }
|
||||
|
||||
Selection normalized() const;
|
||||
bool contains(int) const;
|
||||
void resize_by(int i);
|
||||
void extend_to(int);
|
||||
|
||||
private:
|
||||
int m_start { 0 };
|
||||
int m_size { 1 };
|
||||
};
|
||||
|
||||
Selection selection() const { return m_selection; }
|
||||
int active_glyph() const { return m_active_glyph; }
|
||||
|
||||
enum class ShouldResetSelection {
|
||||
Yes,
|
||||
No
|
||||
};
|
||||
|
||||
void set_active_glyph(int, ShouldResetSelection = ShouldResetSelection::Yes);
|
||||
void clear_selection() { m_selection.set_size(0); }
|
||||
void scroll_to_glyph(int);
|
||||
void update_glyph(int);
|
||||
|
||||
int rows() const { return m_rows; }
|
||||
int columns() const { return m_columns; }
|
||||
|
||||
Gfx::BitmapFont& font() { return *m_font; }
|
||||
Gfx::BitmapFont const& font() const { return *m_font; }
|
||||
|
||||
Function<void(int)> on_active_glyph_changed;
|
||||
|
||||
private:
|
||||
GlyphMapWidget();
|
||||
virtual void paint_event(PaintEvent&) override;
|
||||
virtual void mousedown_event(MouseEvent&) override;
|
||||
virtual void keydown_event(KeyEvent&) override;
|
||||
virtual void resize_event(ResizeEvent&) override;
|
||||
|
||||
Gfx::IntRect get_outer_rect(int glyph) const;
|
||||
|
||||
void cut_glyph(int glyph);
|
||||
void copy_glyph(int glyph);
|
||||
void paste_glyph(int glyph);
|
||||
void delete_glyph(int glyph);
|
||||
|
||||
RefPtr<Gfx::BitmapFont> m_font;
|
||||
int m_glyph_count { 0x110000 };
|
||||
int m_columns { 0 };
|
||||
int m_rows { 0 };
|
||||
int m_horizontal_spacing { 2 };
|
||||
int m_vertical_spacing { 2 };
|
||||
Selection m_selection;
|
||||
int m_active_glyph { 0 };
|
||||
int m_visible_glyphs { 0 };
|
||||
};
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue