mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-12-13 18:00:40 +00:00
Demos: Start working on a simple WidgetGallery app.
It's good to have a place where we can try out all the different widgets. This needs some more work on a nice layout, and should also include more of the widgets. :^)
This commit is contained in:
parent
d0bc21b96f
commit
149b7f92a7
Notes:
sideshowbarker
2024-07-19 13:58:04 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/149b7f92a7d
9 changed files with 126 additions and 3 deletions
3
Demos/WidgetGallery/.gitignore
vendored
Normal file
3
Demos/WidgetGallery/.gitignore
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
*.o
|
||||
*.d
|
||||
WidgetGallery
|
22
Demos/WidgetGallery/Makefile
Normal file
22
Demos/WidgetGallery/Makefile
Normal file
|
@ -0,0 +1,22 @@
|
|||
include ../../Makefile.common
|
||||
|
||||
OBJS = \
|
||||
main.o
|
||||
|
||||
APP = WidgetGallery
|
||||
|
||||
DEFINES += -DUSERLAND
|
||||
|
||||
all: $(APP)
|
||||
|
||||
$(APP): $(OBJS)
|
||||
$(LD) -o $(APP) $(LDFLAGS) $(OBJS) -lgui -lcore -lc
|
||||
|
||||
.cpp.o:
|
||||
@echo "CXX $<"; $(CXX) $(CXXFLAGS) -o $@ -c $<
|
||||
|
||||
-include $(OBJS:%.o=%.d)
|
||||
|
||||
clean:
|
||||
@echo "CLEAN"; rm -f $(APP) $(OBJS) *.d
|
||||
|
82
Demos/WidgetGallery/main.cpp
Normal file
82
Demos/WidgetGallery/main.cpp
Normal file
|
@ -0,0 +1,82 @@
|
|||
#include <LibGUI/GApplication.h>
|
||||
#include <LibGUI/GWindow.h>
|
||||
#include <LibGUI/GWidget.h>
|
||||
#include <LibGUI/GLabel.h>
|
||||
#include <LibGUI/GButton.h>
|
||||
#include <LibGUI/GBoxLayout.h>
|
||||
#include <LibGUI/GCheckBox.h>
|
||||
#include <LibGUI/GRadioButton.h>
|
||||
#include <LibGUI/GTextBox.h>
|
||||
#include <LibGUI/GProgressBar.h>
|
||||
#include <LibGUI/GScrollBar.h>
|
||||
#include <LibGUI/GSlider.h>
|
||||
#include <LibGUI/GSpinBox.h>
|
||||
#include <LibGUI/GGroupBox.h>
|
||||
#include <LibCore/CTimer.h>
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
GApplication app(argc, argv);
|
||||
|
||||
auto* window = new GWindow;
|
||||
window->set_rect(100, 100, 320, 480);
|
||||
window->set_title("Widget Gallery");
|
||||
|
||||
auto* main_widget = new GWidget;
|
||||
window->set_main_widget(main_widget);
|
||||
main_widget->set_fill_with_background_color(true);
|
||||
main_widget->set_layout(make<GBoxLayout>(Orientation::Vertical));
|
||||
main_widget->layout()->set_margins({ 4, 4, 4, 4 });
|
||||
|
||||
auto* checkbox1 = new GCheckBox("GCheckBox 1", main_widget);
|
||||
auto* checkbox2 = new GCheckBox("GCheckBox 2", main_widget);
|
||||
checkbox2->set_enabled(false);
|
||||
|
||||
auto* radio1 = new GRadioButton("GRadioButton 1", main_widget);
|
||||
auto* radio2 = new GRadioButton("GRadioButton 2", main_widget);
|
||||
radio2->set_enabled(false);
|
||||
|
||||
auto* button1 = new GButton("GButton 1", main_widget);
|
||||
auto* button2 = new GButton("GButton 2", main_widget);
|
||||
button2->set_enabled(false);
|
||||
|
||||
auto* progress1 = new GProgressBar(main_widget);
|
||||
new CTimer(100, [progress1] {
|
||||
progress1->set_value(progress1->value() + 1);
|
||||
if (progress1->value() == progress1->max())
|
||||
progress1->set_value(progress1->min());
|
||||
});
|
||||
|
||||
auto* label1 = new GLabel("GLabel 1", main_widget);
|
||||
auto* label2 = new GLabel("GLabel 2", main_widget);
|
||||
label2->set_enabled(false);
|
||||
|
||||
auto* textbox1 = new GTextBox(main_widget);
|
||||
textbox1->set_text("GTextBox 1");
|
||||
auto* textbox2 = new GTextBox(main_widget);
|
||||
textbox2->set_text("GTextBox 2");
|
||||
textbox2->set_enabled(false);
|
||||
|
||||
auto* spinbox1 = new GSpinBox(main_widget);
|
||||
auto* spinbox2 = new GSpinBox(main_widget);
|
||||
spinbox2->set_enabled(false);
|
||||
|
||||
auto* slider1 = new GSlider(main_widget);
|
||||
auto* slider2 = new GSlider(main_widget);
|
||||
slider2->set_enabled(false);
|
||||
|
||||
auto* scrollbar1 = new GScrollBar(Orientation::Horizontal, main_widget);
|
||||
scrollbar1->set_size_policy(SizePolicy::Fill, SizePolicy::Fixed);
|
||||
scrollbar1->set_preferred_size({ 0, 16 });
|
||||
scrollbar1->set_min(0);
|
||||
scrollbar1->set_max(100);
|
||||
scrollbar1->set_value(50);
|
||||
auto* scrollbar2 = new GScrollBar(Orientation::Horizontal, main_widget);
|
||||
scrollbar2->set_size_policy(SizePolicy::Fill, SizePolicy::Fixed);
|
||||
scrollbar2->set_preferred_size({ 0, 16 });
|
||||
scrollbar2->set_enabled(false);
|
||||
|
||||
window->show();
|
||||
|
||||
return app.exec();
|
||||
}
|
|
@ -33,6 +33,7 @@ build_targets="$build_targets ../Games/Snake"
|
|||
build_targets="$build_targets ../Shell"
|
||||
build_targets="$build_targets ../Demos/HelloWorld"
|
||||
build_targets="$build_targets ../Demos/RetroFetch"
|
||||
build_targets="$build_targets ../Demos/WidgetGallery"
|
||||
build_targets="$build_targets ." # the kernel
|
||||
|
||||
for targ in $build_targets; do
|
||||
|
|
|
@ -81,6 +81,8 @@ cp -v kernel.map mnt/
|
|||
cp -v ../Demos/HelloWorld/HelloWorld mnt/bin/HelloWorld
|
||||
ln -s HelloWorld mnt/bin/hw
|
||||
cp -v ../Demos/RetroFetch/RetroFetch mnt/bin/RetroFetch
|
||||
cp -v ../Demos/WidgetGallery/WidgetGallery mnt/bin/WidgetGallery
|
||||
ln -s WidgetGallery mnt/bin/wg
|
||||
|
||||
# Run local sync script, if it exists
|
||||
if [ -f sync-local.sh ]; then
|
||||
|
|
|
@ -10,6 +10,11 @@ GButton::GButton(GWidget* parent)
|
|||
{
|
||||
}
|
||||
|
||||
GButton::GButton(const String& text, GWidget* parent)
|
||||
: GAbstractButton(text, parent)
|
||||
{
|
||||
}
|
||||
|
||||
GButton::~GButton()
|
||||
{
|
||||
if (m_action)
|
||||
|
|
|
@ -11,6 +11,7 @@ class GAction;
|
|||
|
||||
class GButton : public GAbstractButton {
|
||||
public:
|
||||
GButton(const String& text, GWidget* parent);
|
||||
explicit GButton(GWidget* parent);
|
||||
virtual ~GButton() override;
|
||||
|
||||
|
|
|
@ -25,8 +25,11 @@ static const int s_box_height = 13;
|
|||
GCheckBox::GCheckBox(GWidget* parent)
|
||||
: GAbstractButton(parent)
|
||||
{
|
||||
if (!s_checked_bitmap)
|
||||
s_checked_bitmap = &CharacterBitmap::create_from_ascii(s_checked_bitmap_data, s_checked_bitmap_width, s_checked_bitmap_height).leak_ref();
|
||||
}
|
||||
|
||||
GCheckBox::GCheckBox(const String& text, GWidget* parent)
|
||||
: GAbstractButton(text, parent)
|
||||
{
|
||||
}
|
||||
|
||||
GCheckBox::~GCheckBox()
|
||||
|
@ -57,8 +60,11 @@ void GCheckBox::paint_event(GPaintEvent& event)
|
|||
if (is_being_pressed())
|
||||
painter.draw_rect(box_rect.shrunken(4, 4), Color::MidGray);
|
||||
|
||||
if (is_checked())
|
||||
if (is_checked()) {
|
||||
if (!s_checked_bitmap)
|
||||
s_checked_bitmap = &CharacterBitmap::create_from_ascii(s_checked_bitmap_data, s_checked_bitmap_width, s_checked_bitmap_height).leak_ref();
|
||||
painter.draw_bitmap(box_rect.shrunken(4, 4).location(), *s_checked_bitmap, foreground_color());
|
||||
}
|
||||
|
||||
if (!text().is_empty()) {
|
||||
painter.draw_text(text_rect, text(), TextAlignment::TopLeft, foreground_color());
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
|
||||
class GCheckBox : public GAbstractButton {
|
||||
public:
|
||||
GCheckBox(const String&, GWidget* parent);
|
||||
explicit GCheckBox(GWidget* parent);
|
||||
virtual ~GCheckBox() override;
|
||||
|
||||
|
|
Loading…
Reference in a new issue