Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
# v0.0.21 - 4 Jan 2024
# v0.0.22 - 9 February 2025

* Fixed a bug when using `max_length` where `selection_end` (and `selection_start`) where incorrectly set (thanks to @TheCire for reporting in Discord).
* Fixed a cursor placement and selection background issues in the `Text` component.

# v0.0.21 - 4 January 2025

* Updated clipboard to use getclipboard and setclipboard so the system clipboard is used
* Updated menu to handle scrolling with keyboard if there are too many items, including menu sizing
Expand Down
1 change: 1 addition & 0 deletions app/book_sample.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ def tick(args)
x: 20,
y: 660,
w: 1240,
padding: 10,
prompt: 'Title',
value: "Alice's Adventures in Wonderland 🐰",
font: FONT,
Expand Down
15 changes: 7 additions & 8 deletions lib/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,6 @@ def initialize(**params) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticCo
# Render target for text scrolling
@path = "__input_#{@@id += 1}"

@scroll_x = 0
@scroll_y = 0
@content_w = @w
@content_h = @h

Expand Down Expand Up @@ -113,11 +111,12 @@ def draw_cursor(rt)
else
255
end

rt.primitives << {
x: (@cursor_x - 1).greater(0) - @scroll_x,
y: @cursor_y - @padding - @scroll_y,
y: @cursor_y - @scroll_y,
w: @cursor_width,
h: @font_height + @padding * 2
h: @font_height
}.solid!(**@cursor_color, a: alpha)
end

Expand Down Expand Up @@ -174,21 +173,21 @@ def selection_end=(index)
def insert(str)
@selection_end, @selection_start = @selection_start, @selection_end if @selection_start > @selection_end
insert_at(str, @selection_start, @selection_end)

@selection_start += str.length
@selection_end = @selection_start
end
alias replace insert

def insert_at(str, start_at, end_at = start_at)
end_at, start_at = start_at, end_at if start_at > end_at
if @max_length && @value.length - (end_at - start_at) + str.length > @max_length
str = str[0, @max_length - @value.length + (end_at - start_at) - str.length]
str = str[0, @max_length - @value.length + (end_at - start_at)]
return if str.nil? # too long
end

@value.insert(start_at, end_at, str)
@value_changed = true

@selection_start += str.length
@selection_end = @selection_start
end
alias replace_at insert_at

Expand Down
6 changes: 3 additions & 3 deletions lib/multiline.rb
Original file line number Diff line number Diff line change
Expand Up @@ -358,10 +358,10 @@ def prepare_render_target # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticC
@cursor_x = 0
@scroll_x = 0
if @fill_from_bottom
@cursor_y = 0
@cursor_y = -@padding
rt.primitives << @font_style.label(x: 0, y: 0, text: @prompt, **@prompt_color)
else
@cursor_y = @h - @font_height
@cursor_y = @h - @font_height - @padding
rt.primitives << @font_style.label(x: 0, y: @h - @font_height, text: @prompt, **@prompt_color)
end
else
Expand All @@ -374,7 +374,7 @@ def prepare_render_target # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticC
@cursor_index = 0
end

@cursor_y = @scroll_h - (@cursor_line.number + 1) * @font_height
@cursor_y = @scroll_h - (@cursor_line.number + 1) * @font_height - @padding
@cursor_y += @fill_from_bottom ? @content_h : @h - @content_h if @content_h < @h
if @scroll_h <= @h # total height is less than height of the control
@scroll_y = @fill_from_bottom ? @scroll_h : 0
Expand Down
6 changes: 3 additions & 3 deletions lib/text.rb
Original file line number Diff line number Diff line change
Expand Up @@ -169,13 +169,13 @@ def prepare_render_target

if @value.empty?
@cursor_x = 0
@cursor_y = 0
@cursor_y = @padding
@scroll_x = 0
rt.primitives << @font_style.label(x: 0, y: @padding, text: @prompt, **@prompt_color)
else
# CURSOR AND SCROLL LOCATION
@cursor_x = @font_style.string_width(@value[0, @selection_end].to_s)
@cursor_y = 0
@cursor_y = @padding

if @content_w < @w
@scroll_x = 0
Expand All @@ -199,7 +199,7 @@ def prepare_render_target
right = (@font_style.string_width(@value[0, @selection_start].to_s) - @scroll_x).cap_min_max(0, @w)
end

rt.primitives << { x: left, y: @padding, w: right - left, h: @font_height + @padding * 2 }.solid!(sc)
rt.primitives << { x: left, y: 0, w: right - left, h: @font_height + @padding * 2 }.solid!(sc)
end

# TEXT
Expand Down
2 changes: 1 addition & 1 deletion metadata/game_metadata.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ devid=fascinationworks
devtitle=Fascination Works
gameid=dr-input
gametitle=Dragon Ruby Input
version=0.0.21
version=0.0.22
icon=metadata/icon.png

# === Flags available at all licensing tiers ===
Expand Down
Loading
Loading