mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 09:48:11 +00:00
VisualBuilder: Add icons to the toolbox, and support for GProgressBar.
This commit is contained in:
parent
75c76f6692
commit
b5d1cfef58
9 changed files with 40 additions and 16 deletions
|
@ -5,6 +5,7 @@
|
||||||
#include <LibGUI/GButton.h>
|
#include <LibGUI/GButton.h>
|
||||||
#include <LibGUI/GSpinBox.h>
|
#include <LibGUI/GSpinBox.h>
|
||||||
#include <LibGUI/GTextEditor.h>
|
#include <LibGUI/GTextEditor.h>
|
||||||
|
#include <LibGUI/GProgressBar.h>
|
||||||
|
|
||||||
static GWidget* build_gwidget(WidgetType type, GWidget* parent)
|
static GWidget* build_gwidget(WidgetType type, GWidget* parent)
|
||||||
{
|
{
|
||||||
|
@ -22,6 +23,13 @@ static GWidget* build_gwidget(WidgetType type, GWidget* parent)
|
||||||
editor->set_ruler_visible(false);
|
editor->set_ruler_visible(false);
|
||||||
return editor;
|
return editor;
|
||||||
}
|
}
|
||||||
|
case WidgetType::GProgressBar: {
|
||||||
|
auto* bar = new GProgressBar(parent);
|
||||||
|
bar->set_format(GProgressBar::Format::NoText);
|
||||||
|
bar->set_range(0, 100);
|
||||||
|
bar->set_value(50);
|
||||||
|
return bar;
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
ASSERT_NOT_REACHED();
|
ASSERT_NOT_REACHED();
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
|
@ -30,6 +30,7 @@ enum class WidgetType {
|
||||||
GLabel,
|
GLabel,
|
||||||
GSpinBox,
|
GSpinBox,
|
||||||
GTextEditor,
|
GTextEditor,
|
||||||
|
GProgressBar,
|
||||||
};
|
};
|
||||||
|
|
||||||
class VBWidget : public Retainable<VBWidget>, public Weakable<VBWidget> {
|
class VBWidget : public Retainable<VBWidget>, public Weakable<VBWidget> {
|
||||||
|
|
|
@ -67,22 +67,32 @@ GWindow* make_toolbox_window()
|
||||||
window->set_main_widget(widget);
|
window->set_main_widget(widget);
|
||||||
|
|
||||||
auto* button_button = new GButton(widget);
|
auto* button_button = new GButton(widget);
|
||||||
button_button->set_caption("Button");
|
button_button->set_tooltip("GButton");
|
||||||
|
button_button->set_icon(GraphicsBitmap::load_from_file("/res/icons/vbwidgets/button.png"));
|
||||||
button_button->on_click = [] (GButton&) {
|
button_button->on_click = [] (GButton&) {
|
||||||
if (auto* form = VBForm::current())
|
if (auto* form = VBForm::current())
|
||||||
form->insert_widget(WidgetType::GButton);
|
form->insert_widget(WidgetType::GButton);
|
||||||
};
|
};
|
||||||
auto* spinbox_button = new GButton(widget);
|
auto* spinbox_button = new GButton(widget);
|
||||||
spinbox_button->set_caption("SpinBox");
|
spinbox_button->set_tooltip("GSpinBox");
|
||||||
|
spinbox_button->set_icon(GraphicsBitmap::load_from_file("/res/icons/vbwidgets/spinbox.png"));
|
||||||
spinbox_button->on_click = [] (GButton&) {
|
spinbox_button->on_click = [] (GButton&) {
|
||||||
if (auto* form = VBForm::current())
|
if (auto* form = VBForm::current())
|
||||||
form->insert_widget(WidgetType::GSpinBox);
|
form->insert_widget(WidgetType::GSpinBox);
|
||||||
};
|
};
|
||||||
auto* editor_button = new GButton(widget);
|
auto* editor_button = new GButton(widget);
|
||||||
editor_button->set_caption("TextEditor");
|
editor_button->set_tooltip("GTextEditor");
|
||||||
|
editor_button->set_icon(GraphicsBitmap::load_from_file("/res/icons/vbwidgets/textbox.png"));
|
||||||
editor_button->on_click = [] (GButton&) {
|
editor_button->on_click = [] (GButton&) {
|
||||||
if (auto* form = VBForm::current())
|
if (auto* form = VBForm::current())
|
||||||
form->insert_widget(WidgetType::GTextEditor);
|
form->insert_widget(WidgetType::GTextEditor);
|
||||||
};
|
};
|
||||||
|
auto* progress_bar_button = new GButton(widget);
|
||||||
|
progress_bar_button->set_tooltip("GProgressBar");
|
||||||
|
progress_bar_button->set_icon(GraphicsBitmap::load_from_file("/res/icons/vbwidgets/progressbar.png"));
|
||||||
|
progress_bar_button->on_click = [] (GButton&) {
|
||||||
|
if (auto* form = VBForm::current())
|
||||||
|
form->insert_widget(WidgetType::GProgressBar);
|
||||||
|
};
|
||||||
return window;
|
return window;
|
||||||
}
|
}
|
||||||
|
|
BIN
Base/res/icons/vbwidgets/button.png
Normal file
BIN
Base/res/icons/vbwidgets/button.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 266 B |
BIN
Base/res/icons/vbwidgets/progressbar.png
Normal file
BIN
Base/res/icons/vbwidgets/progressbar.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 186 B |
BIN
Base/res/icons/vbwidgets/spinbox.png
Normal file
BIN
Base/res/icons/vbwidgets/spinbox.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 261 B |
BIN
Base/res/icons/vbwidgets/textbox.png
Normal file
BIN
Base/res/icons/vbwidgets/textbox.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 243 B |
|
@ -51,19 +51,22 @@ void GProgressBar::paint_event(GPaintEvent& event)
|
||||||
float range_size = m_max - m_min;
|
float range_size = m_max - m_min;
|
||||||
float progress = (m_value - m_min) / range_size;
|
float progress = (m_value - m_min) / range_size;
|
||||||
|
|
||||||
// Then we draw the progress text over the gradient.
|
String progress_text;
|
||||||
// We draw it twice, once offset (1, 1) for a drop shadow look.
|
if (m_format != Format::NoText) {
|
||||||
StringBuilder builder;
|
// Then we draw the progress text over the gradient.
|
||||||
builder.append(m_caption);
|
// We draw it twice, once offset (1, 1) for a drop shadow look.
|
||||||
if (m_format == Format::Percentage)
|
StringBuilder builder;
|
||||||
builder.appendf("%d%%", (int)(progress * 100));
|
builder.append(m_caption);
|
||||||
else if (m_format == Format::ValueSlashMax)
|
if (m_format == Format::Percentage)
|
||||||
builder.appendf("%d/%d", m_value, m_max);
|
builder.appendf("%d%%", (int)(progress * 100));
|
||||||
|
else if (m_format == Format::ValueSlashMax)
|
||||||
|
builder.appendf("%d/%d", m_value, m_max);
|
||||||
|
|
||||||
auto progress_text = builder.to_string();
|
progress_text = builder.to_string();
|
||||||
|
|
||||||
painter.draw_text(rect.translated(1, 1), progress_text, TextAlignment::Center, Color::Black);
|
painter.draw_text(rect.translated(1, 1), progress_text, TextAlignment::Center, Color::Black);
|
||||||
painter.draw_text(rect, progress_text, TextAlignment::Center, Color::White);
|
painter.draw_text(rect, progress_text, TextAlignment::Center, Color::White);
|
||||||
|
}
|
||||||
|
|
||||||
// Then we carve out a hole in the remaining part of the widget.
|
// Then we carve out a hole in the remaining part of the widget.
|
||||||
// We draw the text a third time, clipped and inverse, for sharp contrast.
|
// We draw the text a third time, clipped and inverse, for sharp contrast.
|
||||||
|
@ -71,5 +74,7 @@ void GProgressBar::paint_event(GPaintEvent& event)
|
||||||
Rect hole_rect { (int)progress_width, 0, (int)(width() - progress_width), height() };
|
Rect hole_rect { (int)progress_width, 0, (int)(width() - progress_width), height() };
|
||||||
painter.add_clip_rect(hole_rect);
|
painter.add_clip_rect(hole_rect);
|
||||||
painter.fill_rect(hole_rect, Color::White);
|
painter.fill_rect(hole_rect, Color::White);
|
||||||
painter.draw_text(rect.translated(0, 0), progress_text, TextAlignment::Center, Color::Black);
|
|
||||||
|
if (m_format != Format::NoText)
|
||||||
|
painter.draw_text(rect.translated(0, 0), progress_text, TextAlignment::Center, Color::Black);
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,7 +15,7 @@ public:
|
||||||
String caption() const { return m_caption; }
|
String caption() const { return m_caption; }
|
||||||
void set_caption(const String& caption) { m_caption = caption; }
|
void set_caption(const String& caption) { m_caption = caption; }
|
||||||
|
|
||||||
enum Format { Percentage, ValueSlashMax };
|
enum Format { NoText, Percentage, ValueSlashMax };
|
||||||
Format format() const { return m_format; }
|
Format format() const { return m_format; }
|
||||||
void set_format(Format format) { m_format = format; }
|
void set_format(Format format) { m_format = format; }
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue