The source project of this merge request has been removed.
gtk3, gtk4: specify min-width only for discrete level bar blocks
For the block inside a LevelBar
, apply the min-width
property only when it is in discrete mode, so it is more visually accurate when the value results in a bar shorter than min-width
.
Test program, Gtk4
import gi
gi.require_version("Gtk", "4.0")
from gi.repository import Gtk
class MainApplication(Gtk.Application):
def __init__(self):
super().__init__(application_id='org.gtk.Example')
self.connect('activate', self.on_activate)
self.interval = 2
def init_window(self):
self.win = Gtk.ApplicationWindow(application=self)
self.grid = Gtk.Grid()
self.win.set_default_size(300, 0)
self.win.set_child(self.grid)
self.bar = Gtk.LevelBar()
self.bar.props.value = 2
self.bar.props.max_value = 40
self.btn = Gtk.Button()
self.btn.props.label = f"increase by {self.interval}"
self.label = Gtk.Label()
self.update_label()
self.btn.connect('clicked', lambda _: self.incr(self.interval))
self.bar.connect('notify', lambda _, __: self.update_label())
self.grid.attach(self.bar, 0, 0, 2, 1)
self.grid.attach(self.btn, 0, 1, 1, 1)
self.grid.attach(self.label, 1, 1, 1, 1)
def incr(self, value):
self.bar.props.value += value
def update_label(self):
self.label.props.label = f"current value: {self.bar.props.value:02.0f}"
def on_activate(self, _):
self.init_window()
self.win.present()
app = MainApplication()
app.run(None)
Test program, Gtk3
import gi
gi.require_version("Gtk", "3.0")
from gi.repository import Gtk
class MainApplication(Gtk.Application):
def __init__(self):
super().__init__(application_id='org.gtk.Example')
self.connect('activate', self.on_activate)
self.interval = 2
def init_window(self):
self.win = Gtk.ApplicationWindow(application=self)
self.grid = Gtk.Grid()
self.win.set_default_size(300, 0)
self.win.add(self.grid)
self.bar = Gtk.LevelBar()
self.bar.props.value = 2
self.bar.props.max_value = 40
self.btn = Gtk.Button()
self.btn.props.label = f"increase by {self.interval}"
self.label = Gtk.Label()
self.update_label()
self.btn.connect('clicked', lambda _: self.incr(self.interval))
self.bar.connect('notify', lambda _, __: self.update_label())
self.grid.attach(self.bar, 0, 0, 2, 1)
self.grid.attach(self.btn, 0, 1, 1, 1)
self.grid.attach(self.label, 1, 1, 1, 1)
def incr(self, value):
self.bar.props.value += value
def update_label(self):
self.label.props.label = f"current value: {self.bar.props.value:02.0f}"
def on_activate(self, _):
self.init_window()
self.win.show_all()
app = MainApplication()
app.run(None)
Before | After |
---|---|
Edited by hexchain