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

LibGUI: Add a simple GGroupBox widget.

This needs some work on the visual side, but it gets the job done already.
This commit is contained in:
Andreas Kling 2019-04-10 05:52:15 +02:00
parent b980c32662
commit f6543c5946
5 changed files with 65 additions and 10 deletions

View file

@ -7,6 +7,7 @@
#include <LibGUI/GTextBox.h>
#include <LibGUI/GCheckBox.h>
#include <LibGUI/GSpinBox.h>
#include <LibGUI/GGroupBox.h>
#include <stdlib.h>
FontEditorWidget::FontEditorWidget(const String& path, RetainPtr<Font>&& edited_font, GWidget* parent)
@ -26,20 +27,23 @@ FontEditorWidget::FontEditorWidget(const String& path, RetainPtr<Font>&& edited_
m_glyph_editor_widget = new GlyphEditorWidget(*m_edited_font, this);
m_glyph_editor_widget->move_to({ 5, 5 });
auto* fixed_width_checkbox = new GCheckBox(this);
fixed_width_checkbox->set_caption("Fixed width");
fixed_width_checkbox->set_checked(m_edited_font->is_fixed_width());
fixed_width_checkbox->set_relative_rect({ 5, 195, 100, 20 });
auto* font_group_box = new GGroupBox("Font metadata", this);
font_group_box->set_relative_rect(5, 195, 210, 70);
m_name_textbox = new GTextBox(this);
m_name_textbox->set_relative_rect({ 5, 220, 300, 20 });
m_name_textbox = new GTextBox(font_group_box);
m_name_textbox->set_relative_rect(10, 20, 180, 20);
m_name_textbox->set_text(m_edited_font->name());
m_name_textbox->on_change = [this] {
m_edited_font->set_name(m_name_textbox->text());
};
auto* fixed_width_checkbox = new GCheckBox(font_group_box);
fixed_width_checkbox->set_relative_rect(10, 45, 190, 20);
fixed_width_checkbox->set_caption("Fixed width");
fixed_width_checkbox->set_checked(m_edited_font->is_fixed_width());
m_path_textbox = new GTextBox(this);
m_path_textbox->set_relative_rect({ 5, 245, 300, 20 });
m_path_textbox->set_relative_rect(5, 270, 210, 20);
m_path_textbox->set_text(m_path);
m_path_textbox->on_change = [this] {
m_path = m_path_textbox->text();
@ -47,7 +51,7 @@ FontEditorWidget::FontEditorWidget(const String& path, RetainPtr<Font>&& edited_
auto* save_button = new GButton(this);
save_button->set_caption("Save");
save_button->set_relative_rect({ 5, 270, 100, 20 });
save_button->set_relative_rect({ 5, 300, 105, 20 });
save_button->on_click = [this] (GButton&) {
dbgprintf("write to file: '%s'\n", m_path.characters());
m_edited_font->write_to_file(m_path);
@ -55,7 +59,7 @@ FontEditorWidget::FontEditorWidget(const String& path, RetainPtr<Font>&& edited_
auto* quit_button = new GButton(this);
quit_button->set_caption("Quit");
quit_button->set_relative_rect({ 110, 270, 100, 20 });
quit_button->set_relative_rect({ 110, 300, 105, 20 });
quit_button->on_click = [] (GButton&) {
exit(0);
};

View file

@ -26,7 +26,7 @@ int main(int argc, char** argv)
auto* window = new GWindow;
window->set_title("FontEditor");
window->set_rect({ 50, 50, 390, 295 });
window->set_rect({ 50, 50, 390, 325 });
auto* font_editor = new FontEditorWidget(path, move(edited_font));
window->set_main_widget(font_editor);
window->set_should_exit_event_loop_on_close(true);

31
LibGUI/GGroupBox.cpp Normal file
View file

@ -0,0 +1,31 @@
#include <LibGUI/GGroupBox.h>
#include <LibGUI/GPainter.h>
#include <SharedGraphics/StylePainter.h>
GGroupBox::GGroupBox(const String& name, GWidget* parent)
: GWidget(parent)
, m_name(name)
{
set_fill_with_background_color(true);
set_background_color(Color::LightGray);
}
GGroupBox::~GGroupBox()
{
}
void GGroupBox::paint_event(GPaintEvent& event)
{
GPainter painter(*this);
painter.add_clip_rect(event.rect());
Rect frame_rect {
0, font().glyph_height() / 2,
width(), height() - font().glyph_height() / 2
};
StylePainter::paint_frame(painter, frame_rect, FrameShape::Panel, FrameShadow::Sunken, 1);
Rect text_rect { 4, 0, font().width(m_name) + 6, font().glyph_height() };
painter.fill_rect(text_rect, background_color());
painter.draw_text(text_rect, m_name, TextAlignment::Center, foreground_color());
}

19
LibGUI/GGroupBox.h Normal file
View file

@ -0,0 +1,19 @@
#pragma once
#include <LibGUI/GWidget.h>
class GGroupBox : public GWidget {
public:
GGroupBox(const String& name, GWidget* parent);
virtual ~GGroupBox() override;
String name() const { return m_name; }
virtual const char* class_name() const override { return "GGroupBox"; }
protected:
virtual void paint_event(GPaintEvent&) override;
private:
String m_name;
};

View file

@ -64,6 +64,7 @@ LIBGUI_OBJS = \
GHttpResponse.o \
GHttpJob.o \
GSpinBox.o \
GGroupBox.o \
GWindow.o
OBJS = $(SHAREDGRAPHICS_OBJS) $(LIBGUI_OBJS)