Module: Charming::Presentation::Layout
- Defined in:
- lib/charming/presentation/layout.rb,
lib/charming/presentation/layout/pane.rb,
lib/charming/presentation/layout/rect.rb,
lib/charming/presentation/layout/split.rb,
lib/charming/presentation/layout/builder.rb,
lib/charming/presentation/layout/overlay.rb,
lib/charming/presentation/layout/screen_layout.rb
Overview
Layout contains generic screen-size math and composition helpers. It is intentionally unaware of application shells such as sidebars or nav panes.
Defined Under Namespace
Classes: Builder, Overlay, Pane, Rect, ScreenLayout, Split
Class Method Summary
collapse
-
.available_height(screen, reserved: 0, min: nil, max: nil) ⇒ Object
-
.available_width(screen, reserved: 0, min: nil, max: nil) ⇒ Object
-
.clamp_size(value, min: nil, max: nil) ⇒ Object
-
.selected_window_start(selected_index:, item_count:, window_size:) ⇒ Object
-
.stack_or_row(*blocks, narrow:, gap: 0) ⇒ Object
Class Method Details
.available_height(screen, reserved: 0, min: nil, max: nil) ⇒ Object
21
22
23
|
# File 'lib/charming/presentation/layout.rb', line 21
def available_height(screen, reserved: 0, min: nil, max: nil)
clamp_size(screen.height - reserved, min: min, max: max)
end
|
.available_width(screen, reserved: 0, min: nil, max: nil) ⇒ Object
17
18
19
|
# File 'lib/charming/presentation/layout.rb', line 17
def available_width(screen, reserved: 0, min: nil, max: nil)
clamp_size(screen.width - reserved, min: min, max: max)
end
|
.clamp_size(value, min: nil, max: nil) ⇒ Object
10
11
12
13
14
15
|
# File 'lib/charming/presentation/layout.rb', line 10
def clamp_size(value, min: nil, max: nil)
size = value.to_i
size = [size, min].max if min
size = [size, max].min if max
size
end
|
.selected_window_start(selected_index:, item_count:, window_size:) ⇒ Object
33
34
35
36
37
38
39
40
|
# File 'lib/charming/presentation/layout.rb', line 33
def selected_window_start(selected_index:, item_count:, window_size:)
count = item_count.to_i
size = [window_size.to_i, 1].max
selected = selected_index.to_i.clamp(0, [count - 1, 0].max)
max_start = [count - size, 0].max
(selected - size + 1).clamp(0, max_start)
end
|
.stack_or_row(*blocks, narrow:, gap: 0) ⇒ Object
25
26
27
28
29
30
31
|
# File 'lib/charming/presentation/layout.rb', line 25
def stack_or_row(*blocks, narrow:, gap: 0)
if narrow
UI.join_vertical(*blocks, gap: gap)
else
UI.join_horizontal(*blocks, gap: gap)
end
end
|