Skip to content

Commit

Permalink
Extend libwindow with more component interactions
Browse files Browse the repository at this point in the history
  • Loading branch information
maxdev1 committed Feb 18, 2025
1 parent 0dab2c5 commit a72e7d1
Show file tree
Hide file tree
Showing 27 changed files with 817 additions and 62 deletions.
7 changes: 7 additions & 0 deletions applications/libwindow/inc/libwindow/component.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ class g_component : public g_bounding_component
bool setDispatchesFocus(bool d);
bool isDispatchesFocus();

bool setPreferredSize(g_dimension size);

bool setNumericProperty(int property, uint32_t value);
bool getNumericProperty(int property, uint32_t* out);

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

bool setFlexOrientation(bool horizontal);
bool setFlexComponentInfo(g_component* child, float grow, float shrink, int basis);
bool setFlexPadding(g_insets padding);
bool setFlexGap(int gap);

void handle(g_ui_component_event_header* header);

bool setLayout(g_ui_layout_manager layout);
Expand Down
82 changes: 79 additions & 3 deletions applications/libwindow/inc/libwindow/interface.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,12 @@ typedef uint8_t g_ui_protocol_command_id;
#define G_UI_PROTOCOL_CANVAS_BLIT ((g_ui_protocol_command_id) 12)
#define G_UI_PROTOCOL_REGISTER_DESKTOP_CANVAS ((g_ui_protocol_command_id) 13)
#define G_UI_PROTOCOL_GET_SCREEN_DIMENSION ((g_ui_protocol_command_id) 14)
#define G_UI_PROTOCOL_FLEX_SET_ORIENTATION ((g_ui_protocol_command_id) 15)
#define G_UI_PROTOCOL_FLEX_SET_COMPONENT_INFO ((g_ui_protocol_command_id) 16)
#define G_UI_PROTOCOL_FLEX_SET_PADDING ((g_ui_protocol_command_id) 17)
#define G_UI_PROTOCOL_SCROLLPANE_SET_CONTENT ((g_ui_protocol_command_id) 18)
#define G_UI_PROTOCOL_SCROLLPANE_SET_FIXED ((g_ui_protocol_command_id) 19)
#define G_UI_PROTOCOL_SET_PREFERRED_SIZE ((g_ui_protocol_command_id) 20)

/**
* Common status for requests
Expand All @@ -91,6 +97,8 @@ const g_ui_component_type G_UI_COMPONENT_TYPE_LABEL = 2;
const g_ui_component_type G_UI_COMPONENT_TYPE_TEXTFIELD = 3;
const g_ui_component_type G_UI_COMPONENT_TYPE_CANVAS = 4;
const g_ui_component_type G_UI_COMPONENT_TYPE_SELECTION = 5;
const g_ui_component_type G_UI_COMPONENT_TYPE_PANEL = 6;
const g_ui_component_type G_UI_COMPONENT_TYPE_SCROLLPANE = 7;

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

/**
*
Expand Down Expand Up @@ -148,6 +157,15 @@ typedef struct
g_tid window_server_delegate;
} __attribute__((packed)) g_ui_initialize_response;

/**
* Generic response
*/
typedef struct
{
g_ui_message_header header;
g_ui_protocol_status status;
} __attribute__((packed)) g_ui_simple_response;

/**
* Request sent to create a component.
*/
Expand Down Expand Up @@ -199,7 +217,7 @@ typedef struct
} __attribute__((packed)) g_ui_component_add_child_response;

/**
* Request/response for setting bounds
* Setting bounds
*/
typedef struct
{
Expand All @@ -208,11 +226,15 @@ typedef struct
g_rectangle bounds;
} __attribute__((packed)) g_ui_component_set_bounds_request;

/**
* Setting preferred size
*/
typedef struct
{
g_ui_message_header header;
g_ui_protocol_status status;
} __attribute__((packed)) g_ui_component_set_bounds_response;
g_ui_component_id id;
g_dimension size;
} __attribute__((packed)) g_ui_component_set_preferred_size_request;

/**
* Request/response for getting bounds
Expand Down Expand Up @@ -350,6 +372,60 @@ typedef struct
g_dimension size;
} __attribute__((packed)) g_ui_get_screen_dimension_response;

/**
* Setting flex orientation
*/
typedef struct
{
g_ui_message_header header;
g_ui_component_id id;
bool horizontal;
} __attribute__((packed)) g_ui_flex_set_orientation_request;

