1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-28 01:47:34 +00:00

LibGUI: Add Widget focus policies

Every widget now has a GUI::FocusPolicy that determines how it can
receive focus:

- NoFocus: The widget is not focusable (default)
- TabFocus: The widget can be focused using the tab key.
- ClickFocus: The widget can be focused by clicking on it.
- StrongFocus: Both of the above.

For widgets that have a focus proxy, getting/setting the focus policy
will affect the proxy instead.
This commit is contained in:
Andreas Kling 2020-10-30 10:58:27 +01:00
parent 34014fa838
commit aef56159a8
32 changed files with 64 additions and 40 deletions

View file

@ -109,6 +109,8 @@ ConsoleWidget::ConsoleWidget()
print_html(JS::MarkupGenerator::html_from_value(m_interpreter->vm().last_value()));
};
set_focus_proxy(m_input);
auto& clear_button = bottom_container.add<GUI::Button>();
clear_button.set_size_policy(GUI::SizePolicy::Fixed, GUI::SizePolicy::Fixed);
clear_button.set_preferred_size(22, 22);
@ -165,8 +167,4 @@ void ConsoleWidget::clear_output()
m_output_view->update();
}
void ConsoleWidget::focusin_event(GUI::FocusEvent&)
{
m_input->set_focus(true);
}
}

View file

@ -47,9 +47,6 @@ public:
private:
ConsoleWidget();
virtual bool accepts_focus() const override { return true; }
virtual void focusin_event(GUI::FocusEvent&) override;
RefPtr<GUI::TextBox> m_input;
RefPtr<Web::InProcessWebView> m_output_view;
RefPtr<Web::DOM::Element> m_output_container;

View file

@ -34,6 +34,7 @@ GlyphMapWidget::GlyphMapWidget(Gfx::Font& mutable_font)
{
m_glyph_count = mutable_font.glyph_count();
set_relative_rect({ 0, 0, preferred_width(), preferred_height() });
set_focus_policy(GUI::FocusPolicy::StrongFocus);
}
GlyphMapWidget::~GlyphMapWidget()

View file

@ -53,7 +53,6 @@ public:
private:
explicit GlyphMapWidget(Gfx::Font&);
virtual bool accepts_focus() const override { return true; }
virtual void paint_event(GUI::PaintEvent&) override;
virtual void mousedown_event(GUI::MouseEvent&) override;
virtual void keydown_event(GUI::KeyEvent&) override;

View file

@ -42,6 +42,7 @@
HexEditor::HexEditor()
{
set_focus_policy(GUI::FocusPolicy::StrongFocus);
set_scrollbars_enabled(true);
set_font(Gfx::Font::default_fixed_width_font());
set_background_role(ColorRole::Base);

View file

@ -74,7 +74,6 @@ protected:
virtual void mouseup_event(GUI::MouseEvent&) override;
virtual void mousemove_event(GUI::MouseEvent&) override;
virtual void keydown_event(GUI::KeyEvent&) override;
virtual bool accepts_focus() const override { return true; }
private:
bool m_readonly { false };

View file

@ -105,7 +105,7 @@ SamplerWidget::SamplerWidget(TrackManager& track_manager)
m_open_button = m_open_button_and_recorded_sample_name_container->add<GUI::Button>();
m_open_button->set_size_policy(GUI::SizePolicy::Fixed, GUI::SizePolicy::Fixed);
m_open_button->set_preferred_size(24, 24);
m_open_button->set_focusable(false);
m_open_button->set_focus_policy(GUI::FocusPolicy::TabFocus);
m_open_button->set_icon(Gfx::Bitmap::load_from_file("/res/icons/16x16/open.png"));
m_open_button->on_click = [this](auto) {
Optional<String> open_path = GUI::FilePicker::get_open_filepath(window());

View file

@ -36,6 +36,7 @@ namespace PixelPaint {
ImageEditor::ImageEditor()
{
set_focus_policy(GUI::FocusPolicy::StrongFocus);
}
ImageEditor::~ImageEditor()

View file

@ -82,8 +82,6 @@ public:
private:
ImageEditor();
virtual bool accepts_focus() const override { return true; }
virtual void paint_event(GUI::PaintEvent&) override;
virtual void second_paint_event(GUI::PaintEvent&) override;
virtual void mousedown_event(GUI::MouseEvent&) override;