Module: Lich::Common::GUI::WindowSettings
- Defined in:
- documented/common/gui/window_settings.rb
Constant Summary collapse
- SETTINGS_FILE =
'login_gui_settings.yml'- MIN_DIMENSION =
100- DARWIN_SPACER =
28
Class Method Summary collapse
-
.apply_to_window(window, settings) ⇒ void
Applies the given settings to the specified window.
-
.capture_geometry(window) ⇒ Hash
Captures the current geometry of the specified window.
-
.load(data_dir) ⇒ Hash
Loads window settings from a YAML file.
-
.save(data_dir, width:, height:, position:) ⇒ Boolean
Saves the window settings to a YAML file.
Class Method Details
.apply_to_window(window, settings) ⇒ void
This method returns an undefined value.
Applies the given settings to the specified window.
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'documented/common/gui/window_settings.rb', line 57 def apply_to_window(window, settings) return if settings.empty? width = [settings[:width], MIN_DIMENSION].max height = [settings[:height], MIN_DIMENSION].max position = settings[:position] window.resize(width, height) return unless valid_position?(position) constrained_position = constrain_to_monitor(position, width, height) spacer = darwin? ? DARWIN_SPACER : 0 window.move(constrained_position[0], constrained_position[1] + spacer) end |
.capture_geometry(window) ⇒ Hash
Captures the current geometry of the specified window.
76 77 78 79 80 81 82 |
# File 'documented/common/gui/window_settings.rb', line 76 def capture_geometry(window) { width: window.allocation.width, height: window.allocation.height, position: window.position } end |
.load(data_dir) ⇒ Hash
Loads window settings from a YAML file.
18 19 20 21 22 23 24 25 26 27 |
# File 'documented/common/gui/window_settings.rb', line 18 def load(data_dir) settings_file = File.join(data_dir, SETTINGS_FILE) return {} unless File.exist?(settings_file) settings = YAML.safe_load(File.read(settings_file), permitted_classes: [Symbol], symbolize_names: true) validate_settings(settings) ? settings : {} rescue StandardError => e Lich.log "warning: Could not load window settings: #{e.}" {} end |
.save(data_dir, width:, height:, position:) ⇒ Boolean
Saves the window settings to a YAML file.
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'documented/common/gui/window_settings.rb', line 36 def save(data_dir, width:, height:, position:) return false unless valid_dimensions?(width, height) && valid_position?(position) settings_file = File.join(data_dir, SETTINGS_FILE) settings = { width: width, height: height, position: position } File.open(settings_file, 'w') { |f| f.write(YAML.dump(settings)) } true rescue StandardError => e Lich.log "warning: Could not save window settings: #{e.}" false end |