I dunno
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
(define (widget-checkbox-icon-switch widget event)
|
||||
(if (= (widget-get-icon widget) 1)
|
||||
(widget-set-icon! widget 2)
|
||||
(widget-set-icon! widget 1)))
|
||||
|
||||
(define (widget-checkbox text flag . args)
|
||||
(apply
|
||||
widget-new
|
||||
(append
|
||||
(list 'container #:horizontal #t #:layout-spacing 8)
|
||||
args
|
||||
(list
|
||||
(widget-new 'plain #:style style-icon-button #:icon 1 #:aspect-ratio 1
|
||||
#:on-click (lambda (w e) (widget-checkbox-icon-switch w e) (flags-switch flag)))
|
||||
(widget-new 'label #:style style-default #:text text #:layout-weight 1)))))
|
||||
|
||||
(define (widget-spinner . args)
|
||||
(apply
|
||||
widget-new
|
||||
(append
|
||||
(list 'container #:horizontal #t #:layout-spacing 8)
|
||||
args
|
||||
(list
|
||||
(widget-new 'plain #:style style-icon-button #:icon 3 #:aspect-ratio 1)
|
||||
(widget-new 'label #:style style-default #:layout-weight 1)
|
||||
(widget-new 'plain #:style style-icon-button #:icon 4 #:aspect-ratio 1)))))
|
||||
@@ -0,0 +1,45 @@
|
||||
(define COLOR_TRANSPARENT '(0.0 0.0 0.0 0.0))
|
||||
(define COLOR_WHITE '(1.0 1.0 1.0 1.0))
|
||||
(define COLOR_BLACK '(0.0 0.0 0.0 1.0))
|
||||
|
||||
(define style-default
|
||||
(style-new #:text-color COLOR_WHITE
|
||||
#:text-color-hovered COLOR_WHITE
|
||||
#:text-color-clicked COLOR_WHITE
|
||||
#:ghost-text-color '(1.0 1.0 1.0 0.5)
|
||||
#:icon-color COLOR_WHITE
|
||||
#:icon-color-hovered COLOR_WHITE
|
||||
#:icon-color-clicked COLOR_WHITE
|
||||
#:scrollbar-color COLOR_WHITE
|
||||
#:scrollbar-color-hovered COLOR_WHITE
|
||||
#:scrollbar-color-clicked COLOR_WHITE
|
||||
#:border-color COLOR_WHITE
|
||||
#:progress-color COLOR_WHITE
|
||||
#:resize-handle-color COLOR_WHITE))
|
||||
|
||||
(define style-window
|
||||
(style-new #:background-color '(0.2 0.2 0.2 1.0)
|
||||
#:background-color-hovered '(0.2 0.2 0.2 1.0)
|
||||
#:background-color-clicked '(0.3 0.3 0.3 1.0)
|
||||
#:text-color COLOR_WHITE
|
||||
#:text-color-hovered COLOR_WHITE
|
||||
#:text-color-clicked COLOR_WHITE
|
||||
#:border-color '(0.5 0.5 0.5 1.0)
|
||||
#:resize-handle-color COLOR_WHITE
|
||||
#:border-width 3))
|
||||
|
||||
(define style-container
|
||||
(style-new #:background-color '(0.3 0.3 0.3 1.0)
|
||||
#:background-color-hovered '(0.3 0.3 0.3 1.0)
|
||||
#:background-color-clicked '(0.3 0.3 0.3 1.0)
|
||||
#:border-color '(0.4 0.4 0.4 1.0)
|
||||
#:border-width 2))
|
||||
|
||||
(define style-icon-button
|
||||
(style-new #:icon-color COLOR_WHITE
|
||||
#:icon-color-hovered '(1.0 1.0 0.0 1.0)
|
||||
#:icon-color-clicked '(1.0 0.0 0.0 1.0)))
|
||||
|
||||
(define style-tooltip
|
||||
(style-new
|
||||
#:background-color COLOR_BLACK))
|
||||
@@ -1,64 +1,5 @@
|
||||
(define COLOR_TRANSPARENT '(0.0 0.0 0.0 0.0))
|
||||
(define COLOR_WHITE '(1.0 1.0 1.0 1.0))
|
||||
(define COLOR_BLACK '(0.0 0.0 0.0 1.0))
|
||||
|
||||
(define style-default
|
||||
(style-new #:text-color COLOR_WHITE
|
||||
#:text-color-hovered COLOR_WHITE
|
||||
#:text-color-clicked COLOR_WHITE
|
||||
#:ghost-text-color '(1.0 1.0 1.0 0.5)
|
||||
#:icon-color COLOR_WHITE
|
||||
#:icon-color-hovered COLOR_WHITE
|
||||
#:icon-color-clicked COLOR_WHITE
|
||||
#:scrollbar-color COLOR_WHITE
|
||||
#:scrollbar-color-hovered COLOR_WHITE
|
||||
#:scrollbar-color-clicked COLOR_WHITE
|
||||
#:border-color COLOR_WHITE
|
||||
#:progress-color COLOR_WHITE
|
||||
#:resize-handle-color COLOR_WHITE))
|
||||
|
||||
(define style-window
|
||||
(style-new #:background-color '(0.2 0.2 0.2 1.0)
|
||||
#:background-color-hovered '(0.2 0.2 0.2 1.0)
|
||||
#:background-color-clicked '(0.3 0.3 0.3 1.0)
|
||||
#:text-color COLOR_WHITE
|
||||
#:text-color-hovered COLOR_WHITE
|
||||
#:text-color-clicked COLOR_WHITE
|
||||
#:border-color '(0.5 0.5 0.5 1.0)
|
||||
#:resize-handle-color COLOR_WHITE
|
||||
#:border-width 3))
|
||||
|
||||
(define style-container
|
||||
(style-new #:background-color '(0.3 0.3 0.3 1.0)
|
||||
#:background-color-hovered '(0.3 0.3 0.3 1.0)
|
||||
#:background-color-clicked '(0.3 0.3 0.3 1.0)
|
||||
#:border-color '(0.4 0.4 0.4 1.0)
|
||||
#:border-width 2))
|
||||
|
||||
(define style-icon-button
|
||||
(style-new #:icon-color COLOR_WHITE
|
||||
#:icon-color-hovered '(1.0 1.0 0.0 1.0)
|
||||
#:icon-color-clicked '(1.0 0.0 0.0 1.0)))
|
||||
|
||||
|
||||
(define (widget-checkbox-icon-switch widget event)
|
||||
(if (= (widget-get-icon widget) 1)
|
||||
(widget-set-icon! widget 2)
|
||||
(widget-set-icon! widget 1)))
|
||||
|
||||
;; The function is evaulated and returns a pointer, the game eats it
|
||||
;; and adds it to the UI root. Boom.
|
||||
(define (widget-checkbox text flag . args)
|
||||
(apply
|
||||
widget-new
|
||||
(append
|
||||
(list 'container #:horizontal #t #:layout-spacing 8)
|
||||
args
|
||||
(list
|
||||
(widget-new 'plain #:style style-icon-button #:icon 1 #:aspect-ratio 1
|
||||
#:on-click (lambda (w e) (widget-checkbox-icon-switch w e) (flags-switch flag)))
|
||||
(widget-new 'label #:style style-default #:text text #:layout-weight 1)))))
|
||||
|
||||
(widget-new
|
||||
'window
|
||||
#:style style-window
|
||||
@@ -74,5 +15,9 @@
|
||||
#:layout-padding 8
|
||||
#:layout-spacing 8
|
||||
#:horizontal #t
|
||||
(widget-checkbox "Flight" "flight_enabled" #:layout-weight 0.5 #:h 20 #:tooltip "Testt")
|
||||
(widget-checkbox "Wireframe" "wireframe_enabled" #:layout-weight 0.5 #:h 20 #:tooltip "test222")))
|
||||
(widget-checkbox "Flight" "flight_enabled" #:layout-weight 0.5 #:h 20)
|
||||
(widget-checkbox "Wireframe" "wireframe_enabled" #:layout-weight 0.5 #:h 20)
|
||||
(widget-new 'label #:style style-default #:layout-weight 1 #:h 20
|
||||
#:on-tick (lambda (w e) (widget-set-text! w (number->string (random 10000)))))
|
||||
(widget-spinner #:layout-weight 1 #:h 20)
|
||||
(widget-new 'entry #:style style-default #:layout-weight 1 #:h 20 #:text "Enter text...")))
|
||||
|
||||
@@ -1,16 +1,3 @@
|
||||
(define COLOR_WHITE '(1.0 1.0 1.0 1.0))
|
||||
(define COLOR_BLACK '(0.0 0.0 0.0 1.0))
|
||||
|
||||
(define style-tooltip
|
||||
(style-new
|
||||
#:background-color COLOR_BLACK))
|
||||
|
||||
(define style-tooltip-text
|
||||
(style-new
|
||||
#:text-color COLOR_WHITE
|
||||
#:text-color-hovered COLOR_WHITE
|
||||
#:text-color-clicked COLOR_WHITE))
|
||||
|
||||
(widget-new
|
||||
'flowbox
|
||||
#:style style-tooltip
|
||||
@@ -19,4 +6,4 @@
|
||||
#:horizontal #t
|
||||
#:layout-padding 4
|
||||
#:layout-spacing 8
|
||||
(widget-new 'multiline #:line-height 20 #:layout-weight 1 #:style style-tooltip-text))
|
||||
(widget-new 'multiline #:line-height 20 #:layout-weight 1 #:style style-default))
|
||||
|
||||
@@ -24,6 +24,9 @@ uiman_init ()
|
||||
ui_root = Widget_new ();
|
||||
IVEC2_SETI (ui_root->size, sdl_window_w, sdl_window_h);
|
||||
|
||||
scm_c_primitive_load ("res/scripts/global/ui_styles.scm");
|
||||
scm_c_primitive_load ("res/scripts/global/ui_composites.scm");
|
||||
|
||||
SCM scm_debug = scm_c_primitive_load ("res/scripts/ui/debug_window.scm");
|
||||
Widget *debug_window = (Widget *) scm_to_pointer (scm_debug);
|
||||
Widget_add_child (ui_root, debug_window);
|
||||
|
||||
@@ -5,12 +5,16 @@
|
||||
#include "widget_fw.h"
|
||||
#include "widget_core.h"
|
||||
|
||||
void ui_boilerplate_entry_move_left (Widget *self, SDL_Event *sdl_event, void *userdata);
|
||||
void ui_boilerplate_entry_move_right (Widget *self, SDL_Event *sdl_event, void *userdata);
|
||||
void ui_boilerplate_entry_delete_backward (Widget *self, SDL_Event *sdl_event, void *userdata);
|
||||
void ui_boilerplate_entry_delete_forward (Widget *self, SDL_Event *sdl_event, void *userdata);
|
||||
void ui_boilerplate_entry_input_text (Widget *self, SDL_Event *sdl_event, void *userdata);
|
||||
void ui_boilerplate_entry_start_input (Widget *self, SDL_Event *sdl_event, void *userdata);
|
||||
void ui_boilerplate_entry_stop_input (Widget *self, SDL_Event *sdl_event, void *userdata);
|
||||
|
||||
void ui_boilerplate_scrollbar_scroll_up (Widget *self, SDL_Event *sdl_event, void *userdata);
|
||||
void ui_boilerplate_scrollbar_scroll_down (Widget *self, SDL_Event *sdl_event, void *userdata);
|
||||
|
||||
void ui_boilerplate_scrollbar_start_scroll (Widget *self, SDL_Event *sdl_event, void *userdata);
|
||||
void ui_boilerplate_scrollbar_scroll (Widget *self, SDL_Event *sdl_event, void *userdata);
|
||||
void ui_boilerplate_scrollbar_stop_scroll (Widget *self, SDL_Event *sdl_event, void *userdata);
|
||||
|
||||
@@ -195,7 +195,7 @@ void Widget_add_child (Widget *parent, Widget *child);
|
||||
void Widget_entry_input_text (Widget *widget, const char *text);
|
||||
void Widget_scrollable_scroll (Widget *widget, ivec2 direction);
|
||||
|
||||
static inline gboolean wcond_tooltip (Widget *widget, void *userdata) { UNUSED (userdata); return widget->tooltip != NULL; }
|
||||
static inline gboolean wcond_tooltip (Widget *widget, void *userdata) { UNUSED (userdata); return widget->tooltip->len > 0; }
|
||||
static inline gboolean wcond_event (Widget *widget, void *event) { WidgetEvent e = GPOINTER_TO_INT (event); return widget->on_event[e] != NULL; }
|
||||
static inline gboolean wcond_any (Widget *widget, void *userdata) { UNUSED (widget, userdata); return TRUE; }
|
||||
|
||||
|
||||
@@ -171,6 +171,16 @@ _wgg_build (const char *type)
|
||||
{
|
||||
w->kind = WIDGET_ENTRY;
|
||||
w->do_render = Widget_render_entry;
|
||||
w->entry.content = g_string_new (NULL);
|
||||
w->entry.ghost_text = g_string_new (NULL);
|
||||
|
||||
w->on_event[EVENT_FOCUS_GAINED] = ui_boilerplate_entry_start_input;
|
||||
w->on_event[EVENT_FOCUS_LOST] = ui_boilerplate_entry_stop_input;
|
||||
w->on_event[EVENT_TEXT_INPUT] = ui_boilerplate_entry_input_text;
|
||||
w->on_key[SDL_SCANCODE_BACKSPACE] = ui_boilerplate_entry_delete_backward;
|
||||
w->on_key[SDL_SCANCODE_DELETE] = ui_boilerplate_entry_delete_forward;
|
||||
w->on_key[SDL_SCANCODE_LEFT] = ui_boilerplate_entry_move_left;
|
||||
w->on_key[SDL_SCANCODE_RIGHT] = ui_boilerplate_entry_move_right;
|
||||
}
|
||||
|
||||
if (!g_strcmp0 (type, "multiline"))
|
||||
@@ -342,6 +352,9 @@ _wgg_set_property (Widget *w, const char *key, SCM val)
|
||||
break;
|
||||
case WIDGET_WINDOW:
|
||||
g_string_overwrite (w->window.title, 0, scm_to_utf8_string (val));
|
||||
break;
|
||||
case WIDGET_ENTRY:
|
||||
g_string_overwrite (w->entry.ghost_text, 0, scm_to_utf8_string (val));
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@@ -457,6 +470,39 @@ _wg_set_icon (SCM widget_ptr, SCM icon_val)
|
||||
return SCM_UNSPECIFIED;
|
||||
}
|
||||
|
||||
static SCM
|
||||
_wg_get_child (SCM widget_ptr, SCM index_val)
|
||||
{
|
||||
Widget *w = (Widget *) scm_to_pointer (widget_ptr);
|
||||
int index = scm_to_int (index_val);
|
||||
return scm_from_pointer (g_array_index (w->children, Widget *, index), NULL);
|
||||
}
|
||||
|
||||
static SCM
|
||||
_wg_set_text (SCM widget_ptr, SCM val)
|
||||
{
|
||||
Widget *w = (Widget *) scm_to_pointer (widget_ptr);
|
||||
|
||||
switch (w->kind)
|
||||
{
|
||||
case WIDGET_LABEL:
|
||||
g_string_overwrite (w->label.text, 0, scm_to_utf8_string (val));
|
||||
break;
|
||||
case WIDGET_MULTILINE_TEXT:
|
||||
g_string_overwrite (w->multiline_text.text, 0, scm_to_utf8_string (val));
|
||||
break;
|
||||
case WIDGET_WINDOW:
|
||||
g_string_overwrite (w->window.title, 0, scm_to_utf8_string (val));
|
||||
break;
|
||||
case WIDGET_ENTRY:
|
||||
g_string_overwrite (w->entry.ghost_text, 0, scm_to_utf8_string (val));
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return SCM_UNSPECIFIED;
|
||||
}
|
||||
|
||||
void
|
||||
widget_guile_register ()
|
||||
{
|
||||
@@ -465,4 +511,8 @@ widget_guile_register ()
|
||||
|
||||
scm_c_define_gsubr ("widget-get-icon", 1, 0, 0, _wg_get_icon);
|
||||
scm_c_define_gsubr ("widget-set-icon!", 2, 0, 0, _wg_set_icon);
|
||||
|
||||
scm_c_define_gsubr ("widget-get-child", 2, 0, 0, _wg_get_child);
|
||||
|
||||
scm_c_define_gsubr ("widget-set-text!", 2, 0, 0, _wg_set_text);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user