From d8ab9ed87ce99e6fed47519eba889ba6116fd68b Mon Sep 17 00:00:00 2001 From: Andrew Kaster Date: Fri, 27 Oct 2023 14:24:15 -0600 Subject: [PATCH] LibGfx+Userland: Remove dependency on GUI::TabWidget from StylePainter Move TabPosition into its own file, and using it into the global namespace the same way we do for Gfx::Orientation. This unbreaks the gn build, and out of tree builds. --- .../Applications/Browser/BrowserWindow.cpp | 4 ++-- Userland/Applications/CrashReporter/main.cpp | 4 ++-- .../Spreadsheet/SpreadsheetWidget.cpp | 2 +- .../HackStudio/Debugger/DebugInfoWidget.cpp | 2 +- .../DevTools/HackStudio/HackStudioWidget.cpp | 2 +- Userland/Libraries/LibGUI/TabWidget.h | 8 +------- .../Libraries/LibGfx/ClassicStylePainter.cpp | 10 +++++----- .../Libraries/LibGfx/ClassicStylePainter.h | 2 +- Userland/Libraries/LibGfx/StylePainter.cpp | 2 +- Userland/Libraries/LibGfx/StylePainter.h | 6 +++--- Userland/Libraries/LibGfx/TabPosition.h | 20 +++++++++++++++++++ 11 files changed, 38 insertions(+), 24 deletions(-) create mode 100644 Userland/Libraries/LibGfx/TabPosition.h diff --git a/Userland/Applications/Browser/BrowserWindow.cpp b/Userland/Applications/Browser/BrowserWindow.cpp index db2cfbe493..7621ca6125 100644 --- a/Userland/Applications/Browser/BrowserWindow.cpp +++ b/Userland/Applications/Browser/BrowserWindow.cpp @@ -131,13 +131,13 @@ BrowserWindow::BrowserWindow(WebView::CookieJar& cookie_jar, Vector const& Browser::BookmarksBarWidget::the().set_visible(show_bookmarks_bar); m_window_actions.on_vertical_tabs = [this](auto& action) { - m_tab_widget->set_tab_position(action.is_checked() ? GUI::TabWidget::TabPosition::Left : GUI::TabWidget::TabPosition::Top); + m_tab_widget->set_tab_position(action.is_checked() ? TabPosition::Left : TabPosition::Top); Config::write_bool("Browser"sv, "Preferences"sv, "VerticalTabs"sv, action.is_checked()); }; bool vertical_tabs = Config::read_bool("Browser"sv, "Preferences"sv, "VerticalTabs"sv, false); m_window_actions.vertical_tabs_action().set_checked(vertical_tabs); - m_tab_widget->set_tab_position(vertical_tabs ? GUI::TabWidget::TabPosition::Left : GUI::TabWidget::TabPosition::Top); + m_tab_widget->set_tab_position(vertical_tabs ? TabPosition::Left : TabPosition::Top); build_menus(); diff --git a/Userland/Applications/CrashReporter/main.cpp b/Userland/Applications/CrashReporter/main.cpp index ef1f053837..86e1244ac1 100644 --- a/Userland/Applications/CrashReporter/main.cpp +++ b/Userland/Applications/CrashReporter/main.cpp @@ -244,7 +244,7 @@ ErrorOr serenity_main(Main::Arguments arguments) backtrace_label.set_fixed_height(16); auto& backtrace_tab_widget = backtrace_tab.add(); - backtrace_tab_widget.set_tab_position(GUI::TabWidget::TabPosition::Bottom); + backtrace_tab_widget.set_tab_position(TabPosition::Bottom); auto& cpu_registers_tab = tab_widget.add_tab("CPU Registers"_string); cpu_registers_tab.set_layout(4); @@ -254,7 +254,7 @@ ErrorOr serenity_main(Main::Arguments arguments) cpu_registers_label.set_fixed_height(16); auto& cpu_registers_tab_widget = cpu_registers_tab.add(); - cpu_registers_tab_widget.set_tab_position(GUI::TabWidget::TabPosition::Bottom); + cpu_registers_tab_widget.set_tab_position(TabPosition::Bottom); auto& environment_tab = tab_widget.add_tab("Environment"_string); environment_tab.set_layout(4); diff --git a/Userland/Applications/Spreadsheet/SpreadsheetWidget.cpp b/Userland/Applications/Spreadsheet/SpreadsheetWidget.cpp index a06d904b8b..e88d52b596 100644 --- a/Userland/Applications/Spreadsheet/SpreadsheetWidget.cpp +++ b/Userland/Applications/Spreadsheet/SpreadsheetWidget.cpp @@ -72,7 +72,7 @@ SpreadsheetWidget::SpreadsheetWidget(GUI::Window& parent_window, Vector(); - m_tab_widget->set_tab_position(GUI::TabWidget::TabPosition::Bottom); + m_tab_widget->set_tab_position(TabPosition::Bottom); m_cell_value_editor = cell_value_editor; m_current_cell_label = current_cell_label; diff --git a/Userland/DevTools/HackStudio/Debugger/DebugInfoWidget.cpp b/Userland/DevTools/HackStudio/Debugger/DebugInfoWidget.cpp index 4e2b018c4e..77c64f177f 100644 --- a/Userland/DevTools/HackStudio/Debugger/DebugInfoWidget.cpp +++ b/Userland/DevTools/HackStudio/Debugger/DebugInfoWidget.cpp @@ -76,7 +76,7 @@ DebugInfoWidget::DebugInfoWidget() auto& splitter = bottom_box.add(); m_backtrace_view = splitter.add(); auto& variables_tab_widget = splitter.add(); - variables_tab_widget.set_tab_position(GUI::TabWidget::TabPosition::Bottom); + variables_tab_widget.set_tab_position(TabPosition::Bottom); variables_tab_widget.add_widget(build_variables_tab()); variables_tab_widget.add_widget(build_registers_tab()); diff --git a/Userland/DevTools/HackStudio/HackStudioWidget.cpp b/Userland/DevTools/HackStudio/HackStudioWidget.cpp index 2305984657..f625226f96 100644 --- a/Userland/DevTools/HackStudio/HackStudioWidget.cpp +++ b/Userland/DevTools/HackStudio/HackStudioWidget.cpp @@ -1371,7 +1371,7 @@ ErrorOr HackStudioWidget::create_action_tab(GUI::Widget& parent) void HackStudioWidget::create_project_tab(GUI::Widget& parent) { m_project_tab = parent.add(); - m_project_tab->set_tab_position(GUI::TabWidget::TabPosition::Bottom); + m_project_tab->set_tab_position(TabPosition::Bottom); auto& tree_view_container = m_project_tab->add_tab("Files"_string); tree_view_container.set_layout(GUI::Margins {}, 2); diff --git a/Userland/Libraries/LibGUI/TabWidget.h b/Userland/Libraries/LibGUI/TabWidget.h index 356a232216..f69b1914a1 100644 --- a/Userland/Libraries/LibGUI/TabWidget.h +++ b/Userland/Libraries/LibGUI/TabWidget.h @@ -9,19 +9,13 @@ #include #include +#include namespace GUI { class TabWidget : public Widget { C_OBJECT(TabWidget) public: - enum TabPosition { - Top, - Bottom, - Left, - Right, - }; - virtual ~TabWidget() override = default; TabPosition tab_position() const { return m_tab_position; } diff --git a/Userland/Libraries/LibGfx/ClassicStylePainter.cpp b/Userland/Libraries/LibGfx/ClassicStylePainter.cpp index e4ca0a0f91..db0fe3522d 100644 --- a/Userland/Libraries/LibGfx/ClassicStylePainter.cpp +++ b/Userland/Libraries/LibGfx/ClassicStylePainter.cpp @@ -18,7 +18,7 @@ namespace Gfx { -void ClassicStylePainter::paint_tab_button(Painter& painter, IntRect const& rect, Palette const& palette, bool active, bool hovered, bool enabled, GUI::TabWidget::TabPosition position, bool in_active_window, bool accented) +void ClassicStylePainter::paint_tab_button(Painter& painter, IntRect const& rect, Palette const& palette, bool active, bool hovered, bool enabled, TabPosition position, bool in_active_window, bool accented) { Color base_color = palette.button(); Color highlight_color2 = palette.threed_highlight(); @@ -36,7 +36,7 @@ void ClassicStylePainter::paint_tab_button(Painter& painter, IntRect const& rect accent = accent.to_grayscale(); switch (position) { - case GUI::TabWidget::TabPosition::Top: + case TabPosition::Top: // Base painter.fill_rect({ 1, 1, rect.width() - 2, rect.height() - 1 }, base_color); @@ -58,7 +58,7 @@ void ClassicStylePainter::paint_tab_button(Painter& painter, IntRect const& rect painter.draw_line({ rect.width() - 2, 2 }, { rect.width() - 2, rect.height() - 1 }, shadow_color1); painter.set_pixel(rect.width() - 2, 1, shadow_color2); break; - case GUI::TabWidget::TabPosition::Bottom: + case TabPosition::Bottom: // Base painter.fill_rect({ 0, 0, rect.width() - 1, rect.height() }, base_color); @@ -79,7 +79,7 @@ void ClassicStylePainter::paint_tab_button(Painter& painter, IntRect const& rect painter.draw_line({ rect.width() - 2, 0 }, { rect.width() - 2, rect.height() - 3 }, shadow_color1); painter.set_pixel({ rect.width() - 2, rect.height() - 2 }, shadow_color2); break; - case GUI::TabWidget::TabPosition::Left: + case TabPosition::Left: // Base tab painter.fill_rect({ 1, 1, rect.width(), rect.height() - 1 }, base_color); painter.draw_line({ 2, 0 }, { rect.width(), 0 }, highlight_color2); @@ -98,7 +98,7 @@ void ClassicStylePainter::paint_tab_button(Painter& painter, IntRect const& rect painter.set_pixel({ 1, 1 }, highlight_color2); painter.set_pixel({ 1, rect.height() - 2 }, shadow_color2); break; - case GUI::TabWidget::TabPosition::Right: + case TabPosition::Right: // Base tab painter.fill_rect({ 0, 1, rect.width() - 1, rect.height() - 1 }, base_color); painter.draw_line({ 0, 0 }, { rect.width() - 2, 0 }, highlight_color2); diff --git a/Userland/Libraries/LibGfx/ClassicStylePainter.h b/Userland/Libraries/LibGfx/ClassicStylePainter.h index 1a9b98e69f..1778ac7381 100644 --- a/Userland/Libraries/LibGfx/ClassicStylePainter.h +++ b/Userland/Libraries/LibGfx/ClassicStylePainter.h @@ -16,7 +16,7 @@ namespace Gfx { class ClassicStylePainter : public BaseStylePainter { public: virtual void paint_button(Painter&, IntRect const&, Palette const&, ButtonStyle, bool pressed, bool hovered = false, bool checked = false, bool enabled = true, bool focused = false, bool default_button = false) override; - virtual void paint_tab_button(Painter&, IntRect const&, Palette const&, bool active, bool hovered, bool enabled, GUI::TabWidget::TabPosition position, bool in_active_window, bool accented) override; + virtual void paint_tab_button(Painter&, IntRect const&, Palette const&, bool active, bool hovered, bool enabled, TabPosition position, bool in_active_window, bool accented) override; virtual void paint_frame(Painter&, IntRect const&, Palette const&, FrameStyle, bool skip_vertical_lines = false) override; virtual void paint_window_frame(Painter&, IntRect const&, Palette const&) override; virtual void paint_progressbar(Painter&, IntRect const&, Palette const&, int min, int max, int value, StringView text, Orientation = Orientation::Horizontal) override; diff --git a/Userland/Libraries/LibGfx/StylePainter.cpp b/Userland/Libraries/LibGfx/StylePainter.cpp index 256aed6305..17bfcad087 100644 --- a/Userland/Libraries/LibGfx/StylePainter.cpp +++ b/Userland/Libraries/LibGfx/StylePainter.cpp @@ -18,7 +18,7 @@ BaseStylePainter& StylePainter::current() return style; } -void StylePainter::paint_tab_button(Painter& painter, IntRect const& rect, Palette const& palette, bool active, bool hovered, bool enabled, GUI::TabWidget::TabPosition position, bool in_active_window, bool accented) +void StylePainter::paint_tab_button(Painter& painter, IntRect const& rect, Palette const& palette, bool active, bool hovered, bool enabled, TabPosition position, bool in_active_window, bool accented) { current().paint_tab_button(painter, rect, palette, active, hovered, enabled, position, in_active_window, accented); } diff --git a/Userland/Libraries/LibGfx/StylePainter.h b/Userland/Libraries/LibGfx/StylePainter.h index 9a7de46282..c61dfbf1da 100644 --- a/Userland/Libraries/LibGfx/StylePainter.h +++ b/Userland/Libraries/LibGfx/StylePainter.h @@ -7,9 +7,9 @@ #pragma once #include -#include #include #include +#include namespace Gfx { @@ -38,7 +38,7 @@ public: virtual ~BaseStylePainter() = default; virtual void paint_button(Painter&, IntRect const&, Palette const&, ButtonStyle, bool pressed, bool hovered = false, bool checked = false, bool enabled = true, bool focused = false, bool default_button = false) = 0; - virtual void paint_tab_button(Painter&, IntRect const&, Palette const&, bool active, bool hovered, bool enabled, GUI::TabWidget::TabPosition position, bool in_active_window, bool accented) = 0; + virtual void paint_tab_button(Painter&, IntRect const&, Palette const&, bool active, bool hovered, bool enabled, TabPosition position, bool in_active_window, bool accented) = 0; virtual void paint_frame(Painter&, IntRect const&, Palette const&, FrameStyle, bool skip_vertical_lines = false) = 0; virtual void paint_window_frame(Painter&, IntRect const&, Palette const&) = 0; virtual void paint_progressbar(Painter&, IntRect const&, Palette const&, int min, int max, int value, StringView text, Orientation = Orientation::Horizontal) = 0; @@ -57,7 +57,7 @@ public: // FIXME: These are here for API compatibility, we should probably remove them and move BaseStylePainter into here static void paint_button(Painter&, IntRect const&, Palette const&, ButtonStyle, bool pressed, bool hovered = false, bool checked = false, bool enabled = true, bool focused = false, bool default_button = false); - static void paint_tab_button(Painter&, IntRect const&, Palette const&, bool active, bool hovered, bool enabled, GUI::TabWidget::TabPosition position, bool in_active_window, bool accented); + static void paint_tab_button(Painter&, IntRect const&, Palette const&, bool active, bool hovered, bool enabled, TabPosition position, bool in_active_window, bool accented); static void paint_frame(Painter&, IntRect const&, Palette const&, FrameStyle, bool skip_vertical_lines = false); static void paint_window_frame(Painter&, IntRect const&, Palette const&); static void paint_progressbar(Painter&, IntRect const&, Palette const&, int min, int max, int value, StringView text, Orientation = Orientation::Horizontal); diff --git a/Userland/Libraries/LibGfx/TabPosition.h b/Userland/Libraries/LibGfx/TabPosition.h new file mode 100644 index 0000000000..5f0cb75c8b --- /dev/null +++ b/Userland/Libraries/LibGfx/TabPosition.h @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2023, Andrew Kaster + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#pragma once + +namespace Gfx { + +enum TabPosition { + Top, + Bottom, + Left, + Right, +}; + +} + +using Gfx::TabPosition;