|
RMGui 0.15.0
C11 retained-mode UI library: layout kernel, style schema, widget painters, fonts, software framebuffer
|
dropdown.h — the dropdown element: a closed row showing the selected option and a popup of option rows the host declares while it is open. More...
#include <stddef.h>#include <stdint.h>#include "fb.h"#include "font.h"#include "geom.h"#include "input.h"#include "style.h"#include "draw_target.h"#include "ui_context.h"Data Structures | |
| struct | rmgui_dropdown_t |
| Retained dropdown state, caller-owned, written by rmgui_dropdown_init and rmgui_dropdown_input only; the host reads open (declare the popup while 1), selected and first_visible, and sets or clears RMGUI_STYLE_STATE_DISABLED in states. More... | |
| struct | rmgui_dropdown_view_t |
| Borrow an initialized dropdown and its optional array of state->count NUL-terminated labels. More... | |
Macros | |
| #define | RMGUI_DROPDOWN_NONE UINT32_MAX |
| The hover / pressed value meaning "no option". | |
Functions | |
| int | rmgui_dropdown_prepare (const rmgui_ui_t *ui, const rmgui_dropdown_view_t *dropdown) |
| Prepare the selected label and truncation dots before recording; emits no commands. | |
| int | rmgui_dropdown_draw (const rmgui_ui_t *ui, const rmgui_dropdown_view_t *dropdown, rmgui_rect_t box) |
| Draw the closed row, even while the host's popup is open. | |
| int | rmgui_dropdown_option_prepare (const rmgui_ui_t *ui, const rmgui_dropdown_view_t *dropdown, size_t option) |
| Prepare one option's label before recording, with no commands emitted. | |
| int | rmgui_dropdown_option_draw (const rmgui_ui_t *ui, const rmgui_dropdown_view_t *dropdown, size_t option, rmgui_rect_t box) |
| Draw a LIST_ROW-styled option in a host-arranged popup row. | |
| int | rmgui_dropdown_init (rmgui_dropdown_t *self, size_t count, size_t visible_rows, size_t selected) |
| Resets self to a closed dropdown over count options with selected committed and at most visible_rows popup rows. | |
| rmgui_size_t | rmgui_dropdown_measure (const rmgui_font_t *font, const rmgui_style_resolved_t *rs, const char *const *labels, size_t count) |
| Minimum outer size of the closed row for count option labels in font: the widest label plus rs->chevron_width plus the DROPDOWN face inset on both sides. | |
| void | rmgui_dropdown_paint (rmgui_fb_t *fb, rmgui_font_t *font, const rmgui_style_resolved_t *rs, rmgui_rect_t rect, rmgui_rect_t clip, const char *label) |
| Paints the closed row into rect: its face, label in font cut with "..." to the content area outside the trailing rs->chevron_width slot, and an antialiased downward chevron centered in that slot. | |
| rmgui_style_states_t | rmgui_dropdown_option_states (const rmgui_dropdown_t *self, size_t option) |
| State set of popup row option for painting with rmgui_list_row_paint: HOVER under the pointer, PRESSED while pressed and hovered, SELECTED for the committed option, FOCUSED for the highlighted option while open, DISABLED while the dropdown is. | |
| rmgui_input_result_t | rmgui_dropdown_input (rmgui_dropdown_t *self, rmgui_rect_t row, const rmgui_rect_t *options, const rmgui_input_t *in) |
| Applies one event. | |
| void | rmgui_dropdown_paint_to (rmgui_target_t *, rmgui_font_t *, const rmgui_style_resolved_t *, rmgui_rect_t, rmgui_rect_t, const char *) |
| Explicit dropdown destination, preserving fitted labels and chevron. | |
dropdown.h — the dropdown element: a closed row showing the selected option and a popup of option rows the host declares while it is open.
| #define RMGUI_DROPDOWN_NONE UINT32_MAX |
The hover / pressed value meaning "no option".
| int rmgui_dropdown_prepare | ( | const rmgui_ui_t * | ui, |
| const rmgui_dropdown_view_t * | dropdown ) |
Prepare the selected label and truncation dots before recording; emits no commands.
Returns 0, or -1 for invalid arguments, style or preparation.
| int rmgui_dropdown_draw | ( | const rmgui_ui_t * | ui, |
| const rmgui_dropdown_view_t * | dropdown, | ||
| rmgui_rect_t | box ) |
Draw the closed row, even while the host's popup is open.
Returns 0 or -1 for invalid arguments or style; paint errors latch on the target.
| int rmgui_dropdown_option_prepare | ( | const rmgui_ui_t * | ui, |
| const rmgui_dropdown_view_t * | dropdown, | ||
| size_t | option ) |
Prepare one option's label before recording, with no commands emitted.
Option is an absolute index, not a visible row offset. Returns 0 or -1.
| int rmgui_dropdown_option_draw | ( | const rmgui_ui_t * | ui, |
| const rmgui_dropdown_view_t * | dropdown, | ||
| size_t | option, | ||
| rmgui_rect_t | box ) |
Draw a LIST_ROW-styled option in a host-arranged popup row.
Option is an absolute index. Returns 0 or -1 for invalid arguments or style; paint errors latch on the target.
| int rmgui_dropdown_init | ( | rmgui_dropdown_t * | self, |
| size_t | count, | ||
| size_t | visible_rows, | ||
| size_t | selected ) |
Resets self to a closed dropdown over count options with selected committed and at most visible_rows popup rows.
Returns 0, or -1 (self unchanged) when self is NULL, count is 0 or above INT_MAX (the input result index type ceiling), visible_rows is 0 or above count, or selected >= count.
| rmgui_size_t rmgui_dropdown_measure | ( | const rmgui_font_t * | font, |
| const rmgui_style_resolved_t * | rs, | ||
| const char *const * | labels, | ||
| size_t | count ) |
Minimum outer size of the closed row for count option labels in font: the widest label plus rs->chevron_width plus the DROPDOWN face inset on both sides.
A built-in Lion face reserves at least the width of its trailing well on the right. Height is max(rs->min_height, rs->line_height + both vertical insets). A NULL label measures as empty. rs NULL, or labels NULL with count > 0, returns {0, 0}.
| void rmgui_dropdown_paint | ( | rmgui_fb_t * | fb, |
| rmgui_font_t * | font, | ||
| const rmgui_style_resolved_t * | rs, | ||
| rmgui_rect_t | rect, | ||
| rmgui_rect_t | clip, | ||
| const char * | label ) |
Paints the closed row into rect: its face, label in font cut with "..." to the content area outside the trailing rs->chevron_width slot, and an antialiased downward chevron centered in that slot.
The chevron scales with the available slot, uses rs->chevron, and is clipped to the slot and caller clip. The built-in Lion face centers the chevron in its authored trailing well, at the same size unless the well is narrower, and draws it in the ink that reads best on that well's art: the scheme's text or background role chosen by contrast against the well, as a label is chosen against the face, with rs->chevron kept when it already reads at least as well, or when the ink is invisible. Faces without a well use rs->chevron. Label ink cannot enter either the reserved slot or the well. No pixel outside the intersection of rect and clip is written. NULL fb or rs paints nothing; a NULL label paints as empty and a NULL font paints no label.
| rmgui_style_states_t rmgui_dropdown_option_states | ( | const rmgui_dropdown_t * | self, |
| size_t | option ) |
State set of popup row option for painting with rmgui_list_row_paint: HOVER under the pointer, PRESSED while pressed and hovered, SELECTED for the committed option, FOCUSED for the highlighted option while open, DISABLED while the dropdown is.
An option >= count returns NORMAL.
| rmgui_input_result_t rmgui_dropdown_input | ( | rmgui_dropdown_t * | self, |
| rmgui_rect_t | row, | ||
| const rmgui_rect_t * | options, | ||
| const rmgui_input_t * | in ) |
Applies one event.
row is the closed row's arranged rect; options holds the arranged rects of the visible_rows popup rows showing options first_visible.. and is read only while open (NULL is treated as no rows). While open the host delivers every pointer and key event to this element first.
Closed: click on the row (press and release inside), SPACE or ENTER opens the popup (OPEN) with the selected option highlighted and revealed. Open: click on an option or ENTER picks it (CHANGE, value = option, popup closed); click on the row, ESC, or a press outside the row and every option closes it (CANCEL; the outside press is not consumed so the host routes it on); UP/DOWN/PAGE_UP/PAGE_DOWN/HOME/END move the highlight, clamped, and reveal it; WHEEL over the row or popup scrolls first_visible by notches_y, clamped (notches_x is ignored). While DISABLED an inside PRESS on the row or an open popup option reports REFUSED (value 0, consumed 1, captured 0); otherwise it tracks HOVER and FOCUSED without opening/picking. An already-open popup closes with CANCEL first. self or in NULL returns NONE.
| void rmgui_dropdown_paint_to | ( | rmgui_target_t * | , |
| rmgui_font_t * | , | ||
| const rmgui_style_resolved_t * | , | ||
| rmgui_rect_t | , | ||
| rmgui_rect_t | , | ||
| const char * | ) |
Explicit dropdown destination, preserving fitted labels and chevron.
RECORD needs prepared label/dot glyphs and immutable sheets; failures latch.