Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[REQUEST] placeholder-font #1690

Closed
2 tasks done
urasssopretty opened this issue Aug 27, 2022 · 3 comments
Closed
2 tasks done

[REQUEST] placeholder-font #1690

urasssopretty opened this issue Aug 27, 2022 · 3 comments

Comments

@urasssopretty
Copy link

Before opening a feature request

  • I checked the next branch to see if the feature has already been implemented
  • I searched existing reports to see if it is already requested.

What is the user problem or growth opportunity you want to see solved?

i would like to see placeholder-font to set thinner or smaller font in placeholder(entry)

How do you know that this problem exists today? Why is this important?

I couldn't find such functionality. Besides, the font is usually installed in the configuration{}, so I think that it was installing only once

Who will benefit from it?

i, me, myself, mb another customer and theme-makers

Rofi version (rofi -v)

1.7.3

Configuration

https://gist.github.com/urasssopretty/3ccf1e8d996ed15182118ddcbd73399d

Additional information

No response

@DaveDavenport
Copy link
Collaborator

diff --git a/include/widgets/textbox.h b/include/widgets/textbox.h
index b8b5ea20..19d48ae5 100644
--- a/include/widgets/textbox.h
+++ b/include/widgets/textbox.h
@@ -65,6 +65,7 @@ typedef struct {
   char *text;
   const char *placeholder;
   int show_placeholder;
+  int prev_show_placeholder;
   PangoLayout *layout;
   int tbft;
   int markup;
diff --git a/source/widgets/textbox.c b/source/widgets/textbox.c
index 00ab1ac1..0c442d6c 100644
--- a/source/widgets/textbox.c
+++ b/source/widgets/textbox.c
@@ -122,9 +122,8 @@ textbox_editable_trigger_action(widget *wid,
   return WIDGET_TRIGGER_ACTION_RESULT_IGNORED;
 }
 
-static void textbox_initialize_font(textbox *tb) {
+static void textbox_initialize_font(textbox *tb, const char *font) {
   tb->tbfc = tbfc_default;
-  const char *font = rofi_theme_get_string(WIDGET(tb), "font", NULL);
   if (font) {
     TBFontConfig *tbfc = g_hash_table_lookup(tbfc_cache, font);
     if (tbfc == NULL) {
@@ -203,9 +202,12 @@ textbox *textbox_create(widget *parent, WidgetType type, const char *name,
   tb->changed = FALSE;
 
   tb->layout = pango_layout_new(p_context);
+
+  tb->prev_show_placeholder = -1;
   textbox_font(tb, tbft);
 
-  textbox_initialize_font(tb);
+  const char *font = rofi_theme_get_string(WIDGET(tb), "font", NULL);
+  textbox_initialize_font(tb, font);
   textbox_tab_stops(tb);
 
   if ((tb->flags & TB_WRAP) == TB_WRAP) {
@@ -460,6 +462,23 @@ static void textbox_draw(widget *wid, cairo_t *draw) {
     __textbox_update_pango_text(tb);
   }
 
+  if (tb->prev_show_placeholder != tb->show_placeholder) {
+    if (tb->show_placeholder) {
+      const char *font =
+          rofi_theme_get_string(WIDGET(tb), "font-placeholder", NULL);
+      if (font) {
+        printf("%s\n", font);
+        textbox_initialize_font(tb, font);
+      }
+    } else {
+      const char *font = rofi_theme_get_string(WIDGET(tb), "font", NULL);
+      if (font) {
+        printf("%s\n", font);
+        textbox_initialize_font(tb, font);
+      }
+    }
+    tb->prev_show_placeholder = tb->show_placeholder;
+  }
   // Skip the side MARGIN on the X axis.
   int x;
   int top = widget_padding_get_top(WIDGET(tb));

could be problematic with resizing.

@DaveDavenport
Copy link
Collaborator

Maybe making the placeholder string support pango markup better, then you can just hint what you want.
https://docs.gtk.org/Pango/pango_markup.html

@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 29, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants