feat(Label): add label control #60
No reviewers
Labels
No labels
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
mupen64/ugui!60
Loading…
Reference in a new issue
No description provided.
Delete branch "label-control"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Adds a label control.
Pretty useless for now, but it will have selectability added in the future.
Closes #34
Pull request overview
Adds a new
labelcontrol to theuguicontrol registry, wiring it into the build amalgamation and showcasing usage in an existing demo.Changes:
ControlTypeto include"label".src/ugui/controls/label.luaimplementingugui.registry.labeland theugui.label()wrapper.build.pyand add a demo usage.Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.
"label"to theControlTypeunion.💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
@ -0,0 +1,50 @@--The
Labeldocs mentionfont_size/font_namefields, but the implementation never uses them (rendering always usesugui.standard_styler.params.font_*). Either remove these fields from the API docs for now, or implement support (for example by mapping them intocontrol.styler_mixinso they actually affect rendering).The docstring says
ugui.labelreturnsinteger, Meta, but the registry logic always returnsprimary = nil, so the first return value is alwaysnil. Please update the annotation to reflect the actual return type (e.g.nil, Meta).@ -0,0 +38,4 @@draw = function(control)local visual_state = ugui.get_visual_state(control)ugui.standard_styler.draw_rich_text(control.rectangle, control.align_x, control.align_y, control.text, control.color, visual_state, control.plaintext, control.font_name, control.font_size)end,draw_rich_textrequires a non-nilcolor(BreitbandGraphicsDrawTextParams.coloris mandatory).Label.coloris documented as optional, butcontrol.coloris passed through directly, sonilwill likely error at runtime. Either makecolorrequired invalidate, or provide a default (e.g. a standard styler text color for the currentvisual_state).ControlTypewas extended with"label", but the codebase keeps control type definitions centralized insrc/ugui/types.lua(e.g.Button,TextBox,ScrollBar, etc.).Label's---@classwas added insidecontrols/label.lua, which is inconsistent with the existing convention and makes types harder to discover. Consider moving theLabelclass annotation intotypes.luaalongside the other controls and keeping control files implementation-only.Pull request overview
Adds a new
Labelcontrol to ugui and extends rich-text rendering utilities to support per-call font overrides, laying groundwork for future selectable/copyable label text (Issue #34).Changes:
ugui.labelcontrol and registers it in the control registry.standard_stylerrich-text drawing/measurement to accept optionalfont_name/font_size.Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 6 comments.
Show a summary per file
ControlTypeunion to include"label".draw_rich_text/compute_rich_text.ugui.label(...)wrapper.Comments suppressed due to low confidence (1)
src/ugui/styler.lua:327
plaintextbranch,compute_rich_textreturnssegment_dataas an object withsegment/rectanglekeys rather than an array of segment entries, which doesn't match the annotated return type and the non-plaintext branch. Returning a consistent array shape (e.g., one-element list) will avoid surprising consumers that iteratesegment_data.💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
@ -0,0 +11,4 @@---@field public font_name string? The font family of the text. If `nil`, the default font family is used.---@field public align_x Alignment? The text's horizontal alignment inside the control rectangle. If `nil`, `alignment.center` is assumed.---@field public align_y Alignment? The text's vertical alignment inside the control rectangle. If `nil`, `alignment.center` is assumed.---A label that contains text.This repo centralizes control
---@classdefinitions insrc/ugui/types.lua(e.g. Button/ToggleButton/TextBox/etc.). To keep tooling and docs consistent, consider adding theLabelclass definition there and avoiding defining control classes in individual control implementation files.@ -0,0 +37,4 @@---@param control Labeldraw = function(control)local visual_state = ugui.get_visual_state(control)ugui.standard_styler.draw_rich_text(control.rectangle, control.align_x, control.align_y, control.text, control.color, visual_state, control.plaintext, control.font_name, control.font_size)Labelis documented as allowingcolorto be nil, butdraw_rich_textultimately passes the color intoBreitbandGraphics.draw_text2, which callsbrush_from_color(params.color)and will error on nil. Either makecolorrequired (and validate it), or provide a sensible default color (e.g. a newugui.standard_styler.params.label.text[visual_state]or similar) whencontrol.coloris nil.@ -0,0 +47,4 @@ugui.label = function(control)local result = ugui.control(control, 'label')return result.primary, result.metaendThere is an established test suite for controls (see
test/*.luaandtest/runner.lua). Since this introduces a new public control (ugui.label), please add atest/label.luagroup exercising at least validation and drawing codepaths (e.g., default alignments/font overrides) and register it intest/runner.luaso it runs in CI/local test runs.@ -311,3 +313,3 @@compute_rich_text = function(text, plaintext)compute_rich_text = function(text, plaintext, font_name, font_size)if not text thenreturn {segment_data = {}, size = {x = 0, y = 0}}compute_rich_textnow requiresfont_name/font_sizebut doesn't default them when callers omit the new args. There are existing call sites (e.g. TabControl sizing, tooltip sizing, and richtext tests) that callcompute_rich_text(text, plaintext)/compute_rich_text(text); with the current implementation this will pass nil intoBreitbandGraphics.get_text_sizeand can error. Consider makingfont_name/font_sizeoptional and defaulting tougui.standard_styler.params.*when nil to preserve backward compatibility.ugui.internal.parse_rich_textreturns an ordered array of segments, but this loop iterates it withpairs(segments), which does not guarantee traversal order. That can lead to rich text being measured/laid out out of order. Useipairs(segments)here (andipairs(segment_data)in the later aggregation loops) to keep ordering deterministic.@ -138,3 +138,3 @@---@alias ControlType "button" | "toggle_button" | "carrousel_button" | "textbox" | "joystick" | "trackbar" | "listbox" | "scrollbar" | "combobox" | "menu" | "numberbox"---@alias ControlType "label" | "button" | "toggle_button" | "carrousel_button" | "textbox" | "joystick" | "trackbar" | "listbox" | "scrollbar" | "combobox" | "menu" | "numberbox"---@alias ControlReturnValue { primary: any, meta: Meta }ControlTypenow includes "label", but there is no corresponding---@class Labelinsrc/ugui/types.luaalongside the other controls. Adding it there keeps the public type surface complete for users relying on the type annotations.