0

Having a text part, which is basically center aligned.

text { "elm.text";
            scale: 1; 
            clip_to: "elm.clipper";
            desc { "default";
               visible: 1;
               rel1.to: "elm.clipper";
               rel2.to: "elm.clipper";
               align: 0 0.5; //NOT WORKING
               text {
                  text: "elm.text very very very long";
                  size: 24;
                  align: 0.5 0.5;
                  ellipsis: -1;
               }       
            }

Center alignment works, but I want this text to be left-aligned if it's longer than it's container.

I don't want to use min, as it ruins my layout.

I also don't want to use any scripting, as it ruins user experience.

Do I have an option to solve this very fast?

Daniel
  • 2,318
  • 2
  • 22
  • 53

2 Answers2

0

Is there any reason not to use ellipsis?

I think, ellipsis: 0; is the simplest way.

If not, you need to create another state and do STATE_SET according to the situation.

     text { "elm.text";
        scale;
        clip_to: "elm.clipper";
        desc { "default";
           vis;
           rel.to: "elm.clipper";
           align: 0.0 0.5;
           text {
              text: "elm.text text"; // for short text
              size: 24;
              align: 0.5 0.5;
              ellipsis: 0;
           }
        }
        desc { "left_align"; // for long text
           inherit: "default" 0.0;
           text.align: 0.0 0.5;
        }
     }
wonrst
  • 31
  • 1
  • I need long text to be aligned *left* without other state. The problem with `ellipsis: 0` is that it will not align my long text left (if `align: 0.5 0.5` is still active). If I create another state, what would be the fastest way to decide weather the text should be in default state or left state? - Taking into account that text will be changed from C code. – Daniel Jun 08 '21 at 15:40
  • long text not left aligned on `ellipsis: 0;` ? In this case, long text should be left-aligned. And it works fine in my environment. If you share your full code(edc), it may help to find other problems. – wonrst Jun 09 '21 at 03:14
  • If you keep `text.align: 0.5 0.5`, no matter if you also apply `text.ellipsis: 0`, text will be centered. If you **don't keep** `text.align: 0.5 0.5`, and create a new STATE, yes it works, but WHO will decide about which state should be applied to the text? – Daniel Jun 10 '21 at 07:02
0

I think you should use a script.

But you don't want it. Right?

I don't know any other way, but I'll share the method below.

First, set "min:1 1;" to text (the text part is increased by the length of the text.)

in script :
      public text_len = 0;
      public clipper_len = 0;

      ...
      public set_align() {
         new x, y, w, h;
         get_geometry(PART:"elm.text", x, y, w, h);
         set_int(text_len, w);
         get_geometry(PART:"elm.clipper", x, y, w, h);
         set_int(clipper_len, w);

         if (get_int(text_len) > get_int(clipper_len)) {
            run_program(PROGRAM:"set_left");
         }
         else {
            run_program(PROGRAM:"set_center");
         }
      }

The same logic can be implemented in c code, but it can be more complex.

Dharman
  • 30,962
  • 25
  • 85
  • 135
wonrst
  • 31
  • 1
  • Thanks. Who will call `set_align`? I would need to call this whenever `elm.text` is changed by `elm_object_part_text_set`. – Daniel Jun 15 '21 at 08:52