/**
* Setting flex info for a component
*/
typedef struct
{
g_ui_message_header header;
g_ui_component_id parent;
g_ui_component_id child;
float grow;
float shrink;
int basis;
} __attribute__((packed)) g_ui_flex_set_component_info;

/**
* Setting flex padding
*/
typedef struct
{
g_ui_message_header header;
g_ui_component_id id;
g_insets insets;
} __attribute__((packed)) g_ui_flex_set_padding;

/**
* Scrollpane content
*/
typedef struct
{
g_ui_message_header header;
g_ui_component_id scrollpane;
g_ui_component_id content;
} __attribute__((packed)) g_ui_scrollpane_set_content;

/**
* Scrollpane fixed sizes
*/
typedef struct
{
g_ui_message_header header;
g_ui_component_id scrollpane;
bool width;
bool height;
} __attribute__((packed)) g_ui_scrollpane_set_fixed;

/**
* Event structures
*/
Expand Down
36 changes: 36 additions & 0 deletions applications/libwindow/inc/libwindow/panel.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* *
* Ghost, a micro-kernel based operating system for the x86 architecture *
* Copyright (C) 2025, Max Schlüssel <lokoxe@gmail.com> *
* *
* This program is free software: you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, either version 3 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
* *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

#ifndef LIBWINDOW_PANEL
#define LIBWINDOW_PANEL

#include "component.hpp"

class g_panel : virtual public g_component
{
public:
explicit g_panel(g_ui_component_id id) : g_component(id)
{
}

static g_panel* create();
};

#endif
1 change: 1 addition & 0 deletions applications/libwindow/inc/libwindow/properties.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,6 @@
#define G_UI_PROPERTY_VISIBLE 10
#define G_UI_PROPERTY_FOCUSABLE 11
#define G_UI_PROPERTY_DISPATCHES_FOCUS 12
#define G_UI_PROPERTY_FLEX_GAP 13

#endif
39 changes: 39 additions & 0 deletions applications/libwindow/inc/libwindow/scrollpane.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* *
* Ghost, a micro-kernel based operating system for the x86 architecture *
* Copyright (C) 2025, Max Schlüssel <lokoxe@gmail.com> *
* *
* This program is free software: you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, either version 3 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
* *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

#ifndef LIBWINDOW_SCROLLPANE
#define LIBWINDOW_SCROLLPANE

#include "component.hpp"

class g_scrollpane : virtual public g_component
{
public:
explicit g_scrollpane(g_ui_component_id id) : g_component(id)
{
}

static g_scrollpane* create();

bool setContent(g_component* content);
bool setFixed(bool width, bool height);
};

#endif
117 changes: 108 additions & 9 deletions applications/libwindow/src/component.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,17 +68,14 @@ bool g_component::setBounds(const g_rectangle& rect)
g_send_message_t(g_ui_delegate_tid, &request, sizeof(g_ui_component_set_bounds_request), tx);

// read response
size_t bufferSize = sizeof(g_message_header) + sizeof(g_ui_component_set_bounds_response);
uint8_t buffer[bufferSize];

bool success = false;
if(g_receive_message_t(buffer, bufferSize, tx) == G_MESSAGE_RECEIVE_STATUS_SUCCESSFUL)
size_t buflen = sizeof(g_message_header) + sizeof(g_ui_simple_response);
uint8_t buffer[buflen];
if(g_receive_message_t(buffer, buflen, tx) == G_MESSAGE_RECEIVE_STATUS_SUCCESSFUL)
{
auto response = (g_ui_component_set_bounds_response*) G_MESSAGE_CONTENT(buffer);
success = response->status == G_UI_PROTOCOL_SUCCESS;
auto response = (g_ui_simple_response*) G_MESSAGE_CONTENT(buffer);
return response->status == G_UI_PROTOCOL_SUCCESS;
}

return success;
return false;
}

g_rectangle g_component::getBounds()
Expand Down Expand Up @@ -284,3 +281,105 @@ bool g_component::setDispatchesFocus(bool d)
{
return setNumericProperty(G_UI_PROPERTY_DISPATCHES_FOCUS, d ? 1 : 0);
}

