mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 21:07:36 +00:00
LibGUI: Start adding an automatic widget layout system.
My needs are really quite simple, so I'm just going to add what I need as I go along. The first thing I needed was a simple box layout with widgets being able to say whether they prefer fixed or fill for both their vertical and horizontal sizes. I also made a simple GStatusBar so FileManager can show how many bytes worth of files are in the current directory.
This commit is contained in:
parent
2cf1dd5b6f
commit
2def3d8d3f
22 changed files with 411 additions and 29 deletions
|
@ -4,7 +4,7 @@
|
|||
#include <AK/Assertions.h>
|
||||
#include <AK/StdLibExtras.h>
|
||||
|
||||
#ifdef LIBGUI
|
||||
#ifdef USERLAND
|
||||
#include <LibGUI/GWidget.h>
|
||||
#include <LibGUI/GWindow.h>
|
||||
#include <LibC/gui.h>
|
||||
|
@ -20,7 +20,7 @@ Painter::Painter(GraphicsBitmap& bitmap)
|
|||
m_clip_rect = { { 0, 0 }, bitmap.size() };
|
||||
}
|
||||
|
||||
#ifdef LIBGUI
|
||||
#ifdef USERLAND
|
||||
Painter::Painter(GWidget& widget)
|
||||
: m_font(&widget.font())
|
||||
{
|
||||
|
@ -34,9 +34,9 @@ Painter::Painter(GWidget& widget)
|
|||
m_target = GraphicsBitmap::create_wrapper(backing.size, backing.pixels);
|
||||
ASSERT(m_target);
|
||||
m_window = widget.window();
|
||||
m_translation.move_by(widget.relative_position());
|
||||
m_translation.move_by(widget.window_relative_rect().location());
|
||||
// NOTE: m_clip_rect is in Window coordinates since we are painting into its backing store.
|
||||
m_clip_rect = widget.relative_rect();
|
||||
m_clip_rect = widget.window_relative_rect();
|
||||
m_clip_rect.intersect(m_target->rect());
|
||||
|
||||
#ifdef DEBUG_WIDGET_UNDERDRAW
|
||||
|
@ -49,7 +49,7 @@ Painter::Painter(GWidget& widget)
|
|||
|
||||
Painter::~Painter()
|
||||
{
|
||||
#ifdef LIBGUI
|
||||
#ifdef USERLAND
|
||||
m_target = nullptr;
|
||||
int rc = gui_release_window_backing_store(m_backing_store_id);
|
||||
ASSERT(rc == 0);
|
||||
|
|
|
@ -52,6 +52,16 @@ public:
|
|||
return { x() + width() / 2, y() + height() / 2 };
|
||||
}
|
||||
|
||||
void set_location(const Point& location)
|
||||
{
|
||||
m_location = location;
|
||||
}
|
||||
|
||||
void set_size(const Size& size)
|
||||
{
|
||||
m_size = size;
|
||||
}
|
||||
|
||||
void inflate(int w, int h)
|
||||
{
|
||||
set_x(x() - w / 2);
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
#pragma once
|
||||
|
||||
#include <AK/AKString.h>
|
||||
|
||||
struct GUI_Size;
|
||||
|
||||
class Size {
|
||||
|
@ -29,8 +31,17 @@ public:
|
|||
return !(*this == other);
|
||||
}
|
||||
|
||||
Size& operator-=(const Size& other)
|
||||
{
|
||||
m_width -= other.m_width;
|
||||
m_height -= other.m_height;
|
||||
return *this;
|
||||
}
|
||||
|
||||
operator GUI_Size() const;
|
||||
|
||||
String to_string() const { return String::format("[%d,%d]", m_width, m_height); }
|
||||
|
||||
private:
|
||||
int m_width { 0 };
|
||||
int m_height { 0 };
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue