Grid of buttons over image with inset?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
3
down vote

favorite
1












I'm in-setting a grid of buttons over an image, and I think it's probably a very simple thing that I'm missing. In the example below Scaled doesn't work to stretch the Button's properly:



Graphics[Inset[ExampleData["TestImage", "Lena"], Scaled[0, 1], 
Scaled[0, 1], Scaled[1]],
Inset[Button["test", Print[1], Background -> RGBColor[1, 0, 0, 0.3],
ImageSize -> Automatic], Scaled[0, 1], Scaled[0, 1],
Scaled[1, 1/2]],
Inset[Button["test", Print[1], Background -> RGBColor[0, 1, 0.3],
ImageSize -> Automatic], Scaled[0, 1/2], Scaled[0, 1/2],
Scaled[1, 1/2]]
, PlotRange -> 0, 1, 0, 1]


enter image description here



It should look like this:



enter image description here



The above I made with this:



Overlay[ExampleData["TestImage", "Lena"], 
TextGrid[Button["test", Print[1],
Background -> RGBColor[1, 0, 0, 0.3],
ImageSize -> 512, 256], Button["test", Print[2],
Background -> RGBColor[0, 1, 0, 0.3],
ImageSize -> 512, 256], Spacings -> 0, 0]]


Which would be a solution except that:



  • I don't want to give explicit ImageSizes


  • Overlay kills the buttons