bool g_component::setPreferredSize(g_dimension size)
{
if(!g_ui_initialized)
return false;

g_message_transaction tx = g_get_message_tx_id();

g_ui_component_set_preferred_size_request request;
request.header.id = G_UI_PROTOCOL_SET_PREFERRED_SIZE;
request.id = this->id;
request.size = size;
g_send_message_t(g_ui_delegate_tid, &request, sizeof(request), tx);

size_t buflen = sizeof(g_message_header) + sizeof(g_ui_simple_response);
uint8_t buffer[buflen];
if(g_receive_message_t(buffer, buflen, tx) == G_MESSAGE_RECEIVE_STATUS_SUCCESSFUL)
{
auto response = (g_ui_simple_response*) G_MESSAGE_CONTENT(buffer);
return response->status == G_UI_PROTOCOL_SUCCESS;
}
return false;
}

bool g_component::setFlexOrientation(bool horizontal)
{
if(!g_ui_initialized)
return false;

g_message_transaction tx = g_get_message_tx_id();

g_ui_flex_set_orientation_request request;
request.header.id = G_UI_PROTOCOL_FLEX_SET_ORIENTATION;
request.id = this->id;
request.horizontal = horizontal;
g_send_message_t(g_ui_delegate_tid, &request, sizeof(g_ui_flex_set_orientation_request), tx);

size_t buflen = sizeof(g_message_header) + sizeof(g_ui_simple_response);
uint8_t buffer[buflen];
if(g_receive_message_t(buffer, buflen, tx) == G_MESSAGE_RECEIVE_STATUS_SUCCESSFUL)
{
auto response = (g_ui_simple_response*) G_MESSAGE_CONTENT(buffer);
return response->status == G_UI_PROTOCOL_SUCCESS;
}
return false;
}

bool g_component::setFlexComponentInfo(g_component* child, float grow, float shrink, int basis)
{
if(!g_ui_initialized)
return false;

g_message_transaction tx = g_get_message_tx_id();

g_ui_flex_set_component_info request;
request.header.id = G_UI_PROTOCOL_FLEX_SET_COMPONENT_INFO;
request.parent = this->id;
request.child = child->id;
request.grow = grow;
request.shrink = shrink;
request.basis = basis;
g_send_message_t(g_ui_delegate_tid, &request, sizeof(g_ui_flex_set_component_info), tx);

size_t buflen = sizeof(g_message_header) + sizeof(g_ui_simple_response);
uint8_t buffer[buflen];
if(g_receive_message_t(buffer, buflen, tx) == G_MESSAGE_RECEIVE_STATUS_SUCCESSFUL)
{
auto response = (g_ui_simple_response*) G_MESSAGE_CONTENT(buffer);
return response->status == G_UI_PROTOCOL_SUCCESS;
}
return false;
}


bool g_component::setFlexPadding(g_insets padding)
{
if(!g_ui_initialized)
return false;

g_message_transaction tx = g_get_message_tx_id();

g_ui_flex_set_padding request;
request.header.id = G_UI_PROTOCOL_FLEX_SET_PADDING;
request.id = this->id;
request.insets = padding;
g_send_message_t(g_ui_delegate_tid, &request, sizeof(g_ui_flex_set_padding), tx);

size_t buflen = sizeof(g_message_header) + sizeof(g_ui_simple_response);
uint8_t buffer[buflen];
if(g_receive_message_t(buffer, buflen, tx) == G_MESSAGE_RECEIVE_STATUS_SUCCESSFUL)
{
auto response = (g_ui_simple_response*) G_MESSAGE_CONTENT(buffer);
return response->status == G_UI_PROTOCOL_SUCCESS;
}
return false;
}


bool g_component::setFlexGap(int gap)
{
return setNumericProperty(G_UI_PROPERTY_FLEX_GAP, gap);
}
26 changes: 26 additions & 0 deletions applications/libwindow/src/panel.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* *
* Ghost, a micro-kernel based operating system for the x86 architecture *
* Copyright (C) 2015, Max Schlüssel <lokoxe@gmail.com> *
* *
* This program is free software: you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, either version 3 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
* *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

#include "libwindow/panel.hpp"

g_panel* g_panel::create()
{
return createComponent<g_panel, G_UI_COMPONENT_TYPE_PANEL>();
}
Loading

0 comments on commit a72e7d1

Please sign in to comment.