Compare commits

...

4 Commits

Author SHA1 Message Date
4cbdea954a
wind: Generate random windows on keypresses
All checks were successful
continuous-integration/drone/pr Build is passing
2023-08-06 12:45:13 +02:00
ec256e058d
wind: Make sure windows have a minimum size to fit the titlebar 2023-08-06 12:44:56 +02:00
6388672d00
libui: Properly cut off the last drawn character if necessary 2023-08-06 12:44:35 +02:00
36c1374c16
libui: Add Rect::contains(Rect) 2023-08-06 12:44:16 +02:00
5 changed files with 32 additions and 2 deletions

View File

@ -21,6 +21,15 @@ namespace ui
*/
bool contains(Point point);
/**
* @brief Check if another rectangle is contained in this one.
*
* @param point The rectangle to check.
* @return true The other rectangle is contained inside this one.
* @return false The other rectangle is not contained inside this one.
*/
bool contains(Rect rect);
/**
* @brief Normalize a point to fit inside this rectangle.
*

View File

@ -101,7 +101,7 @@ namespace ui
{
u32 line = offset;
int mask = 1 << (m_psf_header.width - 1);
for (int x = 0; x < m_psf_header.width; x++)
for (int x = 0; x < width; x++)
{
if (*((u32*)glyph) & mask) *(u32*)(canvas.ptr + line) = color.raw;
mask >>= 1;

View File

@ -8,6 +8,15 @@ namespace ui
(point.y <= (pos.y + height));
}
bool Rect::contains(Rect rect)
{
if (!contains(rect.pos)) return false;
Point rel = relative(rect.pos);
if ((rel.x + rect.width) > width) return false;
if ((rel.y + rect.height) > height) return false;
return true;
}
Point Rect::normalize(Point point)
{
if (point.x < pos.x) point.x = pos.x;

View File

@ -42,6 +42,8 @@ void Window::focus()
Window::Window(ui::Rect r, ui::Color c, StringView n) : surface(r), color(c), name(n)
{
auto font = ui::Font::default_font();
if (surface.width < 36) surface.width = 36;
if (surface.height < (font->height() + 20)) surface.height = font->height() + 20;
titlebar = ui::Rect { 0, 0, surface.width, font->height() + 20 };
close_button = ui::Rect { surface.width - 26, 10, 16, 16 };
contents = ui::Rect { 0, font->height() + 20, surface.width, surface.height - (font->height() + 20) };

View File

@ -11,10 +11,13 @@
#include <string.h>
#include <sys/ioctl.h>
#include <sys/poll.h>
#include <time.h>
#include <unistd.h>
Result<int> luna_main(int argc, char** argv)
{
srand((unsigned)time(NULL));
StringView socket_path = "/tmp/wind.sock";
StringView user;
@ -105,7 +108,14 @@ Result<int> luna_main(int argc, char** argv)
{
moon::KeyboardPacket packet;
TRY(keyboard->read_typed(packet));
background = ui::Color::from_rgb(0x00, 0x00, packet.key * 2);
if (!packet.released)
{
TRY(make<Window>(ui::Rect { rand() % screen.canvas().width, rand() % screen.canvas().height,
rand() % screen.canvas().width, rand() % screen.canvas().height },
ui::Color::from_rgb(static_cast<u8>(rand() % 256), static_cast<u8>(rand() % 256),
static_cast<u8>(rand() % 256)),
strerror(packet.key)));
}
}
if (fds[2].revents & POLLIN)
{