mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 16:47:36 +00:00
LibGUI: Remove ControlBoxButton widget
ComboBoxes and SpinBoxes were still relying on ascii-to-bitmap icons instead of PNGs. This makes it easier to theme in the future.
This commit is contained in:
parent
24120d9dca
commit
d8fa479d05
7 changed files with 11 additions and 157 deletions
|
@ -22,7 +22,6 @@ set(SOURCES
|
|||
ColumnsView.cpp
|
||||
ComboBox.cpp
|
||||
Command.cpp
|
||||
ControlBoxButton.cpp
|
||||
Desktop.cpp
|
||||
Dialog.cpp
|
||||
DisplayLink.cpp
|
||||
|
|
|
@ -24,8 +24,8 @@
|
|||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <LibGUI/Button.h>
|
||||
#include <LibGUI/ComboBox.h>
|
||||
#include <LibGUI/ControlBoxButton.h>
|
||||
#include <LibGUI/Desktop.h>
|
||||
#include <LibGUI/ListView.h>
|
||||
#include <LibGUI/Model.h>
|
||||
|
@ -91,7 +91,8 @@ ComboBox::ComboBox()
|
|||
m_open_button->click();
|
||||
};
|
||||
|
||||
m_open_button = add<ControlBoxButton>(ControlBoxButton::DownArrow);
|
||||
m_open_button = add<Button>();
|
||||
m_open_button->set_icon(Gfx::Bitmap::load_from_file("/res/icons/16x16/downward-triangle.png"));
|
||||
m_open_button->set_focus_policy(GUI::FocusPolicy::NoFocus);
|
||||
m_open_button->on_click = [this](auto) {
|
||||
if (m_list_window->is_visible())
|
||||
|
|
|
@ -33,7 +33,6 @@
|
|||
namespace GUI {
|
||||
|
||||
class ComboBoxEditor;
|
||||
class ControlBoxButton;
|
||||
|
||||
class ComboBox : public Frame {
|
||||
C_OBJECT(ComboBox);
|
||||
|
@ -74,7 +73,7 @@ private:
|
|||
void navigate_relative(int);
|
||||
|
||||
RefPtr<ComboBoxEditor> m_editor;
|
||||
RefPtr<ControlBoxButton> m_open_button;
|
||||
RefPtr<Button> m_open_button;
|
||||
RefPtr<Window> m_list_window;
|
||||
RefPtr<ListView> m_list_view;
|
||||
Optional<ModelIndex> m_selected_index;
|
||||
|
|
|
@ -1,93 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2020, Charles Chaucer <thankyouverycool@github>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <LibGUI/ControlBoxButton.h>
|
||||
#include <LibGUI/Painter.h>
|
||||
#include <LibGfx/CharacterBitmap.h>
|
||||
#include <LibGfx/Palette.h>
|
||||
|
||||
namespace GUI {
|
||||
|
||||
static const char* s_up_arrow_bitmap_data = {
|
||||
" "
|
||||
" # "
|
||||
" ### "
|
||||
" ##### "
|
||||
" ####### "
|
||||
" "
|
||||
};
|
||||
|
||||
static const char* s_down_arrow_bitmap_data = {
|
||||
" "
|
||||
" ####### "
|
||||
" ##### "
|
||||
" ### "
|
||||
" # "
|
||||
" "
|
||||
};
|
||||
|
||||
static Gfx::CharacterBitmap* s_up_arrow_bitmap;
|
||||
static Gfx::CharacterBitmap* s_down_arrow_bitmap;
|
||||
static const int s_bitmap_width = 9;
|
||||
static const int s_bitmap_height = 6;
|
||||
|
||||
ControlBoxButton::ControlBoxButton(Type type)
|
||||
: m_type(type)
|
||||
{
|
||||
}
|
||||
|
||||
ControlBoxButton::~ControlBoxButton()
|
||||
{
|
||||
}
|
||||
|
||||
void ControlBoxButton::paint_event(PaintEvent& event)
|
||||
{
|
||||
Painter painter(*this);
|
||||
painter.add_clip_rect(event.rect());
|
||||
|
||||
Gfx::StylePainter::paint_button(painter, rect(), palette(), Gfx::ButtonStyle::Normal, is_being_pressed(), is_hovered(), is_checked(), is_enabled(), is_focused());
|
||||
|
||||
auto button_location = rect().location().translated((width() - s_bitmap_width) / 2, (height() - s_bitmap_height) / 2);
|
||||
|
||||
if (is_being_pressed())
|
||||
button_location.move_by(1, 1);
|
||||
|
||||
if (type() == UpArrow) {
|
||||
if (!s_up_arrow_bitmap)
|
||||
s_up_arrow_bitmap = &Gfx::CharacterBitmap::create_from_ascii(s_up_arrow_bitmap_data, s_bitmap_width, s_bitmap_height).leak_ref();
|
||||
if (!is_enabled())
|
||||
painter.draw_bitmap(button_location.translated(1, 1), *s_up_arrow_bitmap, palette().threed_highlight());
|
||||
painter.draw_bitmap(button_location, *s_up_arrow_bitmap, is_enabled() ? palette().button_text() : palette().threed_shadow1());
|
||||
} else {
|
||||
if (!s_down_arrow_bitmap)
|
||||
s_down_arrow_bitmap = &Gfx::CharacterBitmap::create_from_ascii(s_down_arrow_bitmap_data, s_bitmap_width, s_bitmap_height).leak_ref();
|
||||
if (!is_enabled())
|
||||
painter.draw_bitmap(button_location.translated(1, 1), *s_down_arrow_bitmap, palette().threed_highlight());
|
||||
painter.draw_bitmap(button_location, *s_down_arrow_bitmap, is_enabled() ? palette().button_text() : palette().threed_shadow1());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,52 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2020, Charles Chaucer <thankyouverycool@github>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <LibGUI/Button.h>
|
||||
|
||||
namespace GUI {
|
||||
|
||||
class ControlBoxButton final : public Button {
|
||||
C_OBJECT(ControlBoxButton);
|
||||
|
||||
public:
|
||||
enum Type {
|
||||
UpArrow,
|
||||
DownArrow
|
||||
};
|
||||
|
||||
virtual ~ControlBoxButton() override;
|
||||
|
||||
private:
|
||||
explicit ControlBoxButton(const Type type);
|
||||
virtual void paint_event(PaintEvent& event) override;
|
||||
|
||||
Type m_type { DownArrow };
|
||||
Type type() const { return m_type; }
|
||||
};
|
||||
|
||||
}
|
|
@ -24,7 +24,7 @@
|
|||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <LibGUI/ControlBoxButton.h>
|
||||
#include <LibGUI/Button.h>
|
||||
#include <LibGUI/SpinBox.h>
|
||||
#include <LibGUI/TextBox.h>
|
||||
|
||||
|
@ -52,11 +52,13 @@ SpinBox::SpinBox()
|
|||
set_value(m_value - 1);
|
||||
};
|
||||
|
||||
m_increment_button = add<ControlBoxButton>(ControlBoxButton::UpArrow);
|
||||
m_increment_button = add<Button>();
|
||||
m_increment_button->set_icon(Gfx::Bitmap::load_from_file("/res/icons/16x16/upward-triangle.png"));
|
||||
m_increment_button->set_focus_policy(GUI::FocusPolicy::NoFocus);
|
||||
m_increment_button->on_click = [this](auto) { set_value(m_value + 1); };
|
||||
m_increment_button->set_auto_repeat_interval(150);
|
||||
m_decrement_button = add<ControlBoxButton>(ControlBoxButton::DownArrow);
|
||||
m_decrement_button = add<Button>();
|
||||
m_decrement_button->set_icon(Gfx::Bitmap::load_from_file("/res/icons/16x16/downward-triangle.png"));
|
||||
m_decrement_button->set_focus_policy(GUI::FocusPolicy::NoFocus);
|
||||
m_decrement_button->on_click = [this](auto) { set_value(m_value - 1); };
|
||||
m_decrement_button->set_auto_repeat_interval(150);
|
||||
|
|
|
@ -30,8 +30,6 @@
|
|||
|
||||
namespace GUI {
|
||||
|
||||
class ControlBoxButton;
|
||||
|
||||
class SpinBox : public Widget {
|
||||
C_OBJECT(SpinBox)
|
||||
public:
|
||||
|
@ -56,8 +54,8 @@ protected:
|
|||
|
||||
private:
|
||||
RefPtr<TextEditor> m_editor;
|
||||
RefPtr<ControlBoxButton> m_increment_button;
|
||||
RefPtr<ControlBoxButton> m_decrement_button;
|
||||
RefPtr<Button> m_increment_button;
|
||||
RefPtr<Button> m_decrement_button;
|
||||
|
||||
int m_min { 0 };
|
||||
int m_max { 100 };
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue