Label with fixed size
Hi all: I need to create a label with a fixed size in pixels, and if the text is too large, elipsize it. Is it possible? I tried nearly all kind of ways and tricks (even capturing the size-allocate signal and adjust there the maximum-character property until the size is fine), but can't get it. Thanks. -- Nos leemos RASTER(Linux user #228804) ras...@rastersoft.com http://www.rastersoft.com ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: Label with fixed size
On Thu, 2014-08-28 at 18:14 +0200, rastersoft wrote: > Hi all: > > I need to create a label with a fixed size in pixels, and if the text is > too large, elipsize it. Is it possible? I tried nearly all kind of ways > and tricks (even capturing the size-allocate signal and adjust there the > maximum-character property until the size is fine), but can't get it. > > Thanks. > When you REALLY need this, you may try the GTK Fixed container. It allows to position widgets at absolute positions, and at the same time, it prevents widgets from expanding itself. Try the Ruby code below -- for me it always displays "Not a..." even when I resize the main window. Of course you may read the documentation of the Fixed container. require 'gtk3' window = Gtk::Window.new window.border_width = 10 window.set_default_size(80, -1) window.signal_connect("destroy") {Gtk.main_quit} f = Gtk::Fixed.new l = Gtk::Label.new('Not a long text') l.set_size_request(50, -1) l.ellipsize = Pango::ELLIPSIZE_END #f.put(l, 0, 0) f.add(l) window.add(f) window.show_all Gtk.main ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: Label with fixed size
Hi! Well, it *nearly* worked: the label is cut as expected, but the fixed itself gets expanded, so I end with a Gtk.Fixed as big as would be the label "as is", with a cut label inside... Is it possible to also avoid the Gtk.Fixed to be resized? El 29/08/14 a las #4, Stefan Salewski escribió: On Thu, 2014-08-28 at 18:14 +0200, rastersoft wrote: Hi all: I need to create a label with a fixed size in pixels, and if the text is too large, elipsize it. Is it possible? I tried nearly all kind of ways and tricks (even capturing the size-allocate signal and adjust there the maximum-character property until the size is fine), but can't get it. Thanks. When you REALLY need this, you may try the GTK Fixed container. It allows to position widgets at absolute positions, and at the same time, it prevents widgets from expanding itself. Try the Ruby code below -- for me it always displays "Not a..." even when I resize the main window. Of course you may read the documentation of the Fixed container. require 'gtk3' window = Gtk::Window.new window.border_width = 10 window.set_default_size(80, -1) window.signal_connect("destroy") {Gtk.main_quit} f = Gtk::Fixed.new l = Gtk::Label.new('Not a long text') l.set_size_request(50, -1) l.ellipsize = Pango::ELLIPSIZE_END #f.put(l, 0, 0) f.add(l) window.add(f) window.show_all Gtk.main -- Nos leemos RASTER(Linux user #228804) ras...@rastersoft.com http://www.rastersoft.com ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: Label with fixed size
Ok, I found how to fix this problem: overriding the "get_preferred_width" method in a label to set it to the desired width. Et voila! Thanks anyway! El 29/08/14 a las #4, rastersoft escribió: Hi! Well, it *nearly* worked: the label is cut as expected, but the fixed itself gets expanded, so I end with a Gtk.Fixed as big as would be the label "as is", with a cut label inside... Is it possible to also avoid the Gtk.Fixed to be resized? El 29/08/14 a las #4, Stefan Salewski escribió: On Thu, 2014-08-28 at 18:14 +0200, rastersoft wrote: Hi all: I need to create a label with a fixed size in pixels, and if the text is too large, elipsize it. Is it possible? I tried nearly all kind of ways and tricks (even capturing the size-allocate signal and adjust there the maximum-character property until the size is fine), but can't get it. Thanks. When you REALLY need this, you may try the GTK Fixed container. It allows to position widgets at absolute positions, and at the same time, it prevents widgets from expanding itself. Try the Ruby code below -- for me it always displays "Not a..." even when I resize the main window. Of course you may read the documentation of the Fixed container. require 'gtk3' window = Gtk::Window.new window.border_width = 10 window.set_default_size(80, -1) window.signal_connect("destroy") {Gtk.main_quit} f = Gtk::Fixed.new l = Gtk::Label.new('Not a long text') l.set_size_request(50, -1) l.ellipsize = Pango::ELLIPSIZE_END #f.put(l, 0, 0) f.add(l) window.add(f) window.show_all Gtk.main -- Nos leemos RASTER(Linux user #228804) ras...@rastersoft.com http://www.rastersoft.com ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: Label with fixed size
Well, thats a philosophie of Gtk; it's kind of a space optimization, since fixed layouts often suffer from some problems, especially on smaller devices, etc. . I guess a real Gtk philosopher could explain it much better and much more advertising. However, to solve your problem, we have to know, what your problem is about having the Fixed widget taking as much space as possible. The Gtk Philosophie is not always beautiful, but there are many different Gtk containers, thought for many possible designs. Sunny days, Benjamin On 18:06 Fri 29 Aug , rastersoft wrote: > Hi! > > Well, it *nearly* worked: the label is cut as expected, but the fixed itself > gets expanded, so I end with a Gtk.Fixed as big as would be the label "as > is", with a cut label inside... > > Is it possible to also avoid the Gtk.Fixed to be resized? > > El 29/08/14 a las #4, Stefan Salewski escribió: > >On Thu, 2014-08-28 at 18:14 +0200, rastersoft wrote: > >>Hi all: > >> > >>I need to create a label with a fixed size in pixels, and if the text is > >>too large, elipsize it. Is it possible? I tried nearly all kind of ways > >>and tricks (even capturing the size-allocate signal and adjust there the > >>maximum-character property until the size is fine), but can't get it. > >> > >>Thanks. > >> > >When you REALLY need this, you may try the GTK Fixed container. > >It allows to position widgets at absolute positions, and at the same > >time, it prevents widgets from expanding itself. > > > >Try the Ruby code below -- for me it always displays "Not a..." even > >when I resize the main window. Of course you may read the documentation > >of the Fixed container. > > > >require 'gtk3' > > > >window = Gtk::Window.new > >window.border_width = 10 > >window.set_default_size(80, -1) > > > >window.signal_connect("destroy") {Gtk.main_quit} > > > >f = Gtk::Fixed.new > >l = Gtk::Label.new('Not a long text') > >l.set_size_request(50, -1) > >l.ellipsize = Pango::ELLIPSIZE_END > > > >#f.put(l, 0, 0) > >f.add(l) > > > >window.add(f) > >window.show_all > > > >Gtk.main > > > > > > > > -- > Nos leemos >RASTER(Linux user #228804) > ras...@rastersoft.com http://www.rastersoft.com > > ___ > gtk-app-devel-list mailing list > gtk-app-devel-list@gnome.org > https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: Label with fixed size
Ah wait, let me have a guess: You are drawing something and You want to have the ellipsized text inside the drawing? In this case: Why don't You just put the drawing area inside the Gtk::Fixed, maximizing it to the dimension of the Fixed and then putting the Label just above. On 18:06 Fri 29 Aug , rastersoft wrote: > Hi! > > Well, it *nearly* worked: the label is cut as expected, but the fixed itself > gets expanded, so I end with a Gtk.Fixed as big as would be the label "as > is", with a cut label inside... > > Is it possible to also avoid the Gtk.Fixed to be resized? > > El 29/08/14 a las #4, Stefan Salewski escribió: > >On Thu, 2014-08-28 at 18:14 +0200, rastersoft wrote: > >>Hi all: > >> > >>I need to create a label with a fixed size in pixels, and if the text is > >>too large, elipsize it. Is it possible? I tried nearly all kind of ways > >>and tricks (even capturing the size-allocate signal and adjust there the > >>maximum-character property until the size is fine), but can't get it. > >> > >>Thanks. > >> > >When you REALLY need this, you may try the GTK Fixed container. > >It allows to position widgets at absolute positions, and at the same > >time, it prevents widgets from expanding itself. > > > >Try the Ruby code below -- for me it always displays "Not a..." even > >when I resize the main window. Of course you may read the documentation > >of the Fixed container. > > > >require 'gtk3' > > > >window = Gtk::Window.new > >window.border_width = 10 > >window.set_default_size(80, -1) > > > >window.signal_connect("destroy") {Gtk.main_quit} > > > >f = Gtk::Fixed.new > >l = Gtk::Label.new('Not a long text') > >l.set_size_request(50, -1) > >l.ellipsize = Pango::ELLIPSIZE_END > > > >#f.put(l, 0, 0) > >f.add(l) > > > >window.add(f) > >window.show_all > > > >Gtk.main > > > > > > > > -- > Nos leemos >RASTER(Linux user #228804) > ras...@rastersoft.com http://www.rastersoft.com > > ___ > gtk-app-devel-list mailing list > gtk-app-devel-list@gnome.org > https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: Label with fixed size
I was trying to fix the layout code in Slingshot, the Elementary OS's app launcher. The problem is how to create a button with a text and an icon inside, but with a fixed width, and putting several of those buttons inside a Gtk.Grid, and finally, several grids inside a Gtk.Stack to allow several pages with nice swap animations. Anyway, as I said, I found how to do it, by overriding the "get_preferred_width" method in the Label widget to make it return always the desired width, and putting it inside a Gtk.Fixed widget. El 29/08/14 a las #4, Benjamin Schnitzler escribió: Well, thats a philosophie of Gtk; it's kind of a space optimization, since fixed layouts often suffer from some problems, especially on smaller devices, etc. . I guess a real Gtk philosopher could explain it much better and much more advertising. However, to solve your problem, we have to know, what your problem is about having the Fixed widget taking as much space as possible. The Gtk Philosophie is not always beautiful, but there are many different Gtk containers, thought for many possible designs. Sunny days, Benjamin On 18:06 Fri 29 Aug , rastersoft wrote: Hi! Well, it *nearly* worked: the label is cut as expected, but the fixed itself gets expanded, so I end with a Gtk.Fixed as big as would be the label "as is", with a cut label inside... Is it possible to also avoid the Gtk.Fixed to be resized? El 29/08/14 a las #4, Stefan Salewski escribió: On Thu, 2014-08-28 at 18:14 +0200, rastersoft wrote: Hi all: I need to create a label with a fixed size in pixels, and if the text is too large, elipsize it. Is it possible? I tried nearly all kind of ways and tricks (even capturing the size-allocate signal and adjust there the maximum-character property until the size is fine), but can't get it. Thanks. When you REALLY need this, you may try the GTK Fixed container. It allows to position widgets at absolute positions, and at the same time, it prevents widgets from expanding itself. Try the Ruby code below -- for me it always displays "Not a..." even when I resize the main window. Of course you may read the documentation of the Fixed container. require 'gtk3' window = Gtk::Window.new window.border_width = 10 window.set_default_size(80, -1) window.signal_connect("destroy") {Gtk.main_quit} f = Gtk::Fixed.new l = Gtk::Label.new('Not a long text') l.set_size_request(50, -1) l.ellipsize = Pango::ELLIPSIZE_END #f.put(l, 0, 0) f.add(l) window.add(f) window.show_all Gtk.main -- Nos leemos RASTER(Linux user #228804) ras...@rastersoft.com http://www.rastersoft.com ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list -- Nos leemos RASTER(Linux user #228804) ras...@rastersoft.com http://www.rastersoft.com ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list