1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-16 19:05:08 +00:00

LibGUI: Add a simple GWidget class registry/factory

You can now register a GWidget subclass with REGISTER_GWIDGET(class)
and it will be available for factory construction through the new
GWidgetClassRegistration interface.

To obtain a GWidgetClassRegistration for a given class name, you call
GWidgetClassRegistration::find(class_name). You can also iterate over
all the registered classes using GWCR::for_each(callback).

This will be very useful for implementing a proper GUI designer, and
also in the future for things like script bindings.

NOTE: All of the registrations are done in GWidget.cpp at the moment
since I ran into trouble with the fricken linker pruning the global
constructors this mechanism relies on. :^)
This commit is contained in:
Andreas Kling 2019-11-10 10:58:03 +01:00
parent a353d16ff4
commit ca538b6cee
10 changed files with 109 additions and 8 deletions

View file

@ -1,8 +1,8 @@
#include <LibGUI/GPainter.h>
#include <LibGUI/GScrollBar.h>
#include <LibDraw/CharacterBitmap.h>
#include <LibDraw/GraphicsBitmap.h>
#include <LibDraw/StylePainter.h>
#include <LibGUI/GPainter.h>
#include <LibGUI/GScrollBar.h>
static const char* s_up_arrow_bitmap_data = {
" "
@ -57,6 +57,11 @@ static CharacterBitmap* s_down_arrow_bitmap;
static CharacterBitmap* s_left_arrow_bitmap;
static CharacterBitmap* s_right_arrow_bitmap;
GScrollBar::GScrollBar(GWidget* parent)
: GScrollBar(Orientation::Vertical, parent)
{
}
GScrollBar::GScrollBar(Orientation orientation, GWidget* parent)
: GWidget(parent)
, m_orientation(orientation)
@ -239,7 +244,7 @@ void GScrollBar::mousedown_event(GMouseEvent& event)
return;
}
if (has_scrubber() && scrubber_rect().contains(event.position())) {
m_scrubber_in_use = true;
m_scrubber_in_use = true;
m_scrubbing = true;
m_scrub_start_value = value();
m_scrub_origin = event.position();