summaryrefslogtreecommitdiff
path: root/src/gui
diff options
context:
space:
mode:
authorAndreas Baumann <mail@andreasbaumann.cc>2017-07-01 20:10:14 +0200
committerAndreas Baumann <mail@andreasbaumann.cc>2017-07-01 20:10:14 +0200
commit85df1646ecccc7e484e2efc903166b89e4c55684 (patch)
tree66bb29f09354a3a9bb7b448dfc10929f27d0210e /src/gui
parent8fa1c09199378f86ca7c3fc4b844bd272926cdf6 (diff)
downloadabaos-85df1646ecccc7e484e2efc903166b89e4c55684.tar.gz
abaos-85df1646ecccc7e484e2efc903166b89e4c55684.tar.bz2
fixed get_focus error in widget (called the wrong parent)
the text widget reacts to mouse down and key events and appends text to the output buffer so we have text input in GUI mode
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/desktop.c12
-rw-r--r--src/gui/desktop.h1
-rw-r--r--src/gui/text_widget.c12
-rw-r--r--src/gui/text_widget.h2
-rw-r--r--src/gui/widget.c2
5 files changed, 24 insertions, 5 deletions
diff --git a/src/gui/desktop.c b/src/gui/desktop.c
index ad4aad9..4a3876e 100644
--- a/src/gui/desktop.c
+++ b/src/gui/desktop.c
@@ -13,7 +13,7 @@ static desktop_vtable_t desktop_vtable = {
desktop_on_mouse_down,
desktop_on_mouse_up,
desktop_on_mouse_move,
- composite_widget_on_key_down,
+ desktop_on_key_down,
composite_widget_on_key_up
},
composite_widget_add_child
@@ -94,3 +94,13 @@ void desktop_on_mouse_move( void *obj, const int old_x, const int old_y, const i
desktop->needs_redrawing = true;
}
+
+void desktop_on_key_down( void *obj, char c )
+{
+ desktop_t *desktop = obj;
+
+ composite_widget_on_key_down( obj, c );
+
+ desktop->needs_redrawing = true;
+}
+
diff --git a/src/gui/desktop.h b/src/gui/desktop.h
index a9d1946..f644691 100644
--- a/src/gui/desktop.h
+++ b/src/gui/desktop.h
@@ -25,5 +25,6 @@ void desktop_draw( void *obj, graphics_context_t *context );
void desktop_on_mouse_down( void *obj, const int x, const int y );
void desktop_on_mouse_up( void *obj, const int x, const int y );
void desktop_on_mouse_move( void *obj, const int old_x, const int old_y, const int x, const int y );
+void desktop_on_key_down( void *obj, char c );
#endif // DESKTOP_H
diff --git a/src/gui/text_widget.c b/src/gui/text_widget.c
index dc12c11..f6ba8eb 100644
--- a/src/gui/text_widget.c
+++ b/src/gui/text_widget.c
@@ -12,8 +12,8 @@ static text_widget_vtable_t text_widget_vtable = {
widget_on_mouse_down,
widget_on_mouse_up,
widget_on_mouse_move,
- widget_on_key_down,
- widget_on_key_up
+ text_widget_on_key_down,
+ text_widget_on_key_up
},
text_widget_set_text
};
@@ -25,6 +25,8 @@ void text_widget_init( text_widget_t *widget, widget_t *parent, const int x, con
widget_init( &widget->base, parent, x, y, w, h, background_color );
text_widget_set_text( widget, s );
+
+ widget->base.focusable = true;
widget->base.vtable = (widget_vtable_t *)&text_widget_vtable;
widget->vtable = &text_widget_vtable;
@@ -64,6 +66,12 @@ void text_widget_set_text( void *obj, const char *s )
void text_widget_on_key_down( void *obj, char c )
{
+ text_widget_t *widget = obj;
+
+ if( strlen( widget->s ) < TEXT_WIDGET_MAX_TEXT_SIZE - 1 ) {
+ widget->s[strlen( widget->s )] = c;
+ widget->s[strlen( widget->s )+1] = '\0';
+ }
}
void text_widget_on_key_up( void *obj, char c )
diff --git a/src/gui/text_widget.h b/src/gui/text_widget.h
index 4919e26..3b22cf1 100644
--- a/src/gui/text_widget.h
+++ b/src/gui/text_widget.h
@@ -3,7 +3,7 @@
#include "widget.h"
-#define TEXT_WIDGET_MAX_TEXT_SIZE 100
+#define TEXT_WIDGET_MAX_TEXT_SIZE 300
typedef struct {
widget_vtable_t base;
diff --git a/src/gui/widget.c b/src/gui/widget.c
index 1c26680..81ab264 100644
--- a/src/gui/widget.c
+++ b/src/gui/widget.c
@@ -46,7 +46,7 @@ void widget_get_focus( void *obj, widget_t *widget )
widget_t *o = obj;
if( o->parent != NULL ) {
- o->parent->vtable->get_focus( widget->parent, widget );
+ o->parent->vtable->get_focus( o->parent, widget );
}
}