~yerinalexey/hare-libui

6e5b6d88771c15b2139d97d2854047a402213a26 — Alexey Yerin a month ago 0b689e0
Bind uiRadioButtons
3 files changed, 53 insertions(+), 1 deletions(-)

M README.md
M libui/controls.ha
A libui/radio_buttons.ha
M README.md => README.md +1 -1
@@ 17,7 17,7 @@ create cross-platform GUIs.
* ✅ uiSeparator
* ✅ uiCombobox
* ✅ uiEditableCombobox
* ❌ uiRadioButton
* ✅ uiRadioButtons
* ❌ uiDateTimePicker
* ✅ uiMultilineEntry
* ✅ uiMenu and uiMenuItem

M libui/controls.ha => libui/controls.ha +1 -0
@@ 15,6 15,7 @@ export type control = (
	*label |
	*multiline_entry |
	*progress_bar |
	*radio_buttons |
	*separator |
	*slider |
	*spinbox |

A libui/radio_buttons.ha => libui/radio_buttons.ha +51 -0
@@ 0,0 1,51 @@
use types::c;

export type radio_buttons = opaque;

// Creates a new group of radio buttons.
export fn radio_buttons_new() *radio_buttons = c_uiNewRadioButtons();

// Adds a radio button to a group.
export fn radio_buttons_append(rb: *radio_buttons, text: str) void = {
	const text = c::fromstr(text);
	defer free(text);

	c_uiRadioButtonsAppend(rb, text);
};

// Sets index of the selected radio button.
export fn radio_buttons_set_selected(rb: *radio_buttons, index: size) void = {
	c_uiRadioButtonsSetSelected(rb, index: int);
};

// Gets the index of currently selected radio button.
export fn radio_buttons_get_selected(rb: *radio_buttons) size = {
	return c_uiRadioButtonsSelected(rb): size;
};

// Registers an event handler for radio button selection change.
export fn radio_buttons_on_selected(
	rb: *radio_buttons,
	callback: *fn(self: *radio_buttons, data: nullable *opaque) void,
	data: nullable *opaque,
) void = {
	c_uiRadioButtonsOnSelected(rb, callback, data);
};

@symbol("uiNewRadioButtons") fn c_uiNewRadioButtons() *radio_buttons;
@symbol("uiRadioButtonsAppend") fn c_uiRadioButtonsAppend(
	*radio_buttons,
	*c::char,
) void;
@symbol("uiRadioButtonsSetSelected") fn c_uiRadioButtonsSetSelected(
	*radio_buttons,
	int,
) void;
@symbol("uiRadioButtonsSelected") fn c_uiRadioButtonsSelected(
	*radio_buttons,
) int;
@symbol("uiRadioButtonsOnSelected") fn c_uiRadioButtonsOnSelected(
	*radio_buttons,
	*fn(*radio_buttons, nullable *opaque) void,
	nullable *opaque,
) int;