Skip to content

Instantly share code, notes, and snippets.

@KonnorRogers
Last active August 1, 2025 04:31
Show Gist options
  • Save KonnorRogers/231694893ac2b148b22466594f5c7675 to your computer and use it in GitHub Desktop.
Save KonnorRogers/231694893ac2b148b22466594f5c7675 to your computer and use it in GitHub Desktop.
Label wrapping
# Sample from:
# https://docs.dragonruby.org/#/samples/rendering-basics?id=labels-text-wrapping-mainrb
def tick(args)
lines = ["line1", "line2", "line3", "line4"]
labels = lines.map.with_index do |text, index|
{
x: 1280 / 2,
y: 720 / 2,
text: text,
anchor_y: index
}
end
last_label = labels[-1]
last_label_w, last_label_h = GTK.calcstringbox(last_label.text)
padding_left = 8
padding_right = 8
padding_top = 8
padding_bottom = 8
highlight_box = {
x: last_label.x,
y: last_label.y,
w: last_label_w,
h: last_label_h,
r: 255,
g: 0,
b: 0,
a: 255,
}
highlight_box = highlight_box.anchor_rect(last_label.anchor_x || 0, last_label.anchor_y || 0)
highlight_box.tap do |box|
box.x = box.x - padding_left
box.y = box.y - padding_bottom
box.w = box.w + padding_left + padding_right
box.h = box.h + padding_bottom + padding_top
end
args.outputs.solids << highlight_box
args.outputs.labels.concat(labels)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment