Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX: add scroller! for base #4648

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
53 changes: 35 additions & 18 deletions modules/view/backends/gtk3/gui.reds
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,10 @@ get-face-layout: func [
h [handle!]
][
case [
sym = rich-text [
any [
sym = rich-text
sym = base
][
h: GET-CONTAINER(widget)
if null? h [h: widget]
h
Expand Down Expand Up @@ -955,7 +958,10 @@ change-size: func [
layout: get-face-layout widget sym
y: size/y
if layout <> widget [
if type = rich-text [ ;-- is scrollable
if any [
type = rich-text
type = base
][ ;-- is scrollable
adj: gtk_scrollable_get_vadjustment widget
min: gtk_adjustment_get_lower adj
max: gtk_adjustment_get_upper adj
Expand Down Expand Up @@ -1444,6 +1450,9 @@ update-scroller: func [
bar [handle!]
int [red-integer!]
values [red-value!]
pvalues [red-value!]
ntype [red-word!]
sym [integer!]
widget [handle!]
container [handle!]
pos [float!]
Expand All @@ -1464,7 +1473,10 @@ update-scroller: func [
vertical?: as red-logic! values + SCROLLER_OBJ_VERTICAL?
int: as red-integer! block/rs-head as red-block! (object/get-values parent) + FACE_OBJ_STATE
widget: as handle! int/value
container: get-face-layout widget rich-text
pvalues: get-face-values widget
ntype: as red-word! pvalues + FACE_OBJ_TYPE
sym: symbol/resolve ntype/symbol
container: get-face-layout widget sym

int: as red-integer! values + flag
if flag = SCROLLER_OBJ_VISIBLE? [
Expand Down Expand Up @@ -1687,6 +1699,7 @@ OS-make-view: func [
x [integer!]
y [integer!]
gm [GdkGeometry! value]
add-scroll [subroutine!]
][
stack/mark-native words/_body

Expand Down Expand Up @@ -1718,6 +1731,23 @@ OS-make-view: func [
]

container: null
add-scroll: [
if bits and FACET_FLAGS_SCROLLABLE <> 0 [
container: gtk_scrolled_window_new null null
gtk_container_add container widget
gtk_scrolled_window_set_policy container 1 1
len: 0
loop 2 [
either zero? len [vadjust: gtk_scrollable_get_vadjustment widget][
vadjust: gtk_scrollable_get_hadjustment widget
]
len: len + 1
g_signal_handlers_disconnect_by_data(vadjust widget) ;-- remove default event handler
gtk_adjustment_configure vadjust 0.0 0.0 1.0 0.0 0.0 1.0
gobj_signal_connect(vadjust "value_changed" :vbar-value-changed widget)
]
]
]

case [
sym = check [
Expand Down Expand Up @@ -1749,6 +1779,7 @@ OS-make-view: func [
sym = base [
widget: gtk_layout_new null null
gtk_layout_set_size widget size/x size/y
add-scroll
]
sym = rich-text [
widget: gtk_layout_new null null
Expand All @@ -1762,21 +1793,7 @@ OS-make-view: func [
;--@@ only a few languages may use it, such as Thai. I'll implement it later.
;gobj_signal_connect(handle "retrieve-surrounding" :im-retrieve-surrounding widget)
;gobj_signal_connect(handle "delete-surrounding" :im-delete-surrounding widget)
if bits and FACET_FLAGS_SCROLLABLE <> 0 [
container: gtk_scrolled_window_new null null
gtk_container_add container widget
gtk_scrolled_window_set_policy container 1 1
len: 0
loop 2 [
either zero? len [vadjust: gtk_scrollable_get_vadjustment widget][
vadjust: gtk_scrollable_get_hadjustment widget
]
len: len + 1
g_signal_handlers_disconnect_by_data(vadjust widget) ;-- remove default event handler
gtk_adjustment_configure vadjust 0.0 0.0 1.0 0.0 0.0 1.0
gobj_signal_connect(vadjust "value_changed" :vbar-value-changed widget)
]
]
add-scroll
]
sym = window [
;; FIXME TBD parent should not always be zero, view engine should set it.
Expand Down
38 changes: 38 additions & 0 deletions tests/inner-scroller.red
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
Red [Needs: View]

view [
size 390x220
across space 0x0
base 367x200 with [
flags: 'scrollable
pane: layout/only [
origin 0x0 space 0x0
p: panel 350x800 [
origin 0x0 space 0x0
below
area "A" 350x200
area "B" 350x200
area "C" 350x200
area "D" 350x200
]
]
]
on-created [
put get-scroller face 'horizontal 'visible? no
sc: get-scroller face 'vertical
sc/position: 0
sc/page-size: 200
sc/max-size: 800
]
on-scroll [
sc/position: max 0 min 600 switch event/key [
down [sc/position + 20]
up [sc/position - 20]
page-down [sc/position + sc/page-size]
page-up [sc/position - sc/page-size]
track [event/picked - 1]
end [sc/position]
]
p/offset: as-pair 0 negate sc/position
]
]