mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 13:17:35 +00:00
GSpinBox: Put nice little arrow glyphs on the buttons.
This commit is contained in:
parent
a00a2a9db5
commit
4abffa4dbe
3 changed files with 23 additions and 19 deletions
Binary file not shown.
|
@ -15,10 +15,10 @@ GSpinBox::GSpinBox(GWidget* parent)
|
||||||
m_editor->set_text(String::format("%d", m_value));
|
m_editor->set_text(String::format("%d", m_value));
|
||||||
};
|
};
|
||||||
m_increment_button = new GButton(this);
|
m_increment_button = new GButton(this);
|
||||||
m_increment_button->set_caption("+");
|
m_increment_button->set_caption("\xf6");
|
||||||
m_increment_button->on_click = [this] (GButton&) { set_value(m_value + 1); };
|
m_increment_button->on_click = [this] (GButton&) { set_value(m_value + 1); };
|
||||||
m_decrement_button = new GButton(this);
|
m_decrement_button = new GButton(this);
|
||||||
m_decrement_button->set_caption("-");
|
m_decrement_button->set_caption("\xf7");
|
||||||
m_decrement_button->on_click = [this] (GButton&) { set_value(m_value - 1); };
|
m_decrement_button->on_click = [this] (GButton&) { set_value(m_value - 1); };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -64,7 +64,7 @@ void GSpinBox::set_range(int min, int max)
|
||||||
void GSpinBox::resize_event(GResizeEvent& event)
|
void GSpinBox::resize_event(GResizeEvent& event)
|
||||||
{
|
{
|
||||||
int button_height = event.size().height() / 2;
|
int button_height = event.size().height() / 2;
|
||||||
int button_width = 16;
|
int button_width = 15;
|
||||||
m_increment_button->set_relative_rect(width() - button_width, 0, button_width, button_height);
|
m_increment_button->set_relative_rect(width() - button_width, 0, button_width, button_height);
|
||||||
m_decrement_button->set_relative_rect(width() - button_width, button_height, button_width, button_height);
|
m_decrement_button->set_relative_rect(width() - button_width, button_height, button_width, button_height);
|
||||||
m_editor->set_relative_rect(0, 0, width() - button_width, height());
|
m_editor->set_relative_rect(0, 0, width() - button_width, height());
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
#include <AK/StdLibExtras.h>
|
#include <AK/StdLibExtras.h>
|
||||||
#include <AK/StringBuilder.h>
|
#include <AK/StringBuilder.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
Painter::Painter(GraphicsBitmap& bitmap)
|
Painter::Painter(GraphicsBitmap& bitmap)
|
||||||
: m_target(bitmap)
|
: m_target(bitmap)
|
||||||
|
@ -348,10 +349,12 @@ void Painter::draw_text(const Rect& rect, const char* text, int length, const Fo
|
||||||
{
|
{
|
||||||
String elided_text;
|
String elided_text;
|
||||||
if (elision == TextElision::Right) {
|
if (elision == TextElision::Right) {
|
||||||
|
int text_width = font.width(text, length);
|
||||||
if (font.width(text, length) > rect.width()) {
|
if (font.width(text, length) > rect.width()) {
|
||||||
int glyph_spacing = font.glyph_spacing();
|
int glyph_spacing = font.glyph_spacing();
|
||||||
int new_length = 0;
|
int new_length = 0;
|
||||||
int new_width = font.width("...");
|
int new_width = font.width("...");
|
||||||
|
if (new_width < text_width) {
|
||||||
for (int i = 0; i < length; ++i) {
|
for (int i = 0; i < length; ++i) {
|
||||||
int glyph_width = font.glyph_width(text[i]);
|
int glyph_width = font.glyph_width(text[i]);
|
||||||
// NOTE: Glyph spacing should not be added after the last glyph on the line,
|
// NOTE: Glyph spacing should not be added after the last glyph on the line,
|
||||||
|
@ -371,6 +374,7 @@ void Painter::draw_text(const Rect& rect, const char* text, int length, const Fo
|
||||||
length = elided_text.length();
|
length = elided_text.length();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Point point;
|
Point point;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue