Skip to content

Commit a72e7d1

Browse files
committed
Extend libwindow with more component interactions
1 parent 0dab2c5 commit a72e7d1

27 files changed

+817
-62
lines changed

applications/libwindow/inc/libwindow/component.hpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,8 @@ class g_component : public g_bounding_component
110110
bool setDispatchesFocus(bool d);
111111
bool isDispatchesFocus();
112112

113+
bool setPreferredSize(g_dimension size);
114+
113115
bool setNumericProperty(int property, uint32_t value);
114116
bool getNumericProperty(int property, uint32_t* out);
115117

@@ -119,6 +121,11 @@ class g_component : public g_bounding_component
119121
bool addVisibleListener(g_visible_listener* listener);
120122
bool addVisibleListener(g_visible_listener_func listener);
121123

124+
bool setFlexOrientation(bool horizontal);
125+
bool setFlexComponentInfo(g_component* child, float grow, float shrink, int basis);
126+
bool setFlexPadding(g_insets padding);
127+
bool setFlexGap(int gap);
128+
122129
void handle(g_ui_component_event_header* header);
123130

124131
bool setLayout(g_ui_layout_manager layout);

applications/libwindow/inc/libwindow/interface.hpp

Lines changed: 79 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,12 @@ typedef uint8_t g_ui_protocol_command_id;
7373
#define G_UI_PROTOCOL_CANVAS_BLIT ((g_ui_protocol_command_id) 12)
7474
#define G_UI_PROTOCOL_REGISTER_DESKTOP_CANVAS ((g_ui_protocol_command_id) 13)
7575
#define G_UI_PROTOCOL_GET_SCREEN_DIMENSION ((g_ui_protocol_command_id) 14)
76+
#define G_UI_PROTOCOL_FLEX_SET_ORIENTATION ((g_ui_protocol_command_id) 15)
77+
#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)
79+
#define G_UI_PROTOCOL_SCROLLPANE_SET_CONTENT ((g_ui_protocol_command_id) 18)
80+
#define G_UI_PROTOCOL_SCROLLPANE_SET_FIXED ((g_ui_protocol_command_id) 19)
81+
#define G_UI_PROTOCOL_SET_PREFERRED_SIZE ((g_ui_protocol_command_id) 20)
7682

7783
/**
7884
* Common status for requests
@@ -91,6 +97,8 @@ const g_ui_component_type G_UI_COMPONENT_TYPE_LABEL = 2;
9197
const g_ui_component_type G_UI_COMPONENT_TYPE_TEXTFIELD = 3;
9298
const g_ui_component_type G_UI_COMPONENT_TYPE_CANVAS = 4;
9399
const g_ui_component_type G_UI_COMPONENT_TYPE_SELECTION = 5;
100+
const g_ui_component_type G_UI_COMPONENT_TYPE_PANEL = 6;
101+
const g_ui_component_type G_UI_COMPONENT_TYPE_SCROLLPANE = 7;
94102

95103
/**
96104
* Types of events that can be listened to
@@ -113,6 +121,7 @@ const g_ui_component_event_type G_UI_COMPONENT_EVENT_TYPE_VISIBLE = 9;
113121
typedef uint8_t g_ui_layout_manager;
114122
#define G_UI_LAYOUT_MANAGER_GRID ((g_ui_layout_manager) 0)
115123
#define G_UI_LAYOUT_MANAGER_FLOW ((g_ui_layout_manager) 1)
124+
#define G_UI_LAYOUT_MANAGER_FLEX ((g_ui_layout_manager) 2)
116125

117126
/**
118127
*
@@ -148,6 +157,15 @@ typedef struct
148157
g_tid window_server_delegate;
149158
} __attribute__((packed)) g_ui_initialize_response;
150159

160+
/**
161+
* Generic response
162+
*/
163+
typedef struct
164+
{
165+
g_ui_message_header header;
166+
g_ui_protocol_status status;
167+
} __attribute__((packed)) g_ui_simple_response;
168+
151169
/**
152170
* Request sent to create a component.
153171
*/
@@ -199,7 +217,7 @@ typedef struct
199217
} __attribute__((packed)) g_ui_component_add_child_response;
200218

201219
/**
202-
* Request/response for setting bounds
220+
* Setting bounds
203221
*/
204222
typedef struct
205223
{
@@ -208,11 +226,15 @@ typedef struct
208226
g_rectangle bounds;
209227
} __attribute__((packed)) g_ui_component_set_bounds_request;
210228

229+
/**
230+
* Setting preferred size
231+
*/
211232
typedef struct
212233
{
213234
g_ui_message_header header;
214-
g_ui_protocol_status status;
215-
} __attribute__((packed)) g_ui_component_set_bounds_response;
235+
g_ui_component_id id;
236+
g_dimension size;
237+
} __attribute__((packed)) g_ui_component_set_preferred_size_request;
216238

217239
/**
218240
* Request/response for getting bounds
@@ -350,6 +372,60 @@ typedef struct
350372
g_dimension size;
351373
} __attribute__((packed)) g_ui_get_screen_dimension_response;
352374

375+
/**
376+
* Setting flex orientation
377+
*/
378+
typedef struct
379+
{
380+
g_ui_message_header header;
381+
g_ui_component_id id;
382+
bool horizontal;
383+
} __attribute__((packed)) g_ui_flex_set_orientation_request;
384+
385+
/**
386+
* Setting flex info for a component
387+
*/
388+
typedef struct
389+
{
390+
g_ui_message_header header;
391+
g_ui_component_id parent;
392+
g_ui_component_id child;
393+
float grow;
394+
float shrink;
395+
int basis;
396+
} __attribute__((packed)) g_ui_flex_set_component_info;
397+
398+
/**
399+
* Setting flex padding
400+
*/
401+
typedef struct
402+
{
403+
g_ui_message_header header;
404+
g_ui_component_id id;
405+
g_insets insets;
406+
} __attribute__((packed)) g_ui_flex_set_padding;
407+
408+
/**
409+
* Scrollpane content
410+
*/
411+
typedef struct
412+
{
413+
g_ui_message_header header;
414+
g_ui_component_id scrollpane;
415+
g_ui_component_id content;
416+
} __attribute__((packed)) g_ui_scrollpane_set_content;
417+
418+
/**
419+
* Scrollpane fixed sizes
420+
*/
421+
typedef struct
422+
{
423+
g_ui_message_header header;
424+
g_ui_component_id scrollpane;
425+
bool width;
426+
bool height;
427+
} __attribute__((packed)) g_ui_scrollpane_set_fixed;
428+
353429
/**
354430
* Event structures
355431
*/
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
2+
* *
3+
* Ghost, a micro-kernel based operating system for the x86 architecture *
4+
* Copyright (C) 2025, Max Schlüssel <lokoxe@gmail.com> *
5+
* *
6+
* This program is free software: you can redistribute it and/or modify *
7+
* it under the terms of the GNU General Public License as published by *
8+
* the Free Software Foundation, either version 3 of the License, or *
9+
* (at your option) any later version. *
10+
* *
11+
* This program is distributed in the hope that it will be useful, *
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14+
* GNU General Public License for more details. *
15+
* *
16+
* You should have received a copy of the GNU General Public License *
17+
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
18+
* *
19+
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
20+
21+
#ifndef LIBWINDOW_PANEL
22+
#define LIBWINDOW_PANEL
23+
24+
#include "component.hpp"
25+
26+
class g_panel : virtual public g_component
27+
{
28+
public:
29+
explicit g_panel(g_ui_component_id id) : g_component(id)
30+
{
31+
}
32+
33+
static g_panel* create();
34+
};
35+
36+
#endif

applications/libwindow/inc/libwindow/properties.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,5 +38,6 @@
3838
#define G_UI_PROPERTY_VISIBLE 10
3939
#define G_UI_PROPERTY_FOCUSABLE 11
4040
#define G_UI_PROPERTY_DISPATCHES_FOCUS 12
41+
#define G_UI_PROPERTY_FLEX_GAP 13
4142

4243
#endif
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
2+
* *
3+
* Ghost, a micro-kernel based operating system for the x86 architecture *
4+
* Copyright (C) 2025, Max Schlüssel <lokoxe@gmail.com> *
5+
* *
6+
* This program is free software: you can redistribute it and/or modify *
7+
* it under the terms of the GNU General Public License as published by *
8+
* the Free Software Foundation, either version 3 of the License, or *
9+
* (at your option) any later version. *
10+
* *
11+
* This program is distributed in the hope that it will be useful, *
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14+
* GNU General Public License for more details. *
15+
* *
16+
* You should have received a copy of the GNU General Public License *
17+
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
18+
* *
19+
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
20+
21+
#ifndef LIBWINDOW_SCROLLPANE
22+
#define LIBWINDOW_SCROLLPANE
23+
24+
#include "component.hpp"
25+
26+
class g_scrollpane : virtual public g_component
27+
{
28+
public:
29+
explicit g_scrollpane(g_ui_component_id id) : g_component(id)
30+
{
31+
}
32+
33+
static g_scrollpane* create();
34+
35+
bool setContent(g_component* content);
36+
bool setFixed(bool width, bool height);
37+
};
38+
39+
#endif

applications/libwindow/src/component.cpp

Lines changed: 108 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -68,17 +68,14 @@ bool g_component::setBounds(const g_rectangle& rect)
6868
g_send_message_t(g_ui_delegate_tid, &request, sizeof(g_ui_component_set_bounds_request), tx);
6969

7070
// read response
71-
size_t bufferSize = sizeof(g_message_header) + sizeof(g_ui_component_set_bounds_response);
72-
uint8_t buffer[bufferSize];
73-
74-
bool success = false;
75-
if(g_receive_message_t(buffer, bufferSize, tx) == G_MESSAGE_RECEIVE_STATUS_SUCCESSFUL)
71+
size_t buflen = sizeof(g_message_header) + sizeof(g_ui_simple_response);
72+
uint8_t buffer[buflen];
73+
if(g_receive_message_t(buffer, buflen, tx) == G_MESSAGE_RECEIVE_STATUS_SUCCESSFUL)
7674
{
77-
auto response = (g_ui_component_set_bounds_response*) G_MESSAGE_CONTENT(buffer);
78-
success = response->status == G_UI_PROTOCOL_SUCCESS;
75+
auto response = (g_ui_simple_response*) G_MESSAGE_CONTENT(buffer);
76+
return response->status == G_UI_PROTOCOL_SUCCESS;
7977
}
80-
81-
return success;
78+
return false;
8279
}
8380

8481
g_rectangle g_component::getBounds()
@@ -284,3 +281,105 @@ bool g_component::setDispatchesFocus(bool d)
284281
{
285282
return setNumericProperty(G_UI_PROPERTY_DISPATCHES_FOCUS, d ? 1 : 0);
286283
}
284+
285+
bool g_component::setPreferredSize(g_dimension size)
286+
{
287+
if(!g_ui_initialized)
288+
return false;
289+
290+
g_message_transaction tx = g_get_message_tx_id();
291+
292+
g_ui_component_set_preferred_size_request request;
293+
request.header.id = G_UI_PROTOCOL_SET_PREFERRED_SIZE;
294+
request.id = this->id;
295+
request.size = size;
296+
g_send_message_t(g_ui_delegate_tid, &request, sizeof(request), tx);
297+
298+
size_t buflen = sizeof(g_message_header) + sizeof(g_ui_simple_response);
299+
uint8_t buffer[buflen];
300+
if(g_receive_message_t(buffer, buflen, tx) == G_MESSAGE_RECEIVE_STATUS_SUCCESSFUL)
301+
{
302+
auto response = (g_ui_simple_response*) G_MESSAGE_CONTENT(buffer);
303+
return response->status == G_UI_PROTOCOL_SUCCESS;
304+
}
305+
return false;
306+
}
307+
308+
bool g_component::setFlexOrientation(bool horizontal)
309+
{
310+
if(!g_ui_initialized)
311+
return false;
312+
313+
g_message_transaction tx = g_get_message_tx_id();
314+
315+
g_ui_flex_set_orientation_request request;
316+
request.header.id = G_UI_PROTOCOL_FLEX_SET_ORIENTATION;
317+
request.id = this->id;
318+
request.horizontal = horizontal;
319+
g_send_message_t(g_ui_delegate_tid, &request, sizeof(g_ui_flex_set_orientation_request), tx);
320+
321+
size_t buflen = sizeof(g_message_header) + sizeof(g_ui_simple_response);
322+
uint8_t buffer[buflen];
323+
if(g_receive_message_t(buffer, buflen, tx) == G_MESSAGE_RECEIVE_STATUS_SUCCESSFUL)
324+
{
325+
auto response = (g_ui_simple_response*) G_MESSAGE_CONTENT(buffer);
326+
return response->status == G_UI_PROTOCOL_SUCCESS;
327+
}
328+
return false;
329+
}
330+
331+
bool g_component::setFlexComponentInfo(g_component* child, float grow, float shrink, int basis)
332+
{
333+
if(!g_ui_initialized)
334+
return false;
335+
336+
g_message_transaction tx = g_get_message_tx_id();
337+
338+
g_ui_flex_set_component_info request;
339+
request.header.id = G_UI_PROTOCOL_FLEX_SET_COMPONENT_INFO;
340+
request.parent = this->id;
341+
request.child = child->id;
342+
request.grow = grow;
343+
request.shrink = shrink;
344+
request.basis = basis;
345+
g_send_message_t(g_ui_delegate_tid, &request, sizeof(g_ui_flex_set_component_info), tx);
346+
347+
size_t buflen = sizeof(g_message_header) + sizeof(g_ui_simple_response);
348+
uint8_t buffer[buflen];
349+
if(g_receive_message_t(buffer, buflen, tx) == G_MESSAGE_RECEIVE_STATUS_SUCCESSFUL)
350+
{
351+
auto response = (g_ui_simple_response*) G_MESSAGE_CONTENT(buffer);
352+
return response->status == G_UI_PROTOCOL_SUCCESS;
353+
}
354+
return false;
355+
}
356+
357+
358+
bool g_component::setFlexPadding(g_insets padding)
359+
{
360+
if(!g_ui_initialized)
361+
return false;
362+
363+
g_message_transaction tx = g_get_message_tx_id();
364+
365+
g_ui_flex_set_padding request;
366+
request.header.id = G_UI_PROTOCOL_FLEX_SET_PADDING;
367+
request.id = this->id;
368+
request.insets = padding;
369+
g_send_message_t(g_ui_delegate_tid, &request, sizeof(g_ui_flex_set_padding), tx);
370+
371+
size_t buflen = sizeof(g_message_header) + sizeof(g_ui_simple_response);
372+
uint8_t buffer[buflen];
373+
if(g_receive_message_t(buffer, buflen, tx) == G_MESSAGE_RECEIVE_STATUS_SUCCESSFUL)
374+
{
375+
auto response = (g_ui_simple_response*) G_MESSAGE_CONTENT(buffer);
376+
return response->status == G_UI_PROTOCOL_SUCCESS;
377+
}
378+
return false;
379+
}
380+
381+
382+
bool g_component::setFlexGap(int gap)
383+
{
384+
return setNumericProperty(G_UI_PROPERTY_FLEX_GAP, gap);
385+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
2+
* *
3+
* Ghost, a micro-kernel based operating system for the x86 architecture *
4+
* Copyright (C) 2015, Max Schlüssel <lokoxe@gmail.com> *
5+
* *
6+
* This program is free software: you can redistribute it and/or modify *
7+
* it under the terms of the GNU General Public License as published by *
8+
* the Free Software Foundation, either version 3 of the License, or *
9+
* (at your option) any later version. *
10+
* *
11+
* This program is distributed in the hope that it will be useful, *
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14+
* GNU General Public License for more details. *
15+
* *
16+
* You should have received a copy of the GNU General Public License *
17+
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
18+
* *
19+
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
20+
21+
#include "libwindow/panel.hpp"
22+
23+
g_panel* g_panel::create()
24+
{
25+
return createComponent<g_panel, G_UI_COMPONENT_TYPE_PANEL>();
26+
}

0 commit comments

Comments
 (0)