Skip to content

Commit 1045ec9

Browse files
committed
Layout improvements; disable g_yield_t...
1 parent 510bacb commit 1045ec9

File tree

17 files changed

+221
-106
lines changed

17 files changed

+221
-106
lines changed

applications/libwindow/inc/libwindow/component.hpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ class g_component : public g_bounding_component
5959
request.header.id = G_UI_PROTOCOL_CREATE_COMPONENT;
6060
request.type = COMPONENT_CONSTANT;
6161
g_send_message_t(g_ui_delegate_tid, &request, sizeof(g_ui_create_component_request), tx);
62-
// g_yield_t(g_ui_delegate_tid);
62+
// g_yield_t(g_ui_delegate_tid);
6363

6464
size_t bufferSize = sizeof(g_message_header) + sizeof(g_ui_create_component_response);
6565
uint8_t buffer[bufferSize];
@@ -88,6 +88,8 @@ class g_component : public g_bounding_component
8888
return component;
8989
}
9090

91+
bool setSize(g_ui_protocol_command_id command, const g_dimension& size);
92+
9193
public:
9294
explicit g_component(g_ui_component_id id) : id(id), g_bounding_component(this)
9395
{
@@ -104,6 +106,7 @@ class g_component : public g_bounding_component
104106
bool setBounds(const g_rectangle& rect);
105107
g_rectangle getBounds();
106108

109+
107110
bool isVisible();
108111
bool setVisible(bool visible);
109112
bool setBackground(g_color_argb argb);
@@ -113,7 +116,9 @@ class g_component : public g_bounding_component
113116
bool setDispatchesFocus(bool d);
114117
bool isDispatchesFocus();
115118

116-
bool setPreferredSize(g_dimension size);
119+
bool setPreferredSize(const g_dimension& size);
120+
bool setMinimumSize(const g_dimension& size);
121+
bool setMaximumSize(const g_dimension& size);
117122

118123
bool setNumericProperty(int property, uint32_t value);
119124
bool getNumericProperty(int property, uint32_t* out);
@@ -126,7 +131,7 @@ class g_component : public g_bounding_component
126131

127132
bool setFlexOrientation(bool horizontal);
128133
bool setFlexComponentInfo(g_component* child, float grow, float shrink, int basis);
129-
bool setFlexPadding(g_insets padding);
134+
bool setLayoutPadding(g_insets padding);
130135
bool setFlexGap(int gap);
131136

132137
void handle(g_ui_component_event_header* header);

applications/libwindow/inc/libwindow/interface.hpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,13 @@ typedef uint8_t g_ui_protocol_command_id;
7575
#define G_UI_PROTOCOL_GET_SCREEN_DIMENSION ((g_ui_protocol_command_id) 14)
7676
#define G_UI_PROTOCOL_FLEX_SET_ORIENTATION ((g_ui_protocol_command_id) 15)
7777
#define G_UI_PROTOCOL_FLEX_SET_COMPONENT_INFO ((g_ui_protocol_command_id) 16)
78-
#define G_UI_PROTOCOL_FLEX_SET_PADDING ((g_ui_protocol_command_id) 17)
78+
#define G_UI_PROTOCOL_LAYOUT_SET_PADDING ((g_ui_protocol_command_id) 17)
7979
#define G_UI_PROTOCOL_SCROLLPANE_SET_CONTENT ((g_ui_protocol_command_id) 18)
8080
#define G_UI_PROTOCOL_SCROLLPANE_SET_FIXED ((g_ui_protocol_command_id) 19)
8181
#define G_UI_PROTOCOL_SET_PREFERRED_SIZE ((g_ui_protocol_command_id) 20)
8282
#define G_UI_PROTOCOL_DESTROY_COMPONENT ((g_ui_protocol_command_id) 21)
83+
#define G_UI_PROTOCOL_SET_MINIMUM_SIZE ((g_ui_protocol_command_id) 22)
84+
#define G_UI_PROTOCOL_SET_MAXIMUM_SIZE ((g_ui_protocol_command_id) 23)
8385

8486
/**
8587
* Common status for requests
@@ -237,14 +239,14 @@ typedef struct
237239
} __attribute__((packed)) g_ui_component_set_bounds_request;
238240

239241
/**
240-
* Setting preferred size
242+
* Setting size (preferred/minimum/maximum)
241243
*/
242244
typedef struct
243245
{
244246
g_ui_message_header header;
245247
g_ui_component_id id;
246248
g_dimension size;
247-
} __attribute__((packed)) g_ui_component_set_preferred_size_request;
249+
} __attribute__((packed)) g_ui_component_set_size_request;
248250

249251
/**
250252
* Request/response for getting bounds
@@ -413,7 +415,7 @@ typedef struct
413415
g_ui_message_header header;
414416
g_ui_component_id id;
415417
g_insets insets;
416-
} __attribute__((packed)) g_ui_flex_set_padding;
418+
} __attribute__((packed)) g_ui_layout_set_padding;
417419

418420
/**
419421
* Scrollpane content

applications/libwindow/src/component.cpp

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -304,15 +304,30 @@ bool g_component::setDispatchesFocus(bool d)
304304
return setNumericProperty(G_UI_PROPERTY_DISPATCHES_FOCUS, d ? 1 : 0);
305305
}
306306

307-
bool g_component::setPreferredSize(g_dimension size)
307+
bool g_component::setPreferredSize(const g_dimension& size)
308+
{
309+
return setSize(G_UI_PROTOCOL_SET_PREFERRED_SIZE, size);
310+
}
311+
312+
bool g_component::setMinimumSize(const g_dimension& size)
313+
{
314+
return setSize(G_UI_PROTOCOL_SET_MINIMUM_SIZE, size);
315+
}
316+
317+
bool g_component::setMaximumSize(const g_dimension& size)
318+
{
319+
return setSize(G_UI_PROTOCOL_SET_MAXIMUM_SIZE, size);
320+
}
321+
322+
bool g_component::setSize(g_ui_protocol_command_id command, const g_dimension& size)
308323
{
309324
if(!g_ui_initialized)
310325
return false;
311326

312327
g_message_transaction tx = g_get_message_tx_id();
313328

314-
g_ui_component_set_preferred_size_request request;
315-
request.header.id = G_UI_PROTOCOL_SET_PREFERRED_SIZE;
329+
g_ui_component_set_size_request request;
330+
request.header.id = command;
316331
request.id = this->id;
317332
request.size = size;
318333
g_send_message_t(g_ui_delegate_tid, &request, sizeof(request), tx);
@@ -380,18 +395,18 @@ bool g_component::setFlexComponentInfo(g_component* child, float grow, float shr
380395
}
381396

382397

383-
bool g_component::setFlexPadding(g_insets padding)
398+
bool g_component::setLayoutPadding(g_insets padding)
384399
{
385400
if(!g_ui_initialized)
386401
return false;
387402

388403
g_message_transaction tx = g_get_message_tx_id();
389404

390-
g_ui_flex_set_padding request;
391-
request.header.id = G_UI_PROTOCOL_FLEX_SET_PADDING;
405+
g_ui_layout_set_padding request;
406+
request.header.id = G_UI_PROTOCOL_LAYOUT_SET_PADDING;
392407
request.id = this->id;
393408
request.insets = padding;
394-
g_send_message_t(g_ui_delegate_tid, &request, sizeof(g_ui_flex_set_padding), tx);
409+
g_send_message_t(g_ui_delegate_tid, &request, sizeof(g_ui_layout_set_padding), tx);
395410
g_yield_t(g_ui_delegate_tid);
396411

397412
size_t buflen = sizeof(g_message_header) + sizeof(g_ui_simple_response);

applications/windowserver/src/components/component.cpp

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -402,8 +402,20 @@ component_t* component_t::handleKeyEvent(key_event_t& event)
402402

403403
void component_t::setPreferredSize(const g_dimension& size)
404404
{
405-
preferredSize = size;
406-
markParentFor(COMPONENT_REQUIREMENT_LAYOUT);
405+
if(preferredSize != size)
406+
{
407+
preferredSize = size;
408+
markParentFor(COMPONENT_REQUIREMENT_LAYOUT);
409+
}
410+
}
411+
412+
g_dimension component_t::getEffectivePreferredSize()
413+
{
414+
auto preferred = getPreferredSize();
415+
auto min = getMinimumSize();
416+
preferred.width = std::max(preferred.width, min.width);
417+
preferred.height = std::max(preferred.height, min.height);
418+
return preferred;
407419
}
408420

409421
void component_t::setMinimumSize(const g_dimension& size)
@@ -437,6 +449,8 @@ void component_t::markFor(component_requirement_t req)
437449

438450
if(parent)
439451
parent->markChildsFor(req);
452+
453+
windowserver_t::instance()->requestUpdate();
440454
}
441455

442456
void component_t::markChildsFor(component_requirement_t req)
@@ -606,7 +620,7 @@ bool component_t::setNumericProperty(int property, uint32_t value)
606620
}
607621
if(value == G_UI_LAYOUT_MANAGER_GRID)
608622
{
609-
setLayoutManager(new grid_layout_manager_t(1, 1));
623+
setLayoutManager(new grid_layout_manager_t());
610624
return true;
611625
}
612626
if(value == G_UI_LAYOUT_MANAGER_FLEX)

applications/windowserver/src/components/component.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,8 @@ class component_t : public bounding_component_t, public focusable_component_t
175175
return preferredSize;
176176
}
177177

178+
virtual g_dimension getEffectivePreferredSize();
179+
178180
void setMinimumSize(const g_dimension& size);
179181

180182
g_dimension getMinimumSize() const

applications/windowserver/src/components/label.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ label_t::label_t()
3131
setFont(g_font_loader::getDefault());
3232
alignment = g_text_alignment::LEFT;
3333
color = RGB(0, 0, 0);
34+
graphics.resize(1, 1);
3435
}
3536

3637
void label_t::setFont(g_font* newFont)
@@ -58,7 +59,8 @@ void label_t::update()
5859
cairo_save(cr);
5960
cairo_set_font_face(cr, font->getFace());
6061
cairo_set_font_size(cr, fontSize);
61-
cairo_text_extents(cr, this->text.c_str(), &lastExtents);
62+
cairo_text_extents(cr, this->text.c_str(), &textExtents);
63+
cairo_font_extents(cr, &fontExtents);
6264
cairo_restore(cr);
6365

6466
graphics.releaseContext();
@@ -68,7 +70,7 @@ void label_t::update()
6870

6971
void label_t::layout()
7072
{
71-
g_dimension newPreferred(lastExtents.width + 3, lastExtents.height + 3);
73+
g_dimension newPreferred(textExtents.width + 3, fontExtents.height + 3);
7274

7375
// Set new preferred size
7476
auto oldPreferred = getPreferredSize();
@@ -97,15 +99,15 @@ void label_t::paint()
9799
cairo_set_source_rgb(cr, ARGB_FR_FROM(color), ARGB_FB_FROM(color), ARGB_FG_FROM(color));
98100

99101
int textLeft;
100-
int textBot = (bounds.height / 2 - lastExtents.height / 2) + lastExtents.height;
102+
int textBot = (bounds.height / 2 - fontExtents.height / 2) + fontExtents.height;
101103

102104
if(alignment == g_text_alignment::CENTER)
103105
{
104-
textLeft = bounds.width / 2 - lastExtents.width / 2;
106+
textLeft = bounds.width / 2 - textExtents.width / 2;
105107
}
106108
else if(alignment == g_text_alignment::RIGHT)
107109
{
108-
textLeft = bounds.width - lastExtents.width;
110+
textLeft = bounds.width - textExtents.width;
109111
}
110112
else
111113
{

applications/windowserver/src/components/label.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ class label_t : virtual public component_t, virtual public titled_component_t
3232
{
3333
g_font* font;
3434
int fontSize;
35-
cairo_text_extents_t lastExtents;
35+
cairo_text_extents_t textExtents;
36+
cairo_font_extents_t fontExtents;
3637

3738
std::string text;
3839
g_text_alignment alignment;

applications/windowserver/src/components/scrollpane.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,13 +106,9 @@ void scrollpane_t::layout()
106106

107107
auto contentSize = content->getPreferredSize();
108108
if(fixedWidth)
109-
{
110109
contentSize.width = getBounds().width - SCROLLBAR_SIZE;
111-
}
112110
if(fixedHeight)
113-
{
114111
contentSize.height = getBounds().height - SCROLLBAR_SIZE;
115-
}
116112
auto viewportSize = calculateViewport(contentSize);
117113

118114
auto bounds = getBounds();

applications/windowserver/src/interface/interface_receiver.cpp

Lines changed: 40 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
#include "component_registry.hpp"
3232
#include "components/scrollpane.hpp"
3333
#include "interface/interface_receiver.hpp"
34+
35+
#include "layout/grid_layout_manager.hpp"
3436
#include "layout/flex_layout_manager.hpp"
3537

3638
void interfaceReceiverThread()
@@ -455,19 +457,19 @@ void interfaceReceiverProcessCommand(g_message_header* requestMessage)
455457
responseMessage = response;
456458
responseLength = sizeof(g_ui_simple_response);
457459
}
458-
else if(requestUiMessage->id == G_UI_PROTOCOL_FLEX_SET_PADDING)
460+
else if(requestUiMessage->id == G_UI_PROTOCOL_LAYOUT_SET_PADDING)
459461
{
460462
auto response = new g_ui_simple_response;
461463
response->status = G_UI_PROTOCOL_FAIL;
462464

463-
auto request = (g_ui_flex_set_padding*) requestUiMessage;
465+
auto request = (g_ui_layout_set_padding*) requestUiMessage;
464466
component_t* component = component_registry_t::get(request->id);
465467
if(component)
466468
{
467-
auto flexLayoutManager = dynamic_cast<flex_layout_manager_t*>(component->getLayoutManager());
468-
if(flexLayoutManager)
469+
auto layoutManager = component->getLayoutManager();
470+
if(layoutManager)
469471
{
470-
flexLayoutManager->setPadding(request->insets);
472+
layoutManager->setPadding(request->insets);
471473
response->status = G_UI_PROTOCOL_SUCCESS;
472474
}
473475
}
@@ -514,7 +516,7 @@ void interfaceReceiverProcessCommand(g_message_header* requestMessage)
514516
auto response = new g_ui_simple_response;
515517
response->status = G_UI_PROTOCOL_FAIL;
516518

517-
auto request = (g_ui_component_set_preferred_size_request*) requestUiMessage;
519+
auto request = (g_ui_component_set_size_request*) requestUiMessage;
518520
component_t* component = component_registry_t::get(request->id);
519521
if(component)
520522
{
@@ -525,6 +527,38 @@ void interfaceReceiverProcessCommand(g_message_header* requestMessage)
525527
responseMessage = response;
526528
responseLength = sizeof(g_ui_simple_response);
527529
}
530+
else if(requestUiMessage->id == G_UI_PROTOCOL_SET_MINIMUM_SIZE)
531+
{
532+
auto response = new g_ui_simple_response;
533+
response->status = G_UI_PROTOCOL_FAIL;
534+
535+
auto request = (g_ui_component_set_size_request*) requestUiMessage;
536+
component_t* component = component_registry_t::get(request->id);
537+
if(component)
538+
{
539+
component->setMinimumSize(request->size);
540+
response->status = G_UI_PROTOCOL_SUCCESS;
541+
}
542+
543+
responseMessage = response;
544+
responseLength = sizeof(g_ui_simple_response);
545+
}
546+
else if(requestUiMessage->id == G_UI_PROTOCOL_SET_MAXIMUM_SIZE)
547+
{
548+
auto response = new g_ui_simple_response;
549+
response->status = G_UI_PROTOCOL_FAIL;
550+
551+
auto request = (g_ui_component_set_size_request*) requestUiMessage;
552+
component_t* component = component_registry_t::get(request->id);
553+
if(component)
554+
{
555+
component->setMaximumSize(request->size);
556+
response->status = G_UI_PROTOCOL_SUCCESS;
557+
}
558+
559+
responseMessage = response;
560+
responseLength = sizeof(g_ui_simple_response);
561+
}
528562

529563
windowserver_t::instance()->requestUpdate();
530564

applications/windowserver/src/layout/flex_layout_manager.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ class flex_layout_manager_t : public layout_manager_t
5959
this->gap = gap;
6060
}
6161

62-
void setPadding(g_insets padding)
62+
void setPadding(g_insets padding) override
6363
{
6464
this->padding = padding;
6565
}

0 commit comments

Comments
 (0)