mirror of
https://github.com/lutris/lutris
synced 2024-09-15 22:09:55 +00:00
Use styles to suppress the section frame (but keep the contents) when it
contains just one setting. To make this work, the margins all need to be set via styles also.
This commit is contained in:
parent
c151e4b211
commit
948ac302f5
|
@ -18,7 +18,6 @@ from lutris.util.log import logger
|
|||
|
||||
|
||||
class ConfigBox(VBox):
|
||||
|
||||
"""Dynamically generate a vbox built upon on a python dict."""
|
||||
|
||||
config_section = NotImplemented
|
||||
|
@ -78,6 +77,8 @@ class ConfigBox(VBox):
|
|||
self.raw_config = self.lutris_config.raw_system_config
|
||||
|
||||
current_section = None
|
||||
current_vbox = self
|
||||
|
||||
# Go thru all options.
|
||||
for option in self.options:
|
||||
if "scope" in option:
|
||||
|
@ -92,26 +93,14 @@ class ConfigBox(VBox):
|
|||
if callable(option.get("condition")):
|
||||
option["condition"] = option["condition"]()
|
||||
|
||||
if option.get("section"):
|
||||
in_section = True
|
||||
if option["section"] != current_section:
|
||||
current_section = option["section"]
|
||||
frame = Gtk.Frame()
|
||||
frame.set_margin_start(12)
|
||||
frame.set_margin_end(12)
|
||||
frame.set_margin_top(12)
|
||||
frame.set_margin_bottom(12)
|
||||
|
||||
frame.set_label(option["section"])
|
||||
frame_widgets = Gtk.VBox()
|
||||
frame_widgets.set_margin_top(12)
|
||||
frame_widgets.set_margin_bottom(12)
|
||||
frame.add(frame_widgets)
|
||||
if option.get("section") != current_section:
|
||||
current_section = option.get("section")
|
||||
if current_section:
|
||||
frame = ConfigBox.SectionFrame(current_section)
|
||||
current_vbox = frame.vbox
|
||||
self.pack_start(frame, False, False, 0)
|
||||
else:
|
||||
in_section = False
|
||||
frame = None
|
||||
frame_widgets = None
|
||||
else:
|
||||
current_vbox = self
|
||||
|
||||
self.wrapper = Gtk.Box()
|
||||
self.wrapper.set_spacing(12)
|
||||
|
@ -173,10 +162,7 @@ class ConfigBox(VBox):
|
|||
if option.get("advanced"):
|
||||
hbox.get_style_context().add_class("advanced")
|
||||
hbox.pack_start(self.wrapper, True, True, 0)
|
||||
if in_section:
|
||||
frame_widgets.pack_start(hbox, False, False, 0)
|
||||
else:
|
||||
self.pack_start(hbox, False, False, 0)
|
||||
current_vbox.pack_start(hbox, False, False, 0)
|
||||
|
||||
self.show_all()
|
||||
|
||||
|
@ -186,22 +172,24 @@ class ConfigBox(VBox):
|
|||
def set_advanced_visibility(self, value):
|
||||
"""Sets the visibility of every 'advanced' option and every section that
|
||||
contains only 'advanced' options."""
|
||||
|
||||
def update_widgets(widgets):
|
||||
any_visible = False
|
||||
visible_count = 0
|
||||
for widget in widgets:
|
||||
if isinstance(widget, Gtk.Frame):
|
||||
frame_visible = update_widgets(widget.get_child().get_children())
|
||||
any_visible = any_visible or frame_visible
|
||||
widget.set_visible(frame_visible)
|
||||
elif widget.get_style_context().has_class("advanced"):
|
||||
widget.set_visible(value)
|
||||
if value:
|
||||
any_visible = True
|
||||
widget.set_no_show_all(not value)
|
||||
widget.show_all()
|
||||
if isinstance(widget, ConfigBox.SectionFrame):
|
||||
frame_visible_count = update_widgets(widget.vbox.get_children())
|
||||
visible_count += frame_visible_count
|
||||
widget.set_visible(frame_visible_count > 0)
|
||||
widget.set_frame_visible(frame_visible_count > 1)
|
||||
else:
|
||||
any_visible = True
|
||||
return any_visible
|
||||
widget_visible = value or not widget.get_style_context().has_class("advanced")
|
||||
widget.set_visible(widget_visible)
|
||||
widget.set_no_show_all(not widget_visible)
|
||||
if widget_visible:
|
||||
visible_count += 1
|
||||
widget.show_all()
|
||||
|
||||
return visible_count
|
||||
|
||||
update_widgets(self.get_children())
|
||||
|
||||
|
@ -656,6 +644,30 @@ class ConfigBox(VBox):
|
|||
style_context = wrapper.get_style_context()
|
||||
style_context.add_provider(style_provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION)
|
||||
|
||||
class SectionFrame(Gtk.Frame):
|
||||
"""A frame that is styled to have particular margins, and can have its frame hidden.
|
||||
This leaves the content but removes the margins and borders and all that, so it looks
|
||||
like the frame was never there."""
|
||||
|
||||
def __init__(self, section):
|
||||
super().__init__(label=section)
|
||||
self.section = section
|
||||
self.vbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
|
||||
self.add(self.vbox)
|
||||
self.get_style_context().add_class("section-frame")
|
||||
|
||||
def set_frame_visible(self, visible):
|
||||
if visible:
|
||||
self.show_frame()
|
||||
else:
|
||||
self.hide_frame()
|
||||
|
||||
def show_frame(self):
|
||||
self.get_style_context().remove_class("frame-hidden")
|
||||
|
||||
def hide_frame(self):
|
||||
self.get_style_context().add_class("frame-hidden")
|
||||
|
||||
|
||||
class GameBox(ConfigBox):
|
||||
config_section = "game"
|
||||
|
@ -678,7 +690,6 @@ class GameBox(ConfigBox):
|
|||
|
||||
|
||||
class RunnerBox(ConfigBox):
|
||||
|
||||
"""Configuration box for runner specific options"""
|
||||
|
||||
config_section = "runner"
|
||||
|
|
|
@ -272,7 +272,7 @@ system_options = [ # pylint: disable=invalid-name
|
|||
"section": "Gamescope",
|
||||
"option": "gamescope",
|
||||
"type": "bool",
|
||||
"label": _("Enable"),
|
||||
"label": _("Enable Gamescope"),
|
||||
"default": False,
|
||||
"condition": bool(system.find_executable("gamescope")) and linux.LINUX_SYSTEM.nvidia_gamescope_support(),
|
||||
"help": _("Use gamescope to draw the game window isolated from your desktop.\n"
|
||||
|
|
|
@ -27,3 +27,22 @@
|
|||
border-radius: 5px;
|
||||
padding: 3px 6px;
|
||||
}
|
||||
|
||||
.section-frame:not(.frame-hidden) {
|
||||
margin-top: 12;
|
||||
margin-bottom: 12;
|
||||
margin-left: 12;
|
||||
margin-right: 12;
|
||||
}
|
||||
|
||||
.section-frame:not(.frame-hidden) > box {
|
||||
margin-bottom: 6;
|
||||
}
|
||||
|
||||
.section-frame.frame-hidden > border {
|
||||
border: 0;
|
||||
}
|
||||
|
||||
.section-frame.frame-hidden > label {
|
||||
font-size: 0;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue