mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 02:17:34 +00:00
LibVT/Terminal: add a scroll length to the TerminalWidget
The scroll length is the number of lines by which the terminal will go up/down when scrolling the mouse wheel once.
This commit is contained in:
parent
f20becf71b
commit
310fbe48e5
3 changed files with 29 additions and 2 deletions
|
@ -37,6 +37,7 @@
|
||||||
#include <LibGUI/MenuBar.h>
|
#include <LibGUI/MenuBar.h>
|
||||||
#include <LibGUI/RadioButton.h>
|
#include <LibGUI/RadioButton.h>
|
||||||
#include <LibGUI/Slider.h>
|
#include <LibGUI/Slider.h>
|
||||||
|
#include <LibGUI/SpinBox.h>
|
||||||
#include <LibGUI/Widget.h>
|
#include <LibGUI/Widget.h>
|
||||||
#include <LibGUI/Window.h>
|
#include <LibGUI/Window.h>
|
||||||
#include <LibGfx/Font.h>
|
#include <LibGfx/Font.h>
|
||||||
|
@ -138,7 +139,7 @@ RefPtr<GUI::Window> create_settings_window(TerminalWidget& terminal)
|
||||||
auto window = GUI::Window::construct();
|
auto window = GUI::Window::construct();
|
||||||
window->set_title("Terminal Settings");
|
window->set_title("Terminal Settings");
|
||||||
window->set_resizable(false);
|
window->set_resizable(false);
|
||||||
window->set_rect(50, 50, 200, 140);
|
window->set_rect(50, 50, 200, 185);
|
||||||
window->set_modal(true);
|
window->set_modal(true);
|
||||||
|
|
||||||
auto& settings = window->set_main_widget<GUI::Widget>();
|
auto& settings = window->set_main_widget<GUI::Widget>();
|
||||||
|
@ -175,6 +176,19 @@ RefPtr<GUI::Window> create_settings_window(TerminalWidget& terminal)
|
||||||
slider.set_range(0, 255);
|
slider.set_range(0, 255);
|
||||||
slider.set_value(terminal.opacity());
|
slider.set_value(terminal.opacity());
|
||||||
|
|
||||||
|
auto& spinbox_container = settings.add<GUI::GroupBox>("Scroll Length");
|
||||||
|
spinbox_container.set_layout<GUI::VerticalBoxLayout>();
|
||||||
|
spinbox_container.layout()->set_margins({ 6, 16, 6, 6 });
|
||||||
|
spinbox_container.set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed);
|
||||||
|
spinbox_container.set_preferred_size(100, 46);
|
||||||
|
|
||||||
|
auto& spinbox = spinbox_container.add<GUI::SpinBox>();
|
||||||
|
spinbox.set_min(1);
|
||||||
|
spinbox.set_value(terminal.scroll_length());
|
||||||
|
spinbox.on_change = [&terminal](int value) {
|
||||||
|
terminal.set_scroll_length(value);
|
||||||
|
};
|
||||||
|
|
||||||
return window;
|
return window;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -105,6 +105,7 @@ TerminalWidget::TerminalWidget(int ptm_fd, bool automatic_size_policy, RefPtr<Co
|
||||||
m_scrollbar->on_change = [this](int) {
|
m_scrollbar->on_change = [this](int) {
|
||||||
force_repaint();
|
force_repaint();
|
||||||
};
|
};
|
||||||
|
set_scroll_length(m_config->read_num_entry("Window", "ScrollLength", 1));
|
||||||
|
|
||||||
dbgprintf("Terminal: Load config file from %s\n", m_config->file_name().characters());
|
dbgprintf("Terminal: Load config file from %s\n", m_config->file_name().characters());
|
||||||
m_cursor_blink_timer->set_interval(m_config->read_num_entry("Text",
|
m_cursor_blink_timer->set_interval(m_config->read_num_entry("Text",
|
||||||
|
@ -672,7 +673,7 @@ void TerminalWidget::mousewheel_event(GUI::MouseEvent& event)
|
||||||
{
|
{
|
||||||
if (!is_scrollable())
|
if (!is_scrollable())
|
||||||
return;
|
return;
|
||||||
m_scrollbar->set_value(m_scrollbar->value() + event.wheel_delta());
|
m_scrollbar->set_value(m_scrollbar->value() + event.wheel_delta() * scroll_length());
|
||||||
GUI::Frame::mousewheel_event(event);
|
GUI::Frame::mousewheel_event(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -681,6 +682,16 @@ bool TerminalWidget::is_scrollable() const
|
||||||
return m_scrollbar->is_scrollable();
|
return m_scrollbar->is_scrollable();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int TerminalWidget::scroll_length() const
|
||||||
|
{
|
||||||
|
return m_scrollbar->step();
|
||||||
|
}
|
||||||
|
|
||||||
|
void TerminalWidget::set_scroll_length(int length)
|
||||||
|
{
|
||||||
|
m_scrollbar->set_step(length);
|
||||||
|
}
|
||||||
|
|
||||||
String TerminalWidget::selected_text() const
|
String TerminalWidget::selected_text() const
|
||||||
{
|
{
|
||||||
StringBuilder builder;
|
StringBuilder builder;
|
||||||
|
|
|
@ -74,6 +74,8 @@ public:
|
||||||
VT::Position normalized_selection_end() const;
|
VT::Position normalized_selection_end() const;
|
||||||
|
|
||||||
bool is_scrollable() const;
|
bool is_scrollable() const;
|
||||||
|
int scroll_length() const;
|
||||||
|
void set_scroll_length(int);
|
||||||
|
|
||||||
GUI::Action& copy_action() { return *m_copy_action; }
|
GUI::Action& copy_action() { return *m_copy_action; }
|
||||||
GUI::Action& paste_action() { return *m_paste_action; }
|
GUI::Action& paste_action() { return *m_paste_action; }
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue