mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 04:07:44 +00:00
LibGUI: Add a GToolBar class that can be populated with GActions.
The same action can be added to both a menu and a toolbar. Use this to put a toolbar into FileManager. This is pretty neat. :^)
This commit is contained in:
parent
4804609b7e
commit
b704d3d295
24 changed files with 196 additions and 44 deletions
58
LibGUI/GToolBar.cpp
Normal file
58
LibGUI/GToolBar.cpp
Normal file
|
@ -0,0 +1,58 @@
|
|||
#include <LibGUI/GToolBar.h>
|
||||
#include <LibGUI/GBoxLayout.h>
|
||||
#include <LibGUI/GButton.h>
|
||||
#include <LibGUI/GAction.h>
|
||||
#include <SharedGraphics/Painter.h>
|
||||
|
||||
GToolBar::GToolBar(GWidget* parent)
|
||||
: GWidget(parent)
|
||||
{
|
||||
set_size_policy(SizePolicy::Fill, SizePolicy::Fixed);
|
||||
set_preferred_size({ 0, 24 });
|
||||
set_layout(make<GBoxLayout>(Orientation::Horizontal));
|
||||
}
|
||||
|
||||
GToolBar::~GToolBar()
|
||||
{
|
||||
}
|
||||
|
||||
void GToolBar::add_action(RetainPtr<GAction>&& action)
|
||||
{
|
||||
ASSERT(action);
|
||||
GAction* raw_action_ptr = action.ptr();
|
||||
auto item = make<Item>();
|
||||
item->type = Item::Action;
|
||||
item->action = move(action);
|
||||
|
||||
auto* button = new GButton(this);
|
||||
if (item->action->icon())
|
||||
button->set_icon(item->action->icon());
|
||||
else
|
||||
button->set_caption(item->action->text());
|
||||
button->on_click = [raw_action_ptr] (const GButton&) {
|
||||
raw_action_ptr->activate();
|
||||
};
|
||||
|
||||
#if 0
|
||||
// FIXME: Gotta fix GBoxLayout for this to work.
|
||||
button->set_size_policy(SizePolicy::Fixed, SizePolicy::Fixed);
|
||||
button->set_preferred_size({ 16, 16 });
|
||||
#endif
|
||||
|
||||
m_items.append(move(item));
|
||||
}
|
||||
|
||||
void GToolBar::add_separator()
|
||||
{
|
||||
auto item = make<Item>();
|
||||
item->type = Item::Separator;
|
||||
m_items.append(move(item));
|
||||
}
|
||||
|
||||
void GToolBar::paint_event(GPaintEvent& event)
|
||||
{
|
||||
Painter painter(*this);
|
||||
painter.set_clip_rect(event.rect());
|
||||
painter.fill_rect({ 0, 0, width(), height() - 1 }, Color::LightGray);
|
||||
painter.draw_line({ 0, rect().bottom() }, { width() - 1, rect().bottom() }, Color::DarkGray);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue