From ead00fb80b584834e8d7c8a0743918714aae8d96 Mon Sep 17 00:00:00 2001 From: Robert Tari Date: Sun, 27 Apr 2025 02:23:39 +0200 Subject: src/prompt-box.vala: Add manual text wrapping --- src/prompt-box.vala | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/src/prompt-box.vala b/src/prompt-box.vala index b102887..fff7a46 100644 --- a/src/prompt-box.vala +++ b/src/prompt-box.vala @@ -568,7 +568,7 @@ public class PromptBox : FadableBox public void add_message (string text, bool is_error) { - var label = new FadingLabel (text); + var label = new FadingLabel (""); var style_ctx = label.get_style_context(); @@ -601,6 +601,40 @@ public class PromptBox : FadableBox label.xalign = 0.0f; label.set_data ("prompt-box-is-error", is_error); + // Wrap the text if needed + ArcticaGreeter pGreeter = new ArcticaGreeter (); + Pango.Context pContext = label.get_pango_context (); + Pango.Layout pLayout = new Pango.Layout (pContext); + Pango.FontDescription pDescription = null; + Gtk.StateFlags nFlags = style_ctx.get_state (); + style_ctx.get (nFlags, "font", out pDescription, null); + pLayout.set_font_description (pDescription); + StringBuilder pBuilder = new StringBuilder (); + string[] lWords = text.split (" "); + string sLine = ""; + + foreach (string sWord in lWords) + { + string sTest = sLine == "" ? sWord : sLine + " " + sWord; + pLayout.set_text (sTest, -1); + int nWidth = 0; + pLayout.get_size (out nWidth, null); + + if (nWidth / Pango.SCALE > (pGreeter.grid_size * GreeterList.BOX_WIDTH - (int)(GreeterList.BORDER * pGreeter.scaling_factor_widgets * 8)) && sLine != "") + { + pBuilder.append (sLine + "\n"); + sLine = sWord; + } + else + { + sLine = sTest; + } + } + + pBuilder.append (sLine); + label.set_text (pBuilder.str); + //~Wrap the text if needed + attach_item (label); if (is_error) -- cgit v1.2.3 From 0e7e5682b9453e3fc25bb53ca3810230bc946c85 Mon Sep 17 00:00:00 2001 From: Robert Tari Date: Sun, 27 Apr 2025 02:26:33 +0200 Subject: Rewrite Gtk.Alignment --- src/main-window.vala | 40 ++++++++++++++++++---------------------- src/prompt-box.vala | 25 ++++++++++++------------- 2 files changed, 30 insertions(+), 35 deletions(-) diff --git a/src/main-window.vala b/src/main-window.vala index e1e39d2..621b115 100644 --- a/src/main-window.vala +++ b/src/main-window.vala @@ -129,40 +129,30 @@ public class MainWindow : Gtk.Window login_box.add (content_box); var content_align = AGSettings.get_string(AGSettings.KEY_CONTENT_ALIGN); - var x_align = 0.5f; + var x_align = Gtk.Align.CENTER; if (content_align == "left") { - x_align = 0.0f; + x_align = Gtk.Align.START; } else if (content_align == "right") { - x_align = 1.0f; + x_align = Gtk.Align.END; } - var align = new Gtk.Alignment (x_align, 0.0f, 0.0f, 1.0f); + hbox = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 0); + hbox.expand = true; + hbox.show (); + hbox.halign = x_align; + hbox.valign = Gtk.Align.CENTER; if (content_align == "center") { // offset for back button - align.margin_end = greeter.grid_size; + hbox.margin_end = greeter.grid_size; } - align.show (); - content_box.add (align); - - hbox = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 0); - hbox.expand = true; - hbox.show (); - align.add (hbox); - - align = new Gtk.Alignment (0.5f, 0.5f, 0.0f, 0.0f); - align.resize_mode = Gtk.ResizeMode.QUEUE; - align.set_size_request (greeter.grid_size, -1); - align.margin_bottom = greeter.menubar_height; /* offset for menubar at top */ - align.show (); - hbox.add (align); - + content_box.add (hbox); back_button = new FlatButton (); back_button.get_accessible ().set_name (_("Back")); Gtk.button_set_focus_on_click (back_button, false); @@ -191,8 +181,14 @@ public class MainWindow : Gtk.Window back_button.add (image); back_button.clicked.connect (pop_list); - - align.add (back_button); + back_button.halign = Gtk.Align.CENTER; + back_button.valign = Gtk.Align.CENTER; + back_button.hexpand = false; + back_button.vexpand = false; + back_button.resize_mode = Gtk.ResizeMode.QUEUE; + back_button.set_size_request (greeter.grid_size, -1); + back_button.margin_bottom = greeter.menubar_height; + hbox.add (back_button); stack = new ListStack (); stack.show (); diff --git a/src/prompt-box.vala b/src/prompt-box.vala index fff7a46..4c8087e 100644 --- a/src/prompt-box.vala +++ b/src/prompt-box.vala @@ -247,13 +247,12 @@ public class PromptBox : FadableBox message_image = new CachedImage (null); message_image.set_from_icon_name("mail-unread", Gtk.IconSize.BUTTON); - - var align = new Gtk.Alignment (0.5f, 0.5f, 0.0f, 0.0f); - align.valign = Gtk.Align.START; - align.set_size_request (-1, greeter.grid_size); - align.add (message_image); - align.show (); - name_grid.attach (align, COL_NAME_MESSAGE, ROW_NAME, 1, 1); + message_image.halign = Gtk.Align.CENTER; + message_image.valign = Gtk.Align.START; + message_image.hexpand = false; + message_image.vexpand = false; + message_image.set_size_request (-1, greeter.grid_size); + name_grid.attach (message_image, COL_NAME_MESSAGE, ROW_NAME, 1, 1); option_button = new FlatButton (); var option_button_ctx = option_button.get_style_context (); @@ -343,12 +342,12 @@ public class PromptBox : FadableBox small_message_image = new CachedImage (null); small_message_image.set_from_icon_name("mail-unread", Gtk.IconSize.BUTTON); - - var align = new Gtk.Alignment (0.5f, 0.5f, 0.0f, 0.0f); - align.set_size_request (-1, greeter.grid_size); - align.add (small_message_image); - align.show (); - small_name_grid.attach (align, 2, 0, 1, 1); + small_message_image.halign = Gtk.Align.CENTER; + small_message_image.valign = Gtk.Align.CENTER; + small_message_image.hexpand = false; + small_message_image.vexpand = false; + small_message_image.set_size_request (-1, greeter.grid_size); + small_name_grid.attach (small_message_image, 2, 0, 1, 1); small_name_grid.show (); return small_name_grid; -- cgit v1.2.3