share|improve this question

























    up vote
    3
    down vote

    favorite
    1












    I'm in-setting a grid of buttons over an image, and I think it's probably a very simple thing that I'm missing. In the example below Scaled doesn't work to stretch the Button's properly:



    Graphics[Inset[ExampleData["TestImage", "Lena"], Scaled[0, 1], 
    Scaled[0, 1], Scaled[1]],
    Inset[Button["test", Print[1], Background -> RGBColor[1, 0, 0, 0.3],
    ImageSize -> Automatic], Scaled[0, 1], Scaled[0, 1],
    Scaled[1, 1/2]],
    Inset[Button["test", Print[1], Background -> RGBColor[0, 1, 0.3],
    ImageSize -> Automatic], Scaled[0, 1/2], Scaled[0, 1/2],
    Scaled[1, 1/2]]
    , PlotRange -> 0, 1, 0, 1]


    enter image description here



    It should look like this:



    enter image description here



    The above I made with this:



    Overlay[ExampleData["TestImage", "Lena"], 
    TextGrid[Button["test", Print[1],
    Background -> RGBColor[1, 0, 0, 0.3],
    ImageSize -> 512, 256], Button["test", Print[2],
    Background -> RGBColor[0, 1, 0, 0.3],
    ImageSize -> 512, 256], Spacings -> 0, 0]]


    Which would be a solution except that:



    • I don't want to give explicit ImageSizes


    • Overlay kills the buttons









    share|improve this question























      up vote
      3
      down vote

      favorite
      1









      up vote
      3
      down vote

      favorite
      1






      1





      I'm in-setting a grid of buttons over an image, and I think it's probably a very simple thing that I'm missing. In the example below Scaled doesn't work to stretch the Button's properly:



      Graphics[Inset[ExampleData["TestImage", "Lena"], Scaled[0, 1], 
      Scaled[0, 1], Scaled[1]],
      Inset[Button["test", Print[1], Background -> RGBColor[1, 0, 0, 0.3],
      ImageSize -> Automatic], Scaled[0, 1], Scaled[0, 1],
      Scaled[1, 1/2]],
      Inset[Button["test", Print[1], Background -> RGBColor[0, 1, 0.3],
      ImageSize -> Automatic], Scaled[0, 1/2], Scaled[0, 1/2],
      Scaled[1, 1/2]]
      , PlotRange -> 0, 1, 0, 1]


      enter image description here



      It should look like this:



      enter image description here



      The above I made with this:



      Overlay[ExampleData["TestImage", "Lena"], 
      TextGrid[Button["test", Print[1],
      Background -> RGBColor[1, 0, 0, 0.3],
      ImageSize -> 512, 256], Button["test", Print[2],
      Background -> RGBColor[0, 1, 0, 0.3],
      ImageSize -> 512, 256], Spacings -> 0, 0]]


      Which would be a solution except that:



      • I don't want to give explicit ImageSizes


      • Overlay kills the buttons









      share|improve this question













      I'm in-setting a grid of buttons over an image, and I think it's probably a very simple thing that I'm missing. In the example below Scaled doesn't work to stretch the Button's properly:



      Graphics[Inset[ExampleData["TestImage", "Lena"], Scaled[0, 1], 
      Scaled[0, 1], Scaled[1]],
      Inset[Button["test", Print[1], Background -> RGBColor[1, 0, 0, 0.3],
      ImageSize -> Automatic], Scaled[0, 1], Scaled[0, 1],
      Scaled[1, 1/2]],
      Inset[Button["test", Print[1], Background -> RGBColor[0, 1, 0.3],
      ImageSize -> Automatic], Scaled[0, 1/2], Scaled[0, 1/2],
      Scaled[1, 1/2]]
      , PlotRange -> 0, 1, 0, 1]


      enter image description here



      It should look like this:



      enter image description here



      The above I made with this:



      Overlay[ExampleData["TestImage", "Lena"], 
      TextGrid[Button["test", Print[1],
      Background -> RGBColor[1, 0, 0, 0.3],
      ImageSize -> 512, 256], Button["test", Print[2],
      Background -> RGBColor[0, 1, 0, 0.3],
      ImageSize -> 512, 256], Spacings -> 0, 0]]


      Which would be a solution except that:



      • I don't want to give explicit ImageSizes


      • Overlay kills the buttons






      button






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked 2 hours ago









      M.R.

      15.3k552180




      15.3k552180




















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          3
          down vote



          accepted










          You can use the second and third arguments of Overlay:



          image = ExampleData["TestImage", "Lena"]; 
          Overlay[image,
          TextGrid[Button["test", Print[1], Background -> RGBColor[1, 0, 0, 0.3],
          ImageSize -> ImageDimensions[image]/1, 2],
          Button["test", Print[2], Background -> RGBColor[0, 1, 0, 0.3],
          ImageSize -> ImageDimensions[image]/1, 2],
          Spacings -> 0, 0], All, 2]


          Alternatively, use ImageSize -> Scaled[1], Scaled[1/2] with Button and use Scaled[1] as the size argument in Inset:



          Graphics[Inset[ExampleData["TestImage", "Lena"], Scaled[0, 1], 
          Scaled[0, 1], Scaled[1]],
          Inset[Button["test", Print[1], Background -> RGBColor[1, 0, 0, 0.3],
          ImageSize -> Scaled[1], Scaled[1/2]],
          Scaled[0, 1], Scaled[0, 1], Scaled[1]],
          Inset[Button["test", Print[2], Background -> RGBColor[0, 1, 0, 0.3],
          ImageSize -> Scaled[1], Scaled[1/2]],
          Scaled[0, 1/2], Scaled[0, 1], Scaled[1]],
          PlotRange -> 0, 1, 0, 1]





          share|improve this answer






















            Your Answer





            StackExchange.ifUsing("editor", function ()
            return StackExchange.using("mathjaxEditing", function ()
            StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix)
            StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["$", "$"], ["\\(","\\)"]]);
            );
            );
            , "mathjax-editing");

            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "387"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            convertImagesToLinks: false,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: null,
            bindNavPrevention: true,
            postfix: "",
            imageUploader:
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            ,
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );













             

            draft saved


            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f185404%2fgrid-of-buttons-over-image-with-inset%23new-answer', 'question_page');

            );

            Post as a guest






























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            3
            down vote



            accepted










            You can use the second and third arguments of Overlay:



            image = ExampleData["TestImage", "Lena"]; 
            Overlay[image,
            TextGrid[Button["test", Print[1], Background -> RGBColor[1, 0, 0, 0.3],
            ImageSize -> ImageDimensions[image]/1, 2],
            Button["test", Print[2], Background -> RGBColor[0, 1, 0, 0.3],
            ImageSize -> ImageDimensions[image]/1, 2],
            Spacings -> 0, 0], All, 2]


            Alternatively, use ImageSize -> Scaled[1], Scaled[1/2] with Button and use Scaled[1] as the size argument in Inset:



            Graphics[Inset[ExampleData["TestImage", "Lena"], Scaled[0, 1], 
            Scaled[0, 1], Scaled[1]],
            Inset[Button["test", Print[1], Background -> RGBColor[1, 0, 0, 0.3],
            ImageSize -> Scaled[1], Scaled[1/2]],
            Scaled[0, 1], Scaled[0, 1], Scaled[1]],
            Inset[Button["test", Print[2], Background -> RGBColor[0, 1, 0, 0.3],
            ImageSize -> Scaled[1], Scaled[1/2]],
            Scaled[0, 1/2], Scaled[0, 1], Scaled[1]],
            PlotRange -> 0, 1, 0, 1]





            share|improve this answer


























              up vote
              3
              down vote



              accepted










              You can use the second and third arguments of Overlay:



              image = ExampleData["TestImage", "Lena"]; 
              Overlay[image,
              TextGrid[Button["test", Print[1], Background -> RGBColor[1, 0, 0, 0.3],
              ImageSize -> ImageDimensions[image]/1, 2],
              Button["test", Print[2], Background -> RGBColor[0, 1, 0, 0.3],
              ImageSize -> ImageDimensions[image]/1, 2],
              Spacings -> 0, 0], All, 2]


              Alternatively, use ImageSize -> Scaled[1], Scaled[1/2] with Button and use Scaled[1] as the size argument in Inset:



              Graphics[Inset[ExampleData["TestImage", "Lena"], Scaled[0, 1], 
              Scaled[0, 1], Scaled[1]],
              Inset[Button["test", Print[1], Background -> RGBColor[1, 0, 0, 0.3],
              ImageSize -> Scaled[1], Scaled[1/2]],
              Scaled[0, 1], Scaled[0, 1], Scaled[1]],
              Inset[Button["test", Print[2], Background -> RGBColor[0, 1, 0, 0.3],
              ImageSize -> Scaled[1], Scaled[1/2]],
              Scaled[0, 1/2], Scaled[0, 1], Scaled[1]],
              PlotRange -> 0, 1, 0, 1]





              share|improve this answer
























                up vote
                3
                down vote



                accepted







                up vote
                3
                down vote



                accepted






                You can use the second and third arguments of Overlay:



                image = ExampleData["TestImage", "Lena"]; 
                Overlay[image,
                TextGrid[Button["test", Print[1], Background -> RGBColor[1, 0, 0, 0.3],
                ImageSize -> ImageDimensions[image]/1, 2],
                Button["test", Print[2], Background -> RGBColor[0, 1, 0, 0.3],
                ImageSize -> ImageDimensions[image]/1, 2],
                Spacings -> 0, 0], All, 2]


                Alternatively, use ImageSize -> Scaled[1], Scaled[1/2] with Button and use Scaled[1] as the size argument in Inset:



                Graphics[Inset[ExampleData["TestImage", "Lena"], Scaled[0, 1], 
                Scaled[0, 1], Scaled[1]],
                Inset[Button["test", Print[1], Background -> RGBColor[1, 0, 0, 0.3],
                ImageSize -> Scaled[1], Scaled[1/2]],
                Scaled[0, 1], Scaled[0, 1], Scaled[1]],
                Inset[Button["test", Print[2], Background -> RGBColor[0, 1, 0, 0.3],
                ImageSize -> Scaled[1], Scaled[1/2]],
                Scaled[0, 1/2], Scaled[0, 1], Scaled[1]],
                PlotRange -> 0, 1, 0, 1]





                share|improve this answer














                You can use the second and third arguments of Overlay:



                image = ExampleData["TestImage", "Lena"]; 
                Overlay[image,
                TextGrid[Button["test", Print[1], Background -> RGBColor[1, 0, 0, 0.3],
                ImageSize -> ImageDimensions[image]/1, 2],
                Button["test", Print[2], Background -> RGBColor[0, 1, 0, 0.3],
                ImageSize -> ImageDimensions[image]/1, 2],
                Spacings -> 0, 0], All, 2]


                Alternatively, use ImageSize -> Scaled[1], Scaled[1/2] with Button and use Scaled[1] as the size argument in Inset:



                Graphics[Inset[ExampleData["TestImage", "Lena"], Scaled[0, 1], 
                Scaled[0, 1], Scaled[1]],
                Inset[Button["test", Print[1], Background -> RGBColor[1, 0, 0, 0.3],
                ImageSize -> Scaled[1], Scaled[1/2]],
                Scaled[0, 1], Scaled[0, 1], Scaled[1]],
                Inset[Button["test", Print[2], Background -> RGBColor[0, 1, 0, 0.3],
                ImageSize -> Scaled[1], Scaled[1/2]],
                Scaled[0, 1/2], Scaled[0, 1], Scaled[1]],
                PlotRange -> 0, 1, 0, 1]






                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited 2 hours ago

























                answered 2 hours ago









                kglr

                169k8193396




                169k8193396



























                     

                    draft saved


                    draft discarded















































                     


                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f185404%2fgrid-of-buttons-over-image-with-inset%23new-answer', 'question_page');

                    );

                    Post as a guest













































































                    Comments

                    Popular posts from this blog

                    What does second last employer means? [closed]

                    List of Gilmore Girls characters

                    Confectionery