lib/shoes/swt/slot.rb in shoes-swt-4.0.0.pre12 vs lib/shoes/swt/slot.rb in shoes-swt-4.0.0.rc1
- old
+ new
@@ -1,6 +1,7 @@
# frozen_string_literal: true
+
class Shoes
module Swt
class Slot
include Common::Container
include Common::Clickable
@@ -12,30 +13,40 @@
@dsl = dsl
@parent = parent
@real = parent.real
@app = @parent.app
+
+ @scroll = ::Swt::Widgets::Slider.new(@app.real, ::Swt::SWT::VERTICAL)
+ @scroll.add_selection_listener do |_event|
+ update_scroll
+ end
end
# needed by Layouter code, but slots are no physical elements so they
def update_position
end
- # This is more like a temporary work around until slots have a real
- # backend representations that can just hide their contents all together
- # I decided to put this logic in the backend since the hiding is a backend
- # responsibility, although this is more DSL code
- # #904 #905
- def update_visibility
- # Only alter contents on a visibility change
- return if @last_hidden_state == dsl.hidden?
+ def update_scroll
+ @dsl.scroll_top = @scroll.selection
+ end
- @last_hidden_state = dsl.hidden?
+ # This is more than the scrollbar is expected to be on any OS
+ SCROLLBAR_MAX_WIDTH = 20
- if @last_hidden_state
- dsl.contents.each(&:hide)
- else
- dsl.contents.each(&:show)
+ # For some reason, if we set max to match, you can't get past last 10!
+ SCROLLBAR_PADDING = 10
+
+ def update_visibility
+ @scroll.set_visible(@dsl.scroll && @dsl.scroll_max.positive?)
+
+ if @dsl.scroll
+ @scroll.selection = @dsl.scroll_top
+ @scroll.maximum = @dsl.scroll_max + SCROLLBAR_PADDING
+ @scroll.set_bounds @dsl.element_right - SCROLLBAR_MAX_WIDTH + 1,
+ @dsl.element_top,
+ SCROLLBAR_MAX_WIDTH,
+ @dsl.element_height
end
end
def redraw_target
@dsl